-
Notifications
You must be signed in to change notification settings - Fork 2
/
JqplotGraphWidget.php
executable file
·46 lines (38 loc) · 1.63 KB
/
JqplotGraphWidget.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
<?php
Yii::import('application.extensions.jqplot.JqplotWidget');
class JqplotGraphWidget extends JqplotWidget{
public $tagName='div';
public $ajaxOptions=array();
public $defaultAjaxOptions=array(
'dataType'=>'json',
'async'=>false,
'success'=>'js:function(data){ret=data;}'
);
protected function createJQPlotScript($plotdata){
$id=$this->htmlOptions['id'];
$flotoptions=CJavaScript::encode($this->options);
return "$.jqplot('$id',$plotdata,$flotoptions);";
}
protected function createAjaxJQPlotScript(){
$ajaxoptions=array_merge($this->ajaxOptions,$this->defaultAjaxOptions);
$ajax='$.ajax('.CJavaScript::encode($ajaxoptions).');';
$datarenderer='js:function(url,plot,options){var ret=null;'.$ajax.'return ret;}';
$this->options['dataRenderer']=$datarenderer;
$flotoptions=CJavaScript::encode($this->options);
$id=$this->htmlOptions['id'];
return "$.jqplot('$id',[],$flotoptions);";
}
public function run(){
if(!isset($this->htmlOptions['id']))
$this->htmlOptions['id']=$this->getId();
echo CHtml::tag($this->tagName,$this->htmlOptions,'');
if(is_array($this->data))
$script=$this->createJQPlotScript(CJavaScript::encode($this->data));
else {
if(!isset($this->ajaxOptions['url']) && is_string($this->data))
$this->ajaxOptions['url']=$this->data;
$script=$this->createAjaxJQPlotScript($this->ajaxOptions);
}
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->htmlOptions['id'],$script);
}
}