| Current Path : /var/www/html/planmalaysia/common/widgets/flot/ |
| Current File : /var/www/html/planmalaysia/common/widgets/flot/flotWidget.php |
<?php
namespace common\widgets\flot;
use yii\base\Widget;
use yii\helpers\Html;
use yii\base\UserException;
class flotWidget extends Widget
{
/* @property Array */
public $url;
public $option;
public $dataSource;
public $dataSet;
public function init()
{
parent::init();
}
private function prepDataSource()
{
$dataSource = '';
if(!empty($this->dataSource))
{
foreach($this->dataSource as $sodata)
{
$dataSource .=
"
var {$sodata['dataName']} = [];
var sp;
jQuery.each(jsonObj['{$sodata['data']}'], function(i, val)
{
sp = val.date.split('-');
{$sodata['dataName']}[i] = [gd(sp[0],sp[1],sp[2]),val.cnt];
});\n
";
}
}else{
throw new UserException('Please Provide Data set Parameter');
}
return $dataSource;
}
private function prepDataSet()
{
if(!empty($this->dataSet))
{
$dataPrep = "";
$dataSet = $this->dataSet;
// echo '<pre>'; var_dump($dataSet); echo '</pre>';die();
/* open */
$dataPrep .= "var dataset = [";
for ($i = 0; $i < count($dataSet); $i++)
{
$dataPrep .= "
{
label: '".$dataSet[$i]['label']."',
data: ".$dataSet[$i]['source'].",
color: '".$dataSet[$i]['color']."',
bars: {
show: true,
align: 'center',
barWidth: 24 * 60 * 60 * 800,
lineWidth:0
}
},
";
}
/* close */
$dataPrep .= "]; ";
}else{
throw new UserException('Please Provide Data set Parameter');
}
return $dataPrep;
}
public function run()
{
/* Register AssetBundle */
flotAsset::register($this->getView());
return $this->render('@common/widgets/flot/views/_flot',['dataSet'=>$this->prepDataSet(),'dataSource'=>$this->prepDataSource()]);
}
}
?>