Blame view

js/app/views/PlotComponents/PlotZoomPlug.js 11.5 KB
9f08f4eb   Benjamin Renard   Zoom in interacti...
1
/**
b2481b88   Nathanael Jourdane   fix indent
2
3
4
5
6
7
8
9
10
11
12
13
14
 * 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
 *******************************************************************************
 *  :
 */
9f08f4eb   Benjamin Renard   Zoom in interacti...
15
16
17


Ext.define('amdaPlotComp.PlotZoomPlug', {
b2481b88   Nathanael Jourdane   fix indent
18
19
  extend: 'Ext.util.Observable',
  alias: 'plugin.plotZoomPlugin',
9f08f4eb   Benjamin Renard   Zoom in interacti...
20

b2481b88   Nathanael Jourdane   fix indent
21
  id: 'plot-zoom-plug',
9f08f4eb   Benjamin Renard   Zoom in interacti...
22

b2481b88   Nathanael Jourdane   fix indent
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
94
95
96
97
98
99
100
101
102
103
  ttModuleId: 'timetab-win',

  win: null,
  form: null,
  zoomType: '',
  tabId: '',
  panelId: -1,

  linkedTTNode: 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();

    myDesktopApp.getLoadedModule(this.ttModuleId, true, function (module) {
      var targetModuleUI = module.getUiContent();
      if (targetModuleUI)
        targetModuleUI.addInterval(start, stop);
    });
  },

  /**
   *  creation of the window
   */
  show: function (tabId, zoomType, panelId) {
    if (!this.win) {
      this.win = new Ext.Window({
        id: 'plot-zoom-win-' + this.hostCmp.ownerCt.getId(), // Plot window ID
b2481b88   Nathanael Jourdane   fix indent
104
105
106
        x: 0, y: 0,
        baseCls: 'x-panel',
        title: 'Zoom',
b2481b88   Nathanael Jourdane   fix indent
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
        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.tabId = tabId;
    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 & Interval selection - Panel Id : ' + panelId);
        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 ttNameField = this.form.getForm().findField('tt-name');
    if (ttNameField)
      ttNameField.findParentByType('fieldset').setVisible(this.zoomType == 'timeAxis');
b2481b88   Nathanael Jourdane   fix indent
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
  },

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

  /**
   *        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\\TH:i:s'
        },
        {
          xtype: 'datefield', name: 'zoom-max-time', fieldLabel: 'Stop Time',
          format: 'Y-m-d\\TH:i:s'
        },
        {
          xtype: 'numberfield', name: 'zoom-min-float', fieldLabel: 'Min Value'
        },
        {
          xtype: 'numberfield', name: 'zoom-max-float', fieldLabel: 'Max Value'
        },
        {
          xtype: 'button',
          width: 100,
          text: 'Reset interval',
          scope: this,
          handler: function () {
            this.resetMinMaxValue();
          }
        }
      ]
    };

    var insertTTFieldSet = {
      xtype: 'fieldset',
      title: 'TimeTable Insertion',
      name: 'tt-insertion-fieldset',
      collapsible: false,
      layout: {
        type: 'vbox',
        pack: 'start',
        align: 'stretch'
      },
      items: [
        {
          xtype: 'textfield',
          fieldLabel: 'TimeTable Name',
          name: 'tt-name',
          listeners:
            {
              render: function (o, op) {
                var me = this;
                var el = me.el;
                var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                  ddGroup: 'explorerTree',
                  notifyOver: function (ddSource, e, data) {
                    if ((data.records[0].data.nodeType == 'timeTable') && (data.records[0].data.leaf)) {
                      this.valid = true;
                      return this.dropAllowed;
                    }
                    this.valid = false;
                    return this.dropNotAllowed;
                  },
                  notifyDrop: function (ddSource, e, data) {
                    if (!this.valid)
                      return false;
                    me.setValue(data.records[0].get('text'));
                    return true;
                  }
                });
              }
            }
        },
        {
          xtype: 'button',
          width: 100,
          text: 'Insert Interval',
          scope: this,
          handler: function () {
            var me = this;

            var TTname = this.form.getForm().findField('tt-name').getValue();

            myDesktopApp.getLoadedModule(this.ttModuleId, true, function (module) {
              var targetModuleUI = module.getUiContent();
              if (me.linkedTTNode && (me.linkedTTNode.get('text') == TTname)) {
                if (targetModuleUI)
                  me.insertInterval();
                else {
                  me.linkedTTNode.editLeaf(function () {
                    me.insertInterval();
                  });
                }
              }
              else {
                if (TTname == '') {
                  me.linkedTTNode.editLeaf(function () {
                    me.insertInterval();
                  });
                }

                var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
                var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true);
                amdaModel.InteractiveNode.preloadNodes(ttRootNode, function () {
                  var nodeWithSameName = null;

                  if (TTname != '')
                    nodeWithSameName = ttRootNode.findChild('text', TTname, true);

                  if (nodeWithSameName !== null)
                    me.linkedTTNode = nodeWithSameName;
                  else {
                    var obj = Ext.create('amdaModel.TimeTable', {name: TTname, fromPlugin: true});
                    me.linkedTTNode = Ext.create('amdaModel.TimeTableNode', {
                      leaf: true,
                      text: TTname,
                      nodeType: 'timeTable',
                      object: obj
                    });
                  }

                  me.linkedTTNode.editLeaf(function () {
                    me.insertInterval();
                  });
                });
              }
            });
          }
        }
      ]
    };

    this.form = new Ext.form.FormPanel({
      frame: true,
b2481b88   Nathanael Jourdane   fix indent
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
      layout: {
        type: 'vbox',
        pack: 'start',
        align: 'stretch'
      },
      fieldDefaults: {
        labelWidth: 60
      },
      items: [
        intervalFieldSet,
        insertTTFieldSet
      ],
      fbar: [
        {
          text: 'Apply Zoom',
          width: 100,
          scope: this,
          handler: function () {
            if (this.zoomType == 'timeAxis') {
              var minZoom = this.form.getForm().findField('zoom-min-time').getValue();
              var maxZoom = this.form.getForm().findField('zoom-max-time').getValue();
            }
            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',
              'tabId': this.tabId,
              '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',
              'tabId': this.tabId,
              'panelId': this.panelId,
              'axeId': this.zoomType
            });
            this.hostCmp.panelImage.resetZoom();
          }
        }
      ]
    });
    return this.form;
  }
9f08f4eb   Benjamin Renard   Zoom in interacti...
396
});