Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ValueGraphRenderer | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| render | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | class ValueGraphRenderer |
| 4 | { |
| 5 | public static function render($caption, $id, $structure, $input, $categoryName, $reverseOrder = false) |
| 6 | { |
| 7 | $series = []; |
| 8 | foreach ($structure as $node) |
| 9 | { |
| 10 | $data = []; |
| 11 | foreach ($input as $item) |
| 12 | $data[] = $item[$node['name']]; |
| 13 | $series[] = "{ |
| 14 | name: '" . $node['name'] . "', |
| 15 | data: [" . implode(',', $reverseOrder ? array_reverse($data) : $data) . "], |
| 16 | color: '" . $node['color'] . "'}"; |
| 17 | } |
| 18 | |
| 19 | $categories = []; |
| 20 | foreach ($input as $item) |
| 21 | $categories[] = $item[$categoryName]; |
| 22 | |
| 23 | echo " |
| 24 | var options = |
| 25 | { |
| 26 | series: [" . $result = implode(',', $series) . "], |
| 27 | chart: |
| 28 | { |
| 29 | type: 'bar', |
| 30 | height: " . Util::getValueGraphHeight($input) . ", |
| 31 | stacked: true, |
| 32 | foreColor: '" . Util::getGraphGridColor() . "' |
| 33 | }, |
| 34 | plotOptions: |
| 35 | { |
| 36 | bar: |
| 37 | { |
| 38 | horizontal: true, |
| 39 | dataLabels: |
| 40 | { |
| 41 | total: |
| 42 | { |
| 43 | enabled: true, |
| 44 | offsetX: 0, |
| 45 | style: |
| 46 | { |
| 47 | fontSize: '13px', |
| 48 | fontWeight: 900, |
| 49 | color: '" . Util::getGraphGridColor() . "' |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | }, |
| 55 | stroke: |
| 56 | { |
| 57 | width: 1, |
| 58 | colors: ['#fff'] |
| 59 | }, |
| 60 | title: { text: '" . $caption . "' }, |
| 61 | xaxis: |
| 62 | { |
| 63 | categories: [" . implode(',', array_map(fn($c) => "'$c'", $reverseOrder ? array_reverse($categories) : $categories)) . "], |
| 64 | labels: {formatter: function (val) { return val; }} |
| 65 | }, |
| 66 | yaxis: { title: { text: undefined }}, |
| 67 | tooltip: {y: { formatter: function (val) { return val; }}}, |
| 68 | fill: |
| 69 | { |
| 70 | opacity: 1, |
| 71 | colors: ['#74d14c', '#d63a49'] |
| 72 | } |
| 73 | }; |
| 74 | new ApexCharts(document.querySelector('#" . $id . "'), options).render();"; |
| 75 | } |
| 76 | } |