Blame view

js/app/views/VisuUI.js 9.86 KB
5cfea1f2   elena   vizu draft
1
2
3
4
5
6
/**
 * Project       AMDA-NG
 * Name          VisuUI.js
 * @class 	   amdaUI.visuUI
 * @extends      Ext.container.Container
 * @brief	   Visualization Module UI definition (View)
9d412dda   elena   catalog tmp and r...
7
 * @author 	  elena
5cfea1f2   elena   vizu draft
8
9
10
11
 */

Ext.define('amdaUI.VisuUI', {
	extend: 'Ext.container.Container',
9d412dda   elena   catalog tmp and r...
12
13
	alias: 'widget.panelVisu', 
	
5cfea1f2   elena   vizu draft
14
15
16
	constructor: function(config) 
	{
		this.init(config);
9d412dda   elena   catalog tmp and r...
17
18
		this.callParent(arguments);	
		if (this.object) this.reformObject();
5cfea1f2   elena   vizu draft
19
20
	},
	
9d412dda   elena   catalog tmp and r...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	setObject : function (obj) {
		
		this.object = obj;
		this.reformObject();
	},
	
	updateObject : function () {
		
		 return true;
	},
	
	reformObject : function () 
	{	     	    		
		this.fromPlugin = this.object.get('fromPlugin');	
		
		if (this.fromPlugin) {
			this.object.set('id',this.object.get('folderId'));	
			this.object.set('objName',this.object.get('objName'));
		}
		else {
			this.object.set('id',this.object.get('id'));
			this.object.set('name',this.object.get('name'));
		}
5cfea1f2   elena   vizu draft
44
45
46
		// load object into view
		this.loadObject();
	},
9d412dda   elena   catalog tmp and r...
47
		 	
fded4fcb   elena   reload corrected
48
49
50
51
52
53
54
	reset : function() {
								 
		this.parCombo.reset(); 
		this.parCombo1.reset(); 
		this.resetChart();
                     
	},
5cfea1f2   elena   vizu draft
55
56
57
58
59
	/**
	 * load object catalog into this view
	 */
	loadObject : function()
	{ 	  
9d412dda   elena   catalog tmp and r...
60
		    
5cfea1f2   elena   vizu draft
61
62
63
64
65
66
67
68
69
70
71
72
73
		var me = this;
		
		var onAfterInit = function(result, e) 
		{		
			if (!result || !result.success)
			{
				if (result.message)
					myDesktopApp.errorMsg(result.message);
				else
					myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
				return;
			}

9d412dda   elena   catalog tmp and r...
74
75
			me.object.set('name', result.name);
			me.object.set('nbIntervals', result.totalCount);						 			 
5cfea1f2   elena   vizu draft
76
77
			 
			var fields = [], i = 0, index;
9d412dda   elena   catalog tmp and r...
78
			 
5cfea1f2   elena   vizu draft
79
80
			Ext.Array.each(result.parameters, function(obj) 
			{
95dbfcfd   elena   save chart
81
				
86263051   elena   visu second draft
82
				index = 'param'+i.toString();			
5cfea1f2   elena   vizu draft
83
84
85
86
87
88
89
90
91
				fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name,
					convert: function(value, record) {						
						return parseFloat(value);
					}
				}
				);
								
				i++;
			});
fded4fcb   elena   reload corrected
92
93
94
95
96
97

			if (me.chartStore) {				 
				me.parList.removeAll();
				me.reset();
				me.chartStore = null;
			}
5cfea1f2   elena   vizu draft
98
			
fded4fcb   elena   reload corrected
99
	              me.parList.add(fields);
5cfea1f2   elena   vizu draft
100
101
			
			me.chartStore = Ext.create('Ext.data.Store', {
fded4fcb   elena   reload corrected
102
103
				fields : fields,				
		//		autoDestroy: false,
5cfea1f2   elena   vizu draft
104
105
106
107
108
109
110
111
112
		//				pageSize : 200,
		//				buffered : true, 
		//				purgePageCount: 0,
		//				remoteSort: true,
				autoload: false,
				proxy: {
					type: 'direct',
					api :
					{
86263051   elena   visu second draft
113
						read   :  AmdaAction.readIntervalsForChart
5cfea1f2   elena   vizu draft
114
115
					},
					// remplir automatiquement tt, sharedtt , catalog, shared catalog
9d412dda   elena   catalog tmp and r...
116
117
					extraParams : {'typeTT' : 'catalog', 'id' : me.object.get('id'), 
						         'name' : me.object.get('objName'), 'fromPlugin' : me.fromPlugin},
5cfea1f2   elena   vizu draft
118
119
120
121
122
123
124
125
126
127
128
					reader:
					{
						type: 'json',
						root: 'intervals',
						totalProperty : 'totalCount'
					}
				},
				listeners: {
					scope : me,
					load: function(store,records) {        
						//TODO enable plot button
9d412dda   elena   catalog tmp and r...
129
130
						// me.object.set('nbIntervals',me.chartStore.getTotalCount());

fded4fcb   elena   reload corrected
131
132
133
						// load object into form
						var formPanel =  me.items.items[0].items.items[0];
						formPanel.getForm().loadRecord(me.object);
5cfea1f2   elena   vizu draft
134
135
136
					}
				}
			});
56ad05d0   elena   lightware chart
137
138
			
			me.chartStore.load();			 
5cfea1f2   elena   vizu draft
139
		}
56ad05d0   elena   lightware chart
140
				 
9d412dda   elena   catalog tmp and r...
141
142
		AmdaAction.initForChart(this.object.get('id'), this.object.get('objName'), this.fromPlugin, 'catalog', onAfterInit);  
		 
5cfea1f2   elena   vizu draft
143
144
145
	  		
	},
	
