Commit 738e0997d06e99527aef77e2e60b8c34b9b9fbc5
1 parent
1a0151a5
Exists in
master
and in
98 other branches
Draw histogram
Showing
4 changed files
with
193 additions
and
100 deletions
Show diff stats
js/app/views/CatalogVisuHistogram.js
... | ... | @@ -10,23 +10,196 @@ |
10 | 10 | Ext.define('amdaUI.CatalogVisuHistogram', { |
11 | 11 | extend: 'Ext.form.Panel', |
12 | 12 | alias: 'widget.panelCatalogVisuHistogram', |
13 | + histogramStore: null, | |
13 | 14 | |
14 | 15 | constructor: function(config) { |
15 | 16 | this.init(config); |
16 | 17 | this.callParent(arguments); |
17 | 18 | }, |
18 | 19 | |
19 | - initVisu: function() { | |
20 | + getChart: function(catalogStore) { | |
21 | + var paramOpt = { | |
22 | + paramId: '', | |
23 | + index: 0, | |
24 | + title: 'Parameter' | |
25 | + }; | |
26 | + | |
27 | + var paramField = Ext.getCmp('visu-histo-param'); | |
28 | + var paramFieldId = paramField.getValue(); | |
29 | + if (paramFieldId && (paramFieldId != "")) { | |
30 | + var paramField = paramField.getStore().getById(paramFieldId); | |
31 | + if (paramField) { | |
32 | + paramOpt.paramId = paramField.get('paramId'); | |
33 | + paramOpt.index = paramField.get('index'); | |
34 | + paramOpt.title = paramField.get('name'); | |
35 | + if (paramField.get('size') > 1) { | |
36 | + paramOpt.title += '['+opt.index+']'; | |
37 | + paramOpt.paramId += '_COMPONENT_'+opt.index; | |
38 | + } | |
39 | + } | |
40 | + } | |
41 | + | |
42 | + var paramTitleField = Ext.getCmp('visu-histo-title'); | |
43 | + var paramTitle = paramTitleField.getValue(); | |
44 | + if (paramTitle && (paramTitle != "")) { | |
45 | + paramOpt.title = paramTitle; | |
46 | + } | |
47 | + | |
48 | + var nbBinsField = Ext.getCmp('visu-histo-bin-slider'); | |
49 | + var nbBinsValue = nbBinsField.getValue(); | |
50 | + if (nbBinsValue <= 0) { | |
51 | + nbBinsValue = 1 | |
52 | + } | |
53 | + | |
54 | + this.histogramStore = Ext.create('Ext.data.Store', { | |
55 | + fields: ['value', 'count'] | |
56 | + }); | |
57 | + | |
58 | + var minValue = null; | |
59 | + var maxValue = null; | |
60 | + catalogStore.each(function (item) { | |
61 | + minValue = (minValue == null) ? item.get(paramOpt.paramId) : Math.min(minValue, item.get(paramOpt.paramId)); | |
62 | + maxValue = (maxValue == null) ? item.get(paramOpt.paramId) : Math.max(maxValue, item.get(paramOpt.paramId)); | |
63 | + }); | |
64 | + | |
65 | + var binSize = (maxValue-minValue) / (nbBinsValue-1); | |
66 | + var data = []; | |
67 | + for (i = 0; i < nbBinsValue; ++i) { | |
68 | + data.push({ | |
69 | + center: minValue + i * binSize, | |
70 | + count: 0 | |
71 | + }); | |
72 | + } | |
73 | + | |
74 | + catalogStore.each(function (item) { | |
75 | + var valueIndex = Math.floor((item.get(paramOpt.paramId) - minValue) / binSize); | |
76 | + ++data[valueIndex].count; | |
77 | + }); | |
20 | 78 | |
21 | - }, | |
79 | + | |
80 | + this.histogramStore = Ext.create('Ext.data.Store', { | |
81 | + fields: ['center', 'count'] | |
82 | + }); | |
83 | + this.histogramStore.loadData(data); | |
84 | + | |
85 | + var chartConfig = { | |
86 | + style: 'background:#fff', | |
87 | + animate: false, | |
88 | + shadow: false, | |
89 | + store: this.histogramStore, | |
90 | + id: 'visu-chart', | |
91 | + axes: [{ | |
92 | + type: 'Numeric', | |
93 | + position: 'left', | |
94 | + fields: ['count'], | |
95 | + title: 'Number of Hits', | |
96 | + grid : true, | |
97 | + minimum: 0 | |
98 | + }, { | |
99 | + type: 'Category', | |
100 | + position: 'bottom', | |
101 | + fields: ['center'], | |
102 | + title: paramOpt.title | |
103 | + }], | |
104 | + series: [{ | |
105 | + type: 'column', | |
106 | + axis: 'left', | |
107 | + highlight: true, | |
108 | + gutter: 5, | |
109 | + xField: 'center', | |
110 | + yField: 'count'/*, | |
111 | + tips: { | |
112 | + width: 10, | |
113 | + height: 20, | |
114 | + hideDelay: 100, //200 ms | |
115 | + mouseOffset: [0,0], //[15,18] | |
116 | + renderer: function(storeItem, item) { | |
117 | + //this.setTitle(storeItem.index + 1); | |
118 | + } | |
119 | + }*/ | |
120 | + }] | |
121 | + }; | |
122 | + | |
123 | + return Ext.create('Ext.chart.Chart', chartConfig); | |
124 | + }, | |
125 | + | |
126 | + getHistoConfig: function(parametersStore) { | |
127 | + var paramComboConfig = { | |
128 | + xtype: 'combo', | |
129 | + emptyText: 'select parameter', | |
130 | + editable: false, | |
131 | + store: parametersStore, | |
132 | + queryMode: 'local', | |
133 | + displayField: 'text', | |
134 | + valueField: 'id', | |
135 | + id: 'visu-histo-param', | |
136 | + tpl: Ext.create('Ext.XTemplate', | |
137 | + '<tpl for=".">', | |
138 | + '<div class="x-boundlist-item">{name}<tpl if="size > 1">[{index}]</tpl></div>', | |
139 | + '</tpl>' | |
140 | + ), | |
141 | + displayTpl: Ext.create('Ext.XTemplate', | |
142 | + '<tpl for=".">', | |
143 | + '{name}<tpl if="size > 1">[{index}]</tpl>', | |
144 | + '</tpl>' | |
145 | + ) | |
146 | + }; | |
147 | + | |
148 | + var sliderConfig = { | |
149 | + xtype : 'fieldcontainer', | |
150 | + layout: 'hbox', | |
151 | + items: [ | |
152 | + { | |
153 | + xtype:'fieldset', | |
154 | + title: 'Nb. bins', | |
155 | + border: false, | |
156 | + layout: 'hbox', | |
157 | + items: [ | |
158 | + { | |
159 | + xtype: 'slider', | |
160 | + width: 150, | |
161 | + value: 10, | |
162 | + increment: 1, | |
163 | + minValue: 2, | |
164 | + maxValue: 100, | |
165 | + id: 'visu-histo-bin-slider' | |
166 | + }, | |
167 | + { | |
168 | + xtype: 'splitter' | |
169 | + }, | |
170 | + { | |
171 | + xtype: 'numberfield', | |
172 | + hideTrigger: true, | |
173 | + width: 50, | |
174 | + disabled: true, | |
175 | + id: 'visu-histo-bin-value' | |
176 | + } | |
177 | + ] | |
178 | + } | |
179 | + ] | |
180 | + }; | |
181 | + | |
182 | + return { | |
183 | + xtype : 'fieldset', | |
184 | + title : 'Histogram axis', | |
185 | + items : [ | |
186 | + paramComboConfig, | |
187 | + sliderConfig, | |
188 | + { | |
189 | + xtype: 'textfield', | |
190 | + fieldLabel: 'Title', | |
191 | + id: 'visu-histo-title' | |
192 | + } | |
193 | + ] | |
194 | + }; | |
195 | + }, | |
22 | 196 | |
23 | 197 | init : function (config) |
24 | 198 | { |
25 | 199 | var myConf = { |
26 | - //layout: 'border', | |
27 | 200 | items: [ |
28 | - | |
29 | - ] | |
201 | + this.getHistoConfig(config.parametersStore) | |
202 | + ] | |
30 | 203 | }; |
31 | 204 | |
32 | 205 | Ext.apply (this, Ext.apply(arguments, myConf)); | ... | ... |
js/app/views/CatalogVisuScatter.js
... | ... | @@ -79,10 +79,6 @@ Ext.define('amdaUI.CatalogVisuScatter', { |
79 | 79 | return Ext.create('Ext.chart.Chart', chartConfig); |
80 | 80 | }, |
81 | 81 | |
82 | - initVisu: function() { | |
83 | - var me = this; | |
84 | - }, | |
85 | - | |
86 | 82 | getAxisOptions: function(axisName) { |
87 | 83 | var opt = { |
88 | 84 | paramId: '', |
... | ... | @@ -97,9 +93,10 @@ Ext.define('amdaUI.CatalogVisuScatter', { |
97 | 93 | if (paramField) { |
98 | 94 | opt.paramId = paramField.get('paramId'); |
99 | 95 | opt.index = paramField.get('index'); |
100 | - opt.title = paramField.get('name'); | |
96 | + opt.title = paramField.get('name'); | |
101 | 97 | if (paramField.get('size') > 1) { |
102 | 98 | opt.title += '['+opt.index+']'; |
99 | + opt.paramId += '_COMPONENT_'+opt.index; | |
103 | 100 | } |
104 | 101 | } |
105 | 102 | } |
... | ... | @@ -122,8 +119,6 @@ Ext.define('amdaUI.CatalogVisuScatter', { |
122 | 119 | 'max' : axisRangeMax |
123 | 120 | }; |
124 | 121 | } |
125 | - | |
126 | - console.log(opt); | |
127 | 122 | return opt; |
128 | 123 | }, |
129 | 124 | ... | ... |
js/app/views/VisuUI.js
... | ... | @@ -57,15 +57,10 @@ Ext.define('amdaUI.VisuUI', { |
57 | 57 | }, |
58 | 58 | |
59 | 59 | reset : function() { |
60 | - //reset all fieldsets except the first one (name, intervals) | |
61 | - var form = this.items.items[0].items.items[0]; | |
62 | - for (var i = 1; i < 4; i++) { | |
63 | - var fieldset = form.items.items[i]; | |
64 | - Ext.each(fieldset.query('field'), function(field) { | |
60 | + var tabPanel = Ext.getCmp('visu-tabpanel'); | |
61 | + Ext.each(tabPanel.activeTab.items.items[0].query('field'), function(field) { | |
65 | 62 | field.reset(); |
66 | - }); | |
67 | - } | |
68 | - this.resetChart(); | |
63 | + }); | |
69 | 64 | }, |
70 | 65 | |
71 | 66 | /** |
... | ... | @@ -82,10 +77,6 @@ Ext.define('amdaUI.VisuUI', { |
82 | 77 | } |
83 | 78 | }); |
84 | 79 | |
85 | - Ext.Array.each(this.visuTabContents, function(content) { | |
86 | - content.initVisu(); | |
87 | - }); | |
88 | - | |
89 | 80 | var onAfterInit = function(result, e) |
90 | 81 | { |
91 | 82 | if (!result) { |
... | ... | @@ -160,7 +151,6 @@ Ext.define('amdaUI.VisuUI', { |
160 | 151 | this.formPanel.getForm().loadRecord(this.object); |
161 | 152 | }, |
162 | 153 | |
163 | - | |
164 | 154 | /** |
165 | 155 | * Check if changes were made before closing window |
166 | 156 | * @return true if changes |
... | ... | @@ -170,87 +160,22 @@ Ext.define('amdaUI.VisuUI', { |
170 | 160 | return false; |
171 | 161 | }, |
172 | 162 | |
173 | - resetChart : function () { | |
174 | - | |
175 | - var emptyAxesConfig = [{ | |
176 | - type: 'Numeric', | |
177 | - position: 'bottom', | |
178 | - fields: [], | |
179 | - title: 'X axis', | |
180 | - grid : true | |
181 | - }, { | |
182 | - type: 'Numeric', | |
183 | - position: 'left', | |
184 | - fields: [], | |
185 | - title: 'Y axis', | |
186 | - grid: true | |
187 | - }]; | |
188 | - | |
189 | - this.chartConfig.series[0].xField = ''; | |
190 | - this.chartConfig.series[0].yField = ''; | |
191 | - | |
192 | - this.chartConfig.theme = 'Blue'; | |
193 | - | |
194 | - this.chartConfig.axes = emptyAxesConfig; | |
195 | - | |
196 | - var chart = Ext.create('Ext.chart.Chart', this.chartConfig); | |
197 | - this.replaceChart(chart); | |
198 | - | |
199 | - }, | |
200 | - | |
201 | 163 | plotChart : function () { |
202 | - | |
203 | - /*this.chartConfig.store = this.chartStore; | |
204 | - | |
205 | - var xTitle = this.items.items[0].items.items[0].items.items[1].items.items[2].getValue(); | |
206 | - var yTitle = this.items.items[0].items.items[0].items.items[2].items.items[2].getValue(); | |
207 | - | |
208 | - if (xTitle) this.chartConfig.axes[0].title = xTitle; | |
209 | - if (xTitle) this.chartConfig.axes[1].title = yTitle; | |
210 | - | |
211 | - // axis modifs | |
212 | - if (this.comboXrange.getValue() == 'manual') { | |
213 | - var minX = this.comboXrange.next().next().getValue(); | |
214 | - var maxX = this.comboXrange.next().next().next().next().getValue(); | |
215 | - this.chartConfig.axes[0].minimum = minX; | |
216 | - this.chartConfig.axes[0].maximum = maxX ; | |
217 | - } else { | |
218 | - // unset min/max in config | |
219 | - delete this.chartConfig.axes[0].minimum; | |
220 | - delete this.chartConfig.axes[0].maximum; | |
221 | - } | |
222 | - if (this.comboYrange.getValue() == 'manual') { | |
223 | - var minX = this.comboYrange.next().next().getValue(); | |
224 | - var maxX = this.comboYrange.next().next().next().next().getValue(); | |
225 | - // if (minX && maxX) { | |
226 | - this.chartConfig.axes[1].minimum = minX; | |
227 | - this.chartConfig.axes[1].maximum = maxX; | |
228 | - // } | |
229 | - } else { | |
230 | - // unset min/max in config | |
231 | - delete this.chartConfig.axes[1].minimum; | |
232 | - delete this.chartConfig.axes[1].maximum; | |
233 | - } | |
234 | - | |
235 | - var chart = Ext.create('Ext.chart.Chart', this.chartConfig); | |
236 | - | |
237 | - this.replaceChart(chart);*/ | |
238 | 164 | var chart = Ext.getCmp('visu-chart'); |
239 | 165 | var tabPanel = Ext.getCmp('visu-tabpanel'); |
240 | 166 | |
241 | 167 | var chartPanel = chart.up(); |
242 | 168 | chartPanel.remove(chart); |
243 | - console.log(this.catalogStore); | |
244 | 169 | chartPanel.insert(tabPanel.activeTab.items.items[0].getChart(this.catalogStore)); |
245 | 170 | }, |
246 | 171 | |
247 | - replaceChart: function(chart) { | |
248 | - var chartPanel = this.items.items[0].items.items[1]; | |
249 | - var oldChart = chartPanel.down('chart'); | |
250 | - oldIndex = chartPanel.items.indexOf(oldChart); | |
251 | - chartPanel.remove(oldChart); | |
252 | - chartPanel.insert(oldIndex, chart); | |
253 | - }, | |
172 | + saveChart : function() { | |
173 | + var chart = Ext.getCmp('visu-chart'); | |
174 | + chart.save({ | |
175 | + type: 'image/png', | |
176 | + defaultUrl : window.location | |
177 | + }); | |
178 | + }, | |
254 | 179 | |
255 | 180 | initChartTypes: function() { |
256 | 181 | var me = this; | ... | ... |
php/classes/CatalogCacheMgr.php
... | ... | @@ -96,7 +96,7 @@ class CatalogCacheMgr extends TimeTableCacheMgr |
96 | 96 | } |
97 | 97 | |
98 | 98 | public function getIntervalsForChart() { |
99 | - $result = $this->getIntervals(NULL, NULL, NULL, NULL); | |
99 | + $result = $this->getIntervals(NULL, NULL, NULL, NULL); | |
100 | 100 | if (!$result['success']) { |
101 | 101 | return FALSE; |
102 | 102 | } |
... | ... | @@ -116,8 +116,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr |
116 | 116 | //split parameters |
117 | 117 | foreach ($result[intervals] as &$interval) { |
118 | 118 | foreach ($parameters_to_split as $parameter) { |
119 | - $values = explode ($interval[$parameter['id']]); | |
120 | - unlink($interval[$parameter['id']]); | |
119 | + $values = explode (',',$interval[$parameter['id']]); | |
120 | + unset($interval[$parameter['id']]); | |
121 | 121 | foreach ($values as $key => $value) { |
122 | 122 | $interval[$parameter['id'].'_COMPONENT_'.$key] = $value; |
123 | 123 | } | ... | ... |