Commit dfc18147 authored by Kevin Yumang's avatar Kevin Yumang

SERV-2286 - added additional attributes for seriesData object.

parent da3c0c7a
......@@ -85,12 +85,17 @@ function set_data(objectData, elementObject, numberOfCharts, callback) {
// ex '{value} users' - https://echarts.apache.org/en/option.html#yAxis.axisLabel.formatter
let yAxisLabelValueFormat = objectData?.yAxisLabelValueFormat ?? (elementObject.attr('y-axis-label-value-format') ?? null);
// priority is objectData.
// global settings for series data
let showPointValues = objectData?.pointValues ?? ((elementObject.attr('point-values') == 'true' || elementObject.attr('point-values') == true) ?? false);
let stacked = objectData?.stacked ?? ((elementObject.attr('stacked') == 'true' || elementObject.attr('stacked') == true) ?? false);
let isArea = objectData?.isArea ?? ((elementObject.attr('is-area') == 'true' || elementObject.attr('is-area') == true) ?? false);
let markLine = objectData?.markLine ?? (elementObject.attr('mark-line') ?? null); // min | max | average
let categories = objectData?.categories ?? (JSON.parse(elementObject.attr('categories')) ?? null);
let series = objectData?.series ?? (JSON.parse(elementObject.attr('series')) ?? null);
let seriesNames = series && series.map(function(item){ return item.name });
let seriesObject = setSeries(series, elementObject, objectData);
let seriesObject = setSeries(series, showPointValues, stacked, isArea, markLine);
// Options
options = {
......@@ -157,7 +162,7 @@ function set_chart_height(numberOfCharts, chartElement) {
//#region FUNCTIONS FOR OPTIONS
function setSeries(seriesData, elementObject, objectData) {
function setSeries(seriesData, showPointValues, stacked, isArea, markLine) {
// setting the data first checks for the data chart manager object and if specific attributes are not set then will use the chart element parameters. else defaults.
// uses series options if available else use chart manager or chart parameter settings
......@@ -166,11 +171,6 @@ function setSeries(seriesData, elementObject, objectData) {
if(!seriesData || seriesData.length == 0) return [];
let showPointValues = objectData?.pointValues ?? ((elementObject.attr('point-values') == 'true' || elementObject.attr('point-values') == true) ?? false);
let stacked = objectData?.stacked ?? ((elementObject.attr('stacked') == 'true' || elementObject.attr('stacked') == true) ?? false);
let isArea = objectData?.isArea ?? ((elementObject.attr('is-area') == 'true' || elementObject.attr('is-area') == true) ?? false);
let markLine = objectData?.markLine ?? (elementObject.attr('mark-line') ?? null); // min | max | average
for(let i = 0; i < seriesData.length; i++) {
let series = {
......
......@@ -6,11 +6,26 @@ class SeriesData
private $name;
private $categoryValues;
private $index;
private $type;
private $stackName;
private $showPointValues;
private $isArea;
private $markLine;
public function __construct()
{
$this->categoryValues = [];
$this->index = 0;
$this->type = null;
$this->stackName = null;
$this->showPointValues = null;
$this->isArea = null;
$this->markLine = null;
}
public function getIndex() : int
{
return $this->index;
}
private function getName() : string
......@@ -23,9 +38,30 @@ class SeriesData
return $this->categoryValues;
}
public function getIndex() : int
private function getType() : ?string
{
return $this->index;
return $this->type;
}
private function getStackName() : ?string
{
return $this->stackName;
}
private function getShowPointValues() : ?bool
{
return $this->showPointValues;
}
private function getIsArea() : ?bool
{
return $this->isArea;
}
private function getMarkLine() : ?string
{
return $this->markLine;
}
public function setName(string $name) : SeriesData
......@@ -51,13 +87,51 @@ class SeriesData
return $this;
}
public function setType(string $value) : SeriesData
{
$this->type = $value;
return $this;
}
public function setStackName(string $value) : SeriesData
{
$this->stackName = $value;
return $this;
}
public function setShowPointValues(bool $value) : SeriesData
{
$this->showPointValues = $value;
return $this;
}
public function setIsArea(bool $value) : SeriesData
{
$this->isArea = $value;
return $this;
}
public function setMarkLine(string $value) : SeriesData
{
$this->markLine = $value;
return $this;
}
public function toArray(): array
{
return [
'name' => $this->getName(),
'data' => $this->getCategoryValues(),
'index' => $this->getIndex(),
];
$data = [];
$data['name'] = $this->getName();
$data['data'] = $this->getCategoryValues();
$data['index'] = $this->getIndex();
if(!is_null($this->type)) $data['type'] = $this->getType();
if(!is_null($this->stackName)) $data['stacked'] = $this->getStackName();
if(!is_null($this->showPointValues)) $data['pointValues'] = $this->getShowPointValues();
if(!is_null($this->markLine)) $data['markLine'] = $this->getMarkLine();
if(!is_null($this->isArea)) $data['isArea'] = $this->getIsArea();
return $data;
}
}
......@@ -14,24 +14,22 @@
$sd = $chartDataManager::getSeriesDataInstance();
$sd->setName('ONC');
$sd->setCategoryValues(100);
$sd->setCategoryValues([200, 300, 400, 500]);
$sd->setCategoryValues(10);
$sd->setCategoryValues([100, 50, 80, 60]);
$sd->setIndex(0); // 0 as default.
$chartDataManager->addSeries($sd);
$sd = $chartDataManager::getSeriesDataInstance();
$sd->setName('APR');
$sd->setCategoryValues([10,20,30,40,50]);
$sd->setCategoryValues([90,40,70,20,90]);
$sd->setIndex(0);
$sd->setType('bar');
$chartDataManager->addSeries($sd);
$chartDataManager->setHasDataZoom(true);
$chartDataManager->setHasBoundaryGap(false);
$chartDataManager->setIsStacked(true);
$chartDataManager->setIsArea(true);
$chartDataManager->setIsStacked(false);
$chartDataManager->setShowPointValues(true);
$dataObject = $chartDataManager->toJson();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment