corrade-nucleus-nucleons – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
11 | office | 1 | /** |
2 | * @license Highcharts JS v5.0.12 (2017-05-24) |
||
3 | * Exporting module |
||
4 | * |
||
5 | * (c) 2010-2017 Torstein Honsi |
||
6 | * |
||
7 | * License: www.highcharts.com/license |
||
8 | */ |
||
9 | 'use strict'; |
||
10 | (function(factory) { |
||
11 | if (typeof module === 'object' && module.exports) { |
||
12 | module.exports = factory; |
||
13 | } else { |
||
14 | factory(Highcharts); |
||
15 | } |
||
16 | }(function(Highcharts) { |
||
17 | (function(Highcharts) { |
||
18 | /** |
||
19 | * Expoerimental data export module for Highcharts |
||
20 | * |
||
21 | * (c) 2010-2017 Torstein Honsi |
||
22 | * |
||
23 | * License: www.highcharts.com/license |
||
24 | */ |
||
25 | |||
26 | // docs |
||
27 | // - After experimental release: |
||
28 | // - Move info in repo readme to docs/API. |
||
29 | // - Deprecate repo and plugins page |
||
30 | // - Update demos (esp accessibility) to use new URL |
||
31 | // - Before official release, set up systematic tests for all series types |
||
32 | |||
33 | /* eslint indent:0 */ |
||
34 | |||
35 | var each = Highcharts.each, |
||
36 | pick = Highcharts.pick, |
||
37 | win = Highcharts.win, |
||
38 | doc = win.document, |
||
39 | seriesTypes = Highcharts.seriesTypes, |
||
40 | downloadAttrSupported = doc.createElement('a').download !== undefined; |
||
41 | |||
42 | Highcharts.setOptions({ |
||
43 | lang: { |
||
44 | downloadCSV: 'Download CSV', |
||
45 | downloadXLS: 'Download XLS', |
||
46 | viewData: 'View data table' |
||
47 | } |
||
48 | }); |
||
49 | |||
50 | /** |
||
51 | * Get the data rows as a two dimensional array |
||
52 | */ |
||
53 | Highcharts.Chart.prototype.getDataRows = function() { |
||
54 | var options = (this.options.exporting || {}).csv || {}, |
||
55 | xAxis, |
||
56 | xAxes = this.xAxis, |
||
57 | rows = {}, |
||
58 | rowArr = [], |
||
59 | dataRows, |
||
60 | names = [], |
||
61 | i, |
||
62 | x, |
||
63 | xTitle, |
||
64 | // Options |
||
65 | dateFormat = options.dateFormat || '%Y-%m-%d %H:%M:%S', |
||
66 | columnHeaderFormatter = options.columnHeaderFormatter || function(item, key, keyLength) { |
||
67 | if (item instanceof Highcharts.Axis) { |
||
68 | return (item.options.title && item.options.title.text) || |
||
69 | (item.isDatetimeAxis ? 'DateTime' : 'Category'); |
||
70 | } |
||
71 | return item ? |
||
72 | item.name + (keyLength > 1 ? ' (' + key + ')' : '') : |
||
73 | 'Category'; |
||
74 | }, |
||
75 | xAxisIndices = []; |
||
76 | |||
77 | // Loop the series and index values |
||
78 | i = 0; |
||
79 | each(this.series, function(series) { |
||
80 | var keys = series.options.keys, |
||
81 | pointArrayMap = keys || series.pointArrayMap || ['y'], |
||
82 | valueCount = pointArrayMap.length, |
||
83 | requireSorting = series.requireSorting, |
||
84 | categoryMap = {}, |
||
85 | xAxisIndex = Highcharts.inArray(series.xAxis, xAxes), |
||
86 | j; |
||
87 | |||
88 | // Map the categories for value axes |
||
89 | each(pointArrayMap, function(prop) { |
||
90 | categoryMap[prop] = (series[prop + 'Axis'] && series[prop + 'Axis'].categories) || []; |
||
91 | }); |
||
92 | |||
93 | if (series.options.includeInCSVExport !== false && series.visible !== false) { // #55 |
||
94 | |||
95 | // Build a lookup for X axis index and the position of the first |
||
96 | // series that belongs to that X axis. Includes -1 for non-axis |
||
97 | // series types like pies. |
||
98 | if (!Highcharts.find(xAxisIndices, function(index) { |
||
99 | return index[0] === xAxisIndex; |
||
100 | })) { |
||
101 | xAxisIndices.push([xAxisIndex, i]); |
||
102 | } |
||
103 | |||
104 | // Add the column headers, usually the same as series names |
||
105 | j = 0; |
||
106 | while (j < valueCount) { |
||
107 | names.push(columnHeaderFormatter(series, pointArrayMap[j], pointArrayMap.length)); |
||
108 | j++; |
||
109 | } |
||
110 | |||
111 | each(series.points, function(point, pIdx) { |
||
112 | var key = requireSorting ? point.x : pIdx, |
||
113 | prop, |
||
114 | val; |
||
115 | |||
116 | j = 0; |
||
117 | |||
118 | if (!rows[key]) { |
||
119 | // Generate the row |
||
120 | rows[key] = []; |
||
121 | // Contain the X values from one or more X axes |
||
122 | rows[key].xValues = []; |
||
123 | } |
||
124 | rows[key].x = point.x; |
||
125 | rows[key].xValues[xAxisIndex] = point.x; |
||
126 | |||
127 | // Pies, funnels, geo maps etc. use point name in X row |
||
128 | if (!series.xAxis || series.exportKey === 'name') { |
||
129 | rows[key].name = point.name; |
||
130 | } |
||
131 | |||
132 | while (j < valueCount) { |
||
133 | prop = pointArrayMap[j]; // y, z etc |
||
134 | val = point[prop]; |
||
135 | // Pick a Y axis category if present |
||
136 | rows[key][i + j] = pick(categoryMap[prop][val], val); |
||
137 | j++; |
||
138 | } |
||
139 | |||
140 | }); |
||
141 | i = i + j; |
||
142 | } |
||
143 | }); |
||
144 | |||
145 | // Make a sortable array |
||
146 | for (x in rows) { |
||
147 | if (rows.hasOwnProperty(x)) { |
||
148 | rowArr.push(rows[x]); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | var xAxisIndex, column; |
||
153 | dataRows = [names]; |
||
154 | |||
155 | i = xAxisIndices.length; |
||
156 | while (i--) { // Start from end to splice in |
||
157 | xAxisIndex = xAxisIndices[i][0]; |
||
158 | column = xAxisIndices[i][1]; |
||
159 | xAxis = xAxes[xAxisIndex]; |
||
160 | |||
161 | // Sort it by X values |
||
162 | rowArr.sort(function(a, b) { // eslint-disable-line no-loop-func |
||
163 | return a.xValues[xAxisIndex] - b.xValues[xAxisIndex]; |
||
164 | }); |
||
165 | |||
166 | // Add header row |
||
167 | xTitle = columnHeaderFormatter(xAxis); |
||
168 | //dataRows = [[xTitle].concat(names)]; |
||
169 | dataRows[0].splice(column, 0, xTitle); |
||
170 | |||
171 | // Add the category column |
||
172 | each(rowArr, function(row) { // eslint-disable-line no-loop-func |
||
173 | var category = row.name; |
||
174 | if (!category) { |
||
175 | if (xAxis.isDatetimeAxis) { |
||
176 | if (row.x instanceof Date) { |
||
177 | row.x = row.x.getTime(); |
||
178 | } |
||
179 | category = Highcharts.dateFormat(dateFormat, row.x); |
||
180 | } else if (xAxis.categories) { |
||
181 | category = pick( |
||
182 | xAxis.names[row.x], |
||
183 | xAxis.categories[row.x], |
||
184 | row.x |
||
185 | ); |
||
186 | } else { |
||
187 | category = row.x; |
||
188 | } |
||
189 | } |
||
190 | |||
191 | // Add the X/date/category |
||
192 | row.splice(column, 0, category); |
||
193 | }); |
||
194 | } |
||
195 | dataRows = dataRows.concat(rowArr); |
||
196 | |||
197 | return dataRows; |
||
198 | }; |
||
199 | |||
200 | /** |
||
201 | * Get a CSV string |
||
202 | */ |
||
203 | Highcharts.Chart.prototype.getCSV = function(useLocalDecimalPoint) { |
||
204 | var csv = '', |
||
205 | rows = this.getDataRows(), |
||
206 | options = (this.options.exporting || {}).csv || {}, |
||
207 | itemDelimiter = options.itemDelimiter || ',', // use ';' for direct to Excel |
||
208 | lineDelimiter = options.lineDelimiter || '\n'; // '\n' isn't working with the js csv data extraction |
||
209 | |||
210 | // Transform the rows to CSV |
||
211 | each(rows, function(row, i) { |
||
212 | var val = '', |
||
213 | j = row.length, |
||
214 | n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.'; |
||
215 | while (j--) { |
||
216 | val = row[j]; |
||
217 | if (typeof val === 'string') { |
||
218 | val = '"' + val + '"'; |
||
219 | } |
||
220 | if (typeof val === 'number') { |
||
221 | if (n === ',') { |
||
222 | val = val.toString().replace('.', ','); |
||
223 | } |
||
224 | } |
||
225 | row[j] = val; |
||
226 | } |
||
227 | // Add the values |
||
228 | csv += row.join(itemDelimiter); |
||
229 | |||
230 | // Add the line delimiter |
||
231 | if (i < rows.length - 1) { |
||
232 | csv += lineDelimiter; |
||
233 | } |
||
234 | }); |
||
235 | return csv; |
||
236 | }; |
||
237 | |||
238 | /** |
||
239 | * Build a HTML table with the data |
||
240 | */ |
||
241 | Highcharts.Chart.prototype.getTable = function(useLocalDecimalPoint) { |
||
242 | var html = '<table><thead>', |
||
243 | rows = this.getDataRows(); |
||
244 | |||
245 | // Transform the rows to HTML |
||
246 | each(rows, function(row, i) { |
||
247 | var tag = i ? 'td' : 'th', |
||
248 | val, |
||
249 | j, |
||
250 | n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.'; |
||
251 | |||
252 | html += '<tr>'; |
||
253 | for (j = 0; j < row.length; j = j + 1) { |
||
254 | val = row[j]; |
||
255 | // Add the cell |
||
256 | if (typeof val === 'number') { |
||
257 | val = val.toString(); |
||
258 | if (n === ',') { |
||
259 | val = val.replace('.', n); |
||
260 | } |
||
261 | html += '<' + tag + ' class="number">' + val + '</' + tag + '>'; |
||
262 | |||
263 | } else { |
||
264 | html += '<' + tag + '>' + (val === undefined ? '' : val) + '</' + tag + '>'; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | html += '</tr>'; |
||
269 | |||
270 | // After the first row, end head and start body |
||
271 | if (!i) { |
||
272 | html += '</thead><tbody>'; |
||
273 | } |
||
274 | |||
275 | }); |
||
276 | html += '</tbody></table>'; |
||
277 | |||
278 | return html; |
||
279 | }; |
||
280 | |||
281 | Highcharts.Chart.prototype.fileDownload = function(href, extension, content, MIME) { |
||
282 | var a, |
||
283 | blobObject, |
||
284 | name, |
||
285 | options = (this.options.exporting || {}).csv || {}, |
||
286 | url = options.url || 'http://www.highcharts.com/studies/csv-export/download.php'; |
||
287 | |||
288 | if (this.options.exporting.filename) { |
||
289 | name = this.options.exporting.filename; |
||
290 | } else if (this.title) { |
||
291 | name = this.title.textStr.replace(/ /g, '-').toLowerCase(); |
||
292 | } else { |
||
293 | name = 'chart'; |
||
294 | } |
||
295 | |||
296 | // MS specific. Check this first because of bug with Edge (#76) |
||
297 | if (win.Blob && win.navigator.msSaveOrOpenBlob) { |
||
298 | // Falls to msSaveOrOpenBlob if download attribute is not supported |
||
299 | blobObject = new win.Blob([content]); |
||
300 | win.navigator.msSaveOrOpenBlob(blobObject, name + '.' + extension); |
||
301 | |||
302 | // Download attribute supported |
||
303 | } else if (downloadAttrSupported) { |
||
304 | a = doc.createElement('a'); |
||
305 | a.href = href; |
||
306 | a.target = '_blank'; |
||
307 | a.download = name + '.' + extension; |
||
308 | this.container.append(a); // #111 |
||
309 | a.click(); |
||
310 | a.remove(); |
||
311 | |||
312 | } else { |
||
313 | // Fall back to server side handling |
||
314 | Highcharts.post(url, { |
||
315 | data: content, |
||
316 | type: MIME, |
||
317 | extension: extension |
||
318 | }); |
||
319 | } |
||
320 | }; |
||
321 | |||
322 | /** |
||
323 | * Call this on click of 'Download CSV' button |
||
324 | */ |
||
325 | Highcharts.Chart.prototype.downloadCSV = function() { |
||
326 | var csv = this.getCSV(true); |
||
327 | this.fileDownload( |
||
328 | 'data:text/csv,\uFEFF' + encodeURIComponent(csv), |
||
329 | 'csv', |
||
330 | csv, |
||
331 | 'text/csv' |
||
332 | ); |
||
333 | }; |
||
334 | |||
335 | /** |
||
336 | * Call this on click of 'Download XLS' button |
||
337 | */ |
||
338 | Highcharts.Chart.prototype.downloadXLS = function() { |
||
339 | var uri = 'data:application/vnd.ms-excel;base64,', |
||
340 | template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">' + |
||
341 | '<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>' + |
||
342 | '<x:Name>Ark1</x:Name>' + |
||
343 | '<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->' + |
||
344 | '<style>td{border:none;font-family: Calibri, sans-serif;} .number{mso-number-format:"0.00";}</style>' + |
||
345 | '<meta name=ProgId content=Excel.Sheet>' + |
||
346 | '<meta charset=UTF-8>' + |
||
347 | '</head><body>' + |
||
348 | this.getTable(true) + |
||
349 | '</body></html>', |
||
350 | base64 = function(s) { |
||
351 | return win.btoa(unescape(encodeURIComponent(s))); // #50 |
||
352 | }; |
||
353 | this.fileDownload( |
||
354 | uri + base64(template), |
||
355 | 'xls', |
||
356 | template, |
||
357 | 'application/vnd.ms-excel' |
||
358 | ); |
||
359 | }; |
||
360 | |||
361 | /** |
||
362 | * View the data in a table below the chart |
||
363 | */ |
||
364 | Highcharts.Chart.prototype.viewData = function() { |
||
365 | if (!this.dataTableDiv) { |
||
366 | this.dataTableDiv = doc.createElement('div'); |
||
367 | this.dataTableDiv.className = 'highcharts-data-table'; |
||
368 | |||
369 | // Insert after the chart container |
||
370 | this.renderTo.parentNode.insertBefore( |
||
371 | this.dataTableDiv, |
||
372 | this.renderTo.nextSibling |
||
373 | ); |
||
374 | } |
||
375 | |||
376 | this.dataTableDiv.innerHTML = this.getTable(); |
||
377 | }; |
||
378 | |||
379 | |||
380 | // Add "Download CSV" to the exporting menu. Use download attribute if supported, else |
||
381 | // run a simple PHP script that returns a file. The source code for the PHP script can be viewed at |
||
382 | // https://raw.github.com/highslide-software/highcharts.com/master/studies/csv-export/csv.php |
||
383 | if (Highcharts.getOptions().exporting) { |
||
384 | Highcharts.getOptions().exporting.buttons.contextButton.menuItems.push({ |
||
385 | textKey: 'downloadCSV', |
||
386 | onclick: function() { |
||
387 | this.downloadCSV(); |
||
388 | } |
||
389 | }, { |
||
390 | textKey: 'downloadXLS', |
||
391 | onclick: function() { |
||
392 | this.downloadXLS(); |
||
393 | } |
||
394 | }, { |
||
395 | textKey: 'viewData', |
||
396 | onclick: function() { |
||
397 | this.viewData(); |
||
398 | } |
||
399 | }); |
||
400 | } |
||
401 | |||
402 | // Series specific |
||
403 | if (seriesTypes.map) { |
||
404 | seriesTypes.map.prototype.exportKey = 'name'; |
||
405 | } |
||
406 | if (seriesTypes.mapbubble) { |
||
407 | seriesTypes.mapbubble.prototype.exportKey = 'name'; |
||
408 | } |
||
409 | if (seriesTypes.treemap) { |
||
410 | seriesTypes.treemap.prototype.exportKey = 'name'; |
||
411 | } |
||
412 | |||
413 | |||
414 | }(Highcharts)); |
||
415 | })); |