-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathChart.php
48 lines (41 loc) · 934 Bytes
/
Chart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace yii2mod\c3\chart;
use yii\bootstrap\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
/**
* Class Chart
*
* @package yii2mod\c3\chart
*/
class Chart extends Widget
{
/**
* @inheritdoc
*/
public function run()
{
$this->registerAssets();
return Html::tag('div', '', ['id' => $this->options['id']]);
}
/**
* Register assets
*/
protected function registerAssets()
{
$id = $this->options['id'];
$view = $this->getView();
ChartAsset::register($view);
$view->registerJs("var {$id} = c3.generate({$this->getClientOptions()});", $view::POS_END);
}
/**
* Get client options in the json format
*
* @return string
*/
protected function getClientOptions()
{
$this->clientOptions['bindto'] = '#' . $this->options['id'];
return Json::encode($this->clientOptions);
}
}