PlotContextManager.js 3.85 KB
/**
 * 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;
	},

	getIntervalCoordInfo: function (context, panel, crtTimestamp) {
		var intervalName = new Array();
		var intervalId = new Array();
		var intervalText = "";
		Ext.each(panel.intervals, function (interval) {
			if (crtTimestamp > interval.startTime && crtTimestamp < interval.stopTime) {
				intervalName.push(interval.name);
				intervalId.push(interval.id);
			}
			return;
		});
		if (intervalName.length > 0) {
			intervalText = 'TT: ' + intervalName[0] + ', id: [' + intervalId[0];
			for (i = 1; i < intervalName.length; i++) {
				if (intervalName[i] == intervalName[i - 1]) {
					intervalText += ', ' + intervalId[i];
				}
				else {
					intervalText += '] | TT: ' + intervalName[i] + ', id: [' + intervalId[i];
				}
			}
			intervalText += ']'
		}
		return intervalText;
	},

	getAllIntervalParams(context, panel, crtTimestamp) {
		var allParams = new Array();

		Ext.each(panel.intervals, function (interval) {
			if (crtTimestamp > interval.startTime && crtTimestamp < interval.stopTime && interval.params != "") {
				allParams.push(interval.params);
			}
			return;

		});
		return allParams;
	},

	getIntervalLinks(allintervalParams) {
		var links = new Array();
		Ext.each(allintervalParams, function (allParams) {

			var params = allParams.split('|');

			Ext.each(params, function (param) {
				if (param.toLowerCase().startsWith("http://") || param.toLowerCase().startsWith("https://")) {
					links.push(param);
				}
				return;
			});
			return;
		});
		return links;
	},

	isInterval: function (context, panel, crtTimestamp) {
		isInterval = false;
		Ext.each(panel.intervals, function (interval) {
			if (crtTimestamp > interval.startTime && crtTimestamp < interval.stopTime) {
				isInterval = true;
			}
			return;
		});
		return isInterval;
	},


	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);
	}
});