1 /* tslint:disable */ |
|
2 /* eslint-disable */ |
|
3 (function ($) { |
|
4 if (!Array.prototype.find) { |
|
5 Object.defineProperty(Array.prototype, 'find', { |
|
6 value: function(predicate) { |
|
7 // 1. Let O be ? ToObject(this value). |
|
8 if (this == null) { |
|
9 throw new TypeError('"this" is null or not defined'); |
|
10 } |
|
11 |
|
12 var o = Object(this); |
|
13 |
|
14 // 2. Let len be ? ToLength(? Get(O, "length")). |
|
15 var len = o.length >>> 0; |
|
16 |
|
17 // 3. If IsCallable(predicate) is false, throw a TypeError exception. |
|
18 if (typeof predicate !== 'function') { |
|
19 throw new TypeError('predicate must be a function'); |
|
20 } |
|
21 |
|
22 // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. |
|
23 var thisArg = arguments[1]; |
|
24 |
|
25 // 5. Let k be 0. |
|
26 var k = 0; |
|
27 |
|
28 // 6. Repeat, while k < len |
|
29 while (k < len) { |
|
30 // a. Let Pk be ! ToString(k). |
|
31 // b. Let kValue be ? Get(O, Pk). |
|
32 // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). |
|
33 // d. If testResult is true, return kValue. |
|
34 var kValue = o[k]; |
|
35 if (predicate.call(thisArg, kValue, k, o)) { |
|
36 return kValue; |
|
37 } |
|
38 // e. Increase k by 1. |
|
39 k++; |
|
40 } |
|
41 |
|
42 // 7. Return undefined. |
|
43 return undefined; |
|
44 } |
|
45 }); |
|
46 } |
|
47 if (!Array.prototype.findIndex) { |
|
48 Object.defineProperty(Array.prototype, 'findIndex', { |
|
49 value: function(predicate) { |
|
50 // 1. Let O be ? ToObject(this value). |
|
51 if (this == null) { |
|
52 throw new TypeError('"this" is null or not defined'); |
|
53 } |
|
54 |
|
55 var o = Object(this); |
|
56 |
|
57 // 2. Let len be ? ToLength(? Get(O, "length")). |
|
58 var len = o.length >>> 0; |
|
59 |
|
60 // 3. If IsCallable(predicate) is false, throw a TypeError exception. |
|
61 if (typeof predicate !== 'function') { |
|
62 throw new TypeError('predicate must be a function'); |
|
63 } |
|
64 |
|
65 // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. |
|
66 var thisArg = arguments[1]; |
|
67 |
|
68 // 5. Let k be 0. |
|
69 var k = 0; |
|
70 |
|
71 // 6. Repeat, while k < len |
|
72 while (k < len) { |
|
73 // a. Let Pk be ! ToString(k). |
|
74 // b. Let kValue be ? Get(O, Pk). |
|
75 // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). |
|
76 // d. If testResult is true, return k. |
|
77 var kValue = o[k]; |
|
78 if (predicate.call(thisArg, kValue, k, o)) { |
|
79 return k; |
|
80 } |
|
81 // e. Increase k by 1. |
|
82 k++; |
|
83 } |
|
84 |
|
85 // 7. Return -1. |
|
86 return -1; |
|
87 }, |
|
88 configurable: true, |
|
89 writable: true |
|
90 }); |
|
91 } |
|
92 |
|
93 $.extend($.jqx._jqxGrid.prototype, { |
|
94 _getChartDataFields: function (data) { |
|
95 var that = this; |
|
96 var record = data[0]; |
|
97 var stringOnly = true, |
|
98 xAxisDataField, |
|
99 series = []; |
|
100 |
|
101 for (var dataField in record) { |
|
102 if (dataField === '$' || dataField === 'uid' || dataField === 'boundindex' || dataField === 'uniqueid' || dataField === 'visibleindex') { |
|
103 continue; |
|
104 } |
|
105 |
|
106 var dataType = that.source._source.dataFields.find(function (gridField) { return gridField.name === dataField }).type; |
|
107 |
|
108 if (dataType === 'string') { |
|
109 var index = that.columns.records.findIndex(function (col) { return col.datafield === dataField }); |
|
110 |
|
111 if (index === 0) { |
|
112 xAxisDataField = dataField; |
|
113 } |
|
114 } |
|
115 else { |
|
116 stringOnly = false; |
|
117 series.push({ dataField: dataField, displayText: dataField }); |
|
118 } |
|
119 } |
|
120 |
|
121 return { xAxisDataField: xAxisDataField, series: series, stringOnly: stringOnly }; |
|
122 }, |
|
123 |
|
124 createChart: function (type, dataSource) { |
|
125 var that = this; |
|
126 var gridSelection = that.getselection(), |
|
127 selectedRows = gridSelection.rows, |
|
128 selectedCells = gridSelection.cells, |
|
129 chartElement = document.createElement('div'), |
|
130 chartData = [], |
|
131 seriesGroup = {}; |
|
132 var rowsToPlot = [], |
|
133 columnsToPlot = [], |
|
134 series; |
|
135 |
|
136 if (selectedCells && selectedCells.length > 1) { |
|
137 selectedCells.forEach(function (cell) { |
|
138 if (rowsToPlot.indexOf(cell.rowindex) === -1) { |
|
139 rowsToPlot.push(cell.rowindex); |
|
140 } |
|
141 |
|
142 if (columnsToPlot.indexOf(cell.datafield) === -1) { |
|
143 columnsToPlot.push(cell.datafield); |
|
144 } |
|
145 }); |
|
146 } |
|
147 |
|
148 if (selectedRows.length === 0 && selectedCells.length === 0) { |
|
149 var dataSource = that.source.records; |
|
150 } |
|
151 |
|
152 if (dataSource) { |
|
153 chartData = chartData.concat(dataSource); |
|
154 } |
|
155 else { |
|
156 var dataSource = that.source.records; |
|
157 |
|
158 for (var i = 0; i < dataSource.length; i++) { |
|
159 var record = {}; |
|
160 |
|
161 if (selectedRows.length > 0) { |
|
162 if (selectedRows.indexOf(i) === -1) { |
|
163 continue; |
|
164 } |
|
165 } |
|
166 else if (selectedCells.length > 0) { |
|
167 if (selectedCells.length > 1) { |
|
168 if (rowsToPlot.indexOf(i) === -1) { |
|
169 continue; |
|
170 } |
|
171 |
|
172 columnsToPlot.forEach(function (dataField) { |
|
173 record[dataField] = dataSource[i][dataField]; |
|
174 }); |
|
175 chartData.push(record); |
|
176 continue; |
|
177 } |
|
178 } |
|
179 |
|
180 that.columns.records.forEach(function (col) { record[col.datafield] = dataSource[i][col.datafield] }); |
|
181 chartData.push(record); |
|
182 } |
|
183 } |
|
184 |
|
185 var chartDataFields = that._getChartDataFields(chartData); |
|
186 |
|
187 if (chartDataFields.stringOnly) { |
|
188 if (that.showheader) { |
|
189 var chartIcon = that.element.querySelector('#' + type); |
|
190 |
|
191 that.toolbar[0].firstElementChild.classList.add('warning'); |
|
192 |
|
193 if (chartIcon) { |
|
194 chartIcon.classList.add('warning'); |
|
195 } |
|
196 |
|
197 setTimeout(function () { |
|
198 that.toolbar[0].firstElementChild.classList.remove('warning'); |
|
199 |
|
200 if (chartIcon) { |
|
201 chartIcon.classList.remove('warning'); |
|
202 } |
|
203 }, 1000); |
|
204 } |
|
205 |
|
206 return; |
|
207 } |
|
208 |
|
209 series = chartDataFields.series; |
|
210 |
|
211 var chart = {}; |
|
212 |
|
213 chart.title = ''; |
|
214 chart.description = ''; |
|
215 chart.showLegend = true; |
|
216 chart.showBorderLine = false; |
|
217 chart.padding = { left: 5, top: 10, right: 5, bottom: 5 }; |
|
218 chart.source = chartData; |
|
219 chart.xAxis = |
|
220 { |
|
221 dataField: chartDataFields.xAxisDataField, |
|
222 gridLines: { |
|
223 visible: true |
|
224 } |
|
225 }; |
|
226 chart.valueAxis = |
|
227 { |
|
228 displayValueAxis: true, |
|
229 description: that.charting.description, |
|
230 axisSize: 'auto', |
|
231 formatSettings: that.charting.formatSettings |
|
232 }; |
|
233 chart.colorScheme = that.charting.colorScheme; |
|
234 chart.seriesGroups = [seriesGroup]; |
|
235 |
|
236 seriesGroup.formatSettings = that.charting.formatSettings; |
|
237 seriesGroup.series = series; |
|
238 |
|
239 if (type === 'line') { |
|
240 series.forEach(function (serie) { |
|
241 serie.symbolSize = 8; |
|
242 serie.symbolType = 'square'; |
|
243 }); |
|
244 } |
|
245 else if (type === 'pie') { |
|
246 var pieDataField = series[0].dataField; |
|
247 |
|
248 delete seriesGroup.formatSettings; |
|
249 seriesGroup.formatFunction = function (value, index) { |
|
250 if (isNaN(value)) { |
|
251 if (typeof value === 'object') { |
|
252 return index; |
|
253 } |
|
254 |
|
255 return value; |
|
256 } |
|
257 |
|
258 return value; |
|
259 }; |
|
260 seriesGroup.showLabels = true; |
|
261 series.length = 0; |
|
262 series.push({ |
|
263 dataField: pieDataField, |
|
264 displayText: chartDataFields.xAxisDataField, |
|
265 initialAngle: 0 |
|
266 }); |
|
267 } |
|
268 else if (type === 'bar') { |
|
269 type = 'column'; |
|
270 seriesGroup.orientation = 'horizontal'; |
|
271 chart.xAxis.textRotationAngle = 90; |
|
272 chart.valueAxis.textRotationAngle = 30; |
|
273 chart.valueAxis.flip = true; |
|
274 } |
|
275 else if (type === 'area') { |
|
276 var opacity = 1; |
|
277 |
|
278 for (var i = 0; i < series.length; i++) { |
|
279 series[i].opacity = opacity; |
|
280 opacity -= 0.2; |
|
281 opacity = Math.max(0.3, opacity); |
|
282 } |
|
283 } |
|
284 |
|
285 seriesGroup.type = type; |
|
286 |
|
287 if (that.charting.ready) { |
|
288 that.charting.ready(chart); |
|
289 } |
|
290 |
|
291 if (that.charting.appendTo) { |
|
292 var container = that.charting.appendTo === 'string' ? document.querySelector(that.charting.appendTo) : that.charting.appendTo; |
|
293 |
|
294 if (container) { |
|
295 var chartInstance = new jqxChart(chartElement, chart); |
|
296 container.appendChild(chartElement); |
|
297 } |
|
298 } |
|
299 else { |
|
300 that._openChartDialog(chartElement, type, chart); |
|
301 } |
|
302 }, |
|
303 |
|
304 _openChartDialog: function (chart, chartType, settings) { |
|
305 var that = this; |
|
306 |
|
307 if (!that.charting.dialog.enabled) { |
|
308 return false; |
|
309 } |
|
310 |
|
311 var dialogElement = document.createElement('div'); |
|
312 |
|
313 dialogElement.innerHTML = '<div>' + that.charting.dialog.header + '</div><div style="overflow:hidden;"></div>'; |
|
314 |
|
315 var chartLabel = chartType.substring(0, 1).toUpperCase() + chartType.substring(1); |
|
316 |
|
317 chart.style.width = '100%'; |
|
318 chart.style.height = '100%'; |
|
319 |
|
320 var dialog = new jqxWindow(dialogElement, { |
|
321 width: that.charting.dialog.width, |
|
322 height: that.charting.dialog.height, |
|
323 position: that.charting.dialog.position, |
|
324 isModal: true |
|
325 }); |
|
326 |
|
327 dialog.open(); |
|
328 |
|
329 setTimeout(function () { |
|
330 dialogElement.querySelector('.jqx-widget-content').appendChild(chart); |
|
331 var chartInstance = new jqxChart(chart, settings); |
|
332 }, 100); |
|
333 |
|
334 dialog.on('close', function () { |
|
335 dialog.destroy(); |
|
336 }); |
|
337 } |
|
338 }); |
|
339 })(jqxBaseFramework); |
|