PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.0
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / blocks / chart / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.0, at includes/blocks/chart/block.php

90 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Chart;
3
4 use ABlocks\Controls\Range;
5
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 use ABlocks\Classes\BlockBaseAbstract;
12 use ABlocks\Classes\CssGenerator;
13 use ABlocks\Classes\CssGeneratorV2;
14 use ABlocks\Controls\Alignment;
15
16 class Block extends BlockBaseAbstract {
17 protected $block_name = 'chart';
18 protected $script_depends = [ 'ablocks-chart.js-script' ];
19 public function build_css_v1( $attributes ) {
20 $css_generator = new CssGenerator( $attributes, $this->block_name );
21 $css_generator->add_class_styles(
22 '{{WRAPPER}}',
23 $this->get_wrapper_css( $attributes ),
24 $this->get_wrapper_css( $attributes, 'Tablet' ),
25 $this->get_wrapper_css( $attributes, 'Mobile' )
26 );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}} .ablocks-chart-canvas',
30 $this->get_chart_css( $attributes ),
31 $this->get_chart_css( $attributes, 'Tablet' ),
32 $this->get_chart_css( $attributes, 'Mobile' )
33 );
34
35 return $css_generator->generate_css();
36 }
37 public function build_css_v2( $attributes ) {
38 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
39 $css_generator->add_class_styles(
40 '{{WRAPPER}}',
41 $this->get_wrapper_css( $attributes ),
42 $this->get_wrapper_css( $attributes, 'Tablet' ),
43 $this->get_wrapper_css( $attributes, 'Mobile' )
44 );
45
46 $css_generator->add_class_styles(
47 '{{WRAPPER}} .ablocks-chart-canvas',
48 $this->get_chart_css( $attributes ),
49 $this->get_chart_css( $attributes, 'Tablet' ),
50 $this->get_chart_css( $attributes, 'Mobile' )
51 );
52
53 return $css_generator->generate_css();
54 }
55 public function build_css( $attributes ) {
56 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
57 return $this->build_css_v2( $attributes );
58 }
59 return $this->build_css_v1( $attributes );
60 }
61
62 public function get_wrapper_css( $attributes, $device = '' ) {
63 return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : [];
64 }
65
66 public function get_chart_css( $attributes, $device = '' ) {
67 $css = [];
68 $widthCSS = Range::get_css([
69 'attributeValue' => $attributes['chartWidth'],
70 'attribute_object_key' => 'value',
71 'isResponsive' => true,
72 'defaultValue' => 95,
73 'hasUnit' => true,
74 'unitDefaultValue' => '%',
75 'property' => 'width',
76 'device' => $device,
77 ]);
78 if ( ! empty( $widthCSS['width'] ) ) {
79 $widthCSS['width'] = $widthCSS['width'] . ' !important';
80 }
81 $heightCSS = [];
82 $heightCSS['height'] = 'auto' . ' !important';
83 return array_merge(
84 $widthCSS,
85 $heightCSS
86 );
87 }
88
89 }
90