Revert "Revert "* Refactor to ajax get chart data when enter design and preview.""
This reverts commit f3356158a2.
This commit is contained in:
@@ -119,6 +119,7 @@ class screen extends control
|
||||
$chartID = $this->post->sourceID;
|
||||
$type = $this->post->type;
|
||||
$queryType = isset($_POST['queryType']) ? $this->post->queryType : 'filter';
|
||||
$component = isset($_POST['component']) ? json_decode($this->post->component) : null;
|
||||
|
||||
$type = ($type == 'Tables' or $type == 'pivot') ? 'pivot' : 'chart';
|
||||
|
||||
|
||||
+99
-36
@@ -141,6 +141,39 @@ class screenModel extends model
|
||||
return $chartData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate chartData of new screen.
|
||||
*
|
||||
* @param object $screen
|
||||
* @param string $year
|
||||
* @param string $dept
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function genNewChartData($screen, $year, $month, $dept, $account)
|
||||
{
|
||||
$this->loadModel('pivot');
|
||||
$scheme = json_decode($screen->scheme);
|
||||
|
||||
foreach($scheme->componentList as $component)
|
||||
{
|
||||
if(!empty($component->isGroup))
|
||||
{
|
||||
foreach($component->groupList as $key => $groupComponent)
|
||||
{
|
||||
if(isset($groupComponent->key) and $groupComponent->key === 'Select') $groupComponent = $this->buildSelect($groupComponent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($component->key) and $component->key === 'Select') $component = $this->buildSelect($component);
|
||||
}
|
||||
}
|
||||
|
||||
return $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a component of screen.
|
||||
*
|
||||
@@ -152,39 +185,30 @@ class screenModel extends model
|
||||
*/
|
||||
public function genComponentData($chart, $type = 'chart', $component = null, $filters = '')
|
||||
{
|
||||
if(empty($chart) || ($chart->stage == 'draft' || $chart->deleted == '1'))
|
||||
$chart = clone($chart);
|
||||
if($type == 'pivot' and $chart)
|
||||
{
|
||||
if(empty($component)) $component = new stdclass();
|
||||
$component->option = new stdclass();
|
||||
if($type == 'chart')
|
||||
{
|
||||
$component->option->title = new stdclass();
|
||||
$component->option->title->text = sprintf($this->lang->screen->noChartData, $chart->name);
|
||||
$component->option->title->left = 'center';
|
||||
$component->option->title->top = '50%';
|
||||
|
||||
$component->option->xAxis = new stdclass();
|
||||
$component->option->xAxis->show = false;
|
||||
$component->option->yAxis = new stdclass();
|
||||
$component->option->yAxis->show = false;
|
||||
}
|
||||
else if($type == 'pivot')
|
||||
{
|
||||
$component->option->ineffective = 1;
|
||||
$component->option->header = array();
|
||||
$component->option->align = array('center');
|
||||
$component->option->headerBGC = 'transparent';
|
||||
$component->option->oddRowBGC = 'transparent';
|
||||
$component->option->evenRowBGC = 'transparent';
|
||||
$component->option->columnWidth = array();
|
||||
$component->option->rowspan = array();
|
||||
$component->option->colspan = array();
|
||||
$component->option->rowNum = 1;
|
||||
$component->option->dataset = array(array(sprintf($this->lang->screen->noPivotData, $chart->name)));
|
||||
}
|
||||
return $component;
|
||||
$chart = $this->loadModel('pivot')->processPivot($chart);
|
||||
$chart->settings = json_encode($chart->settings);
|
||||
}
|
||||
|
||||
if(empty($filters) and !empty($chart->filters))
|
||||
{
|
||||
if($type == 'pivot')
|
||||
{
|
||||
list($sql, $filters) = $this->loadModel($type)->getFilterFormat($chart->sql, json_decode($chart->filters, true));
|
||||
$chart->sql = $sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
$filters = $this->loadModel($type)->getFilterFormat(json_decode($chart->filters, true));
|
||||
}
|
||||
}
|
||||
|
||||
list($component, $typeChanged) = $this->initComponent($chart, $type, $component);
|
||||
|
||||
if(empty($chart) || ($chart->stage == 'draft' || $chart->deleted == '1')) return $this->genNotFoundOrDraftComponentOption($component);
|
||||
|
||||
$chart = clone($chart);
|
||||
if($type == 'pivot' and $chart)
|
||||
{
|
||||
@@ -229,11 +253,7 @@ class screenModel extends model
|
||||
foreach($component->option->dataset->seriesData as $seriesData) $legends[] = $seriesData->name;
|
||||
$component->option->legend->data = $legends;
|
||||
}
|
||||
elseif($component->type == 'waterpolo')
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else
|
||||
elseif($component->type != 'waterpolo')
|
||||
{
|
||||
$series = array();
|
||||
for($i = 1; $i < count($component->option->dataset->dimensions); $i ++) $series[] = $defaultSeries[0];
|
||||
@@ -1429,6 +1449,8 @@ class screenModel extends model
|
||||
{
|
||||
if(!$chart->settings)
|
||||
{
|
||||
a($chart);
|
||||
die;
|
||||
$component->request = json_decode('{"requestDataType":0,"requestHttpType":"get","requestUrl":"","requestIntervalUnit":"second","requestContentType":0,"requestParamsBodyType":"none","requestSQLContent":{"sql":"select * from where"},"requestParams":{"Body":{"form-data":{},"x-www-form-urlencoded":{},"json":"","xml":""},"Header":{},"Params":{}}}');
|
||||
$component->events = json_decode('{"baseEvent":{},"advancedEvents":{}}');
|
||||
$component->key = "PieCommon";
|
||||
@@ -1487,13 +1509,29 @@ class screenModel extends model
|
||||
*/
|
||||
public function buildPieCircleChart($component, $chart)
|
||||
{
|
||||
$option = new stdclass();
|
||||
$option->type = 'nomal';
|
||||
$option->series = array();
|
||||
$option->series[0] = new stdclass();
|
||||
$option->series[0]->type = 'pie';
|
||||
$option->series[0]->radius = '70%';
|
||||
$option->series[0]->roseType = false;
|
||||
$option->backgroundColor = 'rgba(0,0,0,0)';
|
||||
$option->series[0]->data = array();
|
||||
$option->series[0]->data[0] = new stdclass();
|
||||
$option->series[0]->data[0]->value = array();
|
||||
$option->series[0]->data[0]->value[0] = 0;
|
||||
$option->series[0]->data[1] = new stdclass();
|
||||
$option->series[0]->data[1]->value = array();
|
||||
$option->series[0]->data[1]->value[0] = 0;
|
||||
|
||||
if(!$chart->settings)
|
||||
{
|
||||
$component->request = json_decode('{"requestDataType":0,"requestHttpType":"get","requestUrl":"","requestIntervalUnit":"second","requestContentType":0,"requestParamsBodyType":"none","requestSQLContent":{"sql":"select * from where"},"requestParams":{"Body":{"form-data":{},"x-www-form-urlencoded":{},"json":"","xml":""},"Header":{},"Params":{}}}');
|
||||
$component->events = json_decode('{"baseEvent":{},"advancedEvents":{}}');
|
||||
$component->key = "PieCircle";
|
||||
$component->chartConfig = json_decode('{"key":"PieCircle","chartKey":"VPieCircle","conKey":"VCPieCircle","title":"饼图","category":"Pies","categoryName":"饼图","package":"Charts","chartFrame":"echarts","image":"/static/png/pie-circle-258fcce7.png"}');
|
||||
$component->option = json_decode('{"type":"nomal","series":[{"type":"pie","radius":"70%","roseType":false}],"backgroundColor":"rgba(0,0,0,0)"}');
|
||||
$component->option = $option;
|
||||
|
||||
return $this->setComponentDefaults($component);
|
||||
}
|
||||
@@ -1524,6 +1562,8 @@ class screenModel extends model
|
||||
}
|
||||
$doneData = round((array_sum($sourceData) != 0 and !empty($sourceData['done'])) ? $sourceData['done'] / array_sum($sourceData) : 0, 4);
|
||||
$component->option->dataset = $doneData;
|
||||
if(!isset($component->option->series) || !is_array($component->option->series)) $component->option->series = $option->series;
|
||||
if(!isset($component->option)) $component->option = $option;
|
||||
$component->option->series[0]->data[0]->value = array($doneData);
|
||||
$component->option->series[0]->data[1]->value = array(1 - $doneData);
|
||||
}
|
||||
@@ -1925,6 +1965,29 @@ class screenModel extends model
|
||||
* @return void
|
||||
*/
|
||||
public function initComponent($chart, $type, $component = null)
|
||||
{
|
||||
if($type == 'metric') return $this->initMetricComponent($chart, $component);
|
||||
if($type == 'chart' || $type == 'pivot') return $this->initChartAndPivotComponent($chart, $type, $component);
|
||||
|
||||
return array($component, false);
|
||||
}
|
||||
|
||||
public function initMetricComponent($metric, $component = null)
|
||||
{
|
||||
if(!$component) $component = new stdclass();
|
||||
if(!isset($component->id)) $component->id = $metric->id;
|
||||
if(!isset($component->sourceID)) $component->sourceID = $metric->id;
|
||||
if(!isset($component->title)) $component->title = $metric->name;
|
||||
if(!isset($component->type)) $component->type = 'metric';
|
||||
if(!isset($component->chartConfig)) $component->chartConfig = json_decode($this->config->screen->chartConfig['metric']);
|
||||
if(!isset($component->option)) $component->option = new stdclass();
|
||||
|
||||
$component->chartConfig->sourceID = $metric->id;
|
||||
|
||||
return array($component, false);
|
||||
}
|
||||
|
||||
public function initChartAndPivotComponent($chart, $type, $component = null)
|
||||
{
|
||||
if(!$component) $component = new stdclass();
|
||||
if(!$chart) return array($component, false);
|
||||
|
||||
Reference in New Issue
Block a user