Blame view

js/app/views/PlotComponents/PlotPreviewUI.js 9.39 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   Menouar AZIB   Disable Next and ...
16
	extend: 'Ext.panel.Panel',
c9071a43   Benjamin Renard   Add instant plot ...
17

50098ef1   Menouar 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   Menouar AZIB   Disable Next and ...
24
25
26
	],

	isPlotFunction: false,
d7558ac5   Menouar AZIB   Fix: when you run...
27
	disableDownloadingData:false,
50098ef1   Menouar AZIB   Disable Next and ...
28
29
30
31
32
33
	panelImage: null,
	crtContext: null,
	sliderPage: null,
	contextualMenu: null,
	hiddenForm: null,
	panelResultInstance: null,
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
34
35
36
37
	gotoDateGroup: null,
	downloadDataBtn: null,
	folder: null,
	plotFile: null,
c9071a43   Benjamin Renard   Add instant plot ...
38

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

	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...
65
66
67
68
69
70
71
72
73
74
75
76
	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   Menouar AZIB   Disable Next and ...
77
78
79
	createPlotImage: function (resultFolder, plotFile) {
		var me = this;
		var size = this.getImageSize();
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
80
81
		this.folder = resultFolder;
		this.plotFile = plotFile;
50098ef1   Menouar AZIB   Disable Next and ...
82
83
84
85
		this.panelImage = Ext.create('amdaPlotComp.PlotResultImage', {
			src: this.getImageUrl(resultFolder, plotFile),
			width: size.width,
			height: size.height,
a81112fb   Erdogan Furkan   #9980 - Coordinat...
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
			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   Menouar AZIB   Disable Next and ...
142
143
144
145
			onContextMenu: function (absoluteX, absoluteY, imageX, imageY) {
				me.contextualMenu.showAt(absoluteX, absoluteY);
			}
		});
c9071a43   Benjamin Renard   Add instant plot ...
146

50098ef1   Menouar AZIB   Disable Next and ...
147
148
149
150
151
		return this.panelImage;
	},

	updatePlotImage: function (configResult, newPlot) {
		this.crtContext = configResult.context;
d7558ac5   Menouar AZIB   Fix: when you run...
152
		this.isPlotFunction = configResult.plotFile.includes("plotFunction") || configResult.plotFile.includes("histoPlot");
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
153
154
155
156
		this.interactiveId = configResult.interactiveId;
		this.panelId = configResult.panelId;
		this.folder = configResult.folder;
		this.plotFile = configResult.plotFile;
c9071a43   Benjamin Renard   Add instant plot ...
157

6e1e1bf4   Benjamin Renard   Fix some bugs wit...
158
159
160
161

		this.panelImage.setSrc(this.getImageUrl(this.folder, configResult.plotFile));
		this.time = new Date(configResult.time);
		this.time = Ext.Date.add(this.time, Ext.Date.MINUTE, this.time.getTimezoneOffset());
679ab391   Menouar AZIB   is isPlotFunction...
162
		if (!this.isPlotFunction)
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
163
			Ext.getCmp('plotPreview-goto-Date').setValue(this.time);
50098ef1   Menouar AZIB   Disable Next and ...
164
165
166
		var size = this.getImageSize();
		this.panelImage.setSize(size.width, size.height);

6e1e1bf4   Benjamin Renard   Fix some bugs wit...
167
168
		this.gotoDateGroup.setVisible(!this.isPlotFunction);

50098ef1   Menouar AZIB   Disable Next and ...
169
170
171
172
173
		this.panelImage.refreshMe();
	},

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

50098ef1   Menouar AZIB   Disable Next and ...
175
176
		this.crtContext = configResult.context;
		this.interactiveId = configResult.interactiveId;
3afa41ee   Erdogan Furkan   #10663 - Fixed bug
177
178
		this.time = new Date(configResult.time);
		this.time = Ext.Date.add(this.time, Ext.Date.MINUTE, this.time.getTimezoneOffset());
50098ef1   Menouar AZIB   Disable Next and ...
179
		this.panelId = configResult.panelId;
8686a026   Menouar AZIB   Disable actions l...
180
181
		//Solution temporaire
		this.isPlotFunction = configResult.plotFile.includes("plotFunction") || configResult.plotFile.includes("histoPlot");
1bc6ba4d   Menouar AZIB   Disable downloadi...
182
		this.disableDownloadingData = configResult.plotFile.includes("histoPlot");
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
183
		this.plotFile = configResult.plotFile;
50098ef1   Menouar AZIB   Disable Next and ...
184

a81112fb   Erdogan Furkan   #9980 - Coordinat...
185
186
187
188
189
		this.coordinatesField = new Ext.toolbar.TextItem({
			width: 300,
			text: ''
		});

