| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
use ABlocks\Controls\Alignment; |
| 8 |
use ABlocks\Controls\Range; |
| 9 |
|
| 10 |
$attributes = [ |
| 11 |
'block_id' => array( |
| 12 |
'type' => 'string', |
| 13 |
'default' => '', |
| 14 |
), |
| 15 |
'blockVersion' => array( |
| 16 |
'type' => 'number', |
| 17 |
'default' => '', |
| 18 |
), |
| 19 |
'chartType' => [ |
| 20 |
'type' => 'string', |
| 21 |
'default' => 'bar', |
| 22 |
], |
| 23 |
'chartBG' => [ |
| 24 |
'type' => 'string', |
| 25 |
'default' => '#fff', |
| 26 |
], |
| 27 |
'data' => [ |
| 28 |
'type' => 'object', |
| 29 |
'default' => [ |
| 30 |
'labels' => [ 'January', 'February', 'March', 'April', 'May', 'June' ], |
| 31 |
'datasets' => [ |
| 32 |
[ |
| 33 |
'label' => 'Sales', |
| 34 |
'data' => [ 300, 500, 200, 800, 700, 900 ], |
| 35 |
'backgroundColor' => 'rgba(75, 192, 192, 0.6)', |
| 36 |
'borderColor' => 'rgba(75, 192, 192, 1)', |
| 37 |
'borderWidth' => 1, |
| 38 |
'pointStyle' => 'star', |
| 39 |
'pointRadius' => 8, |
| 40 |
'pointHoverRadius' => 12, |
| 41 |
], |
| 42 |
[ |
| 43 |
'label' => 'buys', |
| 44 |
'data' => [ 400, 600, 300, 900, 800, 800 ], |
| 45 |
'backgroundColor' => 'yellow', |
| 46 |
'borderColor' => 'red', |
| 47 |
'borderWidth' => 1, |
| 48 |
'pointStyle' => 'triangle', |
| 49 |
'pointRadius' => 8, |
| 50 |
'pointHoverRadius' => 12, |
| 51 |
], |
| 52 |
], |
| 53 |
], |
| 54 |
], |
| 55 |
'options' => [ |
| 56 |
'type' => 'object', |
| 57 |
'default' => [ |
| 58 |
'responsive' => true, |
| 59 |
'aspectRatio' => 1, |
| 60 |
'maintainAspectRatio' => true, |
| 61 |
'scales' => [ |
| 62 |
'x' => [ |
| 63 |
'ticks' => [ |
| 64 |
'color' => 'blue', |
| 65 |
'font' => [ |
| 66 |
'size' => 14, |
| 67 |
], |
| 68 |
], |
| 69 |
'grid' => [ |
| 70 |
'display' => true, |
| 71 |
'color' => 'lightgray', |
| 72 |
'lineWidth' => 1, |
| 73 |
], |
| 74 |
'title' => [ |
| 75 |
'display' => true, |
| 76 |
'text' => 'X-Axis Label', |
| 77 |
'color' => 'darkblue', |
| 78 |
'align' => 'center', |
| 79 |
'font' => [ |
| 80 |
'size' => 16, |
| 81 |
'weight' => 'bold', |
| 82 |
], |
| 83 |
], |
| 84 |
], |
| 85 |
'y' => [ |
| 86 |
'ticks' => [ |
| 87 |
'color' => 'green', |
| 88 |
'font' => [ |
| 89 |
'size' => 14, |
| 90 |
], |
| 91 |
], |
| 92 |
'grid' => [ |
| 93 |
'display' => true, |
| 94 |
'color' => 'gray', |
| 95 |
'lineWidth' => 1, |
| 96 |
], |
| 97 |
'title' => [ |
| 98 |
'display' => true, |
| 99 |
'text' => 'Y-Axis Label', |
| 100 |
'color' => 'darkgreen', |
| 101 |
'align' => 'center', |
| 102 |
'font' => [ |
| 103 |
'size' => 16, |
| 104 |
'weight' => 'bold', |
| 105 |
], |
| 106 |
], |
| 107 |
], |
| 108 |
], |
| 109 |
'plugins' => [ |
| 110 |
'legend' => [ |
| 111 |
'position' => 'top', |
| 112 |
'labels' => [ |
| 113 |
'usePointStyle' => true, |
| 114 |
], |
| 115 |
], |
| 116 |
'title' => [ |
| 117 |
'display' => true, |
| 118 |
'text' => 'Monthly Sales', |
| 119 |
'position' => 'top', |
| 120 |
'align' => 'center', |
| 121 |
'padding' => 10, |
| 122 |
'font' => [ |
| 123 |
'size' => 20, |
| 124 |
'weight' => 'bold', |
| 125 |
], |
| 126 |
], |
| 127 |
'subtitle' => [ |
| 128 |
'display' => false, |
| 129 |
'text' => 'Custom Chart Subtitle', |
| 130 |
'position' => 'top', |
| 131 |
'align' => 'center', |
| 132 |
'padding' => 10, |
| 133 |
'font' => [ |
| 134 |
'size' => 12, |
| 135 |
'weight' => 'bold', |
| 136 |
], |
| 137 |
], |
| 138 |
], |
| 139 |
], |
| 140 |
], |
| 141 |
|
| 142 |
]; |
| 143 |
|
| 144 |
$attributes = array_merge( |
| 145 |
$attributes, |
| 146 |
Alignment::get_attribute( 'alignment', true, [ 'value' => 'left' ] ), |
| 147 |
Range::get_attribute([ |
| 148 |
'attributeName' => 'chartHeight', |
| 149 |
'attributeObjectKey' => 'value', |
| 150 |
'isResponsive' => false, |
| 151 |
'defaultValue' => 620, |
| 152 |
'hasUnit' => true, |
| 153 |
'unitDefaultValue' => 'px', |
| 154 |
]), |
| 155 |
Range::get_attribute([ |
| 156 |
'attributeName' => 'chartWidth', |
| 157 |
'attributeObjectKey' => 'value', |
| 158 |
'isResponsive' => false, |
| 159 |
'defaultValue' => 95, |
| 160 |
'hasUnit' => true, |
| 161 |
'unitDefaultValue' => '%', |
| 162 |
]), |
| 163 |
); |
| 164 |
|
| 165 |
return array_merge( $attributes, \ABlocks\Classes\BlockGlobal::get_attributes() ); |
| 166 |
|
| 167 |
|