amcharts.rb 3.2.0.1 → 3.2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +1,88 @@
1
1
  AmCharts.AmExport = AmCharts.Class({
2
- construct: function (chart,cfg) {
3
- var _this = this;
4
- _this.DEBUG = false;
5
- _this.chart = chart;
6
- _this.canvas = null;
7
- _this.svgs = [];
8
- _this.cfg = {
9
- menuTop : 'auto',
10
- menuLeft : 'auto',
11
- menuRight : '0px',
12
- menuBottom : '0px',
13
- menuItems : [{
14
- textAlign : 'center',
15
- icon : _this.chart.pathToImages + 'export.png',
16
- iconTitle : 'Save chart as an image',
17
- format : 'png'
2
+ construct: function(chart, cfg) {
3
+ var _this = this;
4
+ _this.DEBUG = false;
5
+ _this.chart = chart;
6
+ _this.canvas = null;
7
+ _this.svgs = [];
8
+ _this.cfg = {
9
+ menuTop: 'auto',
10
+ menuLeft: 'auto',
11
+ menuRight: '0px',
12
+ menuBottom: '0px',
13
+ menuItems: [{
14
+ textAlign: 'center',
15
+ icon: _this.chart.pathToImages + 'export.png',
16
+ iconTitle: 'Save chart as an image',
17
+ format: 'png'
18
18
  }],
19
- menuItemStyle : {
20
- backgroundColor : 'transparent',
21
- rollOverBackgroundColor : '#EFEFEF',
22
- color : '#000000',
23
- rollOverColor : '#CC0000',
24
- paddingTop : '6px',
25
- paddingRight : '6px',
26
- paddingBottom : '6px',
27
- paddingLeft : '6px',
28
- marginTop : '0px',
29
- marginRight : '0px',
30
- marginBottom : '0px',
31
- marginLeft : '0px',
32
- textAlign : 'left',
33
- textDecoration : 'none',
34
- fontFamily : _this.chart.fontFamily,
35
- fontSize : _this.chart.fontSize + 'px'
19
+ menuItemStyle: {
20
+ backgroundColor: 'transparent',
21
+ rollOverBackgroundColor: '#EFEFEF',
22
+ color: '#000000',
23
+ rollOverColor: '#CC0000',
24
+ paddingTop: '6px',
25
+ paddingRight: '6px',
26
+ paddingBottom: '6px',
27
+ paddingLeft: '6px',
28
+ marginTop: '0px',
29
+ marginRight: '0px',
30
+ marginBottom: '0px',
31
+ marginLeft: '0px',
32
+ textAlign: 'left',
33
+ textDecoration: 'none',
34
+ fontFamily: _this.chart.fontFamily,
35
+ fontSize: _this.chart.fontSize + 'px'
36
36
  },
37
- menuItemOutput : {
38
- backgroundColor : '#FFFFFF',
39
- fileName : 'amChart',
40
- format : 'png',
41
- output : 'dataurlnewwindow',
42
- render : 'browser',
43
- dpi : 90,
44
- onclick : function(instance,config,event) {
37
+ menuItemOutput: {
38
+ backgroundColor: '#FFFFFF',
39
+ fileName: 'amChart',
40
+ format: 'png',
41
+ output: 'dataurlnewwindow',
42
+ render: 'browser',
43
+ dpi: 90,
44
+ onclick: function(instance, config, event) {
45
45
  instance.output(config);
46
46
  }
47
47
  },
48
- removeImagery : true
48
+ removeImagery: true
49
49
  };
50
50
  _this.processing = {
51
- buffer : [],
52
- drawn : 0,
53
- timer : 0
54
- }
51
+ buffer: [],
52
+ drawn: 0,
53
+ timer: 0
54
+ };
55
55
 
56
56
  // Config dependency adaption
57
- if ( typeof(window.canvg) != 'undefined' && typeof(window.RGBColor) != 'undefined' ) {
57
+ if (typeof(window.canvg) != 'undefined' && typeof(window.RGBColor) != 'undefined') {
58
58
  _this.cfg.menuItemOutput.render = 'canvg';
59
59
  }
60
- if ( typeof(window.saveAs) != 'undefined' ) {
60
+ if (typeof(window.saveAs) != 'undefined') {
61
61
  _this.cfg.menuItemOutput.output = 'save';
62
62
  }
63
- if ( AmCharts.isIE && AmCharts.IEversion < 10 ) {
63
+ if (AmCharts.isIE && AmCharts.IEversion < 10) {
64
64
  _this.cfg.menuItemOutput.output = 'dataurlnewwindow';
65
65
  }
66
66
 
67
67
  // Merge given configs
68
- if ( cfg ) {
69
- cfg.menuItemOutput = AmCharts.extend(_this.cfg.menuItemOutput,cfg.menuItemOutput || {});
70
- cfg.menuItemStyle = AmCharts.extend(_this.cfg.menuItemStyle,cfg.menuItemStyle || {});
71
- _this.cfg = AmCharts.extend(_this.cfg,cfg);
68
+ if (cfg) {
69
+ cfg.menuItemOutput = AmCharts.extend(_this.cfg.menuItemOutput, cfg.menuItemOutput || {});
70
+ cfg.menuItemStyle = AmCharts.extend(_this.cfg.menuItemStyle, cfg.menuItemStyle || {});
71
+ _this.cfg = AmCharts.extend(_this.cfg, cfg);
72
72
  }
73
73
 
74
74
  // Add reference to chart
75
75
  _this.chart.AmExport = _this;
76
76
 
77
77
  // Listen to the drawer
78
- _this.chart.addListener('rendered',function() {
78
+ _this.chart.addListener('rendered', function() {
79
79
  _this.setup();
80
80
  });
81
81
 
82
82
  // DEBUG; Public reference
83
- if ( _this.DEBUG ) { window.AmExport = _this };
83
+ if (_this.DEBUG) {
84
+ window.AmExport = _this;
85
+ }
84
86
  },
85
87
 
86
88
  /*
@@ -88,7 +90,7 @@ AmCharts.AmExport = AmCharts.Class({
88
90
  @param **args
89
91
  */
90
92
  log: function() {
91
- console.log('AmExport: ',arguments);
93
+ console.log('AmExport: ', arguments);
92
94
  },
93
95
 
94
96
  /* PUBLIC
@@ -98,10 +100,12 @@ AmCharts.AmExport = AmCharts.Class({
98
100
  setup: function() {
99
101
  var _this = this;
100
102
 
101
- if ( _this.DEBUG == 10 ) { _this.log('SETUP START'); } // DEBUG
103
+ if (_this.DEBUG == 10) {
104
+ _this.log('SETUP START');
105
+ } // DEBUG
102
106
 
103
107
 
104
- if ( !AmCharts.isIE || ( AmCharts.isIE && AmCharts.IEversion > 9 ) ) {
108
+ if (!AmCharts.isIE || (AmCharts.isIE && AmCharts.IEversion > 9)) {
105
109
  window.clearTimeout(_this.processing.timer);
106
110
  _this.processing.timer = setTimeout(function() {
107
111
  // Polify SVG; needs to wait
@@ -109,10 +113,14 @@ AmCharts.AmExport = AmCharts.Class({
109
113
 
110
114
  // Build Buttons
111
115
  _this.generateButtons();
112
- if ( _this.DEBUG == 10 ) { _this.log('SETUP END'); } // DEBUG
113
- },1000);
116
+ if (_this.DEBUG == 10) {
117
+ _this.log('SETUP END');
118
+ } // DEBUG
119
+ }, 1000);
114
120
  } else {
115
- if ( _this.DEBUG == 10 ) { _this.log('< IE10 NOT SUPPORTED'); } // DEBUG
121
+ if (_this.DEBUG == 10) {
122
+ _this.log('< IE10 NOT SUPPORTED');
123
+ } // DEBUG
116
124
  }
117
125
  },
118
126
 
@@ -123,26 +131,19 @@ AmCharts.AmExport = AmCharts.Class({
123
131
  */
124
132
  generateBinaryArray: function(base64_string) {
125
133
  var
126
- len = base64_string.length
127
- , buffer = new Uint8Array(len / 4 * 3 | 0)
128
- , i = 0
129
- , outptr = 0
130
- , last = [0, 0]
131
- , state = 0
132
- , save = 0
133
- , rank
134
- , code
135
- , undef
136
- , base64_ranks = new Uint8Array([
137
- 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1
138
- , -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
139
- , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
140
- , -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
141
- , 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
142
- ]);
134
+ len = base64_string.length,
135
+ buffer = new Uint8Array(len / 4 * 3 | 0),
136
+ i = 0,
137
+ outptr = 0,
138
+ last = [0, 0],
139
+ state = 0,
140
+ save = 0,
141
+ rank, code, undef, base64_ranks = new Uint8Array([
142
+ 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
143
+ ]);
143
144
  while (len--) {
144
145
  code = base64_string.charCodeAt(i++);
145
- rank = base64_ranks[code-43];
146
+ rank = base64_ranks[code - 43];
146
147
  if (rank !== 255 && rank !== undef) {
147
148
  last[1] = last[0];
148
149
  last[0] = code;
@@ -150,10 +151,10 @@ AmCharts.AmExport = AmCharts.Class({
150
151
  state++;
151
152
  if (state === 4) {
152
153
  buffer[outptr++] = save >>> 16;
153
- if (last[1] !== 61 /* padding character */) {
154
+ if (last[1] !== 61 /* padding character */ ) {
154
155
  buffer[outptr++] = save >>> 8;
155
156
  }
156
- if (last[0] !== 61 /* padding character */) {
157
+ if (last[0] !== 61 /* padding character */ ) {
157
158
  buffer[outptr++] = save;
158
159
  }
159
160
  state = 0;
@@ -171,27 +172,29 @@ AmCharts.AmExport = AmCharts.Class({
171
172
  @param base64_datastring string
172
173
  @param type string
173
174
  */
174
- generateBlob: function(datastring,type) {
175
- var _this = this,
176
- header_end = datastring.indexOf(',') + 1,
177
- header = datastring.substring(0,header_end),
178
- data = datastring,
179
- blob = new Blob();
180
-
181
- if ( header.indexOf('base64') != -1 ) {
175
+ generateBlob: function(datastring, type) {
176
+ var _this = this,
177
+ header_end = datastring.indexOf(',') + 1,
178
+ header = datastring.substring(0, header_end),
179
+ data = datastring,
180
+ blob = new Blob();
181
+
182
+ if (header.indexOf('base64') != -1) {
182
183
  data = _this.generateBinaryArray(datastring.substring(header_end));
183
184
  }
184
185
 
185
186
  // Fake blob for IE
186
- if ( AmCharts.isIE && AmCharts.IEversion < 10 ) {
187
- blob.data = data;
188
- blob.size = data.length;
189
- blob.type = type;
190
- blob.encoding = 'base64';
187
+ if (AmCharts.isIE && AmCharts.IEversion < 10) {
188
+ blob.data = data;
189
+ blob.size = data.length;
190
+ blob.type = type;
191
+ blob.encoding = 'base64';
191
192
  } else {
192
- blob = new Blob([data],{type: type});
193
+ blob = new Blob([data], {
194
+ type: type
195
+ });
193
196
  }
194
- return blob
197
+ return blob;
195
198
  },
196
199
 
197
200
  /*
@@ -199,16 +202,20 @@ AmCharts.AmExport = AmCharts.Class({
199
202
  @param config object
200
203
  */
201
204
  generatePDF: function(cfg) {
202
- var _this = this,
203
- pdf = {output: function() {return ''}},
204
- data = _this.canvas.toDataURL('image/jpeg'), // JSPDF ONLY SUPPORTS JPG
205
- width = (_this.canvas.width * 25.4) / cfg.dpi,
206
- height = (_this.canvas.height * 25.4) / cfg.dpi;
205
+ var _this = this,
206
+ pdf = {
207
+ output: function() {
208
+ return '';
209
+ }
210
+ },
211
+ data = _this.canvas.toDataURL('image/jpeg'), // JSPDF ONLY SUPPORTS JPG
212
+ width = (_this.canvas.width * 25.4) / cfg.dpi,
213
+ height = (_this.canvas.height * 25.4) / cfg.dpi;
207
214
 
208
215
  // Check
209
- if ( window.jsPDF ) {
216
+ if (window.jsPDF) {
210
217
  pdf = new jsPDF();
211
- if ( pdf.addImage ) {
218
+ if (pdf.addImage) {
212
219
  pdf.addImage(data, 'JPEG', 0, 0, width, height);
213
220
  } else {
214
221
  alert("Missing jsPDF plugin; Please add the 'addImage' plugin.");
@@ -225,9 +232,9 @@ AmCharts.AmExport = AmCharts.Class({
225
232
  @param format void()
226
233
  @param callback; given callback function which returns the blob or datastring of the configured ouput type
227
234
  */
228
- output: function(cfg,externalCallback) {
229
- var _this = this,
230
- cfg = AmCharts.extend(AmCharts.extend({},_this.cfg.menuItemOutput),cfg||{});
235
+ output: function(cfg, externalCallback) {
236
+ var _this = this;
237
+ cfg = AmCharts.extend(AmCharts.extend({}, _this.cfg.menuItemOutput), cfg || {});
231
238
 
232
239
  /* PRIVATE
233
240
  Callback function which gets called after the drawing process is done
@@ -235,93 +242,96 @@ AmCharts.AmExport = AmCharts.Class({
235
242
  */
236
243
  function internalCallback() {
237
244
  var data = null;
238
- if ( _this.DEBUG == 10 ) { _this.log('OUTPUT',format); } // DEBUG
245
+ var blob;
246
+ if (_this.DEBUG == 10) {
247
+ _this.log('OUTPUT', format);
248
+ } // DEBUG
239
249
 
240
250
  // SVG
241
- if ( cfg.format == 'image/svg+xml' || cfg.format == 'svg' ) {
242
- for ( var i = 0; i < _this.processing.buffer.length; i++ ) {
243
- data = new XMLSerializer().serializeToString(_this.processing.buffer[i][0]),
244
- blob = _this.generateBlob(data,'image/svg+xml');
251
+ if (cfg.format == 'image/svg+xml' || cfg.format == 'svg') {
252
+ for (var i = 0; i < _this.processing.buffer.length; i++) {
253
+ data = new XMLSerializer().serializeToString(_this.processing.buffer[i][0]);
254
+ blob = _this.generateBlob(data, 'image/svg+xml');
245
255
 
246
- if ( cfg.output == 'save' ) {
256
+ if (cfg.output == 'save') {
247
257
  saveAs(blob, cfg.fileName + '.svg');
248
- } else if ( cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring' ) {
258
+ } else if (cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring') {
249
259
  blob = 'data:image/svg+xml;base64,' + btoa(data);
250
- } else if ( cfg.output == 'dataurlnewwindow' ) {
260
+ } else if (cfg.output == 'dataurlnewwindow') {
251
261
  window.open('data:image/svg+xml;base64,' + btoa(data));
252
- } else if ( cfg.output == 'datauri' || cfg.output == 'dataurl' ) {
262
+ } else if (cfg.output == 'datauri' || cfg.output == 'dataurl') {
253
263
  location.href = 'data:image/svg+xml;base64,' + btoa(data);
254
- } else if ( cfg.output == 'datastream' ) {
264
+ } else if (cfg.output == 'datastream') {
255
265
  location.href = 'data:image/octet-stream;base64,' + btoa(data);
256
266
  }
257
267
 
258
- if ( externalCallback )
259
- externalCallback.apply(_this,[blob]);
268
+ if (externalCallback)
269
+ externalCallback.apply(_this, [blob]);
260
270
  }
261
- // PDF
262
- } else if ( cfg.format == 'application/pdf' || cfg.format == 'pdf' ) {
263
- data = _this.generatePDF(cfg).output('dataurlstring'),
264
- blob = _this.generateBlob(data,'application/pdf');
271
+ // PDF
272
+ } else if (cfg.format == 'application/pdf' || cfg.format == 'pdf') {
273
+ data = _this.generatePDF(cfg).output('dataurlstring');
274
+ blob = _this.generateBlob(data, 'application/pdf');
265
275
 
266
- if ( cfg.output == 'save' ) {
276
+ if (cfg.output == 'save') {
267
277
  saveAs(blob, cfg.fileName + '.pdf');
268
- } else if ( cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring' ) {
278
+ } else if (cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring') {
269
279
  blob = data;
270
- } else if ( cfg.output == 'dataurlnewwindow' ) {
280
+ } else if (cfg.output == 'dataurlnewwindow') {
271
281
  window.open(data);
272
- } else if ( cfg.output == 'datauri' || cfg.output == 'dataurl' ) {
282
+ } else if (cfg.output == 'datauri' || cfg.output == 'dataurl') {
273
283
  location.href = data;
274
- } else if ( cfg.output == 'datastream' ) {
275
- location.href = data.replace('application/pdf','application/octet-stream');
284
+ } else if (cfg.output == 'datastream') {
285
+ location.href = data.replace('application/pdf', 'application/octet-stream');
276
286
  }
277
-
278
- if ( externalCallback )
279
- externalCallback.apply(_this,[blob]);
280
287
 
281
- // PNG
282
- } else if ( cfg.format == 'image/png' || cfg.format == 'png' ) {
283
- data = _this.canvas.toDataURL('image/png'),
284
- blob = _this.generateBlob(data,'image/png');
288
+ if (externalCallback)
289
+ externalCallback.apply(_this, [blob]);
285
290
 
286
- if ( cfg.output == 'save' ) {
291
+ // PNG
292
+ } else if (cfg.format == 'image/png' || cfg.format == 'png') {
293
+ data = _this.canvas.toDataURL('image/png');
294
+ blob = _this.generateBlob(data, 'image/png');
295
+
296
+ if (cfg.output == 'save') {
287
297
  saveAs(blob, cfg.fileName + '.png');
288
- } else if ( cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring' ) {
298
+ } else if (cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring') {
289
299
  blob = data;
290
- } else if ( cfg.output == 'dataurlnewwindow' ) {
300
+ } else if (cfg.output == 'dataurlnewwindow') {
291
301
  window.open(data);
292
- } else if ( cfg.output == 'datauri' || cfg.output == 'dataurl' ) {
302
+ } else if (cfg.output == 'datauri' || cfg.output == 'dataurl') {
293
303
  location.href = data;
294
- } else if ( cfg.output == 'datastream' ) {
295
- location.href = data.replace('image/png','image/octet-stream');
304
+ } else if (cfg.output == 'datastream') {
305
+ location.href = data.replace('image/png', 'image/octet-stream');
296
306
  }
297
307
 
298
- if ( externalCallback )
299
- externalCallback.apply(_this,[blob]);
308
+ if (externalCallback)
309
+ externalCallback.apply(_this, [blob]);
300
310
 
301
- // JPG
302
- } else if ( cfg.format == 'image/jpeg' || cfg.format == 'jpeg' || cfg.format == 'jpg' ) {
303
- data = _this.canvas.toDataURL('image/jpeg'),
304
- blob = _this.generateBlob(data,'image/jpeg');
311
+ // JPG
312
+ } else if (cfg.format == 'image/jpeg' || cfg.format == 'jpeg' || cfg.format == 'jpg') {
313
+ data = _this.canvas.toDataURL('image/jpeg');
314
+ blob = _this.generateBlob(data, 'image/jpeg');
305
315
 
306
- if ( cfg.output == 'save' ) {
316
+ if (cfg.output == 'save') {
307
317
  saveAs(blob, cfg.fileName + '.jpg');
308
- } else if ( cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring' ) {
318
+ } else if (cfg.output == 'datastring' || cfg.output == 'datauristring' || cfg.output == 'dataurlstring') {
309
319
  blob = data;
310
- } else if ( cfg.output == 'dataurlnewwindow' ) {
320
+ } else if (cfg.output == 'dataurlnewwindow') {
311
321
  window.open(data);
312
- } else if ( cfg.output == 'datauri' || cfg.output == 'dataurl' ) {
322
+ } else if (cfg.output == 'datauri' || cfg.output == 'dataurl') {
313
323
  location.href = data;
314
- } else if ( cfg.output == 'datastream' ) {
315
- location.href = data.replace('image/jpeg','image/octet-stream');
324
+ } else if (cfg.output == 'datastream') {
325
+ location.href = data.replace('image/jpeg', 'image/octet-stream');
316
326
  }
317
327
 
318
- if ( externalCallback )
319
- externalCallback.apply(_this,[blob]);
328
+ if (externalCallback)
329
+ externalCallback.apply(_this, [blob]);
320
330
  }
321
331
 
322
332
  }
323
333
 
324
- return _this.generateOutput(cfg,internalCallback);
334
+ return _this.generateOutput(cfg, internalCallback);
325
335
  },
326
336
 
327
337
  /* PUBLIC
@@ -329,49 +339,51 @@ AmCharts.AmExport = AmCharts.Class({
329
339
  @param none
330
340
  */
331
341
  polifySVG: function() {
332
- var _this = this;
333
- var svgs = _this.chart.div.getElementsByTagName('svg');
342
+ var _this = this;
343
+ var svgs = _this.chart.div.getElementsByTagName('svg');
334
344
 
335
345
  // Recursive function to force the attributes
336
- function recursiveChange(svg,tag) {
346
+ function recursiveChange(svg, tag) {
337
347
  var items = svg.getElementsByTagName(tag);
338
348
 
339
- for ( var i = 0; i < items.length; i++) {
349
+ for (var i = 0; i < items.length; i++) {
340
350
 
341
- if ( _this.cfg.removeImagery ) {
351
+ if (_this.cfg.removeImagery) {
342
352
  items[i].parentNode.removeChild(items[i]);
343
353
 
344
354
  } else {
345
- var image = document.createElement('img');
346
- var canvas = document.createElement('canvas');
347
- var ctx = canvas.getContext('2d');
348
-
349
- canvas.width = items[i].getAttribute('width');
350
- canvas.height = items[i].getAttribute('height');
351
- image.src = items[i].getAttribute('xlink:href');
352
- image.width = items[i].getAttribute('width');
353
- image.height = items[i].getAttribute('height');
355
+ var image = document.createElement('img');
356
+ var canvas = document.createElement('canvas');
357
+ var ctx = canvas.getContext('2d');
358
+
359
+ canvas.width = items[i].getAttribute('width');
360
+ canvas.height = items[i].getAttribute('height');
361
+ image.src = items[i].getAttribute('xlink:href');
362
+ image.width = items[i].getAttribute('width');
363
+ image.height = items[i].getAttribute('height');
354
364
 
355
365
  try {
356
- ctx.drawImage(image,0,0,image.width,image.height);
357
- datastring = canvas.toDataURL(); // image.src; // canvas.toDataURL(); //
358
- } catch(err) {
359
- datastring = image.src; // image.src; // canvas.toDataURL(); //
366
+ ctx.drawImage(image, 0, 0, image.width, image.height);
367
+ datastring = canvas.toDataURL(); // image.src; // canvas.toDataURL(); //
368
+ } catch (err) {
369
+ datastring = image.src; // image.src; // canvas.toDataURL(); //
360
370
 
361
371
  _this.log('Tainted canvas, reached browser CORS security; origin from imagery must be equal to the server!');
362
372
  throw new Error(err);
363
373
  }
364
374
 
365
- items[i].setAttribute('xlink:href',datastring);
375
+ items[i].setAttribute('xlink:href', datastring);
366
376
  }
367
377
 
368
- if ( _this.DEBUG == 10 ) { _this.log('POLIFIED',items[i]); } // DEBUG
378
+ if (_this.DEBUG == 10) {
379
+ _this.log('POLIFIED', items[i]);
380
+ } // DEBUG
369
381
  }
370
382
  }
371
383
 
372
384
  // Loop through svgs to add some standardization
373
- for ( var i = 0; i < svgs.length; i++ ) {
374
- var parent = svgs[i].parentNode;
385
+ for (var i = 0; i < svgs.length; i++) {
386
+ var parent = svgs[i].parentNode;
375
387
 
376
388
  // Put some attrs to it
377
389
  /*
@@ -383,11 +395,13 @@ AmCharts.AmExport = AmCharts.Class({
383
395
  svgs[i].setAttribute('height',parent.style.height);
384
396
  */
385
397
 
386
- if ( _this.DEBUG == 10 ) { _this.log('POLIFIED',svgs[i]); } // DEBUG
398
+ if (_this.DEBUG == 10) {
399
+ _this.log('POLIFIED', svgs[i]);
400
+ } // DEBUG
387
401
 
388
402
  // Force link adaption
389
- recursiveChange(svgs[i],'pattern');
390
- recursiveChange(svgs[i],'image');
403
+ recursiveChange(svgs[i], 'pattern');
404
+ recursiveChange(svgs[i], 'image');
391
405
 
392
406
  _this.svgs.push(svgs[i]);
393
407
  }
@@ -399,61 +413,73 @@ AmCharts.AmExport = AmCharts.Class({
399
413
  Generates the canvas with the given SVGs and configured renderer
400
414
  @param callback; function(); gets called after drawing process on the canvas has been finished
401
415
  */
402
- generateOutput: function(cfg,callback) {
403
- var _this = this,
404
- svgs = _this.chart.div.getElementsByTagName('svg'),
405
- canvas = document.createElement('canvas'),
416
+ generateOutput: function(cfg, callback) {
417
+ var _this = this,
418
+ svgs = _this.chart.div.getElementsByTagName('svg'),
419
+ canvas = document.createElement('canvas'),
406
420
  context = canvas.getContext('2d'),
407
- offset = {
421
+ offset = {
408
422
  y: 0,
409
423
  x: 0
410
424
  },
411
- tmp = {};
425
+ tmp = {};
412
426
 
413
427
  // Reset
414
- _this.processing.buffer = [];
415
- _this.processing.drawn = 0;
416
- _this.canvas = canvas;
428
+ _this.processing.buffer = [];
429
+ _this.processing.drawn = 0;
430
+ _this.canvas = canvas;
417
431
 
418
432
  // Walkthroug SVGs
419
- if ( _this.DEBUG == 10 ) { _this.log('START EXPORT'); } // DEBUG
420
- if ( _this.DEBUG == 10 ) { _this.log('START BUFFERING'); } // DEBUG
421
- for ( var i = 0; i < svgs.length; i++ ) {
422
- var parent = svgs[i].parentNode,
423
- svgX = Number(parent.style.left.slice(0,-2)),
424
- svgY = Number(parent.style.top.slice(0,-2));
425
- tmp = AmCharts.extend({},offset);
433
+ if (_this.DEBUG == 10) {
434
+ _this.log('START EXPORT');
435
+ } // DEBUG
436
+ if (_this.DEBUG == 10) {
437
+ _this.log('START BUFFERING');
438
+ } // DEBUG
439
+ for (var i = 0; i < svgs.length; i++) {
440
+ var parent = svgs[i].parentNode,
441
+ svgX = Number(parent.style.left.slice(0, -2)),
442
+ svgY = Number(parent.style.top.slice(0, -2));
443
+ tmp = AmCharts.extend({}, offset);
426
444
 
427
445
  // Overtake parent position if givwn
428
- offset.x = svgX?svgX:offset.x;
429
- offset.y = svgY?svgY:offset.y;
446
+ offset.x = svgX ? svgX : offset.x;
447
+ offset.y = svgY ? svgY : offset.y;
430
448
 
431
- _this.processing.buffer.push([svgs[i],AmCharts.extend({},offset)]);
449
+ _this.processing.buffer.push([svgs[i], AmCharts.extend({}, offset)]);
432
450
 
433
451
  // Put back from "cache"
434
- if ( svgY&&svgX ) {
452
+ if (svgY && svgX) {
435
453
  offset = tmp;
436
454
 
437
- // New offset for next one
455
+ // New offset for next one
438
456
  } else {
439
- offset.y += svgY?0:parent.offsetHeight;
457
+ offset.y += svgY ? 0 : parent.offsetHeight;
440
458
  }
441
459
 
442
- if ( _this.DEBUG == 10 ) { _this.log('BUFFERED',svgs[i],offset); } // DEBUG
460
+ if (_this.DEBUG == 10) {
461
+ _this.log('BUFFERED', svgs[i], offset);
462
+ } // DEBUG
443
463
  }
444
- if ( _this.DEBUG == 10 ) { _this.log('END BUFFERING'); } // DEBUG
464
+ if (_this.DEBUG == 10) {
465
+ _this.log('END BUFFERING');
466
+ } // DEBUG
445
467
 
446
468
  // Apply background
447
- if ( _this.DEBUG == 10 ) { _this.log('START DRAWING',cfg.render); } // DEBUG
448
- if ( _this.DEBUG == 10 ) { _this.log('FILL BACKGROUND'); } // DEBUG
449
- canvas.id = AmCharts.getUniqueId();
450
- canvas.width = _this.chart.divRealWidth;
451
- canvas.height = _this.chart.divRealHeight;
469
+ if (_this.DEBUG == 10) {
470
+ _this.log('START DRAWING', cfg.render);
471
+ } // DEBUG
472
+ if (_this.DEBUG == 10) {
473
+ _this.log('FILL BACKGROUND');
474
+ } // DEBUG
475
+ canvas.id = AmCharts.getUniqueId();
476
+ canvas.width = _this.chart.divRealWidth;
477
+ canvas.height = _this.chart.divRealHeight;
452
478
 
453
479
  // Set given background; jpeg default
454
- if ( cfg.backgroundColor || format == 'image/jpeg' ) {
455
- context.fillStyle = cfg.backgroundColor || '#FFFFFF';
456
- context.fillRect(0,0,canvas.width,canvas.height);
480
+ if (cfg.backgroundColor || format == 'image/jpeg') {
481
+ context.fillStyle = cfg.backgroundColor || '#FFFFFF';
482
+ context.fillRect(0, 0, canvas.width, canvas.height);
457
483
  }
458
484
 
459
485
  /* PRIVATE
@@ -461,62 +487,76 @@ AmCharts.AmExport = AmCharts.Class({
461
487
  @param none;
462
488
  */
463
489
  function drawItWhenItsLoaded() {
464
- var img,buffer,offset,source;
490
+ var img, buffer, offset, source;
465
491
 
466
492
  // DRAWING PROCESS DONE
467
- if ( _this.processing.buffer.length == _this.processing.drawn ) {
468
- if ( _this.DEBUG == 10 ) { _this.log('END DRAWING'); } // DEBUG
493
+ if (_this.processing.buffer.length == _this.processing.drawn) {
494
+ if (_this.DEBUG == 10) {
495
+ _this.log('END DRAWING');
496
+ } // DEBUG
469
497
  return callback();
470
498
 
471
- // LOOPING LUI
499
+ // LOOPING LUI
472
500
  } else {
473
- if ( _this.DEBUG == 10 ) { _this.log('DRAW',_this.processing.drawn + 1,'OF',_this.processing.buffer.length); } // DEBUG
501
+ if (_this.DEBUG == 10) {
502
+ _this.log('DRAW', _this.processing.drawn + 1, 'OF', _this.processing.buffer.length);
503
+ } // DEBUG
474
504
 
475
- buffer = _this.processing.buffer[_this.processing.drawn];
476
- source = new XMLSerializer().serializeToString(buffer[0]); //source = 'data:image/svg+xml;base64,' + btoa();
477
- offset = buffer[1];
505
+ buffer = _this.processing.buffer[_this.processing.drawn];
506
+ source = new XMLSerializer().serializeToString(buffer[0]); //source = 'data:image/svg+xml;base64,' + btoa();
507
+ offset = buffer[1];
478
508
 
479
- if ( _this.DEBUG == 10 ) { _this.log('SOURCE',source); } // DEBUG
509
+ if (_this.DEBUG == 10) {
510
+ _this.log('SOURCE', source);
511
+ } // DEBUG
480
512
 
481
513
  // NATIVE
482
- if ( cfg.render == 'browser' ) {
483
- img = new Image();
484
- img.id = AmCharts.getUniqueId();
485
- source = 'data:image/svg+xml;base64,' + btoa(source);
514
+ if (cfg.render == 'browser') {
515
+ img = new Image();
516
+ img.id = AmCharts.getUniqueId();
517
+ source = 'data:image/svg+xml;base64,' + btoa(source);
486
518
 
487
519
  //img.crossOrigin = "Anonymous";
488
- img.onload = function() {
489
- context.drawImage(this,buffer[1].x,buffer[1].y);
520
+ img.onload = function() {
521
+ context.drawImage(this, buffer[1].x, buffer[1].y);
490
522
  _this.processing.drawn++;
491
523
 
492
- if ( _this.DEBUG == 10 ) { _this.log('ONLOAD',this); } // DEBUG
524
+ if (_this.DEBUG == 10) {
525
+ _this.log('ONLOAD', this);
526
+ } // DEBUG
493
527
  drawItWhenItsLoaded();
494
- }
495
- img.onerror = function() {
496
- if ( _this.DEBUG == 10 ) { _this.log('ONERROR',this); } // DEBUG
497
- context.drawImage(this,buffer[1].x,buffer[1].y);
528
+ };
529
+ img.onerror = function() {
530
+ if (_this.DEBUG == 10) {
531
+ _this.log('ONERROR', this);
532
+ } // DEBUG
533
+ context.drawImage(this, buffer[1].x, buffer[1].y);
498
534
  _this.processing.drawn++;
499
535
  drawItWhenItsLoaded();
500
- }
501
- img.src = source;
502
-
503
- if ( _this.DEBUG == 10 ) { _this.log('ADD',img); } // DEBUG
504
- if ( img.complete || typeof(img.complete) == 'undefined' || img.complete === undefined ) {
505
- if ( _this.DEBUG == 10 ) { _this.log('FORCE ONLOAD',img); } // DEBUG
536
+ };
537
+ img.src = source;
538
+
539
+ if (_this.DEBUG == 10) {
540
+ _this.log('ADD', img);
541
+ } // DEBUG
542
+ if (img.complete || typeof(img.complete) == 'undefined' || img.complete === undefined) {
543
+ if (_this.DEBUG == 10) {
544
+ _this.log('FORCE ONLOAD', img);
545
+ } // DEBUG
506
546
  img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
507
547
  img.src = source;
508
548
  }
509
549
 
510
- // CANVG
511
- } else if ( cfg.render == 'canvg' ) {
512
- canvg(canvas,source,{
513
- offsetX : offset.x,
514
- offsetY : offset.y,
515
- ignoreMouse : true,
516
- ignoreAnimation : true,
517
- ignoreDimensions : true,
518
- ignoreClear : true,
519
- renderCallback : function() {
550
+ // CANVG
551
+ } else if (cfg.render == 'canvg') {
552
+ canvg(canvas, source, {
553
+ offsetX: offset.x,
554
+ offsetY: offset.y,
555
+ ignoreMouse: true,
556
+ ignoreAnimation: true,
557
+ ignoreDimensions: true,
558
+ ignoreClear: true,
559
+ renderCallback: function() {
520
560
  _this.processing.drawn++;
521
561
  drawItWhenItsLoaded();
522
562
  }
@@ -532,63 +572,63 @@ AmCharts.AmExport = AmCharts.Class({
532
572
  @param none;
533
573
  */
534
574
  generateButtons: function() {
535
- var _this = this,
536
- div = document.createElement('div'),
537
- lvl = 0;
575
+ var _this = this,
576
+ div = document.createElement('div'),
577
+ lvl = 0;
538
578
 
539
579
  // Push sublings
540
580
  function createList(items) {
541
- var ul = document.createElement('ul');
581
+ var ul = document.createElement('ul');
542
582
 
543
- ul.setAttribute('style','list-style: none; margin: 0; padding: 0;');
583
+ ul.setAttribute('style', 'list-style: none; margin: 0; padding: 0;');
544
584
 
545
585
  // Walkthrough items
546
- for ( var i = 0; i < items.length; i++ ) {
547
- var li = document.createElement('li'),
548
- img = document.createElement('img'),
549
- a = document.createElement('a'),
550
- item = items[i],
551
- children = null,
552
- itemStyle = AmCharts.extend(AmCharts.extend({},_this.cfg.menuItemStyle),items[i]);
586
+ for (var i = 0; i < items.length; i++) {
587
+ var li = document.createElement('li'),
588
+ img = document.createElement('img'),
589
+ a = document.createElement('a'),
590
+ item = items[i],
591
+ children = null,
592
+ itemStyle = AmCharts.extend(AmCharts.extend({}, _this.cfg.menuItemStyle), items[i]);
553
593
 
554
594
  // MERGE CFG
555
- item = AmCharts.extend(AmCharts.extend({},_this.cfg.menuItemOutput),item);
595
+ item = AmCharts.extend(AmCharts.extend({}, _this.cfg.menuItemOutput), item);
556
596
 
557
597
  // ICON
558
- if ( item['icon'] ) {
598
+ if (item['icon']) {
559
599
  img.alt = '';
560
600
  img.src = item['icon'];
561
- img.setAttribute('style','margin: 0 auto;border: none;outline: none');
562
- if ( item['iconTitle'] ) {
563
- img.title=item['iconTitle'];
601
+ img.setAttribute('style', 'margin: 0 auto;border: none;outline: none');
602
+ if (item['iconTitle']) {
603
+ img.title = item['iconTitle'];
564
604
  }
565
605
  a.appendChild(img);
566
606
  }
567
607
 
568
608
  // TITLE; STYLING
569
- a.href = '#';
570
- if ( item['title'] ) {
571
- img.setAttribute('style','margin-right: 5px;');
572
- a.innerHTML += item.title;
609
+ a.href = '#';
610
+ if (item['title']) {
611
+ img.setAttribute('style', 'margin-right: 5px;');
612
+ a.innerHTML += item.title;
573
613
  }
574
- a.setAttribute('style','display: block;');
575
- AmCharts.extend(a.style,itemStyle)
614
+ a.setAttribute('style', 'display: block;');
615
+ AmCharts.extend(a.style, itemStyle);
576
616
 
577
617
  // ONCLICK
578
- a.onclick = item.onclick.bind(a,_this,item);
618
+ a.onclick = item.onclick.bind(a, _this, item);
579
619
  li.appendChild(a);
580
620
 
581
621
  // APPEND SIBLINGS
582
- if ( item.items ) {
622
+ if (item.items) {
583
623
  children = createList(item.items);
584
624
  li.appendChild(children);
585
625
 
586
626
  li.onmouseover = function() {
587
627
  children.style.display = 'block';
588
- }
628
+ };
589
629
  li.onmouseout = function() {
590
630
  children.style.display = 'none';
591
- }
631
+ };
592
632
  children.style.display = 'none';
593
633
  }
594
634
 
@@ -597,27 +637,29 @@ AmCharts.AmExport = AmCharts.Class({
597
637
 
598
638
  // Apply hover
599
639
  a.onmouseover = function() {
600
- this.style.backgroundColor = itemStyle.rollOverBackgroundColor;
601
- this.style.color = itemStyle.rollOverColor;
602
- this.style.borderColor = itemStyle.rollOverBorderColor;
603
- }
640
+ this.style.backgroundColor = itemStyle.rollOverBackgroundColor;
641
+ this.style.color = itemStyle.rollOverColor;
642
+ this.style.borderColor = itemStyle.rollOverBorderColor;
643
+ };
604
644
  a.onmouseout = function() {
605
- this.style.backgroundColor = itemStyle.backgroundColor;
606
- this.style.color = itemStyle.color;
607
- this.style.borderColor = itemStyle.borderColor;
608
- }
645
+ this.style.backgroundColor = itemStyle.backgroundColor;
646
+ this.style.color = itemStyle.color;
647
+ this.style.borderColor = itemStyle.borderColor;
648
+ };
609
649
  }
610
650
  lvl++;
611
651
 
612
- if ( _this.DEBUG == 10 ) { _this.log('MENU',ul); } // DEBUG
652
+ if (_this.DEBUG == 10) {
653
+ _this.log('MENU', ul);
654
+ } // DEBUG
613
655
 
614
656
  return ul;
615
657
  }
616
658
 
617
659
  // Style wrapper; Push into chart div
618
- div.setAttribute('style','position: absolute;top:'+ _this.cfg.menuTop +';right:'+ _this.cfg.menuRight +';bottom:'+ _this.cfg.menuBottom +';left:'+ _this.cfg.menuLeft +';box-shadow:0px 0px 1px 0px rgba(0,0,0,0);');
660
+ div.setAttribute('style', 'position: absolute;top:' + _this.cfg.menuTop + ';right:' + _this.cfg.menuRight + ';bottom:' + _this.cfg.menuBottom + ';left:' + _this.cfg.menuLeft + ';box-shadow:0px 0px 1px 0px rgba(0,0,0,0);');
619
661
  div.appendChild(createList(_this.cfg.menuItems));
620
- _this.chart.div.style.position = 'relative';
621
- _this.chart.div.appendChild(div);
662
+ //_this.chart.div.style.position = 'relative';
663
+ _this.chart.containerDiv.appendChild(div);
622
664
  }
623
665
  });