-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChart.php
More file actions
84 lines (66 loc) · 1.68 KB
/
Copy pathChart.php
File metadata and controls
84 lines (66 loc) · 1.68 KB
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
<?php
/**
* @author Bogdan Burim <bgdn2007@ukr.net>
*/
namespace bburim\flot;
use Yii;
use yii\base\Model;
use yii\web\View;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\base\Widget as Widget;
class Chart extends Widget
{
public $options = [];
public $data = [];
public $htmlOptions = [];
public $plugins = [];
public $excanvas = false;
/**
* @var string the name of the container element that contains the progress bar. Defaults to 'div'.
*/
public $tagName = 'div';
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
//checks for the element id
if (!isset($this->htmlOptions['id'])) {
$this->htmlOptions['id'] = $this->getId();
}
parent::init();
}
/**
* Renders the widget.
*/
public function run()
{
$this->registerPlugin();
echo Html::tag($this->tagName, '', $this->htmlOptions);
}
protected function registerPlugin()
{
$id = $this->htmlOptions['id'];
$view = $this->getView();
if ($this->excanvas) {
ChartAsset::$extra_js[] = defined('YII_DEBUG') && YII_DEBUG ? 'excanvas.js' : 'excanvas.min.js';
}
if ($this->plugins && is_array($this->plugins)) {
foreach ($this->plugins as $plugin_code) {
$plugin_jsname = Plugin::getFilename($plugin_code);
if ($plugin_jsname) {
ChartAsset::$extra_js[] = $plugin_jsname;
}
}
}
ChartAsset::register($view);
$flotdata = Json::encode($this->data);
$flotoptions = Json::encode($this->options);
$placeholder = "$('#${id}')";
$js = [];
$js[] = "$.plot({$placeholder}, {$flotdata}, {$flotoptions});";
$view->registerJs(implode("\n", $js),View::POS_READY);
}
}