ResultDataPlot.js 2.72 KB
Ext.define('treps.controller.Data.Plot.ResultDataPlot', {
	extend: 'Ext.app.Controller',

	requires : [
		'treps.controller.Data.Plot.DataPlotManager'
	],

	views: [
		'Steps.ExportDefinition.ExportDefinitionPanel'
	],

	refs: [
		{
			ref: 'dataPlotPanel',
			selector: 'data_plot'
		},
		{
			ref: 'rangeSlider',
			selector: '#slideRange'
		}
	],

        init: function() {
                var me = this;

		this.control({
			'#nextRange': {
                                click: me.onNextRange,
                                scope: me
                        },
			'#prevRange': {
				click: me.onPrevRange,
				scope: me
			},
			'#slideRange': {
				changecomplete: me.onSlideRange,
				scope: me
			}
		});
        },

	onNextRange: function() {
		var slider = this.getRangeSlider();

		var minRec = treps.controller.Data.Plot.DataPlotManager.nextRange();
		slider.setValue(minRec);
	},

	onPrevRange: function() {
		var slider = this.getRangeSlider();

		var minRec = treps.controller.Data.Plot.DataPlotManager.prevRange();
		slider.setValue(minRec);
	},

	onSlideRange: function(slider, newValue, thumb, eOpts) {
		treps.controller.Data.Plot.DataPlotManager.setMin(newValue);
	},

	reconfigureRangeSlider: function(total)
	{
		var slider = this.getRangeSlider();
		slider.setMinValue(0);
		slider.increment = treps.Constants.PLOT_MAX_POINTS;
		var maxVal = (total - (total%treps.Constants.PLOT_MAX_POINTS));
		slider.setMaxValue(maxVal);
	},

	reconfigureDataPlot: function(srcVectors, resVectors, srcFrame, dstFrame)
	{
		var dataPlotMgr = treps.controller.Data.Plot.DataPlotManager;

		var plotPanel = this.getDataPlotPanel();

		var srcStore = treps.controller.Data.Store.DataStoreManager.getStore('SourceDataStore');

		var resStore = treps.controller.Data.Store.DataStoreManager.getStore('ResultDataStore');

		var useTime = (treps.model.Session.get('sourceTimeFormat') != "");

		dataPlotMgr.reconfigure(plotPanel, treps.Constants.PLOT_MAX_POINTS, srcStore, resStore, srcFrame, dstFrame);

		if ((srcVectors.length > 0) && (srcVectors.length != resVectors.length))
		{
			treps.Messages.showError("Plot data error : Source and result vectors don't have the same length!");
			return;
		}

		this.reconfigureRangeSlider(srcStore.totalCount);

		Ext.each(srcVectors, function(srcVector, index)
			{
				Ext.each(resVectors, function(resVector, index)
					{
						if (srcVector['id'] == resVector['id'])
						{
							dataPlotMgr.addPlot(
								useTime,
								srcVector['id'],
								srcVector['comp_1'], srcVector['comp_2'], srcVector['comp_3'],
								resVector['comp_1'], resVector['comp_2'], resVector['comp_3']);
						}
					});
			});

		if (srcVectors.length == 0)
			plotPanel.body.update("No vector to plot");

		dataPlotMgr.updateRange();
	}
});