PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 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 All 81 releases
← All changes | includes/blocks/chart/block.php +93 -0 2.7.6 → 2.14.0 View file →
@@ -1,0 +1,93 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
27 + );
28 +
29 + $css_generator->add_class_styles(
30 + '{{WRAPPER}} .ablocks-chart-canvas',
31 + $this->get_chart_css( $attributes ),
32 + $this->get_chart_css( $attributes, 'Tablet' ),
33 + $this->get_chart_css( $attributes, 'Mobile' ),
34 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_chart_css( $attributes, $device ); } )
35 + );
36 +
37 + return $css_generator->generate_css();
38 + }
39 + public function build_css_v2( $attributes ) {
40 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
41 + $css_generator->add_class_styles(
42 + '{{WRAPPER}}',
43 + $this->get_wrapper_css( $attributes ),
44 + $this->get_wrapper_css( $attributes, 'Tablet' ),
45 + $this->get_wrapper_css( $attributes, 'Mobile' ),
46 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
47 + );
48 +
49 + $css_generator->add_class_styles(
50 + '{{WRAPPER}} .ablocks-chart-canvas',
51 + $this->get_chart_css( $attributes ),
52 + $this->get_chart_css( $attributes, 'Tablet' ),
53 + $this->get_chart_css( $attributes, 'Mobile' ),
54 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_chart_css( $attributes, $device ); } )
55 + );
56 +
57 + return $css_generator->generate_css();
58 + }
59 + public function build_css( $attributes ) {
60 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
61 + return $this->build_css_v2( $attributes );
62 + }
63 + return $this->build_css_v1( $attributes );
64 + }
65 +
66 + public function get_wrapper_css( $attributes, $device = '' ) {
67 + return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : [];
68 + }
69 +
70 + public function get_chart_css( $attributes, $device = '' ) {
71 + $css = [];
72 + $widthCSS = Range::get_css([
73 + 'attributeValue' => $attributes['chartWidth'],
74 + 'attribute_object_key' => 'value',
75 + 'isResponsive' => true,
76 + 'defaultValue' => 95,
77 + 'hasUnit' => true,
78 + 'unitDefaultValue' => '%',
79 + 'property' => 'width',
80 + 'device' => $device,
81 + ]);
82 + if ( ! empty( $widthCSS['width'] ) ) {
83 + $widthCSS['width'] = $widthCSS['width'] . ' !important';
84 + }
85 + $heightCSS = [];
86 + $heightCSS['height'] = 'auto' . ' !important';
87 + return array_merge(
88 + $widthCSS,
89 + $heightCSS
90 + );
91 + }
92 +
93 +}