| Conditions | 1 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | public function render($flags = null) |
||
| 20 | { |
||
| 21 | $script = []; |
||
| 22 | |||
| 23 | // First, setup the canvas context |
||
| 24 | $script[] = "var ctx = document.getElementById( \"{$this->chart->getId()}\" ).getContext( \"2d\" );"; |
||
| 25 | |||
| 26 | // Now, setup the chart instance |
||
| 27 | $jsonRenderer = new Json($this->chart); |
||
| 28 | $json = $jsonRenderer->render($flags); |
||
| 29 | $script[] = "var chart = new Chart( ctx, {$json} );"; |
||
| 30 | $scriptString = implode("\n", $script); |
||
| 31 | |||
| 32 | // Return the script |
||
| 33 | return <<<JS |
||
| 34 | window.onload=(function(oldLoad){return function(){ |
||
| 35 | if (oldLoad) { |
||
| 36 | oldLoad(); |
||
| 37 | } |
||
| 38 | |||
| 39 | {$scriptString}; |
||
| 40 | |||
| 41 | if (! window.hasOwnProperty('chartInstances')) { |
||
| 42 | window.chartInstances = {}; |
||
| 43 | } |
||
| 44 | |||
| 45 | window.chartInstances['{$this->chart->getId()}'] = chart; |
||
| 46 | }})(window.onload); |
||
| 51 |