50098ef1   Menouar AZIB   Disable Next and ...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
		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();
				}
			}
		});
f1405d82   Menouar AZIB   Add Button Downlo...
208

6e1e1bf4   Benjamin Renard   Fix some bugs wit...
209
210
211
212
		this.gotoDateGroup = new Ext.container.ButtonGroup({
			columns: 4,
			hidden: this.isPlotFunction,
			items: [
f1405d82   Menouar AZIB   Add Button Downlo...
213
214
215
216
				{
					xtype: 'datefield',
					allowBlank: true,
					format: 'Y-m-d\\TH:i:s.u',
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
217
					id: 'plotPreview-goto-Date',
f1405d82   Menouar AZIB   Add Button Downlo...
218
219
220
221
222
223
224
225
226
					value: this.time,
					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');
							}
a0db7984   Erdogan Furkan   #10663 - Done
227
						} else {
f1405d82   Menouar AZIB   Add Button Downlo...
228
							return value;
a0db7984   Erdogan Furkan   #10663 - Done
229
						}
a0db7984   Erdogan Furkan   #10663 - Done
230
					}
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
231
				}, 
f1405d82   Menouar AZIB   Add Button Downlo...
232
				{
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
233
					xtype: 'button',
f1405d82   Menouar AZIB   Add Button Downlo...
234
235
236
					text: 'Change cut time',
					scope: this,
					handler: function (bt) {
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
237
						var newTime = Ext.getCmp('plotPreview-goto-Date').getValue();
f1405d82   Menouar AZIB   Add Button Downlo...
238
239
240
241
						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() });
					}
				},
f1405d82   Menouar AZIB   Add Button Downlo...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
				{
					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
257
				}
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
258
259
			],
		});
f1405d82   Menouar AZIB   Add Button Downlo...
260

6e1e1bf4   Benjamin Renard   Fix some bugs wit...
261
262
263
264
265
266
267
268
269
		this.downloadDataBtn = new Ext.button.Button({
			xtype: 'button',
			text: 'Download Data',
			handler: function () {
				var path = me.getImageUrl(me.folder, me.plotFile.replace(".png", ""));
				path += "_data.txt";
				window.open(path, "_blank");
			}
		});
f1405d82   Menouar AZIB   Add Button Downlo...
270
271
272
273
274

		var topToolbar =
		{
			xtype: 'toolbar',
			dock: 'top',
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
275
276
			items: [
				this.gotoDateGroup,
1bc6ba4d   Menouar AZIB   Disable downloadi...
277
				me.disableDownloadingData ? null: this.downloadDataBtn,
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
278
			]
a0db7984   Erdogan Furkan   #10663 - Done
279
		}
a81112fb   Erdogan Furkan   #9980 - Coordinat...
280
281
282
283
284
285
286
287
288
289
		var mouseToolbar = {
			xtype: 'toolbar',
			height: 25,
			dock: 'bottom',
			items: [
				this.coordinatesField,
				'->',
				this.sliderPage
			]
		};
ebafe59e   Benjamin Renard   Add the possibili...
290

50098ef1   Menouar AZIB   Disable Next and ...
291
292
293
294
		this.contextualMenu = Ext.create('Ext.menu.Menu', {
			width: 200,
			plain: true,
			items: [
ebafe59e   Benjamin Renard   Add the possibili...
295
				{
50098ef1   Menouar AZIB   Disable Next and ...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
					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...
310

50098ef1   Menouar AZIB   Disable Next and ...
311
312
313
314
						me.hiddenForm.getForm().submit({
							params: {
								sessionId: sessionID,
								interactiveId: me.interactiveId,
6e1e1bf4   Benjamin Renard   Fix some bugs wit...
315
316
								preview: true,
								function: me.isPlotFunction
50098ef1   Menouar AZIB   Disable Next and ...
317
318
319
320
321
							},
							success: function (form, action) { },
							failure: function (form, action) { }
						});
					}
ebafe59e   Benjamin Renard   Add the possibili...
322
				}
50098ef1   Menouar AZIB   Disable Next and ...
323
324
325
326
327
328
329
330
331
			]
		});

		var plotPreviewPanelConfig = {
			preventHeader: true,
			autoScroll: false,
			items: [
				this.createPlotImage(configResult.folder, configResult.plotFile)
			],
f1405d82   Menouar AZIB   Add Button Downlo...
332
			dockedItems:[topToolbar, mouseToolbar]
50098ef1   Menouar AZIB   Disable Next and ...
333
334
335
		};

		Ext.apply(this, plotPreviewPanelConfig);
f1405d82   Menouar AZIB   Add Button Downlo...
336
	},
ebafe59e   Benjamin Renard   Add the possibili...
337
});