diff --git a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php index 88cff1f..6bc7bae 100644 --- a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php +++ b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php @@ -26,12 +26,20 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass { $this->interactiveRequestRealIndexes = array(); + $fullResetZoom = false; + if (isset($input->{'action'})) + { $input = $this->unmarshallActionRequest($input); + $forceTimeZoomReset = isset($input->{'force-time-zoom-reset'}) ? $input->{'force-time-zoom-reset'} : false; + } else + { + $resetZoom = true; //save request $this->saveIHMRequest($input); - + } + //Get active tab $activeTab = NULL; foreach ($input->tabs as $tab) @@ -72,6 +80,9 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass //Plot only current active tab when 'force-single-replot' is active continue; } + //Reset zoom list if needed + if ($fullResetZoom || $forceTimeZoomReset) + $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); } else { @@ -81,6 +92,9 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass //In no interactive request, plot only active tab continue; } + //Reset zoom list if needed + if ($fullResetZoom || $forceTimeZoomReset) + $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); } } @@ -1496,12 +1510,146 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass return $this->unmarshallSynchronize($actionInput, $plotInput); case 'instant' : return $this->unmarshallInstant($actionInput, $plotInput); + case 'undozoom' : + return $this->unmarshallUndoZoom($actionInput, $plotInput); default : throw new Exception('Interactive action not implemented.'); } } - private function unmarshallZoom($input, $plotInput) + private function addZoomInList($input, $isInterval, $minOrFileIndex, $maxOrIntervalIndex) + { + //if $isInterval == true, $minOrFileIndex is the min and $maxOrInetrvalIndex is the max + //if $isInterval == false, $minOrFileIndex is the fileIndex and $maxOrInetrvalIndex is the intervalIndex + + $zoomList = $this->loadZoomList(); + + if (!isset($zoomList->tabs)) + { + //Init zoom list + $zoomList = (Object)array( + 'tabs' => (Object)array() + ); + } + + if (!isset($zoomList->tabs->{$input->{'tabId'}})) + { + $zoomList->tabs->{$input->{'tabId'}} = (Object)array( + 'times' => array(), + 'panels' => (Object)array() + ); + } + + if ($input->{'axeId'} == 'timeAxis') + { + if ($isInterval) + array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( + 'isInterval' => true, + 'min' => $minOrFileIndex, + 'max' => $maxOrIntervalIndex + )); + else + array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( + 'isInterval' => false, + 'ttFileIndex' => $minOrFileIndex, + 'intIndex' => $maxOrIntervalIndex + )); + } + else + { + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) + { + $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}} = (Object) array( + 'axes' => (Object)array() + ); + } + + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) + { + $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}} = array(); + } + + array_push ($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}, (Object)array( + 'min' => $minOrFileIndex, + 'max' => $maxOrIntervalIndex + )); + } + + //save zoom list + $path = $this->getWorkingPath()."zoom.list"; + if (!is_dir($this->getWorkingPath())) + mkdir($this->getWorkingPath(),0777); + $file = fopen($path, 'w'); + fwrite($file, json_encode($zoomList)); + fclose($file); + } + + private function loadZoomList() + { + $path = $this->getWorkingPath()."zoom.list"; + if (!file_exists($path)) + return NULL; + return json_decode(file_get_contents($path)); + } + + private function resetZoomListForTab($tabId, $resetOnlyTimeZoom = false) + { + $zoomList = $this->loadZoomList(); + + if (isset($zoomList->tabs) && isset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId})) + { + if (!$resetOnlyTimeZoom) + unset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}); + else + $zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}->times = array(); + } + + $path = $this->getWorkingPath()."zoom.list"; + if (!is_dir($this->getWorkingPath())) + mkdir($this->getWorkingPath(),0777); + $file = fopen($path, 'w'); + fwrite($file, json_encode($zoomList)); + fclose($file); + } + + private function undoZoomInList($input) + { + $zoomList = $this->loadZoomList(); + + $result = NULL; + if (isset($zoomList->tabs) && isset($zoomList->tabs->{$input->{'tabId'}})) + { + if ($input->{'axeId'} == 'timeAxis') + { + if (count($zoomList->tabs->{$input->{'tabId'}}->times) <= 0) + return NULL; + $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->times); + } + else + { + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) + return NULL; + + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) + return NULL; + + $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}); + } + } + else + return NULL; + + $path = $this->getWorkingPath()."zoom.list"; + if (!is_dir($this->getWorkingPath())) + mkdir($this->getWorkingPath(),0777); + $file = fopen($path, 'w'); + fwrite($file, json_encode($zoomList)); + fclose($file); + + return $result; + } + + private function unmarshallZoom($input, $plotInput, $isUndo = false) { //Find current tab $crtTab = NULL; @@ -1523,18 +1671,43 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass if ($crtTab->{'multi-plot-linked'}) { //Update multi plot time definition - $plotInput->{'timesrc'} = 'Interval'; + if ($plotInput->{'timesrc'} != 'Interval') + { + $plotInput->{'timesrc'} = 'Interval'; + if (!$isUndo) + $this->addZoomInList($input,false, + isset($plotInput->{'ttFileIndex'}) ? $plotInput->{'ttFileIndex'}: 0, + isset($plotInput->{'intIndex'}) ? $plotInput->{'intIndex'}: 0); + } + else + { + if (!$isUndo) + $this->addZoomInList($input,true,$plotInput->{'startDate'},$plotInput->{'stopDate'}); + } $plotInput->{'startDate'} = $input->{'min'}; $plotInput->{'stopDate'} = $input->{'max'}; } else { - $crtTab->{'timesrc'} = 'Interval'; + if ($crtTab->{'timesrc'} != 'Interval') + { + $crtTab->{'timesrc'} = 'Interval'; + if (!$isUndo) + $this->addZoomInList($input,false, + isset($crtTab->{'ttFileIndex'}) ? $crtTab->{'ttFileIndex'} : 0, + isset($crtTab->{'intIndex'}) ? $crtTab->{'intIndex'} : 0); + } + else + { + if (!$isUndo) + $this->addZoomInList($input,true,$crtTab->{'startDate'},$crtTab->{'stopDate'}); + } $crtTab->{'startDate'} = $input->{'min'}; $crtTab->{'stopDate'} = $input->{'max'}; } $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; + $plotInput->{'force-time-zoom-reset'} = false; $this->saveIHMRequest($plotInput); return $plotInput; } @@ -1549,12 +1722,17 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass if ($input->{'axeId'} == $axis->{'id'}) { $axis->{'axis-range-extend'} = false; + $oldMin = $axis->{'axis-range-min'}; + $oldMax = $axis->{'axis-range-max'}; $axis->{'axis-range-min'} = $input->{'min'}; $axis->{'axis-range-max'} = $input->{'max'}; $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; $this->saveIHMRequest($plotInput); //Do not save 'force-single-replot' in request file! $plotInput->{'force-single-replot'} = true; + $plotInput->{'force-time-zoom-reset'} = false; + if (!$isUndo) + $this->addZoomInList($input,true,$oldMin,$oldMax); return $plotInput; } } @@ -1564,6 +1742,27 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass throw new Exception('Cannot retrieve plot panel for zoom action.'); } + private function unmarshallUndoZoom($input, $plotInput) + { + $result = $this->undoZoomInList($input); + if ($result != NULL) + { + if (isset($result->isInterval)) + { + if (!$result->isInterval) + { + $input->ttFileIndex = $result->ttFileIndex; + $input->intIndex = $result->intIndex; + return $this->unmarshallTTGoto($input, $plotInput); + } + } + $input->min = $result->min; + $input->max = $result->max; + return $this->unmarshallZoom($input, $plotInput, true); + } + throw new Exception('No undo zoom to apply.'); + } + private function unmarshallNavigation($input, $plotInput) { //Find current tab @@ -1644,6 +1843,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass } $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; + $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } @@ -1668,15 +1868,18 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass if ($crtTab->{'multi-plot-linked'}) { + $plotInput->{'timesrc'} = 'TimeTable'; $plotInput->{'ttFileIndex'} = $input->{'ttFileIndex'}; $plotInput->{'intIndex'} = $input->{'intIndex'}; } else { + $crtTab->{'timesrc'} = 'TimeTable'; $crtTab->{'ttFileIndex'} = $input->{'ttFileIndex'}; $crtTab->{'intIndex'} = $input->{'intIndex'}; } + $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } @@ -1712,6 +1915,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $crtTab->{'stopDate'} = $plotInput->{'stopDate'}; } + $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } -- libgit2 0.21.2