PlotContextManager.js
2.12 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Project : AMDA-NG
* Name : PlotContextManager.js
* @class amdaPlotComp.PlotContextManager
* @extends
* @brief Manager to retrieve information about a panel by position on the result image
* @author Benjamin Renard
* @version $Id: PlotContextManager.js benjamin $
*/
Ext.define('amdaPlotComp.PlotContextManager', {
singleton: true,
getPanel : function(context, xPos, yPos)
{
if (!context.success)
return null;
if (xPos < 0 || xPos > context.page.width)
return null;
if (yPos < 0 || yPos > context.page.height)
return null;
var resPanel = null;
Ext.each(context.page.panels, function(panel) {
if ((xPos >= panel.x) && (xPos <= (panel.x+panel.width)) && (yPos >= panel.y) && (yPos <= (panel.y+panel.height)))
{
resPanel = panel;
return;
}
});
return resPanel;
},
getPanelById : function(context, panelId)
{
if (!context.success)
return null;
var resPanel = null;
Ext.each(context.page.panels, function(panel) {
if (panel.id == panelId)
{
resPanel = panel;
return;
}
});
return resPanel;
},
getPanelAxisById : function(panelContext, axisId)
{
if (!panelContext || !panelContext.plotArea)
return null;
var resAxis = null;
Ext.each(panelContext.plotArea.axes, function(axis) {
if (axis.id == axisId)
{
resAxis = axis;
return;
}
});
return resAxis;
},
isInPlotArea : function(panelContext, xPos, yPos)
{
if (!panelContext.plotArea)
return false;
return ((xPos >= panelContext.plotArea.x) && (xPos <= (panelContext.plotArea.x+panelContext.plotArea.width)) &&
(yPos >= panelContext.plotArea.y) && (yPos <= (panelContext.plotArea.y+panelContext.plotArea.height)));
},
toAxisValue : function(axisContext, pixelMin, pixelMax, pixelValue)
{
if (pixelMax == pixelMin)
return NaN;
if (axisContext.logarithmic)
{
var value = axisContext.min + (pixelValue - pixelMin)/(pixelMax - pixelMin)*(axisContext.max-axisContext.min);
return Math.pow(10,value);
}
return axisContext.min + (pixelValue - pixelMin)/(pixelMax - pixelMin)*(axisContext.max-axisContext.min);
}
});