Blame view

js/app/views/CatalogVisuHistogram.js 6.88 KB
33705dc4   Benjamin Renard   Catalog visu rework
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * Project       AMDA-NG
 * Name          CatalogVisuHistogram.js
 * @class 	   amdaUI.CatalogVisuHistogram
 * @extends      Ext.container.Container
 * @brief	   Histogram Visualization Module UI definition (View)
 * @author 	  elena
 */

Ext.define('amdaUI.CatalogVisuHistogram', {
	extend: 'Ext.form.Panel',
	alias: 'widget.panelCatalogVisuHistogram',
1962836b   Erdogan Furkan   #10743 - Done
13
14
15
16
17
  requires: [
		'amdaPlotObj.PlotObjectConfig',
		'amdaPlotComp.PlotColorPicker'
	],

738e0997   Benjamin Renard   Draw histogram
18
	histogramStore: null,
560766be   furkan   #6899- Last modif...
19
  visuUI:null,
33705dc4   Benjamin Renard   Catalog visu rework
20
21
22
23
24
	constructor: function(config) {
		this.init(config);
		this.callParent(arguments);
	},

536a676d   Erdogan Furkan   #10701 & #10702 Done
25
  getChartConfig: function(catalogStore,isColorBar=false) {
738e0997   Benjamin Renard   Draw histogram
26
27
		var paramOpt = {
			paramId: '',
738e0997   Benjamin Renard   Draw histogram
28
			title: 'Parameter'
3ccb373f   furkan   #6899 - Done
29
		}; 
738e0997   Benjamin Renard   Draw histogram
30

1962836b   Erdogan Furkan   #10743 - Done
31
32
    var plotColorField = Ext.getCmp('visu-histo-color');
    var plotColor=plotColorField.ownerCt.colorDisplayer.value;
1962836b   Erdogan Furkan   #10743 - Done
33

738e0997   Benjamin Renard   Draw histogram
34
35
36
37
38
		var paramField = Ext.getCmp('visu-histo-param');
		var paramFieldId = paramField.getValue();
		if (paramFieldId && (paramFieldId != "")) {
			var paramField = paramField.getStore().getById(paramFieldId);
			if (paramField) {
b0720b91   Benjamin Renard   Finalize catalog ...
39
				paramOpt.paramId = paramField.get('id');
738e0997   Benjamin Renard   Draw histogram
40
				paramOpt.title = paramField.get('name');
738e0997   Benjamin Renard   Draw histogram
41
42
			}
		}
b0720b91   Benjamin Renard   Finalize catalog ...
43
    else {
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
44
      //myDesktopApp.errorMsg('Missing parameter selection');
b0720b91   Benjamin Renard   Finalize catalog ...
45
46
      return null;
    }
738e0997   Benjamin Renard   Draw histogram
47
48
49
50
51
52
53
54
55
56
57
58
59

		var paramTitleField = Ext.getCmp('visu-histo-title');
		var paramTitle = paramTitleField.getValue();
		if (paramTitle && (paramTitle != "")) {
			paramOpt.title = paramTitle;
		}

    var nbBinsField = Ext.getCmp('visu-histo-bin-slider');
    var nbBinsValue = nbBinsField.getValue();
		if (nbBinsValue <= 0) {
			nbBinsValue = 1
		}

738e0997   Benjamin Renard   Draw histogram
60
61
62
63
64
65
66
		var minValue = null;
		var maxValue = null;
		catalogStore.each(function (item) {
			minValue = (minValue == null) ? item.get(paramOpt.paramId) : Math.min(minValue, item.get(paramOpt.paramId));
			maxValue = (maxValue == null) ? item.get(paramOpt.paramId) : Math.max(maxValue, item.get(paramOpt.paramId));
		});

b0c34835   Benjamin Renard   Fix #8304
67
68
    if ((minValue == null) || (maxValue == null) || (minValue == maxValue)) {
      myDesktopApp.errorMsg('Not enough data or constant data');
b0720b91   Benjamin Renard   Finalize catalog ...
69
70
      return null;
    }
3c7ba0d9   Erdogan Furkan   #10702/10701 - Lo...
71
72
    var isLogScaleX = Ext.getCmp('visu-histo-logbox-X').getValue();
    var isLogScaleY = Ext.getCmp('visu-histo-logbox-Y').getValue();
3ccb373f   furkan   #6899 - Done
73
74
75
76
		var binSize = (maxValue-minValue) / (nbBinsValue);
    var x=[];
    catalogStore.each(function (item) {
			x.push(item.get(paramOpt.paramId));
738e0997   Benjamin Renard   Draw histogram
77
		});
738e0997   Benjamin Renard   Draw histogram
78

3ccb373f   furkan   #6899 - Done
79
80
81
    var trace = {
      x: x,
      type: 'histogram',
1962836b   Erdogan Furkan   #10743 - Done
82
83
84
      marker:{
        color:plotColor,
      },
560766be   furkan   #6899- Last modif...
85
      histnorm: Ext.getCmp('normalizedCheckbox').getValue() ? 'probability': null,
3ccb373f   furkan   #6899 - Done
86
87
88
89
90
      xbins: { end: maxValue, size: binSize, start: minValue }
    };
   
    var data = [trace];
    var layout = {
560766be   furkan   #6899- Last modif...
91
      margin: {l: 60,r: 40, b: 40,t: 40,pad: 5},
13374f3f   Erdogan Furkan   #10584 - Done
92
93
      yaxis: {
        title: Ext.getCmp('normalizedCheckbox').getValue() ? 'Frequency': 'Events',
3c7ba0d9   Erdogan Furkan   #10702/10701 - Lo...
94
        type: isLogScaleY ? 'log' : null
13374f3f   Erdogan Furkan   #10584 - Done
95
      },
3c7ba0d9   Erdogan Furkan   #10702/10701 - Lo...
96
97
98
      xaxis: {
        title: paramOpt.title,
        type: isLogScaleX ? 'log' : null},
13374f3f   Erdogan Furkan   #10584 - Done
99
    };
3ccb373f   furkan   #6899 - Done
100
101
102
		
      var result =  {data:data,layout:layout}
    return result;
738e0997   Benjamin Renard   Draw histogram
103
104
  },

3c7ba0d9   Erdogan Furkan   #10702/10701 - Lo...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  generateLogBox: function(axis){
    return {xtype: 'fieldcontainer',
    fieldLabel: axis+' Log Scale',
    defaultType: 'checkboxfield',
    items: [
      {
        name      : 'logscale'+axis,
        inputValue: false,
        id        : 'visu-histo-logbox-'+axis,
        listeners:{
        change:function(){
          this.visuUI.plotChart();
        },
        scope: this
        }
      }
    ],}
  },

738e0997   Benjamin Renard   Draw histogram
124
125
126
127
128
129
130
  getHistoConfig: function(parametersStore) {
    var paramComboConfig = {
      xtype: 'combo',
      emptyText: 'select parameter',
      editable: false,
      store: parametersStore,
      queryMode: 'local',
b0720b91   Benjamin Renard   Finalize catalog ...
131
      displayField: 'name',
738e0997   Benjamin Renard   Draw histogram
132
      valueField: 'id',
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
133
134
135
136
137
138
139
      id: 'visu-histo-param',
      listeners:{
        change:function(){
          this.visuUI.plotChart();
        },
        scope: this
      }
738e0997   Benjamin Renard   Draw histogram
140
    };
13374f3f   Erdogan Furkan   #10584 - Done
141
    var normalizedbox={
560766be   furkan   #6899- Last modif...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
      xtype: 'fieldcontainer',
            fieldLabel: 'Normalized',
            defaultType: 'checkboxfield',
            items: [
                {
                    name      : 'normalized',
                    inputValue: false,
                    id        : 'normalizedCheckbox',
                    listeners:{
                      change:function(){
                        this.visuUI.plotChart();
                      },
                      scope: this
                    }
                }
            ],
    };
4f728fd9   Erdogan Furkan   For now 2
159
    var colorPicker = this.addColorsPicker('visu-histo-color', 'Color', amdaDefaultConfigs.availableColorsNew, 'standard');
1962836b   Erdogan Furkan   #10743 - Done
160
161
162
		var plotThemeComboConfig = {xtype:'fieldset',
									id:'visu-hiso-color-fieldset',
									margin:'5 0 0 0',
b0f0f1c6   Erdogan Furkan   Minor fixes for C...
163
                  padding:0,
1962836b   Erdogan Furkan   #10743 - Done
164
165
166
167
168
									border:false,
									items:[colorPicker],
								};
		colorPicker.add({id:'visu-histo-color'});

738e0997   Benjamin Renard   Draw histogram
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    var sliderConfig = {
      xtype : 'fieldcontainer',
      layout: 'hbox',
      items: [
        {
          xtype:'fieldset',
          title: 'Nb. bins',
          border: false,
          layout: 'hbox',
          items: [
            {
              xtype: 'slider',
              width: 150,
              value: 10,
              increment: 1,
              minValue: 2,
              maxValue: 100,
b0720b91   Benjamin Renard   Finalize catalog ...
186
187
188
189
190
191
              id: 'visu-histo-bin-slider',
              listeners: {
                change: function ( slider, newValue, thumb, eOpts ) {
                  var binValueField = Ext.getCmp('visu-histo-bin-value');
                  binValueField.setValue(newValue);
                },
560766be   furkan   #6899- Last modif...
192
193
194
                changecomplete: function(){
                  this.visuUI.plotChart();
                },
b0720b91   Benjamin Renard   Finalize catalog ...
195
196
                scope: this
              }
738e0997   Benjamin Renard   Draw histogram
197
198
199
200
201
202
203
204
205
            },
            {
              xtype: 'splitter'
            },
            {
              xtype: 'numberfield',
              hideTrigger: true,
              width: 50,
              disabled: true,
b0720b91   Benjamin Renard   Finalize catalog ...
206
              value: 10,
738e0997   Benjamin Renard   Draw histogram
207
208
209
210
211
212
213
214
215
216
217
218
219
              id: 'visu-histo-bin-value'
            }
        ]
      }
      ]
     };

    return {
      xtype : 'fieldset',
      title : 'Histogram axis',
      items : [
        paramComboConfig,
        sliderConfig,
13374f3f   Erdogan Furkan   #10584 - Done
220
        normalizedbox,
3c7ba0d9   Erdogan Furkan   #10702/10701 - Lo...
221
222
        this.generateLogBox('X'),
        this.generateLogBox('Y'),
738e0997   Benjamin Renard   Draw histogram
223
224
        {
          xtype: 'textfield',
4be0c1c3   Erdogan Furkan   Last modification...
225
          fieldLabel: 'X Title',
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
226
227
228
229
230
231
232
          id: 'visu-histo-title',
          listeners: {
            change: function(){
              this.visuUI.plotChart();
            },
            scope: this
          }
1962836b   Erdogan Furkan   #10743 - Done
233
234
235
        },
        
        plotThemeComboConfig,
738e0997   Benjamin Renard   Draw histogram
236
237
238
      ]
    };
  },
33705dc4   Benjamin Renard   Catalog visu rework
239

1962836b   Erdogan Furkan   #10743 - Done
240
241
242
243
244
245
246
247
248
249
  addColorsPicker: function (name, label, availableColors, mode) {
		if (!mode) {
			mode = 'standard';
		}
		var me =this;
		return new amdaPlotComp.PlotColorPicker({name: name, label: label, mode: mode, colors: availableColors, onChange: function(name, newValue, oldValue) {
			me.visuUI.plotChart();
		}});
	},

33705dc4   Benjamin Renard   Catalog visu rework
250
251
252
	init : function (config)
	{
		var myConf = {
33705dc4   Benjamin Renard   Catalog visu rework
253
			items: [
738e0997   Benjamin Renard   Draw histogram
254
255
          this.getHistoConfig(config.parametersStore)
      ]
33705dc4   Benjamin Renard   Catalog visu rework
256
		};
560766be   furkan   #6899- Last modif...
257
    this.visuUI= config.visuUI;
33705dc4   Benjamin Renard   Catalog visu rework
258
259
260
		Ext.apply (this, Ext.apply(arguments, myConf));
    }
});