Commit 1a0151a5c33bf293fa85c37985e3b5b2900eaf03

Authored by Benjamin Renard
1 parent 903e5e09

wip

js/app/views/CatalogVisuScatter.js
... ... @@ -16,11 +16,12 @@ Ext.define('amdaUI.CatalogVisuScatter', {
16 16 this.callParent(arguments);
17 17 },
18 18  
19   - getChart: function(chart) {
20   - var store = Ext.create('Ext.data.Store', {
21   - fields : [],
22   - autoload : false
23   - });
  19 + getChart: function(catalogStore) {
  20 + var plotTypeField = Ext.getCmp('visu-scatter-type');
  21 + var plotType = plotTypeField.getValue();
  22 +
  23 + var plotColorField = Ext.getCmp('visu-scatter-color');
  24 + plotColor = plotColorField.getValue();
24 25  
25 26 var xAxisOpt = this.getAxisOptions('X');
26 27 var yAxisOpt = this.getAxisOptions('Y');
... ... @@ -29,9 +30,9 @@ Ext.define('amdaUI.CatalogVisuScatter', {
29 30 animate: false,
30 31 mask: false,
31 32 shadow: false,
32   - theme:'Blue',
  33 + theme: plotColor,
33 34 background: { fill : "#fff" },
34   - store: store,
  35 + store: catalogStore,
35 36 id: 'visu-chart',
36 37 axes: [{
37 38 type: 'Numeric',
... ... @@ -50,21 +51,10 @@ Ext.define('amdaUI.CatalogVisuScatter', {
50 51 type: 'scatter',
51 52 showMarkers: true,
52 53 highlight: true,
53   -// markerConfig: {
54   - // radius: 5,
55   -// size: 5
56   -// },
57   - // // axes: ['left', 'bottom'],
58   - xField: '',
59   - yField: '',
60   -// label: {
61   -// // display: 'under',
62   -// // renderer: function(value, label, storeItem, item, i, display, animate, index) {
63   -// // return storeItem.param3;
64   -// // }
65   -// },
  54 + xField: xAxisOpt.paramId,
  55 + yField: yAxisOpt.paramId,
  56 + type: plotType,
66 57 tips: {
67   -// trackMouse: true,
68 58 width: 10,
69 59 height: 20,
70 60 hideDelay: 100, //200 ms
... ... @@ -76,6 +66,16 @@ Ext.define('amdaUI.CatalogVisuScatter', {
76 66 }]
77 67 };
78 68  
  69 + if (xAxisOpt.range) {
  70 + chartConfig.axes[0].minimum = xAxisOpt.range.min;
  71 + chartConfig.axes[0].maximum = xAxisOpt.range.max;
  72 + }
  73 +
  74 + if (yAxisOpt.range) {
  75 + chartConfig.axes[1].minimum = yAxisOpt.range.min;
  76 + chartConfig.axes[1].maximum = yAxisOpt.range.max;
  77 + }
  78 +
79 79 return Ext.create('Ext.chart.Chart', chartConfig);
80 80 },
81 81  
... ... @@ -85,7 +85,7 @@ Ext.define('amdaUI.CatalogVisuScatter', {
85 85  
86 86 getAxisOptions: function(axisName) {
87 87 var opt = {
88   - paramId: null,
  88 + paramId: '',
89 89 index: 0,
90 90 title: axisName+' axis'
91 91 };
... ... @@ -110,6 +110,20 @@ Ext.define('amdaUI.CatalogVisuScatter', {
110 110 opt.title = axisTitle;
111 111 }
112 112  
  113 + var axisScalingField = Ext.getCmp('visu-scatter-'+axisName+'-scaling');
  114 + var axisScaling = axisScalingField.getValue();
  115 + if (axisScaling == 'manual') {
  116 + var axisRangeMinField = Ext.getCmp('visu-scatter-' + axisName + '-range-min');
  117 + var axisRangeMin = axisRangeMinField.getValue();
  118 + var axisRangeMaxField = Ext.getCmp('visu-scatter-' + axisName + '-range-max');
  119 + var axisRangeMax = axisRangeMaxField.getValue();
  120 + opt.range = {
  121 + 'min' : axisRangeMin,
  122 + 'max' : axisRangeMax
  123 + };
  124 + }
  125 +
  126 + console.log(opt);
113 127 return opt;
114 128 },
115 129  
... ... @@ -145,6 +159,7 @@ Ext.define('amdaUI.CatalogVisuScatter', {
145 159 forceSelection:true,
146 160 value: 'auto',
147 161 width: 80,
  162 + id: 'visu-scatter-' + axisName + '-scaling',
148 163 listeners : {
149 164 scope : this,
150 165 change : function(combo, newValue, oldValue) {
... ... @@ -177,7 +192,8 @@ Ext.define('amdaUI.CatalogVisuScatter', {
177 192 xtype: 'numberfield',
178 193 hideTrigger: true,
179 194 width: 50,
180   - disabled: true
  195 + disabled: true,
  196 + id: 'visu-scatter-' + axisName + '-range-min'
181 197 },
182 198 {
183 199 xtype: 'splitter'
... ... @@ -186,7 +202,8 @@ Ext.define('amdaUI.CatalogVisuScatter', {
186 202 xtype: 'numberfield',
187 203 hideTrigger: true,
188 204 width: 50,
189   - disabled: true
  205 + disabled: true,
  206 + id: 'visu-scatter-' + axisName + '-range-max'
190 207 }
191 208 ]
192 209 }
... ... @@ -217,6 +234,7 @@ Ext.define('amdaUI.CatalogVisuScatter', {
217 234 queryMode: 'local',
218 235 valueField: 'type',
219 236 value: 'scatter',
  237 + id: 'visu-scatter-type',
220 238 listeners : {
221 239 scope : this,
222 240 change : function(combo, newValue, oldValue) {
... ... @@ -233,6 +251,7 @@ Ext.define('amdaUI.CatalogVisuScatter', {
233 251 queryMode: 'local',
234 252 valueField: 'type',
235 253 value: 'Blue',
  254 + id: 'visu-scatter-color',
236 255 listeners : {
237 256 scope : this,
238 257 change : function(combo, newValue, oldValue) {
... ...
js/app/views/VisuUI.js
... ... @@ -19,6 +19,7 @@ Ext.define('amdaUI.VisuUI', {
19 19 visuTabContents: [],
20 20  
21 21 parametersStore: null,
  22 + catalogStore: null,
22 23  
23 24 constructor: function(config) {
24 25 this.init(config);
... ... @@ -74,9 +75,20 @@ Ext.define('amdaUI.VisuUI', {
74 75 {
75 76 var me = this;
76 77  
  78 + this.parametersStore.removeAll();
  79 + Ext.Array.each(this.object.get('parameters'), function(param) {
  80 + for (index = 0; index < param.size; ++index) {
  81 + me.parametersStore.add({'id': param.id + (param.size > 1 ? '_COMPONENT_'+index : ''), 'paramId': param.id, 'name' : param.name, 'index': index, 'size': param.size, 'type': param.type});
  82 + }
  83 + });
  84 +
  85 + Ext.Array.each(this.visuTabContents, function(content) {
  86 + content.initVisu();
  87 + });
  88 +
77 89 var onAfterInit = function(result, e)
78 90 {
79   - /*if (!result) {
  91 + if (!result) {
80 92 myDesktopApp.errorMsg(e.message);
81 93 Ext.defer(function(){Ext.Msg.toFront()},10);
82 94  
... ... @@ -94,107 +106,58 @@ Ext.define(&#39;amdaUI.VisuUI&#39;, {
94 106 return;
95 107 }
96 108  
97   - var fields = [], i = 0, index;
98   -
99   - if (!result.cache) {
100   - me.object.set('name', result.name);
101   - me.object.set('nbIntervals', result.totalCount);
102   -
103   - var params = [];
104   - Ext.Array.each(result.parameters, function(item, index) {
105   - params[index] = item;
106   - }, this);
107   -
108   - me.object.set('parameters', params);
109   - }
110   - else {
111   - fields[0] = Ext.create('Ext.data.Field', { name : 'start', id: 'start', text : 'start: date' });
112   - fields[1] = Ext.create('Ext.data.Field', { name : 'stop', id: 'stop', text : 'stop: date' });
113   - i = 2;
114   - }
115   -
116   - Ext.Array.each(me.object.get('parameters'), function(obj) {
117   - index = 'param'+i.toString();
118   - if (obj.type == 2) {
119   - fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name + ': string' });
120   -
121   - }
122   - else if (obj.type == 1){
123   - fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name + ': date' });
124   - }
125   - else {
126   - fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name,
127   - convert: function(value, record) {
128   - return parseFloat(value);
129   - }
130   - });
131   - }
132   - i++;
133   - });
134   -
135   - if (me.chartStore) {
136   - me.parList.removeAll();
137   - me.reset();
138   - me.chartStore = null;
139   - }
140   -
141   - me.parList.add(fields);
142   -
143   - me.chartStore = Ext.create('Ext.data.Store', {
144   - fields : fields,
145   - // autoDestroy: false,
146   - // pageSize : 200,
147   - // buffered : true,
148   - // purgePageCount: 0,
149   - // remoteSort: true,
150   - autoload: false,
151   - proxy: {
152   - type: 'direct',
153   - api :
154   - {
155   - read : AmdaAction.readIntervalsForChart
156   - },
157   - // remplir automatiquement tt, sharedtt , catalog, shared catalog
158   - extraParams : {'typeTT' : 'catalog', 'id' : me.object.get('id'),
159   - 'name' : me.object.get('objName'), 'fromPlugin' : me.fromPlugin},
160   - reader:
161   - {
162   - type: 'json',
163   - root: 'intervals',
164   - totalProperty : 'totalCount'
165   - }
166   - },
167   - listeners: {
168   - scope : me,
169   - load: function(store,records) {
170   - //TODO enable plot button
171   - // me.object.set('nbIntervals',me.chartStore.getTotalCount());
172   -
173   - // load object into form
174   - //BRE - var formPanel = me.items.items[0].items.items[0];
175   - //formPanel.getForm().loadRecord(me.object);
176   - }
177   - }
178   - });
  109 + var dateConvert = function (value, rec) {
  110 + if (!Ext.isDate(value)) {
  111 + var valueString = new String(value);
  112 + return new Date(valueString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' '));
  113 + }
  114 + return value;
  115 + };
  116 +
  117 + var fieldsConfig = [];
  118 + fieldsConfig.push({type: 'date', id: 'start', name : 'start', convert: dateConvert});
  119 + fieldsConfig.push({type: 'date', id: 'stop', name : 'stop', convert: dateConvert});
  120 + me.parametersStore.each(function (param) {
  121 + switch (param.get('type')) {
  122 + case 0: //double
  123 + fieldsConfig.push({
  124 + type: 'float',
  125 + id: param.get('id'),
  126 + name: param.get('id')
  127 + });
  128 + break;
  129 + case 1: //dateTime
  130 + fieldsConfig.push({
  131 + type: 'date',
  132 + id: param.get('id'),
  133 + name : param.get('id'),
  134 + convert: dateConvert
  135 + });
  136 + break;
  137 + case 2: //string
  138 + break;
  139 + case 3: //int
  140 + fieldsConfig.push({
  141 + type: 'int',
  142 + id: param.get('id'),
  143 + name: param.get('id')
  144 + });
  145 + break;
  146 + }
  147 + });
179 148  
180   - me.chartStore.load();*/
  149 + me.catalogStore = Ext.create('Ext.data.Store', {
  150 + fields : fieldsConfig
  151 + });
  152 + me.catalogStore.loadData(result.intervals);
181 153 }
182 154  
183   - //AmdaAction.initForChart(this.object.get('id'), this.object.get('folderId'), this.object.get('objName'), this.fromPlugin, 'catalog', onAfterInit);
  155 + var opt = {
  156 + 'typeTT' : 'catalog', 'id' : this.object.get('id'),
  157 + 'name' : this.object.get('objName')
  158 + };
  159 + AmdaAction.readIntervalsForChart(opt, onAfterInit);
184 160 this.formPanel.getForm().loadRecord(this.object);
185   -
186   - this.parametersStore.removeAll();
187   - Ext.Array.each(this.object.get('parameters'), function(param) {
188   - for (index = 0; index < param.size; ++index) {
189   - me.parametersStore.add({'id': param.id+'_'+index, 'paramId': param.id, 'name' : param.name, 'index': index, 'size': param.size});
190   - }
191   - });
192   -
193   - console.log(this.parametersStore);
194   -
195   - Ext.Array.each(this.visuTabContents, function(content) {
196   - content.initVisu();
197   - });
198 161 },
199 162  
200 163  
... ... @@ -277,7 +240,8 @@ Ext.define(&#39;amdaUI.VisuUI&#39;, {
277 240  
278 241 var chartPanel = chart.up();
279 242 chartPanel.remove(chart);
280   - chartPanel.insert(tabPanel.activeTab.items.items[0].getChart());
  243 + console.log(this.catalogStore);
  244 + chartPanel.insert(tabPanel.activeTab.items.items[0].getChart(this.catalogStore));
281 245 },
282 246  
283 247 replaceChart: function(chart) {
... ... @@ -326,22 +290,22 @@ Ext.define(&#39;amdaUI.VisuUI&#39;, {
326 290  
327 291 init : function (config)
328 292 {
  293 + this.catalogStore = Ext.create('Ext.data.Store', {
  294 + fields: []
  295 + });
  296 +
329 297 this.parametersStore = Ext.create('Ext.data.Store', {
330 298 fields: [
331 299 {name: 'id', type: 'string'},
332 300 {name: 'paramId', type: 'string'},
333 301 {name: 'name', type: 'string'},
334 302 {name: 'index', type: 'int'},
335   - {name: 'size', type: 'int'}
  303 + {name: 'size', type: 'int'},
  304 + {name: 'type', type: 'int'}
336 305 ],
337 306 data: []
338 307 });
339 308  
340   - var store = Ext.create('Ext.data.Store', {
341   - fields : [],
342   - autoload : false
343   - });
344   -
345 309 this.formPanel = Ext.create('Ext.form.Panel', {
346 310 region: 'center',
347 311 layout: 'border',
... ... @@ -379,7 +343,7 @@ Ext.define(&#39;amdaUI.VisuUI&#39;, {
379 343 {
380 344 xtype: 'chart',
381 345 region: 'center',
382   - store: store,
  346 + store: this.catalogStore,
383 347 id: 'visu-chart',
384 348 animate: false,
385 349 mask: false,
... ...
php/classes/AmdaAction.php
... ... @@ -208,15 +208,15 @@ class AmdaAction
208 208 // $component_info["index1"] = $child->getAttribute('index1');
209 209 // if ($child->hasAttribute("index2"))
210 210 // $component_info["index2"] = $child->getAttribute('index2');
211   -//
  211 +//
212 212 // if ($child->hasAttribute("parentId"))
213 213 // $component_info["parentId"] = $child->getAttribute("parentId");
214   -//
  214 +//
215 215 // if ($child->hasAttribute("iconCls"))
216 216 // $iconCls = $child->getAttribute("iconCls");
217   -//
  217 +//
218 218 // if ($isLeaf) $isParameter = true;
219   -//
  219 +//
220 220 // break;
221 221  
222 222 case 'timeTable':
... ... @@ -1168,18 +1168,8 @@ class AmdaAction
1168 1168  
1169 1169 public function readIntervalsForChart($o)
1170 1170 {
1171   - if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) {
1172   -
1173   - if ($o->fromPlugin && $o->id == 'cacheCat') {
1174   - $objMgr = new CatalogCacheMgr();
1175   -
1176   - return $objMgr->getIntervals();
1177   - }
1178   -
1179   - $objMgr = new CatalogMgr();
1180   - }
1181   -
1182   - return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT);
  1171 + $objMgr = new CatalogCacheMgr(TRUE);
  1172 + return $objMgr->getIntervalsForChart();
1183 1173 }
1184 1174  
1185 1175 public function saveTTCacheIntervalsInTT($o)
... ...
php/classes/CatalogCacheMgr.php
... ... @@ -7,12 +7,16 @@
7 7 class CatalogCacheMgr extends TimeTableCacheMgr
8 8 {
9 9 const DEFAULT_PARAM_ID_PREFIX = 'cat_param_id_';
  10 + private $isForVisu = FALSE;
10 11  
11   - function __construct() {
  12 + function __construct($isForVisu = FALSE) {
12 13 $this->objectMgr = new CatalogMgr();
13 14 }
14 15  
15 16 protected function getCacheFileName() {
  17 + if ($this->isForVisu) {
  18 + return "cacheVisuCat";
  19 + }
16 20 return "cacheCat";
17 21 }
18 22  
... ... @@ -89,11 +93,38 @@ class CatalogCacheMgr extends TimeTableCacheMgr
89 93  
90 94 //Save cache file
91 95 return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(), 'parameters' => $this->cache->getParametersInfo());
92   -
93   -
94   -
95 96 }
96 97  
97   -
  98 + public function getIntervalsForChart() {
  99 + $result = $this->getIntervals(NULL, NULL, NULL, NULL);
  100 + if (!$result['success']) {
  101 + return FALSE;
  102 + }
  103 +
  104 + $parameters = $this->cache->getParametersInfo();
  105 + $parameters_to_split = array();
  106 + foreach ($parameters as $parameter) {
  107 + if ($parameter['size'] > 1) {
  108 + $parameters_to_split[] = $parameter;
  109 + }
  110 + }
  111 +
  112 + if (empty($parameters_to_split)) {
  113 + return $result;
  114 + }
  115 +
  116 + //split parameters
  117 + foreach ($result[intervals] as &$interval) {
  118 + foreach ($parameters_to_split as $parameter) {
  119 + $values = explode ($interval[$parameter['id']]);
  120 + unlink($interval[$parameter['id']]);
  121 + foreach ($values as $key => $value) {
  122 + $interval[$parameter['id'].'_COMPONENT_'.$key] = $value;
  123 + }
  124 + }
  125 + }
  126 +
  127 + return $result;
  128 + }
98 129 }
99 130 ?>
... ...
php/classes/TimeTableCacheMgr.php
... ... @@ -228,6 +228,10 @@
228 228 );
229 229 }
230 230  
  231 + public function getIntervalsForChart() {
  232 + return $this->getIntervals(NULL, NULL, NULL, NULL);
  233 + }
  234 +
231 235 public function addInterval($index, $start, $stop) {
232 236 if (!$this->loadFromFile())
233 237 return array('success' => false, 'message' => 'Cannot load cache file');
... ...