Blame view

js/app/views/CatalogVisuHistogram.js 5.19 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',
738e0997   Benjamin Renard   Draw histogram
13
	histogramStore: null,
33705dc4   Benjamin Renard   Catalog visu rework
14
15
16
17
18
19

	constructor: function(config) {
		this.init(config);
		this.callParent(arguments);
	},

b0720b91   Benjamin Renard   Finalize catalog ...
20
  getChartConfig: function(catalogStore) {
738e0997   Benjamin Renard   Draw histogram
21
22
		var paramOpt = {
			paramId: '',
738e0997   Benjamin Renard   Draw histogram
23
24
25
26
27
28
29
30
			title: 'Parameter'
		};

		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 ...
31
				paramOpt.paramId = paramField.get('id');
738e0997   Benjamin Renard   Draw histogram
32
				paramOpt.title = paramField.get('name');
738e0997   Benjamin Renard   Draw histogram
33
34
			}
		}
b0720b91   Benjamin Renard   Finalize catalog ...
35
36
37
38
    else {
      myDesktopApp.errorMsg('Missing parameter selection');
      return null;
    }
738e0997   Benjamin Renard   Draw histogram
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

		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
		}

		this.histogramStore = Ext.create('Ext.data.Store', {
			fields: ['value', 'count']
		});

		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
63
64
    if ((minValue == null) || (maxValue == null) || (minValue == maxValue)) {
      myDesktopApp.errorMsg('Not enough data or constant data');
b0720b91   Benjamin Renard   Finalize catalog ...
65
66
67
      return null;
    }

738e0997   Benjamin Renard   Draw histogram
68
69
70
		var binSize = (maxValue-minValue) / (nbBinsValue-1);
		var data = [];
		for (i = 0; i < nbBinsValue; ++i) {
b0720b91   Benjamin Renard   Finalize catalog ...
71
      var center = minValue + i * binSize;
738e0997   Benjamin Renard   Draw histogram
72
			data.push({
b0720b91   Benjamin Renard   Finalize catalog ...
73
74
75
76
				center: center,
        min: center - binSize/2,
        max: center + binSize/2,
        count: 0
738e0997   Benjamin Renard   Draw histogram
77
78
79
80
81
82
83
			});
		}

		catalogStore.each(function (item) {
			var valueIndex = Math.floor((item.get(paramOpt.paramId) - minValue) / binSize);
			++data[valueIndex].count;
		});
33705dc4   Benjamin Renard   Catalog visu rework
84

738e0997   Benjamin Renard   Draw histogram
85
86

		this.histogramStore = Ext.create('Ext.data.Store', {
b0720b91   Benjamin Renard   Finalize catalog ...
87
			fields: ['center', 'min', 'max', 'count']
738e0997   Benjamin Renard   Draw histogram
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
		});
		this.histogramStore.loadData(data);

		var chartConfig = {
			style: 'background:#fff',
			animate: false,
			shadow: false,
			store: this.histogramStore,
      id: 'visu-chart',
			axes:   [{
				type: 'Numeric',
				position: 'left',
				fields: ['count'],
				title: 'Number of Hits',
				grid : true,
				minimum: 0
			}, {
				type: 'Category',
				position: 'bottom',
				fields: ['center'],
b0720b91   Benjamin Renard   Finalize catalog ...
108
109
110
111
112
113
				title: paramOpt.title,
        label: {
          renderer: function(value, label, storeItem, item, i, display, animate, index) {
            return value.toFixed(2);
          }
        }
738e0997   Benjamin Renard   Draw histogram
114
115
116
117
118
119
120
			}],
			series: [{
				type: 'column',
				axis: 'left',
				highlight: true,
				gutter: 5,
				xField: 'center',
b0720b91   Benjamin Renard   Finalize catalog ...
121
				yField: 'count',
738e0997   Benjamin Renard   Draw histogram
122
        tips: {
738e0997   Benjamin Renard   Draw histogram
123
					height: 20,
b0720b91   Benjamin Renard   Finalize catalog ...
124
					hideDelay: 200,
738e0997   Benjamin Renard   Draw histogram
125
126
					mouseOffset: [0,0],   //[15,18]
					renderer: function(storeItem, item) {
b0720b91   Benjamin Renard   Finalize catalog ...
127
            this.setTitle('['+storeItem.get('min').toFixed(2)+', '+storeItem.get('max').toFixed(2)+']');
738e0997   Benjamin Renard   Draw histogram
128
					}
b0720b91   Benjamin Renard   Finalize catalog ...
129
				}
738e0997   Benjamin Renard   Draw histogram
130
131
132
			}]
		};

b0720b91   Benjamin Renard   Finalize catalog ...
133
    return chartConfig;
738e0997   Benjamin Renard   Draw histogram
134
135
136
137
138
139
140
141
142
  },

  getHistoConfig: function(parametersStore) {
    var paramComboConfig = {
      xtype: 'combo',
      emptyText: 'select parameter',
      editable: false,
      store: parametersStore,
      queryMode: 'local',
b0720b91   Benjamin Renard   Finalize catalog ...
143
      displayField: 'name',
738e0997   Benjamin Renard   Draw histogram
144
      valueField: 'id',
b0720b91   Benjamin Renard   Finalize catalog ...
145
      id: 'visu-histo-param'
738e0997   Benjamin Renard   Draw histogram
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    };

    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 ...
165
166
167
168
169
170
171
172
              id: 'visu-histo-bin-slider',
              listeners: {
                change: function ( slider, newValue, thumb, eOpts ) {
                  var binValueField = Ext.getCmp('visu-histo-bin-value');
                  binValueField.setValue(newValue);
                },
                scope: this
              }
738e0997   Benjamin Renard   Draw histogram
173
174
175
176
177
178
179
180
181
            },
            {
              xtype: 'splitter'
            },
            {
              xtype: 'numberfield',
              hideTrigger: true,
              width: 50,
              disabled: true,
b0720b91   Benjamin Renard   Finalize catalog ...
182
              value: 10,
738e0997   Benjamin Renard   Draw histogram
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
              id: 'visu-histo-bin-value'
            }
        ]
      }
      ]
     };

    return {
      xtype : 'fieldset',
      title : 'Histogram axis',
      items : [
        paramComboConfig,
        sliderConfig,
        {
          xtype: 'textfield',
          fieldLabel: 'Title',
          id: 'visu-histo-title'
        }
      ]
    };
  },
33705dc4   Benjamin Renard   Catalog visu rework
204
205
206
207

	init : function (config)
	{
		var myConf = {
33705dc4   Benjamin Renard   Catalog visu rework
208
			items: [
738e0997   Benjamin Renard   Draw histogram
209
210
          this.getHistoConfig(config.parametersStore)
      ]
33705dc4   Benjamin Renard   Catalog visu rework
211
212
213
214
215
		};

		Ext.apply (this, Ext.apply(arguments, myConf));
    }
});