From 05da1b4dde5abfa6c3d36b8d2f6cb183dd0129ea Mon Sep 17 00:00:00 2001 From: Benjamin Renard <benjamin.renard@akka.eu> Date: Thu, 17 Sep 2015 10:39:12 +0200 Subject: [PATCH] Draw instant plot preview --- src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php | 3 +++ 2 files changed, 182 insertions(+), 13 deletions(-) diff --git a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php index ad5c95c..dbae08c 100644 --- a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php +++ b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php @@ -15,6 +15,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass private $interactiveMultiPlotState = array(); private $interactiveTimeSelectionState = array(); private $interactiveCrtTTFileIndex = -1; + private $interactivePreview = false; /* * @brief method to unmarshall a plot request @@ -206,14 +207,14 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass switch ($tab->{'page-mode'}) { - case 'color' : - $pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR); - break; + case 'grayscale' : $pageNode->setMode(RequestOutputPlotPageModeEnum::GRAYSCALE); break; + case 'color' : default: - throw new Exception('Page mode not implemented.'); + $pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR); + break; } if ($tab->{'page-margins-activated'}) @@ -250,6 +251,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $this->interactiveRequestRealIndexes[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $tabRequestIndex; $this->interactiveMultiPlotState[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $tab->{'multi-plot-linked'}; $this->interactiveTimeSelectionState[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $isIntervalRequest; + $this->interactivePreview = isset($input->{'interactive-preview'}) && ($input->{'interactive-preview'}); $this->paramsData->addWaitingResult(PLOT_RESULT_FILE_KEY."_".$tab->{'id'}, $waitingResultFile); } else @@ -513,7 +515,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass } //reverse axis - $axisNode->setReverse($axisData->{'axis-reverse'} ? "true" : "false"); + if (isset($axisData->{'axis-reverse'})) + $axisNode->setReverse($axisData->{'axis-reverse'} ? "true" : "false"); //axis scale switch ($axisData->{'axis-scale'}) @@ -528,7 +531,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass //axis range if ($axisData->{'axis-range-min'} < $axisData->{'axis-range-max'}) $axisNode->getRange()->setMinMax($axisData->{'axis-range-min'}, $axisData->{'axis-range-max'}); - $axisNode->getRange()->setExtend($axisData->{'axis-range-extend'} ? "true" : "false"); + if (isset($axisData->{'axis-range-extend'})) + $axisNode->getRange()->setExtend($axisData->{'axis-range-extend'} ? "true" : "false"); //axis color $axisNode->setColor($this->hexColor2KernelColor($axisData->{'axis-color'})); @@ -547,20 +551,26 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass } //axis minor and major grid - $axisNode->getTick()->setMinorGrid($axisData->{'axis-grid-minor'} ? "true" : "false"); - $axisNode->getTick()->setMajorGrid($axisData->{'axis-grid-major'} ? "true" : "false"); + if (isset($axisData->{'axis-grid-minor'})) + $axisNode->getTick()->setMinorGrid($axisData->{'axis-grid-minor'} ? "true" : "false"); + if (isset($axisData->{'axis-grid-major'})) + $axisNode->getTick()->setMajorGrid($axisData->{'axis-grid-major'} ? "true" : "false"); //legend - if ($axisData->{'axis-legend-text'} != '') + if (isset($axisData->{'axis-legend-text'}) && $axisData->{'axis-legend-text'} != '') + { $axisNode->getLegend()->setText($axisData->{'axis-legend-text'}); - $axisNode->getLegend()->setColor($this->hexColor2KernelColor($axisData->{'axis-legend-color'})); - $this->unmarshallLabel($axisData, "axis-legend", $axisNode->getLegend()); + $axisNode->getLegend()->setColor($this->hexColor2KernelColor($axisData->{'axis-legend-color'})); + $this->unmarshallLabel($axisData, "axis-legend", $axisNode->getLegend()); + } //Show legend - $axisNode->setShowLegend($axisData->{'axis-legend-activated'} ? "true" : "false"); + if (isset($axisData->{'axis-legend-activated'})) + $axisNode->setShowLegend($axisData->{'axis-legend-activated'} ? "true" : "false"); //Show tick marks - $axisNode->setShowTickMarks($axisData->{'axis-tick-showmarks'} ? "true" : "false"); + if (isset($axisData->{'axis-tick-showmarks'})) + $axisNode->setShowTickMarks($axisData->{'axis-tick-showmarks'} ? "true" : "false"); //Add constants if ($constantAxisId != '') @@ -1382,6 +1392,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass "id" => $key, "index" => $this->interactiveRequestRealIndexes[$key], "multiplot" => $this->interactiveMultiPlotState[$key], + "preview" => $this->interactivePreview, "isInterval" => $this->interactiveTimeSelectionState[$key], "ttFileIndex" => $this->interactiveCrtTTFileIndex, "context" => IHMPlotContextFileClass::parse($this->getWorkingPath().$contextResult), @@ -1469,6 +1480,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass return $this->unmarshallTTGoto($actionInput, $plotInput); case 'synchronize' : return $this->unmarshallSynchronize($actionInput, $plotInput); + case 'instant' : + return $this->unmarshallInstant($actionInput, $plotInput); default : throw new Exception('Interactive action not implemented.'); } @@ -1688,5 +1701,158 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $this->saveIHMRequest($plotInput); return $plotInput; } + + private function unmarshallInstant($input, $plotInput) + { + //Find current tab + $crtTab = NULL; + foreach ($plotInput->{'tabs'} as $tab) + { + if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) + { + $crtTab = $tab; + break; + } + } + + if (!$crtTab) + throw new Exception('Cannot retrieve plot tab for instant plot.'); + + //Find current panel + $crtPanel = NULL; + foreach ($crtTab->{'panels'} as $panel) + { + if ($input->{'panelId'} == $panel->{'id'}) + { + $crtPanel = $panel; + break; + } + } + + if (!$crtPanel) + throw new Exception('Cannot retrieve plot panel for instant plot.'); + + if ($crtPanel->{'panel-plot-type'} != 'timePlot') + throw new Exception('Instant plot action only available for Time plot.'); + + //Find spectra parameter + $crtParam = NULL; + foreach ($crtPanel->{'params'} as $param) + { + if ($param->{'param-drawing-type'} == 'spectro') + { + $crtParam = $param; + break; + } + } + + if (!$crtParam) + throw new Exception('Cannot retrieve plot param for instant plot.'); + + //Find table Y-axis + $crtYAxis = NULL; + foreach ($crtPanel->{'axes'} as $axis) + { + if ($crtParam->{'param-drawing-object'}->{'spectro-yaxis'} == $axis->{'id'}) + { + $crtYAxis = $axis; + break; + } + } + + if (!$crtYAxis) + throw new Exception('Cannot retrieve plot y Axis for instant plot.'); + + //Find color Z-axis + $crtColorAxis = NULL; + foreach ($crtPanel->{'axes'} as $axis) + { + if ($axis->{'id'} == 'color') + { + $crtColorAxis = $axis; + break; + } + } + + if (!$crtColorAxis) + throw new Exception('Cannot retrieve plot color Axis for instant plot.'); + + date_default_timezone_set('UTC'); + $timeStamp = strtotime($input->time); + + $instantPlotInput = (Object)array( + "interactive-preview" => true, + "file-format" => "PNG", + "file-output" => "INTERACTIVE", + "file-prefix" => "instant", + "last-plotted-tab"=> 1, + "timesrc" => "Interval", + "startDate" => date("Y-m-dTH:i:s", $timeStamp - 3600), + "stopDate" => date("Y-m-dTH:i:s", $timeStamp + 3600), + "tabs" => array() + ); + + $instantTab = (Object)array( + "id" => 1, + "multi-plot-linked" => true, + "page-margins-activated" => $crtTab->{"page-margins-activated"}, + "page-margin-x" => $crtTab->{"page-margin-x"}, + "page-margin-y" => $crtTab->{"page-margin-y"}, + "page-orientation" => $crtTab->{"page-orientation"}, + "page-dimension" => $crtTab->{"page-dimension"}, + "page-layout-type" => "vertical", + "page-layout-object" => (Object)array( + "layout-expand" => true, + "layout-panel-height" => 0.5, + "layout-panel-spacing" => 0.05 + ), + "panels" => array() + ); + + $instantPanel = (Object)array( + "id" => "1", + "panel-plot-type" => "instantPlot", + "panel-instant-time" => $input->time, + "axes" => array(), + "params" => array() + ); + + $instantXAxis = (Object)array( + "id" => "xaxis_id", + "axis-type" => "x", + "axis-scale" => $crtYAxis->{"axis-scale"}, + "axis-thickness" => 1 + ); + + $instantYAxis = (Object)array( + "id" => "y-left", + "axis-type" => "y-left", + "axis-scale" => $crtColorAxis->{"axis-scale"}, + "axis-thickness" => 1 + ); + $instantPanel->{"axes"}[] = $instantXAxis; + $instantPanel->{"axes"}[] = $instantYAxis; + + $instantParam = (Object)array( + "id" => 1, + "param-id" => $crtParam->{'param-id'}, + "param-drawing-type" => "iserie", + "param-drawing-object" => (Object)array( + "iserie-tableonx" => true, + "iserie-lines-activated" => true, + "iserie-lines-style" => "plain", + "iserie-lines-width" => 1, + "iserie-lines-color" => "auto" + ) + ); + $instantPanel->{"params"}[] = $instantParam; + + $instantTab->{"panels"}[] = $instantPanel; + + $instantPlotInput->{"tabs"}[] = $instantTab; + + + return $instantPlotInput; + } } ?> \ No newline at end of file diff --git a/src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php b/src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php index bdfd0a9..700b46a 100644 --- a/src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php +++ b/src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php @@ -83,6 +83,9 @@ class IHMPlotContextFileClass { $panelContext['plotArea']['width'] = intval($plotAreaNode->getAttribute('width')); } + //hasSpectro + $panelContext['plotArea']['hasSpectro'] = ($plotAreaNode->getAttribute('hasSpectro') == "true"); + //<axis> $panelContext['plotArea']['axes'] = array(); -- libgit2 0.21.2