From cff8aac611b32a11fd19ffe47ebe26d554153435 Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Tue, 21 Nov 2023 13:37:41 +0800 Subject: [PATCH] * Fix screen and chart preview not keep same,bug#40239. --- module/screen/model.php | 50 ++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/module/screen/model.php b/module/screen/model.php index 4f479df717..0fc4d669bb 100644 --- a/module/screen/model.php +++ b/module/screen/model.php @@ -392,10 +392,12 @@ class screenModel extends model list($group, $metrics, $aggs, $xLabels, $yStats) = $this->loadModel('chart')->getMultiData($settings, $chart->sql, $filters); - $fields = json_decode($chart->fields); - $dimensions = array($settings['xaxis'][0]['field']); - $sourceData = array(); - $clientLang = $this->app->getClientLang(); + $fields = json_decode($chart->fields, true); + $dimensions = array($settings['xaxis'][0]['field']); + $sourceData = array(); + $clientLang = $this->app->getClientLang(); + $xLabelValues = $this->processXLabel($xLabels, $fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + foreach($yStats as $index => $dataList) { $field = zget($fields, $metrics[$index]); @@ -406,6 +408,7 @@ class screenModel extends model foreach($dataList as $valueField => $value) { + $valueField = $xLabelValues[$valueField]; if(empty($sourceData[$valueField])) { $sourceData[$valueField] = new stdclass(); @@ -441,10 +444,12 @@ class screenModel extends model list($group, $metrics, $aggs, $xLabels, $yStats) = $this->loadModel('chart')->getMultiData($settings, $chart->sql, $filters); - $fields = json_decode($chart->fields); - $dimensions = array($settings['xaxis'][0]['field']); - $sourceData = array(); - $clientLang = $this->app->getClientLang(); + $fields = json_decode($chart->fields, true); + $dimensions = array($settings['xaxis'][0]['field']); + $sourceData = array(); + $clientLang = $this->app->getClientLang(); + $xLabelValues = $this->processXLabel($xLabels, $fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + foreach($yStats as $index => $dataList) { $field = zget($fields, $metrics[$index]); @@ -455,6 +460,7 @@ class screenModel extends model foreach($dataList as $valueField => $value) { + $valueField = $xLabelValues[$valueField]; if(empty($sourceData[$valueField])) { $sourceData[$valueField] = new stdclass(); @@ -544,11 +550,13 @@ class screenModel extends model list($group, $metrics, $aggs, $xLabels, $yStats) = $this->loadModel('chart')->getMultiData($settings, $chart->sql, $filters); - $fields = json_decode($chart->fields); + $fields = json_decode($chart->fields, true); $radarIndicator = array(); $seriesData = array(); $max = 0; $clientLang = $this->app->getClientLang(); + $xLabelValues = $this->processXLabel($xLabels, $fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + foreach($yStats as $index => $dataList) { $field = zget($fields, $metrics[$index]); @@ -574,7 +582,7 @@ class screenModel extends model foreach($dataList as $valueField => $value) { $indicator = new stdclass(); - $indicator->name = $valueField; + $indicator->name = $xLabelValues[$valueField]; $indicator->max = $max; $radarIndicator[] = $indicator;; } @@ -765,6 +773,28 @@ class screenModel extends model return $screenFilters; } + /** + * Process xLabel with lang + * + * @param array $xLabel + * @param string $type + * @param string $object + * @param string $field + * @access public + * @return array + */ + public function processXLabel($xLabels, $type, $object, $field) + { + $options = $this->getSysOptions($type, $object, $field); + $xLabelValues = array(); + foreach($xLabels as $index => $label) + { + $xLabelValues[$label] = isset($options[$label]) ? $options[$label] : $label; + } + + return $xLabelValues; + } + /** * Get system options. *