Blame view

js/app/views/PlotTabResultUI.js 6.33 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    
18d4a11e   Benjamin Renard   Save and load plo...
8
 * @version  $Id: PlotTabResultUI.js benjamin $
16035364   Benjamin Renard   First commit
9
10
11
12
13
14
15
16
17
18
19
20
 ********************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *              
 */

Ext.define('amdaUI.PlotTabResultUI', {
    extend: 'Ext.panel.Panel',
 
    alias: 'widget.plotTabResult',

    requires: [
d0b61b72   Benjamin Renard   Show coordinates ...
21
22
        'amdaUI.InteractiveIntervalPlugin',
        'amdaPlotComp.PlotContextManager'
16035364   Benjamin Renard   First commit
23
24
    ],
    
d0b61b72   Benjamin Renard   Show coordinates ...
25
26
    panelImage : null,
    crtContext : null,
18d4a11e   Benjamin Renard   Save and load plo...
27
    
16035364   Benjamin Renard   First commit
28
    constructor: function(config) {
16035364   Benjamin Renard   First commit
29
30
31
32
33
34
        this.addEvents({'pagesize':true});
        
        this.init(config);	 
        this.callParent(arguments);	 
    },  
    
18d4a11e   Benjamin Renard   Save and load plo...
35
    getImageSize : function() {
d0b61b72   Benjamin Renard   Show coordinates ...
36
37
38
39
40
41
42
43
44
    	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.
18d4a11e   Benjamin Renard   Save and load plo...
45
	    } 
16035364   Benjamin Renard   First commit
46
47
    },
    
18d4a11e   Benjamin Renard   Save and load plo...
48
49
    getImageUrl: function(resultFolder, plotFile) {
    	return 'data/'+sessionID +'/RES/'+resultFolder+ '/' + plotFile;
16035364   Benjamin Renard   First commit
50
51
    },
    
d0b61b72   Benjamin Renard   Show coordinates ...
52
53
54
55
56
57
58
59
60
61
    toPixelOnSourceImage : function(value) {
		return value*100/this.sliderPage.getValue();
	},
	
	toPixelOnResultImage : function(value) {
		return value*this.sliderPage.getValue()/100;
	},
	
    createPlotImage: function(resultFolder, plotFile) {
    	var me = this;
18d4a11e   Benjamin Renard   Save and load plo...
62
    	var size = this.getImageSize();
d0b61b72   Benjamin Renard   Show coordinates ...
63
    	this.panelImage = Ext.create('amdaPlotComp.PlotResultImage', {
18d4a11e   Benjamin Renard   Save and load plo...
64
65
66
            src    : this.getImageUrl(resultFolder, plotFile),
            width  : size.width,
            height : size.height,
d0b61b72   Benjamin Renard   Show coordinates ...
67
68
69
70
71
72
73
74
75
76
77
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
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
			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' :
									yLeftText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.y+panel.plotArea.height, panel.plotArea.y, sourceYPos).toPrecision(2));
									break;
								case 'y-right' :
									yRightText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.y+panel.plotArea.height, panel.plotArea.y, sourceYPos).toPrecision(2));
									break;
								case 'xaxis_id' :
									xText = parseFloat(amdaPlotComp.PlotContextManager.toAxisValue(axis, panel.plotArea.x, panel.plotArea.x+panel.plotArea.width, sourceXPos).toPrecision(2));
									break;
								case 'epochAxis' :
									//
									xText = 'ToDo';
									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);
			},
			onClick : function(x, y) {
				//console.log('position : '+me.toPixelOnSourceImage(x)+', '+me.toPixelOnSourceImage(y));
			},
16035364   Benjamin Renard   First commit
145
146
147
        });

        return this.panelImage;
16035364   Benjamin Renard   First commit
148
149
    },
    
18d4a11e   Benjamin Renard   Save and load plo...
150
    updatePlotImage: function(configResult) {
d0b61b72   Benjamin Renard   Show coordinates ...
151
    	this.crtContext = configResult.context;
18d4a11e   Benjamin Renard   Save and load plo...
152
153
154
155
156
157
158
    	
    	this.panelImage.setSrc(this.getImageUrl(configResult.folder, configResult.plotFile));
    	
    	var size = this.getImageSize();
    	this.panelImage.setSize(size.width, size.height);
    	
    	this.panelImage.refreshMe();
16035364   Benjamin Renard   First commit
159
160
    },
    
18d4a11e   Benjamin Renard   Save and load plo...
161
    init: function(configResult){
d0b61b72   Benjamin Renard   Show coordinates ...
162
163
164
165
166
167
    	this.crtContext = configResult.context;
    	
        this.coordinatesField = new Ext.toolbar.TextItem({
            width: 300,
            text : ''
        });
18d4a11e   Benjamin Renard   Save and load plo...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    	
    	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)
                {
        			//ToDo - this.resetMire();
        			var size = this.getImageSize();	 
        			this.panelImage.width  = size.width;
        			this.panelImage.height = size.height;
        			this.panelImage.doComponentLayout();
        			this.fireEvent('pagesize',this,v);
                }
16035364   Benjamin Renard   First commit
188
            }
18d4a11e   Benjamin Renard   Save and load plo...
189
        });
16035364   Benjamin Renard   First commit
190
    	
d0b61b72   Benjamin Renard   Show coordinates ...
191
192
193
194
195
196
197
198
199
200
201
    	var mouseToolbar = {
    		xtype: 'toolbar',
    		height: 25,
            dock: 'bottom',
            items:[
                   this.coordinatesField,
                   this.sliderPage
            ]
    	};
            
    	
18d4a11e   Benjamin Renard   Save and load plo...
202
203
204
205
    	var plotResultTabPanelConfig = {
    			preventHeader : true,
                autoScroll: true,       
                items: [
d0b61b72   Benjamin Renard   Show coordinates ...
206
207
208
                        this.createPlotImage(configResult.folder, configResult.plotFile)
                ],
                dockedItems: [mouseToolbar]
18d4a11e   Benjamin Renard   Save and load plo...
209
210
211
212
213
    	};
            
    	Ext.apply(this , plotResultTabPanelConfig);	
    }
});