/** * Project  : AMDA-NG * Name : PlotZoomPlug.js * @plugin amdaPlotComp.PlotZoomPlug * @extends Ext.util.Observable * @ptype plotZoomPlugin * @brief Plot Zoom UI (View) * @author Benjamin * @version $Id: PlotZoomPlug.js ******************************************************************************** * FT Id : Date : Name - Description ******************************************************************************* * : */ Ext.define('amdaPlotComp.PlotZoomPlug', { extend: 'Ext.util.Observable', alias: 'plugin.plotZoomPlugin', id: 'plot-zoom-plug', ttModuleId: 'timetab-win', catModuleId: 'catalog-win', win: null, form: null, zoomType: '', interactiveId: '', panelId: -1, linkedTTCatNode: null, constructor: function (config) { Ext.apply(this, config); this.callParent(arguments); }, onDestroy: function () { this.win = null; }, init: function (cmp) { this.hostCmp = cmp; }, setMinValue: function (min) { if (!this.form) return; if (this.zoomType == 'timeAxis') this.form.getForm().findField('zoom-min-time').setValue(min); else this.form.getForm().findField('zoom-min-float').setValue(min); }, setMaxValue: function (max) { if (!this.form) return; if (this.zoomType == 'timeAxis') { var minValue = this.form.getForm().findField('zoom-min-time').getValue(); if (minValue <= max) this.form.getForm().findField('zoom-max-time').setValue(max); else { this.form.getForm().findField('zoom-min-time').setValue(max); this.form.getForm().findField('zoom-max-time').setValue(minValue); } } else { var minValue = this.form.getForm().findField('zoom-min-float').getValue(); if (minValue <= max) this.form.getForm().findField('zoom-max-float').setValue(max); else { this.form.getForm().findField('zoom-min-float').setValue(max); this.form.getForm().findField('zoom-max-float').setValue(minValue); } } }, /** * add Interval to Time table **/ insertInterval: function () { if (this.zoomType != 'timeAxis') return; var start = this.form.getForm().findField('zoom-min-time').getValue(); var stop = this.form.getForm().findField('zoom-max-time').getValue(); var TTCatType = this.form.getForm().findField('ttcat-type').getValue(); var isCatalog = (TTCatType == 'catalog'); myDesktopApp.getLoadedModule(isCatalog ? this.catModuleId : this.ttModuleId, true, function (module) { var targetModuleUI = module.getUiContent(); if (targetModuleUI) targetModuleUI.addInterval(start, stop); }); }, /** * creation of the window */ show: function (interactiveId, zoomType, panelId, isPlotFunction_ = false) { this.isPlotFunction = isPlotFunction_; if (!this.win) { this.win = new Ext.Window({ id: 'plot-zoom-win-' + this.hostCmp.ownerCt.getId(), // Plot window ID width: 250, x: 0, y: 0, baseCls: 'x-panel', title: 'Zoom', constrain: true, collapsible: true, resizable: false, ghost: false, renderTo: this.hostCmp.ownerCt.body, items: this.getFormConfig(), listeners: { scope: this, beforeclose: function () { this.hostCmp.panelImage.stopZoom(); Ext.PluginManager.unregister(this); } }, getConstrainVector: function (constrainTo) { var me = this; if (me.constrain || me.constrainHeader) { constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent(); return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo); } } }); this.win.on('destroy', this.onDestroy, this); Ext.PluginManager.register(this); } this.interactiveId = interactiveId; this.updateWinByType(zoomType, panelId); this.win.show(); this.win.setPosition(0, 0); }, close: function () { if (this.win == null) return; this.win.close(); }, updateWinByType: function (zoomType, panelId) { if (this.win == null) return; this.zoomType = zoomType; this.panelId = panelId; switch (zoomType) { case 'timeAxis': this.win.setTitle('Zoom on time axis'); break; case 'y-left': this.win.setTitle('Zoom on Y Left axis - Panel Id : ' + panelId); break; case 'y-right': this.win.setTitle('Zoom on Y Right axis - Panel Id : ' + panelId); break; case 'xaxis_id': this.win.setTitle('Zoom on X axis - Panel Id : ' + panelId); break; } this.form.getForm().findField('zoom-min-time').setVisible(this.zoomType == 'timeAxis'); this.form.getForm().findField('zoom-max-time').setVisible(this.zoomType == 'timeAxis'); this.form.getForm().findField('zoom-min-float').setVisible(this.zoomType != 'timeAxis'); this.form.getForm().findField('zoom-max-float').setVisible(this.zoomType != 'timeAxis'); var ttCatNameField = this.form.getForm().findField('ttcat-name'); if (ttCatNameField) ttCatNameField.findParentByType('fieldset').setVisible(this.zoomType == 'timeAxis'); }, resetMinMaxValue: function () { if (this.zoomType == 'timeAxis') { this.form.getForm().findField('zoom-min-time').setValue(''); this.form.getForm().findField('zoom-max-time').setValue(''); } else { this.form.getForm().findField('zoom-min-float').setValue(null); this.form.getForm().findField('zoom-max-float').setValue(null); } this.hostCmp.panelImage.resetZoom(); }, setTimePlot: function () { var timeObj = new Object(); timeObj.start = this.form.getForm().findField('zoom-min-time').getValue(); timeObj.stop = this.form.getForm().findField('zoom-max-time').getValue(); var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id); plotModule.setTimeInterval(timeObj); }, /** * Main form */ getFormConfig: function () { var intervalFieldSet = { xtype: 'fieldset', title: 'Interval Selection', name: 'interval-selection-fieldset', collapsible: false, layout: { type: 'vbox', pack: 'start', align: 'stretch' }, items: [ { xtype: 'datefield', name: 'zoom-min-time', fieldLabel: 'Start Time', format: 'Y/m/d H:i:s.u', }, { xtype: 'datefield', name: 'zoom-max-time', fieldLabel: 'Stop Time', format: 'Y/m/d H:i:s.u' }, { xtype: 'numberfield', name: 'zoom-min-float', fieldLabel: 'Min Value' }, { xtype: 'numberfield', name: 'zoom-max-float', fieldLabel: 'Max Value' }, { xtype: 'button', width: 100, text: 'Reset', scope: this, handler: function () { this.resetMinMaxValue(); } }, { xtype: 'button', width: 100, text: 'Use in Time Selection', scope: this, handler: function () { this.setTimePlot(); } } ] }; var insertTypeStore = Ext.create('Ext.data.Store', { fields: ['key', 'name'], data: [ { "key": "timeTable", "name": "TimeTable" }, { "key": "catalog", "name": "Catalog" } ] }); var me = this; var insertTTFieldSet = { xtype: 'fieldset', title: 'Add in Time Table or Catalog', name: 'tt-insertion-fieldset', collapsible: false, layout: { type: 'vbox', pack: 'start', align: 'stretch' }, items: [ { xtype: 'combo', fieldLabel: 'Insert In', store: insertTypeStore, queryMode: 'local', displayField: 'name', valueField: 'key', editable: false, value: 'timeTable', name: 'ttcat-type' }, { xtype: 'textfield', fieldLabel: 'Name', name: 'ttcat-name', listeners: { render: function (o, op) { var field = this; var el = this.el; var dropTarget = Ext.create('Ext.dd.DropTarget', el, { ddGroup: 'explorerTree', notifyOver: function (ddSource, e, data) { var TTCatType = me.form.getForm().findField('ttcat-type').getValue(); if (data.records[0].data.leaf && (data.records[0].data.nodeType == TTCatType)) { this.valid = true; return this.dropAllowed; } this.valid = false; return this.dropNotAllowed; }, notifyDrop: function (ddSource, e, data) { if (!this.valid) return false; field.setValue(data.records[0].get('text')); return true; } }); } } }, { xtype: 'button', width: 100, text: 'Insert Interval', scope: this, handler: function () { var me = this; var TTCatType = this.form.getForm().findField('ttcat-type').getValue(); var TTCatName = this.form.getForm().findField('ttcat-name').getValue(); var isCatalog = (TTCatType == 'catalog'); myDesktopApp.getLoadedModule(isCatalog ? this.catModuleId : this.ttModuleId, true, function (module) { var targetModuleUI = module.getUiContent(); if (me.linkedTTCatNode && (me.linkedTTCatNode.get('text') == TTCatName) && (me.linkedTTCatNode.get('nodeType') == TTCatType)) { if (targetModuleUI) me.insertInterval(); else { me.linkedTTCatNode.editLeaf(function () { me.insertInterval(); }); } } else { var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); var ttCatRootNode = explorerTree.getRootNode().findChild('id', isCatalog ? 'catalog-treeRootNode' : 'timeTable-treeRootNode', true); amdaModel.InteractiveNode.preloadNodes(ttCatRootNode, function () { var nodeWithSameName = null; if (TTCatName != '') nodeWithSameName = ttCatRootNode.findChild('text', TTCatName, true); if (nodeWithSameName !== null) me.linkedTTCatNode = nodeWithSameName; else { module.createLinkedNode(); module.getLinkedNode().set('text', TTCatName); me.linkedTTCatNode = module.getLinkedNode(); var obj = { name: TTCatName, fromPlugin: true }; if (isCatalog) { Ext.Msg.prompt('Define Parameters', 'Please enter parameters number for the new catalog:', function (btn, text) { if (btn == 'ok') { obj.nbParameters = parseInt(text, 10); if (isNaN(obj.nbParameters)) { obj.nbParameters = 1; } module.createObject(obj); me.linkedTTCatNode.editLeaf(function () { me.insertInterval(); }); } }); return; } else { module.createObject(obj); } } me.linkedTTCatNode.editLeaf(function () { me.insertInterval(); }); }); } }); } } ] }; //Ici on rajoute les composants associés à la fonctionnalité 'PlotFunction' const plotFunctionComponents = this.createPlotFunctionComponents(); this.form = new Ext.form.FormPanel({ frame: true, width: 255, layout: { type: 'vbox', pack: 'start', align: 'stretch' }, fieldDefaults: { labelWidth: 60 }, items: [ intervalFieldSet, me.isPlotFunction ? plotFunctionComponents : insertTTFieldSet, ], fbar: [ { text: 'Apply Zoom', width: 100, scope: this, handler: function () { if (this.zoomType == 'timeAxis') { var minZoom = Ext.Date.format(this.form.getForm().findField('zoom-min-time').getValue(), 'Y-m-d H:i:s.u'); var maxZoom = Ext.Date.format(this.form.getForm().findField('zoom-max-time').getValue(), 'Y-m-d H:i:s.u'); } else { var minZoom = this.form.getForm().findField('zoom-min-float').getValue(); var maxZoom = this.form.getForm().findField('zoom-max-float').getValue(); } if (!maxZoom || !minZoom || !this.form.getForm().isValid()) { myDesktopApp.warningMsg('Error in values definition'); return; } this.hostCmp.callInteractivePlot({ 'action': 'zoom', 'interactiveId': this.interactiveId, 'panelId': this.panelId, 'axeId': this.zoomType, 'min': minZoom, 'max': maxZoom }); this.hostCmp.panelImage.resetZoom(); } }, { text: 'Undo Zoom', width: 100, scope: this, handler: function () { this.hostCmp.callInteractivePlot({ 'action': 'undozoom', 'interactiveId': this.interactiveId, 'panelId': this.panelId, 'axeId': this.zoomType }); this.hostCmp.panelImage.resetZoom(); } } ] }); return this.form; }, createPlotFunctionComponents: function () { const key_ = "key"; const name_ = "name"; //Combo to choose a type of fucntion to be applied const data_function_type = []; let item_type = {}; item_type[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.fft; item_type[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.fft; data_function_type.push(item_type); item_type = {}; item_type[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.sum; item_type[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.sum; data_function_type.push(item_type); const function_type = Ext.create('Ext.data.Store', { fields: [key_, name_], data: data_function_type }); //Combo to choose type of scaling const data_ = []; const item_log = {}; item_log[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.log; item_log[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.log; data_.push(item_log); const item_linear = {}; item_linear[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.linear; item_linear[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.linear; data_.push(item_linear); const scale = Ext.create('Ext.data.Store', { fields: [key_, name_], data: data_ }); //Combo to choose x type data of FFT const data__ = []; const item_frequency = {}; item_frequency[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.values.frequency; item_frequency[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.values.frequency; data__.push(item_frequency); const item_period = {}; item_period[key_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.values.period; item_period[name_] = amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.values.period; data__.push(item_period); const abscisse = Ext.create('Ext.data.Store', { fields: [key_, name_], data: data__ }); var me = this; const parameterFieldSet = { xtype: 'fieldset', title: 'Parameter Selection', name: 'parameter-selection-fieldset', collapsible: false, layout: { type: 'vbox', pack: 'start', align: 'stretch', }, items: [ { xtype: 'combo', fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.field, store: function_type, queryMode: 'local', displayField: name_, valueField: key_, editable: false, value: amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.sum, name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.name, listeners: { change: function (combo, value) { if (value === amdaPlotObj.PlotObjectConfig.plotFunctionItems.type.values.sum) { me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.name).setVisible(false); me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.nbEchantillons.name).setVisible(false); me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.fe.name).setVisible(false); } else { me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.name).setVisible(true); me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.nbEchantillons.name).setVisible(true); me.form.getForm().findField(amdaPlotObj.PlotObjectConfig.plotFunctionItems.fe.name).setVisible(true); } } } }, { xtype: 'combo', fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.field, store: scale, queryMode: 'local', displayField: name_, valueField: key_, editable: false, value: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.linear, name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.name }, { xtype: 'combo', fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.field, store: abscisse, queryMode: 'local', displayField: name_, valueField: key_, editable: false, hidden: true, value: amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.values.frequency, name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.abscisse.name }, { xtype: 'combo', fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale_ordonnee.field, store: scale, queryMode: 'local', displayField: name_, valueField: key_, editable: false, value: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale.values.linear, name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.scale_ordonnee.name }, { xtype: 'numberfield', name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.nbEchantillons.name, labelWidth: 140, width: 50, minValue: 1, hidden: true, fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.nbEchantillons.field }, { xtype: 'numberfield', name: amdaPlotObj.PlotObjectConfig.plotFunctionItems.fe.name, labelWidth: 160, width: 30, minValue: 0, disabled: true, hidden: true, fieldLabel: amdaPlotObj.PlotObjectConfig.plotFunctionItems.fe.field } ] }; return parameterFieldSet; } });