From 70646e70a1c37997b12fe5256e58f5cbc04ffa72 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 1 Sep 2015 10:42:40 +0200 Subject: [PATCH] Add text legend definition --- src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php | 38 +++++++++++++++++++++++++++++++++++++- src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotLegendsNodeClass.php | 7 +++++++ src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotTextLegendNodeClass.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotTextLegendNodeClass.php diff --git a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php index 42dede2..0a70809 100644 --- a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php +++ b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php @@ -357,10 +357,14 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass throw new Exception('Plot type not implemented.'); } - //Params Legends + //Params Legend if (isset($panelData->{'panel-series-legend'}) && $panelData->{'panel-series-legend'}->{'legend-series-activated'}) $this->unmarshallParamsLegend($panelData->{'panel-series-legend'}, $plotNode->getLegends()->getParamsLegend()); + //Text Legends + foreach ($panelData->{'text-legends'} as $textLegendData) + $this->unmarshallTextLegend($textLegendData, $plotNode->getLegends()); + return $plotNode; } @@ -746,6 +750,38 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $this->unmarshallFont($paramsLegendData, 'legend-series-font', $paramsLegendNode->getFont()); } + protected function unmarshallTextLegend($textLegendData, $legendsNode) + { + $legendNode = $legendsNode->addTextLegend(); + + //Legend text + $legendNode->setText($textLegendData->{'legend-text-value'}); + + //Legend position + switch ($textLegendData->{'legend-text-position'}) + { + case 'top' : + $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::TOP); + break; + case 'bottom' : + $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::BOTTOM); + break; + case 'left' : + $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::LEFT); + break; + case 'right' : + default : + $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::RIGHT); + } + + //Legend text color + $legendNode->setColor($this->hexColor2KernelColor($textLegendData->{'legend-text-color'})); + + //Font + if ($textLegendData->{'legend-text-font-activated'}) + $this->unmarshallFont($textLegendData, 'legend-text-font', $legendNode->getFont()); + } + protected function unmarshallTitle($inputData, $keyPrefix, $titleNode) { if ($inputData->{$keyPrefix.'-text'} != '') diff --git a/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotLegendsNodeClass.php b/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotLegendsNodeClass.php index 398be82..0da5e74 100644 --- a/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotLegendsNodeClass.php +++ b/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotLegendsNodeClass.php @@ -26,6 +26,13 @@ class RequestOutputPlotLegendsNodeClass extends NodeClass return $node; } + + public function addTextLegend() + { + $node = new RequestOutputPlotTextLegendNodeClass(); + $this->addChild($node); + return $node; + } } ?> \ No newline at end of file diff --git a/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotTextLegendNodeClass.php b/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotTextLegendNodeClass.php new file mode 100644 index 0000000..96112f4 --- /dev/null +++ b/src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotTextLegendNodeClass.php @@ -0,0 +1,72 @@ +setAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_TEXT, $text); + } + + public function getText() + { + return $this->getAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_TEXT); + } + + public function setPosition($position) + { + $this->setAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_POSITION, $position); + } + + public function getPosition() + { + return $this->getAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_POSITION); + } + + public function setColor($color) + { + $this->setAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_COLOR, $color); + } + + public function getColor() + { + return $this->getAttribute(REQUESTOUTPUTPLOTTEXTLEGEND_COLOR); + } + + public function getFont() + { + $node = $this->getFirstChildByName(REQUESTOUTPUTPLOTPARAMSLEGEND_FONT); + + if (!isset($node)) + { + $node = new RequestOutputPlotFontNodeClass(); + $this->addChild($node); + } + + return $node; + } +} + +?> \ No newline at end of file -- libgit2 0.21.2