Blame view

js/app/views/PlotComponents/PlotPreviewUI.js 8.26 KB
c9071a43   Benjamin Renard   Add instant plot ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Project   : AMDA-NG
 * Name      : PlotPreviewUI.js
 * @class    amdaPlotComp.PlotPreviewUI
 * @extends  Ext. panel.Panel
 * @brief    Plot Preview UI definition (View)
 * @author    
 * @version  $Id: PlotPreviewUI.js benjamin $
 ********************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *              
 */

Ext.define('amdaPlotComp.PlotPreviewUI', {
50098ef1   Menouard AZIB   Disable Next and ...
16
	extend: 'Ext.panel.Panel',
c9071a43   Benjamin Renard   Add instant plot ...
17

50098ef1   Menouard AZIB   Disable Next and ...
18
19
20
21
22
	alias: 'widget.plotPreview',

	requires: [
		'amdaPlotComp.PlotContextManager',
		'amdaPlotComp.PlotResultImage',
a0db7984   Erdogan Furkan   #10663 - Done
23
		'amdaUI.PlotTabResultUI'
50098ef1   Menouard AZIB   Disable Next and ...
24
25
26
27
28
29
30
31
32
	],

	isPlotFunction: false,
	panelImage: null,
	crtContext: null,
	sliderPage: null,
	contextualMenu: null,
	hiddenForm: null,
	panelResultInstance: null,
c9071a43   Benjamin Renard   Add instant plot ...
33

50098ef1   Menouard AZIB   Disable Next and ...
34
	setPanelResultInstance: function (panelResultInstance_) {
a0db7984   Erdogan Furkan   #10663 - Done
35
36
		this.panelResultInstance = panelResultInstance_;
	},
50098ef1   Menouard AZIB   Disable Next and ...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

	constructor: function (config) {
		this.init(config);
		this.callParent(arguments);
	},

	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.
		}
	},

	getImageUrl: function (resultFolder, plotFile) {
		return 'data/' + sessionID + '/RES/' + resultFolder + '/' + plotFile;
	},

a81112fb   Erdogan Furkan   #9980 - Coordinat...
60
61
62
63
64
65
66
67
68
69
70
71
	toPixelOnSourceImage: function (value) {
		return value * 100 / this.sliderPage.getValue();
	},

	toPixelOnResultImage: function (value) {
		return value * this.sliderPage.getValue() / 100;
	},
	getAxisValue: function (axis, pixelMin, pixelMax, pixelVal) {
		var val = amdaPlotComp.PlotContextManager.toAxisValue(axis, pixelMin, pixelMax, pixelVal);
		return parseFloat(val).toPrecision(5);
	},

50098ef1   Menouard AZIB   Disable Next and ...
72
73
74
75
76
77
78
	createPlotImage: function (resultFolder, plotFile) {
		var me = this;
		var size = this.getImageSize();
		this.panelImage = Ext.create('amdaPlotComp.PlotResultImage', {
			src: this.getImageUrl(resultFolder, plotFile),
			width: size.width,
			height: size.height,
a81112fb   Erdogan Furkan   #9980 - Coordinat...
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
			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 = '';
							Ext.each(panel.plotArea.axes, function (axis) {
								switch (axis.id) {
									case 'y-left':
										yLeftText = me.getAxisValue(axis, panel.plotArea.y + panel.plotArea.height, panel.plotArea.y, sourceYPos);
										break;
									case 'xaxis_id':
										xText = me.getAxisValue(axis, panel.plotArea.x, panel.plotArea.x + panel.plotArea.width, sourceXPos);
										break;
								}

							});

							if (xText != '')
								text += (', X : ' + xText);
							if (yLeftText != '')
								text += (', Y : ' + yLeftText);
						}
						else
							me.panelImage.resetCursor();
					}
				}
				me.coordinatesField.setText(text);
			},
