Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TimeGraphRenderer
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
2
 renderScriptInclude
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3class TimeGraphRenderer
4{
5    public static function render($caption, $id, $input, $value)
6    {
7        echo '<div id="' . $id . '" class="timeGraph"></div>';
8        echo '<script>';
9        $values = [];
10        foreach ($input as $item)
11        {
12            $timeStamp = new DateTime($item['day'])->getTimestamp() * 1000; // ms
13            $values [] = '[' . $timeStamp . ', ' . $item[$value] . ']';
14        }
15
16        echo "
17var options =
18{
19    series: [
20    {
21        name: '" . $caption . "',
22        data: [ " . implode(',', $values) . "],
23        color: '#74d14c'
24    }],
25    chart:
26    {
27        height: 520,
28        type: 'line',
29        foreColor: '" . Util::getGraphGridColor() . "',
30        zoom: {enabled: false}
31    },
32    dataLabels:    { enabled: false },
33    stroke:
34    {
35        curve: 'straight',
36        colors: ['#74d14c']
37    },
38    title:
39    {
40        text: '" . $caption . "',
41        align: 'left'
42    },
43    grid:
44    {
45        row:
46        {
47            colors: ['" . Util::getGraphColor() . "', 'transparent'],
48            opacity: 0.5
49        },
50    },
51    xaxis: { type: 'datetime' },
52    fill:
53    {
54        opacity: 1,
55        colors: ['#74d14c', '#d63a49']
56    }
57};
58var chart = new ApexCharts(document.querySelector('#" . $id . "'), options);
59chart.render();";
60        echo '</script>';
61    }
62
63    // this is weird, why do we include 3rd party js, we should just put the js on our site
64    // instead of depending on availability of theirs
65    public static function renderScriptInclude()
66    {
67        echo '
68<script>
69window.Promise ||
70document.write(
71\' < script src = "https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js" ><\/script > \'
72)
73window.Promise ||
74document.write(
75\'<script src = "https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js" ><\/script > \'
76)
77window.Promise ||
78document.write(
79\'<script src = "https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn" ><\/script > \'
80)
81</script>
82<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>';
83    }
84}