Blame view

js/app/views/PlotTabResultUI.js 21.6 KB
16035364   Benjamin Renard   First commit
1
2
3
/**
 * Project   : AMDA-NG
 * Name      : PlotTabResultUI.js
18d4a11e   Benjamin Renard   Save and load plo...
4
5
 * @class    amdaUI.PlotTabResultUI
 * @extends  Ext. panel.Panel
16035364   Benjamin Renard   First commit
6
7
 * @brief    Plot Tab Result UI definition (View)
 * @author    
bab90f22   Elena.Budnik   format + #5668
8
 * @version  $Id: PlotTabResultUI.js benjamin 
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaUI.PlotTabResultUI', {
bab90f22   Elena.Budnik   format + #5668
12
	extend: 'Ext.panel.Panel',
16035364   Benjamin Renard   First commit
13

bab90f22   Elena.Budnik   format + #5668
14
15
16
17
18
19
20
21
	alias: 'widget.plotTabResult',

	requires: [
		'amdaPlotComp.PlotZoomPlug',
		'amdaPlotComp.PlotExtendShiftPlug',
		'amdaPlotComp.PlotContextManager',
		'amdaPlotComp.PlotResultImage'
	],
18d4a11e   Benjamin Renard   Save and load plo...
22
    
bab90f22   Elena.Budnik   format + #5668
23
24
25
26
27
28
29
30
31
32
	panelImage : null,
	crtContext : null,
	tabId : '',
	multiPlotCheck : null,
	navToolBar : null,
	isTTNavBar : false,
	crtTTFileIndex : 0,
	disableSynchronize: false,
	
	hiddenForm: null,
37e81bff   Benjamin Renard   Direct save of pl...
33
    
bab90f22   Elena.Budnik   format + #5668
34
35
36
37
38
39
	constructor: function(config) {
		this.addEvents({'pagesize':true});
		
		this.init(config);	 
		this.callParent(arguments);	 
	},  
16035364   Benjamin Renard   First commit
40
    
bab90f22   Elena.Budnik   format + #5668
41
42
43
44
45
46
47
48
49
50
51
52
	getImageSize : function() {
		if (!this.crtContext)
			return {
				width : 0,
				height : 0
			};
			
		return  {
				width  : this.crtContext.page.width * this.sliderPage.getValue()/100.,
				height : this.crtContext.page.height * this.sliderPage.getValue()/100.
			} 
	},
16035364   Benjamin Renard   First commit
53
    
bab90f22   Elena.Budnik   format + #5668
54
55
56
	getImageUrl: function(resultFolder, plotFile) {
		return 'data/'+sessionID +'/RES/'+resultFolder+ '/' + plotFile;
	},
16035364   Benjamin Renard   First commit
57
    
bab90f22   Elena.Budnik   format + #5668
58
59
60
61
62
	getInteractiveMultiPlotState: function() {
		if (!this.multiPlotCheck)
			return false;
		return this.multiPlotCheck.getValue();
	},
488b1401   Benjamin Renard   Interactive multi...
63
    
bab90f22   Elena.Budnik   format + #5668
64
	toPixelOnSourceImage : function(value) {
d0b61b72   Benjamin Renard   Show coordinates ...
65
66
67
68
69
70
71
		return value*100/this.sliderPage.getValue();
	},
	
	toPixelOnResultImage : function(value) {
		return value*this.sliderPage.getValue()/100;
	},
	
9f08f4eb   Benjamin Renard   Zoom in interacti...
72
73
74
75
76
77
	createZoomItemsForPanel: function(panelId) {
		var zoomPlugin = this.getPlugin('plot-zoom-plugin-id');
		if (zoomPlugin == null)
			return;
		
		var panelContext = amdaPlotComp.PlotContextManager.getPanelById(this.crtContext, panelId);
caff798e   Benjamin Renard   Fix zoom bar for ...
78
		var size = this.getImageSize();
9f08f4eb   Benjamin Renard   Zoom in interacti...
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		
		var me = this;
		Ext.each(panelContext.plotArea.axes, function (axis) {
			//Events for zoom on a time axis
			var onMinTimeSelection = function (posX) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceXPos = me.toPixelOnSourceImage(posX);
				var crtTimestamp = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.x, panelContext.plotArea.x+panelContext.plotArea.width, sourceXPos);
				var crtTime = new Date(crtTimestamp*1000);
				crtTime = Ext.Date.add(crtTime, Ext.Date.MINUTE, crtTime.getTimezoneOffset());
				zoomPlugin.setMinValue(crtTime);
			};
			
			var onMaxTimeSelection = function (posX) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceXPos = me.toPixelOnSourceImage(posX);
				var crtTimestamp = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.x, panelContext.plotArea.x+panelContext.plotArea.width, sourceXPos);
				var crtTime = new Date(crtTimestamp*1000);
				crtTime = Ext.Date.add(crtTime, Ext.Date.MINUTE, crtTime.getTimezoneOffset());
				zoomPlugin.setMaxValue(crtTime);
			};
			
			//Events for zoom on a Y axis
			var onMinYValueSelection = function(posY) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceYPos = me.toPixelOnSourceImage(posY);
				var crtValue = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.y+panelContext.plotArea.height, panelContext.plotArea.y, sourceYPos);
				zoomPlugin.setMinValue(crtValue);
			};
			
			var onMaxYValueSelection = function(posY) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceYPos = me.toPixelOnSourceImage(posY);
				var crtValue = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.y+panelContext.plotArea.height, panelContext.plotArea.y, sourceYPos);
				zoomPlugin.setMaxValue(crtValue);
			};
			
			//Events for zoom on X axis
			var onMinXValueSelection = function(posX) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceXPos = me.toPixelOnSourceImage(posX);
				var crtValue = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.x, panelContext.plotArea.x + panelContext.plotArea.width, sourceXPos);
				zoomPlugin.setMinValue(crtValue);
			};
			
			var onMaxXValueSelection = function(posX) {
				//Panel and axis context must be retrieved by using the crtContext
				var panelContext = amdaPlotComp.PlotContextManager.getPanelById(me.crtContext, panelId);
				var axisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panelContext, axis.id);
				var sourceXPos = me.toPixelOnSourceImage(posX);
				var crtValue = amdaPlotComp.PlotContextManager.toAxisValue(axisContext, panelContext.plotArea.x, panelContext.plotArea.x + panelContext.plotArea.width, sourceXPos);
				zoomPlugin.setMaxValue(crtValue);
			};
			
			switch (axis.id)
			{
			case 'timeAxis':
				me.contextualMenu.add({
					text:'Zoom on Time Axis',
					handler : function(item, e) {
						zoomPlugin.show(me.tabId, axis.id, panelContext.id);
						zoomPlugin.resetMinMaxValue();
caff798e   Benjamin Renard   Fix zoom bar for ...
151
						me.panelImage.startZoom(true, 0/*me.toPixelOnResultImage(panelContext.y)*/, size.height /*me.toPixelOnResultImage(panelContext.height)*/, onMinTimeSelection, onMaxTimeSelection);
