Blame view

js/app/views/VisuUI.js 8.46 KB
5cfea1f2   elena   vizu draft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * Project       AMDA-NG
 * Name          VisuUI.js
 * @class 	   amdaUI.visuUI
 * @extends      Ext.container.Container
 * @brief	   Visualization Module UI definition (View)
 * @author 	 elena
 */

Ext.define('amdaUI.VisuUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelVisu',

	constructor: function(config) 
	{
		this.init(config);
		this.callParent(arguments);
		 
		//if (this.object) this.loadObject();	         
	},
	
	setObject : function (name,id) 
	{
		// set object
		this.object.set('id',id);
		this.object.set('name',name);
		// load object into view
		this.loadObject();
	},
	
	/**
	 * set params description into this.object
	 */
	setParamInfo : function(parameters) 
	{
		var params = [];
		Ext.Array.each(parameters, function(item, index) {
			params[index] = item;	     	  
		}, this);
		
		this.object.set('parameters', params);	  
	},	
	
	updateCount : function() 
	{
// 		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());		
// 		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
	},
	
	/**
	 * load object catalog into this view
	 */
	loadObject : function()
	{ 	  
		// load object into form
						 		 		
		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;
			}

									 			 
			 
			var fields = [], i = 0, index;
								
			Ext.Array.each(result.parameters, function(obj) 
			{
95dbfcfd   elena   save chart
76
				
86263051   elena   visu second draft
77
				index = 'param'+i.toString();			
5cfea1f2   elena   vizu draft
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
				fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name,
					convert: function(value, record) {						
						return parseFloat(value);
					}
				}
				);
								
				i++;
			});
			
			var newStore  = Ext.create('Ext.data.Store', {
				fields : [ 'text', 'id'],
				data : fields
			});
			
			me.parCombo.bindStore(newStore);
			me.parCombo1.bindStore(newStore);
			
			me.chartStore = Ext.create('Ext.data.Store', {
				fields : fields, 
				autoDestroy: false,
		//				pageSize : 200,
		//				buffered : true, 
		//				purgePageCount: 0,
		//				remoteSort: true,
				autoload: false,
				proxy: {
					type: 'direct',
					api :
					{
86263051   elena   visu second draft
108
						read   :  AmdaAction.readIntervalsForChart
5cfea1f2   elena   vizu draft
109
110
					},
					// remplir automatiquement tt, sharedtt , catalog, shared catalog
86263051   elena   visu second draft
111
					extraParams : {'typeTT' : 'catalog', 'id' : me.object.get('id')},
5cfea1f2   elena   vizu draft
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
					reader:
					{
						type: 'json',
						root: 'intervals',
						totalProperty : 'totalCount'
					}
				},
				listeners: {
					scope : me,
					load: function(store,records) {        
						//TODO enable plot button
					}
				}
			});
	 
			 me.chartStore.load();
									
		}

86263051   elena   visu second draft
131
		AmdaAction.initForChartFromTT(this.object.get('id'), 'catalog', onAfterInit);   			          
5cfea1f2   elena   vizu draft
132
133
134
135
136
137
138
139
140
141
	  		
	},
	
	/**
	 * updated object catalog into this view
	 */
	updateObject : function()
	{ 	  
		// load object into form
		//this.formPanel.getForm().loadRecord(this.object);
95dbfcfd   elena   save chart
142
143
				 			
		var me = this;				   			          
5cfea1f2   elena   vizu draft
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	  		
	},
	
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
	fclose : function() 
	{
		  
	return false;
	},	
	
	plotChart : function () {
		
5cfea1f2   elena   vizu draft
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
		this.chartConfig.store=this.chartStore;
		
		var chart =  Ext.create('Ext.chart.Chart', this.chartConfig);
	//	 chart.bindStore(this.chartStore);
		var chartPanel =  this.items.items[0].items.items[1];
		var oldChart = chartPanel.down('chart');
		oldIndex = chartPanel.items.indexOf(oldChart);
		chartPanel.remove(oldChart);
		chartPanel.insert(oldIndex, chart);								 
	},
	
	init : function (config) 
	{	 
		var store = Ext.create('Ext.data.Store', {
			fields      :  [],			
			autoload    : false
		});
		
		this.chartConfig = {			
			width: 500,
			height: 500,
			animate: true,
			mask: true,
			//      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',
		 		markerConfig: {
		 			radius: 5,
		 			size: 5
				},
		// 		//      axes: ['left', 'bottom'],
				xField: '',
				yField: '',
				label: {
// 					display: 'under',
// 					render: function(value) {
// 						return parseFloat(value);
// 					}
				}
			}]
		}

f965628c   elena   plottype
215
216
217
218
219
220
221
222
		var plotTypeList = Ext.create('Ext.data.Store', {
			fields: ['type'],
			data: [
				{ 'type': 'line'    },
				{ 'type': 'scatter' } 
				] 
		});
		
5cfea1f2   elena   vizu draft
223
224
225
		var parList = Ext.create('Ext.data.Store', {
			fields: [],
			autoload    : false
f965628c   elena   plottype
226
		});		 
5cfea1f2   elena   vizu draft
227
228
229
230
231
232
233
234
235
	
		var chart = Ext.create('Ext.chart.Chart', this.chartConfig);				
 
		this.parCombo = Ext.create('Ext.form.ComboBox', {
			emptyText: 'select parameter',
			editable: false,
			store: parList,
			queryMode: 'local',
			displayField: 'text',
95dbfcfd   elena   save chart
236
237
238
239
240
241
242
243
244
245
246
			valueField: 'id',
			listeners : {
				scope : this,
				change : function(combo, newValue, oldValue) {
					
					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;
				}
			}
5cfea1f2   elena   vizu draft
247
		});
f965628c   elena   plottype
248
                   
5cfea1f2   elena   vizu draft
249
250
251
252
253
254
		this.parCombo1 = Ext.create('Ext.form.ComboBox', {
			emptyText: 'select parameter',
			editable: false,
			store: parList,
			queryMode: 'local',
			displayField: 'text',
95dbfcfd   elena   save chart
255
256
257
258
259
260
261
262
263
264
265
			valueField: 'id',
			listeners : {
				scope : this,
				change : function(combo, newValue, oldValue) {
					
					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;
				}
			}
f965628c   elena   plottype
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
		}); 
		
		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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
		}); 	 
		 
		 
		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: [
				{ 
					xtype : 'fieldset',
					title : 'X axis',
					items : [ 
							this.parCombo,          
							{ 
								xtype : 'fieldcontainer',
								layout: 'hbox',
								items: [{
								xtype: 'textfield',
								flex: 1
								}, {
								xtype: 'splitter'
								}, {
								xtype: 'textfield',
								flex: 1
							}]
						},
						{ 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
							}                                
						]
					},
					{ xtype : 'checkbox' },
					{ xtype : 'checkbox' }
					]
				},
				{ 
					xtype : 'fieldset',
f965628c   elena   plottype
343
344
345
346
					title : 'Plotting Options',
				       items : [
						plotTypeCombo
						]
5cfea1f2   elena   vizu draft
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
				}
				],
				fbar:[
					{   
						type: 'button',
						text: 'Plot',
						scope : this,
						handler: this.plotChart
						
					},{   
						type: 'button',
						text: 'Reset'
					
					}
				]
				}, {
				xtype: 'form',		               
		//		    padding: '3',
				flex: 2,
				items : [
					chart
					],
			fbar:[
95dbfcfd   elena   save chart
370
371
372
373
374
375
376
377
378
379
380
381
382
				{   
				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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
			]
			}    
		]  
		}); 
		
	
		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));	
    }
	 
});