5cfea1f2   elena   vizu draft
146
147
148
149
150
151
152
153
154
	
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
	fclose : function() 
	{
		  
	return false;
fded4fcb   elena   reload corrected
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	},

	resetChart : function () {
		
		this.chartConfig.series[0].xField = '';
		this.chartConfig.series[0].yField = '';
		 
		this.chartConfig.axes[0].title = 'x axe'; 
		this.chartConfig.axes[1].title = 'y axe'; 
		
		var chart =  Ext.create('Ext.chart.Chart', this.chartConfig);		
		this.replaceChart(chart);
										 
	},
5cfea1f2   elena   vizu draft
169
170
171
	
	plotChart : function () {
		
fded4fcb   elena   reload corrected
172
173
174
175
176
177
178
		this.chartConfig.store=this.chartStore;		
		var chart =  Ext.create('Ext.chart.Chart', this.chartConfig);		
		this.replaceChart(chart);
										 
	},
	
	replaceChart: function(chart) {
5cfea1f2   elena   vizu draft
179
		
5cfea1f2   elena   vizu draft
180
181
182
183
		var chartPanel =  this.items.items[0].items.items[1];
		var oldChart = chartPanel.down('chart');
		oldIndex = chartPanel.items.indexOf(oldChart);
		chartPanel.remove(oldChart);
fded4fcb   elena   reload corrected
184
		chartPanel.insert(oldIndex, chart);	
5cfea1f2   elena   vizu draft
185
186
187
188
189
190
191
192
193
194
195
196
	},
	
	init : function (config) 
	{	 
		var store = Ext.create('Ext.data.Store', {
			fields      :  [],			
			autoload    : false
		});
		
		this.chartConfig = {			
			width: 500,
			height: 500,
56ad05d0   elena   lightware chart
197
198
199
			animate: false,
			mask: false,
			shadow: false,
5cfea1f2   elena   vizu draft
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
			//      theme:'Category2',
			store: store,
			axes: [{
				type: 'Numeric',
				position: 'bottom',
				fields: [],
				title: 'x axe',
				grid : true
				}, {
				type: 'Numeric',
				position: 'left',
				fields: [],
				title: 'y axe',
				grid: true
			}],
			series: [{
				type: 'scatter',
56ad05d0   elena   lightware chart
217
218
219
220
221
				showMarkers: false,
// 		 		markerConfig: {
// 		 			radius: 5,
// 		 			size: 5
// 				},
5cfea1f2   elena   vizu draft
222
223
224
225
		// 		//      axes: ['left', 'bottom'],
				xField: '',
				yField: '',
				label: {
fded4fcb   elena   reload corrected
226
227
228
229
//   					display: 'under',
//   					renderer: function(value, label, storeItem, item, i, display, animate, index) {
//   						return storeItem.param3;
//   					}
5cfea1f2   elena   vizu draft
230
				}
9d412dda   elena   catalog tmp and r...
231
232
			}],
			listeners: {
56ad05d0   elena   lightware chart
233
234
235
236
237
238
// 				select: {
// 				fn: function(me, selection) {
// 					me.setZoom(selection);
// 					me.mask.hide();
// 					}
// 				}
9d412dda   elena   catalog tmp and r...
239
			}
5cfea1f2   elena   vizu draft
240
241
		}

f965628c   elena   plottype
242
243
244
245
246
247
248
249
		var plotTypeList = Ext.create('Ext.data.Store', {
			fields: ['type'],
			data: [
				{ 'type': 'line'    },
				{ 'type': 'scatter' } 
				] 
		});
		
fded4fcb   elena   reload corrected
250
251
252
253
		this.parList  = Ext.create('Ext.data.Store', {
				fields : [ 'text', 'id']	
			});
		
5cfea1f2   elena   vizu draft
254
255
256
257
258
		var chart = Ext.create('Ext.chart.Chart', this.chartConfig);				
 
		this.parCombo = Ext.create('Ext.form.ComboBox', {
			emptyText: 'select parameter',
			editable: false,
fded4fcb   elena   reload corrected
259
			store: this.parList,
5cfea1f2   elena   vizu draft
260
261
			queryMode: 'local',
			displayField: 'text',
95dbfcfd   elena   save chart
262
263
264
265
			valueField: 'id',
			listeners : {
				scope : this,
				change : function(combo, newValue, oldValue) {
fded4fcb   elena   reload corrected
266
267
268
269
270
271
272
					if (newValue) {
						this.chartConfig.axes[0].fields = [newValue];
						var rec = combo.findRecordByValue(newValue);
						
						this.chartConfig.axes[0].title = rec.get('text'); 
						this.chartConfig.series[0].xField = newValue;
					}
95dbfcfd   elena   save chart
273
274
				}
			}
5cfea1f2   elena   vizu draft
275
		});
f965628c   elena   plottype
276
                   
5cfea1f2   elena   vizu draft
277
278
279
		this.parCombo1 = Ext.create('Ext.form.ComboBox', {
			emptyText: 'select parameter',
			editable: false,
fded4fcb   elena   reload corrected
280
			store: this.parList,
5cfea1f2   elena   vizu draft
281
282
			queryMode: 'local',
			displayField: 'text',
95dbfcfd   elena   save chart
283
284
285
286
			valueField: 'id',
			listeners : {
				scope : this,
				change : function(combo, newValue, oldValue) {
fded4fcb   elena   reload corrected
287
288
289
290
291
292
					if (newValue) {
						this.chartConfig.axes[1].fields = [newValue];
						var rec = combo.findRecordByValue(newValue);
						this.chartConfig.axes[1].title = rec.get('text'); 
						this.chartConfig.series[0].yField = newValue;
					}
95dbfcfd   elena   save chart
293
294
				}
			}
f965628c   elena   plottype
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
		}); 
		
		var plotTypeCombo = Ext.create('Ext.form.ComboBox', {
			emptyText: 'select plot type',
			editable: false,
			store: plotTypeList,
			queryMode: 'local',
			displayField: 'type',
			valueField: 'type',
			listeners : {
				scope : this,
				change : function(combo, newValue, oldValue) {						 
					this.chartConfig.series[0].type = newValue;
				}
			}
5cfea1f2   elena   vizu draft
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
		}); 	 
		 
		 
		var formPanel =  Ext.create('Ext.form.Panel', { 
			region : 'center',
			layout:  'hbox', 
			bodyStyle: {background : '#dfe8f6'},
			defaults: { border : false, align: 'stretch',  padding: '3'},
			fieldDefaults: { labelWidth: 80, labelAlign : 'top' },
			items: [ 
				{            
				xtype: 'form',
				flex : 1,
				bodyStyle: {background : '#dfe8f6'}, 
				items: [
fded4fcb   elena   reload corrected
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
					{ 
						xtype : 'fieldset',				    
						items : [					 
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',		      
							items: [
								{ xtype:'textfield', fieldLabel: 'Catalog Name', name: 'name', readOnly: true}, 		  
								{ xtype: 'splitter' },			 			 
								{ xtype:'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', readOnly: true}
							]                                                                       
						}					
						]
					},
					{ 
						xtype : 'fieldset',
						title : 'X axis',
						items : [ 
								this.parCombo,          
								{ 
5cfea1f2   elena   vizu draft
345
346
347
348
349
350
351
352
353
354
								xtype : 'fieldcontainer',
								layout: 'hbox',
								items: [{
								xtype: 'textfield',
								flex: 1
								}, {
								xtype: 'splitter'
								}, {
								xtype: 'textfield',
								flex: 1
fded4fcb   elena   reload corrected
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
								}]
							},
							{ xtype : 'checkbox' },
							{ xtype : 'checkbox' }
						]
					},
					{ 
					xtype : 'fieldset',
						title : 'Y axis',
						items : [
							this.parCombo1,                   
							{ 
							xtype : 'fieldcontainer',
							layout: 'hbox',
							items: [{
								xtype: 'textfield',
								flex: 1
								}, {
								xtype: 'splitter'
								}, {
								xtype: 'textfield',
								flex: 1
								}                                
							]
5cfea1f2   elena   vizu draft
379
380
381
						},
						{ xtype : 'checkbox' },
						{ xtype : 'checkbox' }
5cfea1f2   elena   vizu draft
382
383
						]
					},
fded4fcb   elena   reload corrected
384
385
386
387
388
389
390
391
392
					{ 
						xtype : 'fieldset',
						title : 'Plotting Options',
						items : [
								plotTypeCombo
							]
						}
					],
					fbar:[
5cfea1f2   elena   vizu draft
393
394
395
396
397
398
399
400
					{   
						type: 'button',
						text: 'Plot',
						scope : this,
						handler: this.plotChart
						
					},{   
						type: 'button',
6a6e721d   elena   reset
401
402
403
						text: 'Reset',
						scope : this,
						handler: this.reset
5cfea1f2   elena   vizu draft
404
405
					
					}
fded4fcb   elena   reload corrected
406
407
408
409
410
411
412
					]
					}, {
					xtype: 'form',		               
			//		    padding: '3',
					flex: 2,
					items : [
						chart
5cfea1f2   elena   vizu draft
413
					],
fded4fcb   elena   reload corrected
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
					fbar:[
						{   
						type: 'button',
						text: 'Save Chart',
						scope: this,
						handler: function() {
							var chartPanel =  this.items.items[0].items.items[1];
							var chart = chartPanel.down('chart');
							chart.save({
								type: 'image/png'
							});
						}
						
					}
				]
				}    
			]  
5cfea1f2   elena   vizu draft
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
		}); 
		
	
		var myConf = {
			layout: 'border',
			items: [		   
				formPanel, 		     
				{
				xtype: 'panel', 
				region: 'south',
				title: 'Information',
				collapsible: true,
				height: 100,
				autoHide: false,
				bodyStyle: 'padding:5px',
				iconCls:  'icon-information',
				loader: {
					autoLoad: true,
					url: helpDir+'visuHOWTO'
				} 
				}
			] 
		};
	    
		Ext.apply (this, Ext.apply(arguments, myConf));	
    }
	 
});