9f08f4eb   Benjamin Renard   Zoom in interacti...
152
153
154
155
156
157
158
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
					},
					scope: this
				});
				break;
			case 'y-left' :
				me.contextualMenu.add({
					text:'Zoom on Y Left Axis',
					handler : function(item, e) {
						zoomPlugin.show(me.tabId, axis.id, panelContext.id);
						zoomPlugin.resetMinMaxValue();
						me.panelImage.startZoom(false, me.toPixelOnResultImage(panelContext.x), me.toPixelOnResultImage(panelContext.width), onMinYValueSelection, onMaxYValueSelection);
					}
				});
				break;
			case 'y-right' :
				me.contextualMenu.add({
					text:'Zoom on Y Right Axis',
					handler : function(item, e) {
						zoomPlugin.show(me.tabId, axis.id, panelContext.id);
						zoomPlugin.resetMinMaxValue();
						me.panelImage.startZoom(false, me.toPixelOnResultImage(panelContext.x), me.toPixelOnResultImage(panelContext.width), onMinYValueSelection, onMaxYValueSelection);
					}
				});
				break;
			case 'xaxis_id' :
				me.contextualMenu.add({
					text:'Zoom on X Axis',
					handler : function(item, e) {
						zoomPlugin.show(me.tabId, axis.id, panelContext.id);
						zoomPlugin.resetMinMaxValue();
						me.panelImage.startZoom(true, me.toPixelOnResultImage(panelContext.y), me.toPixelOnResultImage(panelContext.height), onMinXValueSelection, onMaxXValueSelection);
					}
				});
				break;
			case 'epochAxis' :
				//Nothing to add
				break;
			}
			
		});
	},
	
