Commit f514c09f87d007544e85f125eb72412157529147

Authored by Menouard AZIB
1 parent bcd0e909

Send Parameter's id and MinSampling in the panel plot context

Showing 1 changed file with 53 additions and 43 deletions   Show diff stats
src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php
1 1 <?php
2 2  
3   -class IHMPlotContextFileClass {
4   - public static function parse($filePath) {
  3 +class IHMPlotContextFileClass
  4 +{
  5 + public static function parse($filePath)
  6 + {
5 7 if (!file_exists($filePath))
6 8 return array("success" => false, "message" => "Cannot load plot context file");
7   -
  9 +
8 10 $doc = new DOMDocument("1.0", "UTF-8");
9 11 $doc->preserveWhiteSpace = false;
10 12 $doc->formatOutput = true;
11   -
  13 +
12 14 if (!$doc->load($filePath))
13 15 return array("success" => false, "message" => "Cannot load plot context file");
14   -
  16 +
15 17 //<page>
16 18 $pageNodes = $doc->getElementsByTagName('page');
17   -
  19 +
18 20 if ($pageNodes->length <= 0)
19 21 return array("success" => false, "message" => "Cannot load context page node");
20   -
  22 +
21 23 $pageNode = $pageNodes->item(0);
22   -
  24 +
23 25 $isPortrait = $pageNode->getAttribute('portrait') == "true";
24   -
  26 +
25 27 $pageContext = array(
26 28 'startTime' => $pageNode->getAttribute('startTime'),
27 29 'stopTime' => $pageNode->getAttribute('stopTime'),
... ... @@ -35,31 +37,46 @@ class IHMPlotContextFileClass {
35 37 'height' => ($isPortrait ? intval($pageNode->getAttribute('width')) : intval($pageNode->getAttribute('height'))),
36 38 'panels' => array()
37 39 );
38   -
  40 +
39 41 //<panel>
40 42 $panelNodes = $pageNode->getElementsByTagName('panel');
41   -
42   - foreach ($panelNodes as $panelNode)
43   - {
  43 +
  44 + foreach ($panelNodes as $panelNode) {
44 45 $panelContext = array(
45 46 'id' => $panelNode->getAttribute('id')
46 47 );
47   -
48   - if ($isPortrait)
49   - {
  48 +
  49 + if ($isPortrait) {
50 50 $panelContext['x'] = intval($panelNode->getAttribute('y'));
51 51 $panelContext['width'] = intval($panelNode->getAttribute('height'));
52 52 $panelContext['height'] = intval($panelNode->getAttribute('width'));
53 53 $panelContext['y'] = $pageContext['height'] - intval($panelNode->getAttribute('x')) - $panelContext['height'];
54   - }
55   - else
56   - {
  54 + } else {
57 55 $panelContext['x'] = intval($panelNode->getAttribute('x'));
58 56 $panelContext['height'] = intval($panelNode->getAttribute('height'));
59 57 $panelContext['y'] = $pageContext['height'] - intval($panelNode->getAttribute('y')) - $panelContext['height'];
60 58 $panelContext['width'] = intval($panelNode->getAttribute('width'));
61 59 }
62 60  
  61 + //Parameters
  62 + $PARAMETERS_TAG = 'parameters';
  63 + $parametersNodes = $panelNode->getElementsByTagName($PARAMETERS_TAG);
  64 + $PARAMETER_TAG = 'parameter';
  65 + if ($parametersNodes->length > 0) {
  66 + $panelContext[$PARAMETERS_TAG] = array();
  67 + $parametersNode = $parametersNodes->item(0);
  68 + $items = $parametersNode->getElementsByTagName($PARAMETER_TAG);
  69 + foreach ($items as $item) {
  70 + $pContext = array(
  71 + 'id' => $item->getAttribute('id'),
  72 + 'MinSampling' => $item->getAttribute('MinSampling')
  73 + );
  74 +
  75 + $panelContext[$PARAMETERS_TAG][] = $pContext;
  76 + }
  77 + }
  78 +
  79 +
63 80 //<intervals>
64 81 $intervalsNodes = $panelNode->getElementsByTagName('intervals');
65 82 if ($intervalsNodes->length > 0) {
... ... @@ -80,53 +97,46 @@ class IHMPlotContextFileClass {
80 97  
81 98 //<plotArea>
82 99 $plotAreaNodes = $panelNode->getElementsByTagName('plotArea');
83   -
84   - if ($plotAreaNodes->length > 0)
85   - {
  100 +
  101 + if ($plotAreaNodes->length > 0) {
86 102 $panelContext['plotArea'] = array();
87 103 $plotAreaNode = $plotAreaNodes->item(0);
88   -
89   - if ($isPortrait)
90   - {
  104 +
  105 + if ($isPortrait) {
91 106 $panelContext['plotArea']['x'] = intval($plotAreaNode->getAttribute('y'));
92 107 $panelContext['plotArea']['width'] = intval($plotAreaNode->getAttribute('height'));
93 108 $panelContext['plotArea']['height'] = intval($plotAreaNode->getAttribute('width'));
94 109 $panelContext['plotArea']['y'] = $pageContext['height'] - intval($plotAreaNode->getAttribute('x')) - $panelContext['plotArea']['height'];
95   - }
96   - else
97   - {
  110 + } else {
98 111 $panelContext['plotArea']['x'] = intval($plotAreaNode->getAttribute('x'));
99 112 $panelContext['plotArea']['height'] = intval($plotAreaNode->getAttribute('height'));
100 113 $panelContext['plotArea']['y'] = $pageContext['height'] - intval($plotAreaNode->getAttribute('y')) - $panelContext['plotArea']['height'];
101 114 $panelContext['plotArea']['width'] = intval($plotAreaNode->getAttribute('width'));
102 115 }
103   -
  116 +
104 117 //hasSpectro
105 118 $panelContext['plotArea']['hasSpectro'] = ($plotAreaNode->getAttribute('hasSpectro') == "true");
106   -
  119 +
107 120 //<axis>
108 121 $panelContext['plotArea']['axes'] = array();
109   -
  122 +
110 123 $axisNodes = $plotAreaNode->getElementsByTagName('axis');
111   -
112   - foreach($axisNodes as $axisNode)
113   - {
  124 +
  125 + foreach ($axisNodes as $axisNode) {
114 126 $axisContext = array(
115   - 'id' => $axisNode->getAttribute('id'),
116   - 'logarithmic' => ($axisNode->getAttribute('logarithmic') == "true"),
117   - 'min' => floatval($axisNode->getAttribute('min')),
118   - 'max' => floatval($axisNode->getAttribute('max'))
  127 + 'id' => $axisNode->getAttribute('id'),
  128 + 'logarithmic' => ($axisNode->getAttribute('logarithmic') == "true"),
  129 + 'min' => floatval($axisNode->getAttribute('min')),
  130 + 'max' => floatval($axisNode->getAttribute('max'))
119 131 );
120   -
  132 +
121 133 $panelContext['plotArea']['axes'][] = $axisContext;
122 134 }
123 135 }
124   -
  136 +
125 137 $pageContext['panels'][] = $panelContext;
126 138 }
127   -
  139 +
128 140 return array("success" => true, "page" => $pageContext);
129 141 }
130 142 }
131   -
132   -?>
133 143 \ No newline at end of file
... ...