50098ef1   Menouard AZIB   Disable Next and ...
135
136
137
138
			onContextMenu: function (absoluteX, absoluteY, imageX, imageY) {
				me.contextualMenu.showAt(absoluteX, absoluteY);
			}
		});
c9071a43   Benjamin Renard   Add instant plot ...
139

50098ef1   Menouard AZIB   Disable Next and ...
140
141
142
143
144
		return this.panelImage;
	},

	updatePlotImage: function (configResult, newPlot) {
		this.crtContext = configResult.context;
c9071a43   Benjamin Renard   Add instant plot ...
145

50098ef1   Menouard AZIB   Disable Next and ...
146
		this.panelImage.setSrc(this.getImageUrl(configResult.folder, configResult.plotFile));
3afa41ee   Erdogan Furkan   #10663 - Fixed bug
147
148
		var newTime = new Date(configResult.time);
		newTime = Ext.Date.add(newTime, Ext.Date.MINUTE, newTime.getTimezoneOffset());
679ab391   Menouard AZIB   is isPlotFunction...
149
150
		if (!this.isPlotFunction)
			Ext.getCmp('plotPreview-goto-Date' + configResult.interactiveId).setValue(newTime);
50098ef1   Menouard AZIB   Disable Next and ...
151
152
153
154
155
156
157
158
		var size = this.getImageSize();
		this.panelImage.setSize(size.width, size.height);

		this.panelImage.refreshMe();
	},

	init: function (configResult) {
		var me = this;
ebafe59e   Benjamin Renard   Add the possibili...
159

50098ef1   Menouard AZIB   Disable Next and ...
160
161
		this.crtContext = configResult.context;
		this.interactiveId = configResult.interactiveId;
3afa41ee   Erdogan Furkan   #10663 - Fixed bug
162
163
		this.time = new Date(configResult.time);
		this.time = Ext.Date.add(this.time, Ext.Date.MINUTE, this.time.getTimezoneOffset());
50098ef1   Menouard AZIB   Disable Next and ...
164
165
166
		this.panelId = configResult.panelId;
		this.isPlotFunction = configResult.plotFile.includes("plotFunction");

a81112fb   Erdogan Furkan   #9980 - Coordinat...
167
168
169
170
171
		this.coordinatesField = new Ext.toolbar.TextItem({
			width: 300,
			text: ''
		});

50098ef1   Menouard AZIB   Disable Next and ...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
		this.sliderPage = new Ext.slider.Single({
			width: 130,
			value: 75,
			increment: 5,
			minValue: 50,
			maxValue: 100,
			fieldLabel: 'Resize',
			labelWidth: 40,
			listeners: {
				scope: this,
				changecomplete: function (s, v) {
					var size = this.getImageSize();
					this.panelImage.width = size.width;
					this.panelImage.height = size.height;
					this.panelImage.doComponentLayout();
				}
			}
		});
		var topToolbar =
91a44df3   Erdogan Furkan   Added Previous/ne...
191
		{
50098ef1   Menouard AZIB   Disable Next and ...
192
193
194
			xtype: 'toolbar',
			dock: 'top',
			items: [{
a0db7984   Erdogan Furkan   #10663 - Done
195
				xtype: 'datefield',
50098ef1   Menouard AZIB   Disable Next and ...
196
				allowBlank: true,
a0db7984   Erdogan Furkan   #10663 - Done
197
198
				format: 'Y-m-d\\TH:i:s.u',
				id: 'plotPreview-goto-Date' + this.interactiveId,
50098ef1   Menouard AZIB   Disable Next and ...
199
				value: this.time,
a0db7984   Erdogan Furkan   #10663 - Done
200
201
202
203
204
205
206
207
208
209
210
211
212
				width: 175,
				renderer: function (value) {
					if (value != null) {
						if (Ext.isDate(value)) {
							return Ext.Date.format(value, 'Y-m-d\\TH:i:s.u');
						} else {
							return Ext.Date.format(new Date(value), 'Y-m-d\\TH:i:s.u');
						}
					} else {
						return value;
					}
				}

50098ef1   Menouard AZIB   Disable Next and ...
213
214
215
216
217
218
219
220
221
222
			}, '-',
			{
				text: 'Change cut time',
				scope: this,
				handler: function (bt) {
					var newTime = Ext.getCmp('plotPreview-goto-Date' + me.interactiveId).getValue();
					newTime = Ext.Date.add(newTime, Ext.Date.MINUTE, -newTime.getTimezoneOffset());
					me.panelResultInstance.callInteractivePlot({ 'action': 'instant', 'interactiveId': me.panelResultInstance.interactiveId, 'panelId': me.panelId, 'time': newTime.toISOString() });
				}
			},
2827a1fc   Erdogan Furkan   Minor fix
223
				'-',
50098ef1   Menouard AZIB   Disable Next and ...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
			{
				xtype: 'button',
				text: 'Previous',
				handler: function () {
					var newTime = new Date(amdaPlotComp.PlotContextManager.getInstantTimePrev(me.crtContext) * 1000);
					me.panelResultInstance.callInteractivePlot({ 'action': 'instant', 'interactiveId': me.panelResultInstance.interactiveId, 'panelId': me.panelId, 'time': newTime.toISOString() });
				}
			},
			{
				xtype: 'button',
				text: 'Next',
				handler: function () {
					var newTime = new Date(amdaPlotComp.PlotContextManager.getInstantTimeNext(me.crtContext) * 1000);
					me.panelResultInstance.callInteractivePlot({ 'action': 'instant', 'interactiveId': me.panelResultInstance.interactiveId, 'panelId': me.panelId, 'time': newTime.toISOString() });
a0db7984   Erdogan Furkan   #10663 - Done
238
				}
50098ef1   Menouard AZIB   Disable Next and ...
239
			}
a0db7984   Erdogan Furkan   #10663 - Done
240
241
			]
		}
a81112fb   Erdogan Furkan   #9980 - Coordinat...
242
243
244
245
246
247
248
249
250
251
		var mouseToolbar = {
			xtype: 'toolbar',
			height: 25,
			dock: 'bottom',
			items: [
				this.coordinatesField,
				'->',
				this.sliderPage
			]
		};
ebafe59e   Benjamin Renard   Add the possibili...
252

50098ef1   Menouard AZIB   Disable Next and ...
253
254
255
256
		this.contextualMenu = Ext.create('Ext.menu.Menu', {
			width: 200,
			plain: true,
			items: [
ebafe59e   Benjamin Renard   Add the possibili...
257
				{
50098ef1   Menouard AZIB   Disable Next and ...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
					text: 'Save Plot',
					handler: function () {
						if (me.hiddenForm == null)
							me.hiddenForm = Ext.create('Ext.form.Panel', {
								title: 'hiddenForm',
								renderTo: Ext.getBody(),
								standardSubmit: true,
								url: 'php/downloadPlot.php',
								timeout: 120000,
								height: 100,
								width: 100,
								hidden: true,
								items: []
							});
ebafe59e   Benjamin Renard   Add the possibili...
272

50098ef1   Menouard AZIB   Disable Next and ...
273
274
275
276
277
278
279
280
281
282
						me.hiddenForm.getForm().submit({
							params: {
								sessionId: sessionID,
								interactiveId: me.interactiveId,
								preview: true
							},
							success: function (form, action) { },
							failure: function (form, action) { }
						});
					}
ebafe59e   Benjamin Renard   Add the possibili...
283
				}
50098ef1   Menouard AZIB   Disable Next and ...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
			]
		});

		var plotPreviewPanelConfig = {
			preventHeader: true,
			autoScroll: false,
			items: [
				this.createPlotImage(configResult.folder, configResult.plotFile)
			],
			dockedItems: me.isPlotFunction ? [mouseToolbar] : [topToolbar, mouseToolbar]
		};

		Ext.apply(this, plotPreviewPanelConfig);
	}
ebafe59e   Benjamin Renard   Add the possibili...
298
});