d0b61b72   Benjamin Renard   Show coordinates ...
194
195
    createPlotImage: function(resultFolder, plotFile) {
    	var me = this;
18d4a11e   Benjamin Renard   Save and load plo...
196
    	var size = this.getImageSize();
d0b61b72   Benjamin Renard   Show coordinates ...
197
    	this.panelImage = Ext.create('amdaPlotComp.PlotResultImage', {
18d4a11e   Benjamin Renard   Save and load plo...
198
199
200
            src    : this.getImageUrl(resultFolder, plotFile),
            width  : size.width,
            height : size.height,
d0b61b72   Benjamin Renard   Show coordinates ...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
			onMouseMove : function(x, y) {
				if (!me.crtContext)
					return;
				
				var sourceXPos = me.toPixelOnSourceImage(x);
				var sourceYPos = me.toPixelOnSourceImage(y);
				var panel = amdaPlotComp.PlotContextManager.getPanel(me.crtContext, sourceXPos, sourceYPos);
				var text = '';
				if (me.panelImage)
				{
					if (!panel)
					{
						me.panelImage.resetCursor();
						text += 'No panel';
					}
					else
					{
						text += 'Panel Id : ';
						text += panel.id;
						if (amdaPlotComp.PlotContextManager.isInPlotArea(panel, sourceXPos, sourceYPos))
						{
							/*me.panelImage.updateCursor(
								me.toPixelOnResultImage(panel.plotArea.x),
								me.toPixelOnResultImage(panel.plotArea.y),
								me.toPixelOnResultImage(panel.plotArea.width),
								me.toPixelOnResultImage(panel.plotArea.height),
								x, y);*/
							me.panelImage.updateCursor(
									me.toPixelOnResultImage(0),
									me.toPixelOnResultImage(0),
									me.toPixelOnResultImage(me.crtContext.page.width),
									me.toPixelOnResultImage(me.crtContext.page.height),
									x, y);
							
							var xText = '';
							var yLeftText = '';
							var yRightText = '';
							Ext.each(panel.plotArea.axes, function (axis) {
								switch (axis.id)
								{
								case 'timeAxis':
									var crtTimestamp = amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.x, panel.plotArea.x+panel.plotArea.width, sourceXPos);
									var crtTime = new Date(crtTimestamp*1000);
									xText = crtTime.toJSON();
									break;
								case 'y-left' :
b3f3c727   Elena.Budnik   Redmine #4937
247
									yLeftText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.y+panel.plotArea.height, panel.plotArea.y, sourceYPos).toFixed(2));
d0b61b72   Benjamin Renard   Show coordinates ...
248
249
									break;
								case 'y-right' :
b3f3c727   Elena.Budnik   Redmine #4937
250
									yRightText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.y+panel.plotArea.height, panel.plotArea.y, sourceYPos).toFixed(2));
d0b61b72   Benjamin Renard   Show coordinates ...
251
252
									break;
								case 'xaxis_id' :
b3f3c727   Elena.Budnik   Redmine #4937
253
									xText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.x, panel.plotArea.x+panel.plotArea.width, sourceXPos).toFixed(2));
d0b61b72   Benjamin Renard   Show coordinates ...
254
255
									break;
								case 'epochAxis' :
b3f3c727   Elena.Budnik   Redmine #4937
256
									xText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.x, panel.plotArea.x+panel.plotArea.width, sourceXPos).toFixed(2));
d0b61b72   Benjamin Renard   Show coordinates ...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
									break;
								}
								
							});
							
							if (xText != '')
								text += (', X : '+xText);
							if (yLeftText != '')
								text += (', Y Left : '+yLeftText);
							if (yRightText != '')
								text += (', Y Right : '+yRightText);
						}
						else
							me.panelImage.resetCursor();
					}
				}
				me.coordinatesField.setText(text);
			},
9f08f4eb   Benjamin Renard   Zoom in interacti...
275
276
277
278
			onContextMenu : function(absoluteX, absoluteY, imageX, imageY) {
				if (!me.crtContext)
					return;
				
87658ba0   Benjamin Renard   TT Navigation in ...
279
				me.contextualMenu.removeAll(true);
9f08f4eb   Benjamin Renard   Zoom in interacti...
280
281
282
283
284
285
286
				
				var sourceXPos = me.toPixelOnSourceImage(imageX);
				var sourceYPos = me.toPixelOnSourceImage(imageY);
				var panel = amdaPlotComp.PlotContextManager.getPanel(me.crtContext, sourceXPos, sourceYPos);
				
				if (panel != null)
				{
c9071a43   Benjamin Renard   Add instant plot ...
287
288
289
					if (panel.plotArea.hasSpectro)
					{
						me.contextualMenu.add([
bab90f22   Elena.Budnik   format + #5668
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
							{
								text:'Instant cut at this position',
								handler : function ()
								{
									var timeAxisContext = amdaPlotComp.PlotContextManager.getPanelAxisById(panel, 'timeAxis');
									if (timeAxisContext == null)
										return;
									var crtTimestamp = amdaPlotComp.PlotContextManager.toAxisValue(timeAxisContext, panel.plotArea.x, panel.plotArea.x+panel.plotArea.width, sourceXPos);
									var crtTime = new Date(crtTimestamp*1000);
									crtTime = Ext.Date.add(crtTime, Ext.Date.MINUTE, crtTime.getTimezoneOffset());
									me.callInteractivePlot({'action' : 'instant', 'tabId' : this.tabId, 'panelId' : panel.id, 'time' : crtTime});
								},
								scope: me
							},
							'-' 
c9071a43   Benjamin Renard   Add instant plot ...
305
306
						]);
					}
9f08f4eb   Benjamin Renard   Zoom in interacti...
307
308
309
310
311
312
313
					if (amdaPlotComp.PlotContextManager.isInPlotArea(panel, sourceXPos, sourceYPos))
						me.createZoomItemsForPanel(panel.id);
				}
				
				if (me.contextualMenu.items.getCount() > 0)
					me.contextualMenu.add('-');
					
37e81bff