/** * Project  : AMDA-NG * Name : PlotPanelObject.js * @class amdaPlotObj.PlotPanelObject * @extends Ext.data.Model * @brief Plot Panel Business Object Definition * @author Benjamin Renard * @version $Id: PlotPanelObject.js benjamin $ ****************************************************************************** * FT Id : Date : Name - Description ****************************************************************************** * : :13/08/2015: BRE - file creation */ Ext.define('amdaPlotObj.PlotPanelObject', { extend: 'Ext.data.Model', idProperty: 'id', requires: [ 'amdaPlotObj.PlotObjectConfig', 'amdaPlotObj.PlotAxisObject', 'amdaPlotObj.PlotParamObject', 'amdaPlotObj.PlotLegendSeriesObject', 'amdaPlotObj.PlotLegendTextObject', 'amdaPlotObj.PlotConstantObject', 'amdaPlotObj.PlotTextObject', 'amdaPlotObj.PlotCurveObject', 'amdaPlotObj.PlotFillObject' ], fields : [ {name: 'id', type: 'string'}, {name: 'panel-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'axes-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'params-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'add-objects-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'legends-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'text-legends-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'drawing-objects-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'fills-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set {name: 'panel-index', type: 'int'}, {name: 'panel-background-color', type: 'string'}, {name: 'panel-title-text', type: 'string'}, {name: 'panel-title-color', type: 'string'}, {name: 'panel-title-position', type: 'string'}, {name: 'panel-title-alignment', type: 'string'}, {name: 'panel-title-font-activated', type: 'boolean'}, {name: 'panel-title-font-name', type: 'string'}, {name: 'panel-title-font-size', type: 'int'}, {name: 'panel-title-font-bold', type: 'boolean'}, {name: 'panel-title-font-italic', type: 'boolean'}, {name: 'panel-plot-type', type: 'string'}, {name: 'panel-font-activated', type: 'boolean'}, {name: 'panel-font-name', type: 'string'}, {name: 'panel-font-size', type: 'int'}, {name: 'panel-font-bold', type: 'boolean'}, {name: 'panel-font-italic', type: 'boolean'}, //Only used with layout Manual {name: 'panel-bounds-x', type: 'float'}, {name: 'panel-bounds-y', type: 'float'}, {name: 'panel-bounds-width', type: 'float'}, {name: 'panel-bounds-height', type: 'float'}, {name: 'panel-margin-left', type: 'float', useNull:true}, {name: 'panel-margin-right', type: 'float', useNull:true}, //Only used with layout Vertical {name: 'panel-prefered-width', type: 'float', useNull:true}, {name: 'panel-prefered-height', type: 'float', useNull:true}, //Only used for xyPlot {name: 'panel-scatter-isotropic', type: 'boolean'}, //Only used for statusPlot and timePlot {name: 'panel-status-position', type: 'string'}, {name: 'panel-status-colormap', type: 'int'}, //Only used for tickPlot and timePlot {name: 'panel-tick-format', type: 'int'}, //Only used for epochPlot {name: 'panel-epoch-centertimeid', type: 'string'}, //Only used for instantPlot {name: 'panel-instant-time', type: 'date', defaultValue:Ext.Date.add(Ext.Date.clearTime(new Date()),Ext.Date.DAY,-1), convert: function(value,rec) { if (!Ext.isDate(value)) { var valueString = new String(value); var date = new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); return date; } return value; } }, //Only used for timePlot, xyPlot, epochPlot and instantPlot {name: 'panel-legend-series', type: 'auto', defaultValue: null}, {name: 'last-param-id', type: 'int', defaultValue:0}, {name: 'last-textlegend-id', type: 'int', defaultValue:0}, {name: 'last-constant-id', type: 'int', defaultValue:0}, {name: 'last-textobj-id', type: 'int', defaultValue:0}, {name: 'last-curve-id', type: 'int', defaultValue:0}, {name: 'last-fill-id', type: 'int', defaultValue:0} ], associations : [ { type : 'hasMany', model : 'amdaPlotObj.PlotAxisObject', name : 'axes' }, { type : 'hasMany', model : 'amdaPlotObj.PlotParamObject', name : 'params' }, { type : 'hasMany', model : 'amdaPlotObj.PlotLegendTextObject', name : 'textLegends' }, { type : 'hasMany', model : 'amdaPlotObj.PlotConstantObject', name : 'constants' }, { type : 'hasMany', model : 'amdaPlotObj.PlotTextObject', name : 'textObjs' }, { type : 'hasMany', model : 'amdaPlotObj.PlotCurveObject', name : 'curves' }, { type : 'hasMany', model : 'amdaPlotObj.PlotFillObject', name : 'fills' }, { type : 'belongsTo', model : 'amdaPlotObj.PlotTabObject' } ], isComponent : false, constructor: function(){ var me = this; me.callParent(arguments); if ((arguments.length > 0) && arguments[0]) { if (arguments[0].axes) me.loadAxes(arguments[0].axes); if (arguments[0].params) me.loadParams(arguments[0].params); if (arguments[0]['text-legends']) me.loadTextLegends(arguments[0]['text-legends']); if (arguments[0].constants) me.loadConstants(arguments[0].constants); if (arguments[0].textObjs) me.loadTextObjs(arguments[0].textObjs); if (arguments[0].curves) me.loadCurves(arguments[0].curves); if (arguments[0].fills) me.loadFills(arguments[0].fills); if (arguments[0]['panel-series-legend']) me.loadSeriesLegend(arguments[0]['panel-series-legend']); } else { //new object, set default fields values me.setDefaultValues(); } this.dirty = false; }, loadAxes: function(axes) { this.axes().loadData(axes); }, loadParams: function(params) { /* Compatability mode */ Ext.each(params, function(param, index) { if (param.hasOwnProperty('is-init')) { return; } params[index]['dim1-sum-type'] = param['dim1-is-range'] ? 1 : 0; params[index]['dim1-min-value'] = param['dim1-min-range']; params[index]['dim1-max-value'] = param['dim1-max-range']; params[index]['dim2-sum-type'] = param['dim2-is-range'] ? 1 : 0; params[index]['dim2-min-value'] = param['dim2-min-range']; params[index]['dim2-max-value'] = param['dim2-max-range']; params[index]['is-init'] = true; }); this.params().loadData(params); }, loadTextLegends: function(textLegends) { this.textLegends().loadData(textLegends); }, loadConstants: function(constants) { this.constants().loadData(constants); }, loadTextObjs: function(textObjs) { this.textObjs().loadData(textObjs); }, loadCurves: function(curves) { this.curves().loadData(curves); }, loadFills: function(fills) { this.fills().loadData(fills); }, loadSeriesLegend: function(seriesLegend) { this.set('panel-legend-series', new amdaPlotObj.PlotLegendSeriesObject(seriesLegend)); this.get('panel-legend-series').dirty = false; }, initAxes : function() { this.axes().removeAll(); switch (this.get('panel-plot-type')) { case 'timePlot' : //Time axis var recs = this.axes().add({id : 'time'}); recs[0].setDefaultValues('time'); //Y Left Axis recs = this.axes().add({id : 'y-left'}); recs[0].setDefaultValues('y-left'); //Y Right Axis recs = this.axes().add({id : 'y-right'}); recs[0].setDefaultValues('y-right'); //Color Axis recs = this.axes().add({id : 'color'}); recs[0].setDefaultValues('color'); break; case 'xyPlot' : //X Axis var recs = this.axes().add({id : 'xaxis_id'}); recs[0].setDefaultValues('x'); //Y Left Axis recs = this.axes().add({id : 'y-left'}); recs[0].setDefaultValues('y-left'); //Y Right Axis recs = this.axes().add({id : 'y-right'}); recs[0].setDefaultValues('y-right'); //Color Axis recs = this.axes().add({id : 'color'}); recs[0].setDefaultValues('color'); break; case 'instantPlot' : //X Axis var recs = this.axes().add({id : 'xaxis_id'}); recs[0].setDefaultValues('x'); //Y Left Axis recs = this.axes().add({id : 'y-left'}); recs[0].setDefaultValues('y-left'); //Color Axis recs = this.axes().add({id : 'color'}); recs[0].setDefaultValues('color'); break; case 'epochPlot' : //Epoch Axis var recs = this.axes().add({id : 'epoch'}); recs[0].setDefaultValues('epoch'); //Y Left Axis recs = this.axes().add({id : 'y-left'}); recs[0].setDefaultValues('y-left'); //Y Right Axis recs = this.axes().add({id : 'y-right'}); recs[0].setDefaultValues('y-right'); //Color Axis recs = this.axes().add({id : 'color'}); recs[0].setDefaultValues('color'); break; case 'statusPlot' : case 'tickPlot' : //Time axis var recs = this.axes().add({id : 'time'}); recs[0].setDefaultValues('time'); break; } }, createNewParam: function(paramId, data, onAfterCreate) { var isPlotOnly = (typeof data !== "undefined") && (typeof data.plotOnly !== "undefined") && data.plotOnly; var isTTCat = (typeof data !== "undefined") && (typeof data.isTTCat !== "undefined") && data.isTTCat; var isVector = (typeof data !== "undefined") && (typeof data.isVector !== "undefined") && data.isVector; var components = (typeof data !== "undefined") && (typeof data.components !== "undefined") && data.components ? data.components : null; this.set('last-param-id', this.get('last-param-id') + 1); var emptyPanel = (this.params().getCount() == 0); var obj = amdaModel.RequestParamObject.getEmptyObj(); obj['id'] = this.get('last-param-id'); var recs = this.params().add(obj); recs[0].set('paramid', paramId); recs[0].set('plotonly', isPlotOnly); if (components != null) { if (components['index1']) { this.isComponent = true; recs[0].set('dim1-index', components['index1']); } if (components['index2']) { recs[0].set('dim2-index', components['index2']); } } recs[0].set('param-type', isTTCat ? 'ttcat' : 'param'); if (isTTCat) { recs[0].set('param-ttcat-name', data.name); } // activate legend if vector & TimePlot if ( isVector && this.get('panel-plot-type') == 'timePlot' ) { this.loadSeriesLegend(); this.get('panel-legend-series').set('legend-series-activated',true); } var me = this; amdaPlotObj.PlotObjectConfig.getParamConfig(paramId, function (success, data) { var availableDrawingObjects = null; //Change type only if the panel is empty! if (success) { if (emptyPanel && !me.isComponent) me.changePlotType(data.panel.plotType); if (data.draw && !me.isComponent) { availableDrawingObjects = recs[0].getAvailableDrawingObjectByPlotType(me.get('panel-plot-type')); Ext.each(availableDrawingObjects, function (drawingObj) { if (drawingObj.key == data.draw.type) { availableDrawingObjects = [{'key' : data.draw.type}]; } }); } } if (!availableDrawingObjects) availableDrawingObjects = recs[0].getAvailableDrawingObjectByPlotType(me.get('panel-plot-type')); recs[0].changeDrawingType(availableDrawingObjects[0].key, data ? data.draw : null); if (success && emptyPanel) { if (data.additionalObjects && data.additionalObjects.curves) { Ext.each(data.additionalObjects.curves, function (curveData) { var newCurve = me.createNewCurve(); newCurve.loadFromData(curveData,recs[0].getId()); }); } //Axes if (data.draw && data.draw.axes) { Ext.Object.each(data.draw.axes, function (axisKey, axisData) { var axis = me.axes().getById(axisKey); if (axis) { Ext.Object.each(axisData, function (optKey, optData) { axis.set(optKey, optData); }); } }); } } me.dirty = true; onAfterCreate(recs[0]); }); }, removeParamById: function(paramId) { //Retrieve param record var paramRecord = this.params().getById(paramId); if (paramRecord == null) return false; this.params().remove(paramRecord); this.dirty = true; var curvesToRemove = []; this.curves().each(function(curve) { if (curve.get('curve-serie-id') == paramId) { curvesToRemove.push(curve); } }); this.curves().remove(curvesToRemove); return true; }, createNewTextLegend: function() { this.set('last-textlegend-id', this.get('last-textlegend-id') + 1); var recs = this.textLegends().add({id : this.get('last-textlegend-id')}); recs[0].setDefaultValues(); this.dirty = true; return recs[0]; }, removeTextLegendById: function(legendId) { //Retrieve text legend record var textLegendRecord = this.textLegends().getById(legendId); if (textLegendRecord == null) return false; this.textLegends().remove(textLegendRecord); this.dirty = true; return true; }, createNewConstant: function() { this.set('last-constant-id', this.get('last-constant-id') + 1); var recs = this.constants().add({id : this.get('last-constant-id')}); recs[0].setDefaultValues(); this.dirty = true; return recs[0]; }, removeConstantById: function(constantId) { //Retrieve constant record var constantRecord = this.constants().getById(constantId); if (constantRecord == null) return false; this.constants().remove(constantRecord); this.dirty = true; return true; }, createNewTextObject: function() { this.set('last-textobj-id', this.get('last-textobj-id') + 1); var recs = this.textObjs().add({id : this.get('last-textobj-id')}); recs[0].setDefaultValues(); this.dirty = true; return recs[0]; }, removeTextObjectById: function(textObjId) { //Retrieve text object record var textObjRecord = this.textObjs().getById(textObjId); if (textObjRecord == null) return false; this.textObjs().remove(textObjRecord); this.dirty = true; return true; }, createNewCurve: function() { this.set('last-curve-id', this.get('last-curve-id') + 1); var recs = this.curves().add({id : this.get('last-curve-id')}); recs[0].setDefaultValues(); this.dirty = true; return recs[0]; }, removeCurveById: function(curveId) { //Retrieve curve record var curveRecord = this.curves().getById(curveId); if (curveRecord == null) return false; this.curves().remove(curveRecord); this.dirty = true; return true; }, createNewFill: function() { this.set('last-fill-id', this.get('last-fill-id') + 1); var recs = this.fills().add({id : this.get('last-fill-id')}); recs[0].setDefaultValues(); this.dirty = true; return recs[0]; }, removeFillById: function(fillId) { //Retrieve fill record var fillRecord = this.fills().getById(fillId); if (fillRecord == null) return false; this.fills().remove(fillRecord); this.dirty = true; return true; }, changePlotType: function(plotType) { if (plotType == this.get('panel-plot-type')) return; this.set('panel-plot-type', plotType); this.params().each(function (param, index) { var availableDrawingObjects = param.getAvailableDrawingObjectByPlotType(plotType); var compatibleDrawingType = false; Ext.each(availableDrawingObjects, function (item, index) { if (param.get('param-drawing-type') == item.key) { compatibleDrawingType = true; } }); if (!compatibleDrawingType) { param.changeDrawingType(availableDrawingObjects[0].key); } }); this.initAxes(); if ((plotType == 'timePlot') || (plotType == 'xyPlot') || (plotType == 'epochPlot') || (plotType == 'instantPlot')) { if (this.get('panel-legend-series') == null) { this.set('panel-legend-series', new amdaPlotObj.PlotLegendSeriesObject()); } } else { this.set('panel-legend-series', null); this.textLegends().removeAll(); } if ((plotType == 'tickPlot') || (plotType == 'statusPlot')) { this.textObjs().removeAll(); this.constants().removeAll(); this.curves().removeAll(); this.fills().removeAll(); } else if (plotType != 'xyPlot') this.curves().removeAll(); }, setDefaultValues: function() { this.set('panel-background-color', amdaPlotObj.PlotObjectConfig.defaultValues.panel.backgroundColor); this.set('panel-title-text', ''); this.set('panel-title-color', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.color); this.set('panel-title-position', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.position); this.set('panel-title-alignment', amdaPlotObj.PlotObjectConfig.defaultValues.panel.title.alignment); this.set('panel-title-font-activated', false); this.set('panel-title-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.name); this.set('panel-title-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.size); this.set('panel-title-font-bold', false); this.set('panel-title-font-italic', false); this.set('panel-font-activated', false); this.set('panel-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.name); this.set('panel-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.panel.font.size); this.set('panel-font-bold', false); this.set('panel-font-italic', false); this.set('panel-bounds-x', 0); this.set('panel-bounds-y', 0); this.set('panel-bounds-width', 1); this.set('panel-bounds-height', 1); this.set('panel-margin-left', null); this.set('panel-margin-right', null); this.set('panel-prefered-width', null); this.set('panel-prefered-height', null); this.set('panel-scatter-isotropic', amdaPlotObj.PlotObjectConfig.defaultValues.panel.isotropic); this.set('panel-status-position', amdaPlotObj.PlotObjectConfig.defaultValues.panel.status.position); this.set('panel-status-colormap', amdaPlotObj.PlotObjectConfig.defaultValues.panel.status.colorMap); this.set('panel-tick-format', ""); this.set('panel-epoch-centertimeid', ""); this.changePlotType(amdaPlotObj.PlotObjectConfig.defaultValues.panel.plotType); }, getPanelShortInfo : function() { var type = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availablePlotTypes, this.get('panel-plot-type')); var info = '#'+this.get('panel-index')+', '+type; switch (this.get('panel-plot-type')) { case 'instantPlot' : info += (', '+Ext.Date.format(this.get('panel-instant-time'), "Y/m/d H:i:s")); break; case 'epochPlot' : info += (', '+this.get('panel-epoch-centertimeid')); break; case 'xyPlot' : if (this.get('panel-scatter-isotropic')) info += ', Isotropic'; break; } return info; }, isDirty : function() { if (this.dirty) return true; var d = false; this.axes().each(function (axe, index) { if (axe.isDirty()) d = true; }); if (d) return d; this.params().each(function (param, index) { if (param.isDirty()) d = true; }); if (d) return d; this.textLegends().each(function (text, index) { if (text.dirty) d = true; }); if (d) return d; this.constants().each(function (constant, index) { if (constant.dirty) d = true; }); if (d) return d; this.textObjs().each(function (textObj, index) { if (textObj.dirty) d = true; }); if (d) return d; this.curves().each(function (curve, index) { if (curve.isDirty()) d = true; }); if (d) return d; this.fills().each(function (fill, index) { if (fill.dirty) d = true; }); if (d) return d; if (this.get('panel-legend-series') != null) if (this.get('panel-legend-series').dirty) return true; return false; }, getJsonValues : function() { var panelValues = new Object(); panelValues['id'] = this.get('id'); panelValues['panel-node-state'] = this.get('panel-node-state'); panelValues['axes-node-state'] = this.get('axes-node-state'); panelValues['params-node-state'] = this.get('params-node-state'); panelValues['add-objects-node-state'] = this.get('add-objects-node-state'); panelValues['legends-node-state'] = this.get('legends-node-state'); panelValues['text-legends-node-state'] = this.get('text-legends-node-state'); panelValues['drawing-objects-node-state'] = this.get('drawing-objects-node-state'); panelValues['fills-node-state'] = this.get('fills-node-state'); panelValues['panel-index'] = this.get('panel-index'); panelValues['panel-background-color'] = this.get('panel-background-color'); panelValues['panel-title-text'] = this.get('panel-title-text'); panelValues['panel-title-color'] = this.get('panel-title-color'); panelValues['panel-title-position'] = this.get('panel-title-position'); panelValues['panel-title-alignment'] = this.get('panel-title-alignment'); panelValues['panel-title-font-activated'] = this.get('panel-title-font-activated'); panelValues['panel-title-font-name'] = this.get('panel-title-font-name'); panelValues['panel-title-font-size'] = this.get('panel-title-font-size'); panelValues['panel-title-font-bold'] = this.get('panel-title-font-bold'); panelValues['panel-title-font-italic'] = this.get('panel-title-font-italic'); panelValues['panel-plot-type'] = this.get('panel-plot-type'); panelValues['panel-font-activated'] = this.get('panel-font-activated'); panelValues['panel-font-name'] = this.get('panel-font-name'); panelValues['panel-font-size'] = this.get('panel-font-size'); panelValues['panel-font-bold'] = this.get('panel-font-bold'); panelValues['panel-font-italic'] = this.get('panel-font-italic'); panelValues['panel-bounds-x'] = this.get('panel-bounds-x'); panelValues['panel-bounds-y'] = this.get('panel-bounds-y'); panelValues['panel-bounds-width'] = this.get('panel-bounds-width'); panelValues['panel-bounds-height'] = this.get('panel-bounds-height'); panelValues['panel-margin-left'] = this.get('panel-margin-left') ? this.get('panel-margin-left') : -1; panelValues['panel-margin-right'] = this.get('panel-margin-right') ? this.get('panel-margin-right') : -1; panelValues['panel-prefered-width'] = this.get('panel-prefered-width') ? this.get('panel-prefered-width') : -1; panelValues['panel-prefered-height'] = this.get('panel-prefered-height') ? this.get('panel-prefered-height') : -1; if (this.get('panel-plot-type') == 'xyPlot') panelValues['panel-scatter-isotropic'] = this.get('panel-scatter-isotropic'); if ((this.get('panel-plot-type') == 'statusPlot') || (this.get('panel-plot-type') == 'timePlot')) { panelValues['panel-status-position'] = this.get('panel-status-position'); panelValues['panel-status-colormap'] = this.get('panel-status-colormap'); } if ((this.get('panel-plot-type') == 'tickPlot') || (this.get('panel-plot-type') == 'timePlot')) { panelValues['panel-tick-format'] = this.get('panel-tick-format'); } if (this.get('panel-plot-type') == 'epochPlot') panelValues['panel-epoch-centertimeid'] = this.get('panel-epoch-centertimeid'); if (this.get('panel-plot-type') == 'instantPlot') panelValues['panel-instant-time'] = this.get('panel-instant-time'); if (this.get('panel-legend-series') != null) panelValues['panel-series-legend'] = this.get('panel-legend-series').getJsonValues(); panelValues['text-legends'] = []; this.textLegends().each(function (legend, index) { panelValues['text-legends'][index] = legend.getJsonValues(); }); panelValues['constants'] = []; this.constants().each(function (constant, index) { panelValues['constants'][index] = constant.getJsonValues(); }); panelValues['textObjs'] = []; this.textObjs().each(function (textObj, index) { panelValues['textObjs'][index] = textObj.getJsonValues(); }); panelValues['curves'] = []; this.curves().each(function (curve, index) { panelValues['curves'][index] = curve.getJsonValues(); }); panelValues['fills'] = []; this.fills().each(function (fill, index) { panelValues['fills'][index] = fill.getJsonValues(); }); panelValues['axes'] = []; this.axes().each(function (axe, index) { panelValues['axes'][index] = axe.getJsonValues(); }); panelValues['params'] = []; this.params().each(function (param, index) { panelValues['params'][index] = param.getJsonValues(); }); panelValues['last-param-id'] = this.get('last-param-id'); panelValues['last-textlegend-id'] = this.get('last-textlegend-id'); panelValues['last-constant-id'] = this.get('last-constant-id'); panelValues['last-textobj-id'] = this.get('last-textobj-id'); panelValues['last-curve-id'] = this.get('last-curve-id'); panelValues['last-fill-id'] = this.get('last-fill-id'); return panelValues; } });