This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWidget.php
85 lines (74 loc) · 1.96 KB
/
Widget.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\amcharts;
use Yii;
use yii\web\View;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
/**
* AmChart Widget For Yii2 class file.
*
* @property array $plugins
*
* @author Sérgio Peixoto <[email protected]>
* @author Alexander Yaremchuk <[email protected]>
*
* @version 1.0
*
* @link https://github.com/asofter/yii2-amcharts
* @link http://www.amcharts.com/
*/
class Widget extends \yii\base\Widget
{
/**
* @var array the HTML attributes for the breadcrumb container tag.
*/
public $options = [];
/**
* @var string the width of the chart
*/
public $width = '640px';
/**
* @var string the height of the chart
*/
public $height = '400px';
/**
* @var array the AmChart configuration array
* @see http://docs.amcharts.com/3/javascriptcharts
*/
public $chartConfiguration = [];
protected $_chartDivId;
public function init()
{
if (!isset($this->options['id'])) {
$this->options['id'] = 'chartdiv-' . $this->getId();
}
$this->chartDivId = $this->options['id'];
AmChartAsset::register($this->getView());
parent::init();
}
public function run()
{
$this->makeChart();
$this->options['style'] = "width: {$this->width}; height: {$this->height};";
echo Html::tag('div', '', $this->options);
}
protected function makeChart()
{
$chartConfiguration = json_encode($this->chartConfiguration);
$js = "AmCharts.makeChart('{$this->chartDivId}', {$chartConfiguration});";
$this->getView()->registerJs($js, View::POS_READY);
}
protected function setChartDivId($value)
{
$this->_chartDivId = $value;
}
protected function getChartDivId()
{
return $this->_chartDivId;
}
}