lazy_high_charts 1.4.1 → 1.4.2.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ /*
2
+ Highcharts JS v3.0.1 (2013-04-09)
3
+ Exporting module
4
+
5
+ (c) 2010-2013 Torstein Hønsi
6
+
7
+ License: www.highcharts.com/license
8
+ */
9
+ (function(e){var y=e.Chart,v=e.addEvent,B=e.removeEvent,m=e.createElement,j=e.discardElement,t=e.css,k=e.merge,r=e.each,p=e.extend,C=Math.max,i=document,z=window,D=e.isTouchDevice,E=e.Renderer.prototype.symbols,s=e.getOptions(),w;p(s.lang,{printChart:"Print chart",downloadPNG:"Download PNG image",downloadJPEG:"Download JPEG image",downloadPDF:"Download PDF document",downloadSVG:"Download SVG vector image",contextButtonTitle:"Chart context menu"});s.navigation={menuStyle:{border:"1px solid #A0A0A0",
10
+ background:"#FFFFFF",padding:"5px 0"},menuItemStyle:{padding:"0 10px",background:"none",color:"#303030",fontSize:D?"14px":"11px"},menuItemHoverStyle:{background:"#4572A5",color:"#FFFFFF"},buttonOptions:{symbolFill:"#E0E0E0",symbolSize:14,symbolStroke:"#666",symbolStrokeWidth:3,symbolX:12.5,symbolY:10.5,align:"right",buttonSpacing:3,height:22,theme:{fill:"white",stroke:"none"},verticalAlign:"top",width:24}};s.exporting={type:"image/png",url:"http://export.highcharts.com/",buttons:{contextButton:{symbol:"menu",
11
+ _titleKey:"contextButtonTitle",menuItems:[{textKey:"printChart",onclick:function(){this.print()}},{separator:!0},{textKey:"downloadPNG",onclick:function(){this.exportChart()}},{textKey:"downloadJPEG",onclick:function(){this.exportChart({type:"image/jpeg"})}},{textKey:"downloadPDF",onclick:function(){this.exportChart({type:"application/pdf"})}},{textKey:"downloadSVG",onclick:function(){this.exportChart({type:"image/svg+xml"})}}]}}};e.post=function(a,b){var c,d;d=m("form",{method:"post",action:a,enctype:"multipart/form-data"},
12
+ {display:"none"},i.body);for(c in b)m("input",{type:"hidden",name:c,value:b[c]},null,d);d.submit();j(d)};p(y.prototype,{getSVG:function(a){var b=this,c,d,x,g,f=k(b.options,a);if(!i.createElementNS)i.createElementNS=function(a,b){return i.createElement(b)};a=m("div",null,{position:"absolute",top:"-9999em",width:b.chartWidth+"px",height:b.chartHeight+"px"},i.body);d=b.renderTo.style.width;g=b.renderTo.style.height;d=f.exporting.sourceWidth||f.chart.width||/px$/.test(d)&&parseInt(d,10)||600;g=f.exporting.sourceHeight||
13
+ f.chart.height||/px$/.test(g)&&parseInt(g,10)||400;p(f.chart,{animation:!1,renderTo:a,forExport:!0,width:d,height:g});f.exporting.enabled=!1;f.chart.plotBackgroundImage=null;f.series=[];r(b.series,function(a){x=k(a.options,{animation:!1,showCheckbox:!1,visible:a.visible});x.isInternal||f.series.push(x)});c=new e.Chart(f,b.callback);r(["xAxis","yAxis"],function(a){r(b[a],function(b,d){var f=c[a][d],e=b.getExtremes(),g=e.userMin,e=e.userMax;(g!==void 0||e!==void 0)&&f.setExtremes(g,e,!0,!1)})});d=c.container.innerHTML;
14
+ f=null;c.destroy();j(a);d=d.replace(/zIndex="[^"]+"/g,"").replace(/isShadow="[^"]+"/g,"").replace(/symbolName="[^"]+"/g,"").replace(/jQuery[0-9]+="[^"]+"/g,"").replace(/url\([^#]+#/g,"url(#").replace(/<svg /,'<svg xmlns:xlink="http://www.w3.org/1999/xlink" ').replace(/ href=/g," xlink:href=").replace(/\n/," ").replace(/<\/svg>.*?$/,"</svg>").replace(/&nbsp;/g," ").replace(/&shy;/g,"­").replace(/<IMG /g,"<image ").replace(/height=([^" ]+)/g,'height="$1"').replace(/width=([^" ]+)/g,'width="$1"').replace(/hc-svg-href="([^"]+)">/g,
15
+ 'xlink:href="$1"/>').replace(/id=([^" >]+)/g,'id="$1"').replace(/class=([^" ]+)/g,'class="$1"').replace(/ transform /g," ").replace(/:(path|rect)/g,"$1").replace(/style="([^"]+)"/g,function(a){return a.toLowerCase()});d=d.replace(/(url\(#highcharts-[0-9]+)&quot;/g,"$1").replace(/&quot;/g,"'");d.match(/ xmlns="/g).length===2&&(d=d.replace(/xmlns="[^"]+"/,""));return d},exportChart:function(a,b){var a=a||{},c=this.options.exporting,c=this.getSVG(k({chart:{borderRadius:0}},c,b,{exporting:{sourceWidth:a.sourceWidth||
16
+ c.sourceWidth,sourceHeight:a.sourceHeight||c.sourceHeight}})),a=k(this.options.exporting,a);e.post(a.url,{filename:a.filename||"chart",type:a.type,width:a.width||0,scale:a.scale||2,svg:c})},print:function(){var a=this,b=a.container,c=[],d=b.parentNode,e=i.body,g=e.childNodes;if(!a.isPrinting)a.isPrinting=!0,r(g,function(a,b){if(a.nodeType===1)c[b]=a.style.display,a.style.display="none"}),e.appendChild(b),z.focus(),z.print(),setTimeout(function(){d.appendChild(b);r(g,function(a,b){if(a.nodeType===
17
+ 1)a.style.display=c[b]});a.isPrinting=!1},1E3)},contextMenu:function(a,b,c,d,e,g,f){var h=this,q=h.options.navigation,n=q.menuItemStyle,o=h.chartWidth,i=h.chartHeight,A="cache-"+a,l=h[A],k=C(e,g),u,j,s;if(!l)h[A]=l=m("div",{className:"highcharts-"+a},{position:"absolute",zIndex:1E3,padding:k+"px"},h.container),u=m("div",null,p({MozBoxShadow:"3px 3px 10px #888",WebkitBoxShadow:"3px 3px 10px #888",boxShadow:"3px 3px 10px #888"},q.menuStyle),l),j=function(){t(l,{display:"none"});f&&f.setState(0)},v(l,
18
+ "mouseleave",function(){s=setTimeout(j,500)}),v(l,"mouseenter",function(){clearTimeout(s)}),r(b,function(a){if(a){var b=a.separator?m("hr",null,null,u):m("div",{onmouseover:function(){t(this,q.menuItemHoverStyle)},onmouseout:function(){t(this,n)},onclick:function(){j();a.onclick.apply(h,arguments)},innerHTML:a.text||h.options.lang[a.textKey]},p({cursor:"pointer"},n),u);h.exportDivElements.push(b)}}),h.exportDivElements.push(u,l),h.exportMenuWidth=l.offsetWidth,h.exportMenuHeight=l.offsetHeight;a=
19
+ {display:"block"};c+h.exportMenuWidth>o?a.right=o-c-e-k+"px":a.left=c-k+"px";d+g+h.exportMenuHeight>i?a.bottom=i-d-k+"px":a.top=d+g-k+"px";t(l,a)},addButton:function(a){var b=this,c=b.renderer,a=k(b.options.navigation.buttonOptions,a),d=a.onclick,i=a.menuItems,g,f,h={stroke:a.symbolStroke,fill:a.symbolFill},q=a.symbolSize||12;if(!b.btnCount)b.btnCount=0;b.btnCount++;if(!b.exportDivElements)b.exportDivElements=[],b.exportSVGElements=[];if(a.enabled!==!1){var n=a.theme,o=n.states,m=o&&o.hover,o=o&&
20
+ o.select,j;delete n.states;d?j=function(){d.apply(b,arguments)}:i&&(j=function(){b.contextMenu("contextmenu",i,f.translateX,f.translateY,f.width,f.height,f);f.setState(2)});a.text&&a.symbol?n.paddingLeft=e.pick(n.paddingLeft,25):a.text||p(n,{width:a.width,height:a.height,padding:0});f=c.button(a.text,0,0,j,n,m,o).attr({title:b.options.lang[a._titleKey],"stroke-linecap":"round"});a.symbol&&(g=c.symbol(a.symbol,a.symbolX-q/2,a.symbolY-q/2,q,q).attr(p(h,{"stroke-width":a.symbolStrokeWidth||1,zIndex:1})).add(f));
21
+ f.add().align(p(a,{width:f.width,x:e.pick(a.x,w)}),!0,"spacingBox");w+=(f.width+a.buttonSpacing)*(a.align==="right"?-1:1);b.exportSVGElements.push(f,g)}},destroyExport:function(a){var a=a.target,b,c;for(b=0;b<a.exportSVGElements.length;b++)c=a.exportSVGElements[b],c.onclick=c.ontouchstart=null,a.exportSVGElements[b]=c.destroy();for(b=0;b<a.exportDivElements.length;b++)c=a.exportDivElements[b],B(c,"mouseleave"),a.exportDivElements[b]=c.onmouseout=c.onmouseover=c.ontouchstart=c.onclick=null,j(c)}});
22
+ E.menu=function(a,b,c,d){return["M",a,b+2.5,"L",a+c,b+2.5,"M",a,b+d/2+0.5,"L",a+c,b+d/2+0.5,"M",a,b+d-1.5,"L",a+c,b+d-1.5]};y.prototype.callbacks.push(function(a){var b,c=a.options.exporting,d=c.buttons;w=0;if(c.enabled!==!1){for(b in d)a.addButton(d[b]);v(a,"destroy",a.destroyExport)}})})(Highcharts);
@@ -0,0 +1,703 @@
1
+ /**
2
+ * @license Highcharts JS v3.0.1 (2013-04-09)
3
+ * Exporting module
4
+ *
5
+ * (c) 2010-2013 Torstein Hønsi
6
+ *
7
+ * License: www.highcharts.com/license
8
+ */
9
+
10
+ // JSLint options:
11
+ /*global Highcharts, document, window, Math, setTimeout */
12
+
13
+ (function (Highcharts) { // encapsulate
14
+
15
+ // create shortcuts
16
+ var Chart = Highcharts.Chart,
17
+ addEvent = Highcharts.addEvent,
18
+ removeEvent = Highcharts.removeEvent,
19
+ createElement = Highcharts.createElement,
20
+ discardElement = Highcharts.discardElement,
21
+ css = Highcharts.css,
22
+ merge = Highcharts.merge,
23
+ each = Highcharts.each,
24
+ extend = Highcharts.extend,
25
+ math = Math,
26
+ mathMax = math.max,
27
+ doc = document,
28
+ win = window,
29
+ isTouchDevice = Highcharts.isTouchDevice,
30
+ M = 'M',
31
+ L = 'L',
32
+ DIV = 'div',
33
+ HIDDEN = 'hidden',
34
+ NONE = 'none',
35
+ PREFIX = 'highcharts-',
36
+ ABSOLUTE = 'absolute',
37
+ PX = 'px',
38
+ UNDEFINED,
39
+ symbols = Highcharts.Renderer.prototype.symbols,
40
+ defaultOptions = Highcharts.getOptions(),
41
+ buttonOffset;
42
+
43
+ // Add language
44
+ extend(defaultOptions.lang, {
45
+ printChart: 'Print chart',
46
+ downloadPNG: 'Download PNG image',
47
+ downloadJPEG: 'Download JPEG image',
48
+ downloadPDF: 'Download PDF document',
49
+ downloadSVG: 'Download SVG vector image',
50
+ contextButtonTitle: 'Chart context menu'
51
+ });
52
+
53
+ // Buttons and menus are collected in a separate config option set called 'navigation'.
54
+ // This can be extended later to add control buttons like zoom and pan right click menus.
55
+ defaultOptions.navigation = {
56
+ menuStyle: {
57
+ border: '1px solid #A0A0A0',
58
+ background: '#FFFFFF',
59
+ padding: '5px 0'
60
+ },
61
+ menuItemStyle: {
62
+ padding: '0 10px',
63
+ background: NONE,
64
+ color: '#303030',
65
+ fontSize: isTouchDevice ? '14px' : '11px'
66
+ },
67
+ menuItemHoverStyle: {
68
+ background: '#4572A5',
69
+ color: '#FFFFFF'
70
+ },
71
+
72
+ buttonOptions: {
73
+ symbolFill: '#E0E0E0',
74
+ symbolSize: 14,
75
+ symbolStroke: '#666',
76
+ symbolStrokeWidth: 3,
77
+ symbolX: 12.5,
78
+ symbolY: 10.5,
79
+ align: 'right',
80
+ buttonSpacing: 3,
81
+ height: 22,
82
+ // text: null,
83
+ theme: {
84
+ fill: 'white', // capture hover
85
+ stroke: 'none'
86
+ },
87
+ verticalAlign: 'top',
88
+ width: 24
89
+ }
90
+ };
91
+
92
+
93
+
94
+ // Add the export related options
95
+ defaultOptions.exporting = {
96
+ //enabled: true,
97
+ //filename: 'chart',
98
+ type: 'image/png',
99
+ url: 'http://export.highcharts.com/',
100
+ //width: undefined,
101
+ //scale: 2
102
+ buttons: {
103
+ contextButton: {
104
+ //x: -10,
105
+ symbol: 'menu',
106
+ _titleKey: 'contextButtonTitle',
107
+ menuItems: [{
108
+ textKey: 'printChart',
109
+ onclick: function () {
110
+ this.print();
111
+ }
112
+ }, {
113
+ separator: true
114
+ }, {
115
+ textKey: 'downloadPNG',
116
+ onclick: function () {
117
+ this.exportChart();
118
+ }
119
+ }, {
120
+ textKey: 'downloadJPEG',
121
+ onclick: function () {
122
+ this.exportChart({
123
+ type: 'image/jpeg'
124
+ });
125
+ }
126
+ }, {
127
+ textKey: 'downloadPDF',
128
+ onclick: function () {
129
+ this.exportChart({
130
+ type: 'application/pdf'
131
+ });
132
+ }
133
+ }, {
134
+ textKey: 'downloadSVG',
135
+ onclick: function () {
136
+ this.exportChart({
137
+ type: 'image/svg+xml'
138
+ });
139
+ }
140
+ }
141
+ // Enable this block to add "View SVG" to the dropdown menu
142
+ /*
143
+ ,{
144
+
145
+ text: 'View SVG',
146
+ onclick: function () {
147
+ var svg = this.getSVG()
148
+ .replace(/</g, '\n&lt;')
149
+ .replace(/>/g, '&gt;');
150
+
151
+ doc.body.innerHTML = '<pre>' + svg + '</pre>';
152
+ }
153
+ } // */
154
+ ]
155
+ }
156
+ }
157
+ };
158
+
159
+ // Add the Highcharts.post utility
160
+ Highcharts.post = function (url, data) {
161
+ var name,
162
+ form;
163
+
164
+ // create the form
165
+ form = createElement('form', {
166
+ method: 'post',
167
+ action: url,
168
+ enctype: 'multipart/form-data'
169
+ }, {
170
+ display: NONE
171
+ }, doc.body);
172
+
173
+ // add the data
174
+ for (name in data) {
175
+ createElement('input', {
176
+ type: HIDDEN,
177
+ name: name,
178
+ value: data[name]
179
+ }, null, form);
180
+ }
181
+
182
+ // submit
183
+ form.submit();
184
+
185
+ // clean up
186
+ discardElement(form);
187
+ };
188
+
189
+ extend(Chart.prototype, {
190
+
191
+ /**
192
+ * Return an SVG representation of the chart
193
+ *
194
+ * @param additionalOptions {Object} Additional chart options for the generated SVG representation
195
+ */
196
+ getSVG: function (additionalOptions) {
197
+ var chart = this,
198
+ chartCopy,
199
+ sandbox,
200
+ svg,
201
+ seriesOptions,
202
+ sourceWidth,
203
+ sourceHeight,
204
+ cssWidth,
205
+ cssHeight,
206
+ options = merge(chart.options, additionalOptions); // copy the options and add extra options
207
+
208
+ // IE compatibility hack for generating SVG content that it doesn't really understand
209
+ if (!doc.createElementNS) {
210
+ /*jslint unparam: true*//* allow unused parameter ns in function below */
211
+ doc.createElementNS = function (ns, tagName) {
212
+ return doc.createElement(tagName);
213
+ };
214
+ /*jslint unparam: false*/
215
+ }
216
+
217
+ // create a sandbox where a new chart will be generated
218
+ sandbox = createElement(DIV, null, {
219
+ position: ABSOLUTE,
220
+ top: '-9999em',
221
+ width: chart.chartWidth + PX,
222
+ height: chart.chartHeight + PX
223
+ }, doc.body);
224
+
225
+ // get the source size
226
+ cssWidth = chart.renderTo.style.width;
227
+ cssHeight = chart.renderTo.style.height;
228
+ sourceWidth = options.exporting.sourceWidth ||
229
+ options.chart.width ||
230
+ (/px$/.test(cssWidth) && parseInt(cssWidth, 10)) ||
231
+ 600;
232
+ sourceHeight = options.exporting.sourceHeight ||
233
+ options.chart.height ||
234
+ (/px$/.test(cssHeight) && parseInt(cssHeight, 10)) ||
235
+ 400;
236
+
237
+ // override some options
238
+ extend(options.chart, {
239
+ animation: false,
240
+ renderTo: sandbox,
241
+ forExport: true,
242
+ width: sourceWidth,
243
+ height: sourceHeight
244
+ });
245
+ options.exporting.enabled = false; // hide buttons in print
246
+ options.chart.plotBackgroundImage = null; // the converter doesn't handle images
247
+
248
+ // prepare for replicating the chart
249
+ options.series = [];
250
+ each(chart.series, function (serie) {
251
+ seriesOptions = merge(serie.options, {
252
+ animation: false, // turn off animation
253
+ showCheckbox: false,
254
+ visible: serie.visible
255
+ });
256
+
257
+ if (!seriesOptions.isInternal) { // used for the navigator series that has its own option set
258
+ options.series.push(seriesOptions);
259
+ }
260
+ });
261
+
262
+ // generate the chart copy
263
+ chartCopy = new Highcharts.Chart(options, chart.callback);
264
+
265
+ // reflect axis extremes in the export
266
+ each(['xAxis', 'yAxis'], function (axisType) {
267
+ each(chart[axisType], function (axis, i) {
268
+ var axisCopy = chartCopy[axisType][i],
269
+ extremes = axis.getExtremes(),
270
+ userMin = extremes.userMin,
271
+ userMax = extremes.userMax;
272
+
273
+ if (userMin !== UNDEFINED || userMax !== UNDEFINED) {
274
+ axisCopy.setExtremes(userMin, userMax, true, false);
275
+ }
276
+ });
277
+ });
278
+
279
+ // get the SVG from the container's innerHTML
280
+ svg = chartCopy.container.innerHTML;
281
+
282
+ // free up memory
283
+ options = null;
284
+ chartCopy.destroy();
285
+ discardElement(sandbox);
286
+
287
+ // sanitize
288
+ svg = svg
289
+ .replace(/zIndex="[^"]+"/g, '')
290
+ .replace(/isShadow="[^"]+"/g, '')
291
+ .replace(/symbolName="[^"]+"/g, '')
292
+ .replace(/jQuery[0-9]+="[^"]+"/g, '')
293
+ .replace(/url\([^#]+#/g, 'url(#')
294
+ .replace(/<svg /, '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ')
295
+ .replace(/ href=/g, ' xlink:href=')
296
+ .replace(/\n/, ' ')
297
+ .replace(/<\/svg>.*?$/, '</svg>') // any HTML added to the container after the SVG (#894)
298
+ /* This fails in IE < 8
299
+ .replace(/([0-9]+)\.([0-9]+)/g, function(s1, s2, s3) { // round off to save weight
300
+ return s2 +'.'+ s3[0];
301
+ })*/
302
+
303
+ // Replace HTML entities, issue #347
304
+ .replace(/&nbsp;/g, '\u00A0') // no-break space
305
+ .replace(/&shy;/g, '\u00AD') // soft hyphen
306
+
307
+ // IE specific
308
+ .replace(/<IMG /g, '<image ')
309
+ .replace(/height=([^" ]+)/g, 'height="$1"')
310
+ .replace(/width=([^" ]+)/g, 'width="$1"')
311
+ .replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>')
312
+ .replace(/id=([^" >]+)/g, 'id="$1"')
313
+ .replace(/class=([^" ]+)/g, 'class="$1"')
314
+ .replace(/ transform /g, ' ')
315
+ .replace(/:(path|rect)/g, '$1')
316
+ .replace(/style="([^"]+)"/g, function (s) {
317
+ return s.toLowerCase();
318
+ });
319
+
320
+ // IE9 beta bugs with innerHTML. Test again with final IE9.
321
+ svg = svg.replace(/(url\(#highcharts-[0-9]+)&quot;/g, '$1')
322
+ .replace(/&quot;/g, "'");
323
+ if (svg.match(/ xmlns="/g).length === 2) {
324
+ svg = svg.replace(/xmlns="[^"]+"/, '');
325
+ }
326
+
327
+ return svg;
328
+ },
329
+
330
+ /**
331
+ * Submit the SVG representation of the chart to the server
332
+ * @param {Object} options Exporting options. Possible members are url, type and width.
333
+ * @param {Object} chartOptions Additional chart options for the SVG representation of the chart
334
+ */
335
+ exportChart: function (options, chartOptions) {
336
+ options = options || {};
337
+
338
+ var chart = this,
339
+ chartExportingOptions = chart.options.exporting,
340
+ svg = chart.getSVG(merge(
341
+ { chart: { borderRadius: 0 } },
342
+ chartExportingOptions,
343
+ chartOptions,
344
+ {
345
+ exporting: {
346
+ sourceWidth: options.sourceWidth || chartExportingOptions.sourceWidth, // docs: option and parameter in exportChart()
347
+ sourceHeight: options.sourceHeight || chartExportingOptions.sourceHeight // docs
348
+ }
349
+ }
350
+ ));
351
+
352
+ // merge the options
353
+ options = merge(chart.options.exporting, options);
354
+
355
+ // do the post
356
+ Highcharts.post(options.url, {
357
+ filename: options.filename || 'chart',
358
+ type: options.type,
359
+ width: options.width || 0, // IE8 fails to post undefined correctly, so use 0
360
+ scale: options.scale || 2,
361
+ svg: svg
362
+ });
363
+
364
+ },
365
+
366
+ /**
367
+ * Print the chart
368
+ */
369
+ print: function () {
370
+
371
+ var chart = this,
372
+ container = chart.container,
373
+ origDisplay = [],
374
+ origParent = container.parentNode,
375
+ body = doc.body,
376
+ childNodes = body.childNodes;
377
+
378
+ if (chart.isPrinting) { // block the button while in printing mode
379
+ return;
380
+ }
381
+
382
+ chart.isPrinting = true;
383
+
384
+ // hide all body content
385
+ each(childNodes, function (node, i) {
386
+ if (node.nodeType === 1) {
387
+ origDisplay[i] = node.style.display;
388
+ node.style.display = NONE;
389
+ }
390
+ });
391
+
392
+ // pull out the chart
393
+ body.appendChild(container);
394
+
395
+ // print
396
+ win.focus(); // #1510
397
+ win.print();
398
+
399
+ // allow the browser to prepare before reverting
400
+ setTimeout(function () {
401
+
402
+ // put the chart back in
403
+ origParent.appendChild(container);
404
+
405
+ // restore all body content
406
+ each(childNodes, function (node, i) {
407
+ if (node.nodeType === 1) {
408
+ node.style.display = origDisplay[i];
409
+ }
410
+ });
411
+
412
+ chart.isPrinting = false;
413
+
414
+ }, 1000);
415
+
416
+ },
417
+
418
+ /**
419
+ * Display a popup menu for choosing the export type
420
+ *
421
+ * @param {String} name An identifier for the menu
422
+ * @param {Array} items A collection with text and onclicks for the items
423
+ * @param {Number} x The x position of the opener button
424
+ * @param {Number} y The y position of the opener button
425
+ * @param {Number} width The width of the opener button
426
+ * @param {Number} height The height of the opener button
427
+ */
428
+ contextMenu: function (name, items, x, y, width, height, button) {
429
+ var chart = this,
430
+ navOptions = chart.options.navigation,
431
+ menuItemStyle = navOptions.menuItemStyle,
432
+ chartWidth = chart.chartWidth,
433
+ chartHeight = chart.chartHeight,
434
+ cacheName = 'cache-' + name,
435
+ menu = chart[cacheName],
436
+ menuPadding = mathMax(width, height), // for mouse leave detection
437
+ boxShadow = '3px 3px 10px #888',
438
+ innerMenu,
439
+ hide,
440
+ hideTimer,
441
+ menuStyle;
442
+
443
+ // create the menu only the first time
444
+ if (!menu) {
445
+
446
+ // create a HTML element above the SVG
447
+ chart[cacheName] = menu = createElement(DIV, {
448
+ className: PREFIX + name
449
+ }, {
450
+ position: ABSOLUTE,
451
+ zIndex: 1000,
452
+ padding: menuPadding + PX
453
+ }, chart.container);
454
+
455
+ innerMenu = createElement(DIV, null,
456
+ extend({
457
+ MozBoxShadow: boxShadow,
458
+ WebkitBoxShadow: boxShadow,
459
+ boxShadow: boxShadow
460
+ }, navOptions.menuStyle), menu);
461
+
462
+ // hide on mouse out
463
+ hide = function () {
464
+ css(menu, { display: NONE });
465
+ if (button) {
466
+ button.setState(0);
467
+ }
468
+ };
469
+
470
+ // Hide the menu some time after mouse leave (#1357)
471
+ addEvent(menu, 'mouseleave', function () {
472
+ hideTimer = setTimeout(hide, 500);
473
+ });
474
+ addEvent(menu, 'mouseenter', function () {
475
+ clearTimeout(hideTimer);
476
+ });
477
+
478
+
479
+ // create the items
480
+ each(items, function (item) {
481
+ if (item) {
482
+ var element = item.separator ?
483
+ createElement('hr', null, null, innerMenu) :
484
+ createElement(DIV, {
485
+ onmouseover: function () {
486
+ css(this, navOptions.menuItemHoverStyle);
487
+ },
488
+ onmouseout: function () {
489
+ css(this, menuItemStyle);
490
+ },
491
+ onclick: function () {
492
+ hide();
493
+ item.onclick.apply(chart, arguments);
494
+ },
495
+ innerHTML: item.text || chart.options.lang[item.textKey]
496
+ }, extend({
497
+ cursor: 'pointer'
498
+ }, menuItemStyle), innerMenu);
499
+
500
+
501
+ // Keep references to menu divs to be able to destroy them
502
+ chart.exportDivElements.push(element);
503
+ }
504
+ });
505
+
506
+ // Keep references to menu and innerMenu div to be able to destroy them
507
+ chart.exportDivElements.push(innerMenu, menu);
508
+
509
+ chart.exportMenuWidth = menu.offsetWidth;
510
+ chart.exportMenuHeight = menu.offsetHeight;
511
+ }
512
+
513
+ menuStyle = { display: 'block' };
514
+
515
+ // if outside right, right align it
516
+ if (x + chart.exportMenuWidth > chartWidth) {
517
+ menuStyle.right = (chartWidth - x - width - menuPadding) + PX;
518
+ } else {
519
+ menuStyle.left = (x - menuPadding) + PX;
520
+ }
521
+ // if outside bottom, bottom align it
522
+ if (y + height + chart.exportMenuHeight > chartHeight) {
523
+ menuStyle.bottom = (chartHeight - y - menuPadding) + PX;
524
+ } else {
525
+ menuStyle.top = (y + height - menuPadding) + PX;
526
+ }
527
+
528
+ css(menu, menuStyle);
529
+ },
530
+
531
+ /**
532
+ * Add the export button to the chart
533
+ */
534
+ addButton: function (options) {
535
+ var chart = this,
536
+ renderer = chart.renderer,
537
+ btnOptions = merge(chart.options.navigation.buttonOptions, options),
538
+ onclick = btnOptions.onclick,
539
+ menuItems = btnOptions.menuItems,
540
+ symbol,
541
+ button,
542
+ symbolAttr = {
543
+ stroke: btnOptions.symbolStroke,
544
+ fill: btnOptions.symbolFill
545
+ },
546
+ symbolSize = btnOptions.symbolSize || 12,
547
+ menuKey;
548
+
549
+ if (!chart.btnCount) {
550
+ chart.btnCount = 0;
551
+ }
552
+ menuKey = chart.btnCount++;
553
+
554
+ // Keeps references to the button elements
555
+ if (!chart.exportDivElements) {
556
+ chart.exportDivElements = [];
557
+ chart.exportSVGElements = [];
558
+ }
559
+
560
+ if (btnOptions.enabled === false) {
561
+ return;
562
+ }
563
+
564
+
565
+ var attr = btnOptions.theme,
566
+ states = attr.states,
567
+ hover = states && states.hover,
568
+ select = states && states.select,
569
+ callback;
570
+
571
+ delete attr.states;
572
+
573
+ if (onclick) {
574
+ callback = function () {
575
+ onclick.apply(chart, arguments);
576
+ };
577
+
578
+ } else if (menuItems) {
579
+ callback = function () {
580
+ chart.contextMenu(
581
+ 'contextmenu',
582
+ menuItems,
583
+ button.translateX,
584
+ button.translateY,
585
+ button.width,
586
+ button.height,
587
+ button
588
+ );
589
+ button.setState(2);
590
+ };
591
+ }
592
+
593
+
594
+ if (btnOptions.text && btnOptions.symbol) {
595
+ attr.paddingLeft = Highcharts.pick(attr.paddingLeft, 25);
596
+
597
+ } else if (!btnOptions.text) {
598
+ extend(attr, {
599
+ width: btnOptions.width,
600
+ height: btnOptions.height,
601
+ padding: 0
602
+ });
603
+ }
604
+
605
+ button = renderer.button(btnOptions.text, 0, 0, callback, attr, hover, select)
606
+ .attr({
607
+ title: chart.options.lang[btnOptions._titleKey],
608
+ 'stroke-linecap': 'round'
609
+ });
610
+
611
+ if (btnOptions.symbol) {
612
+ symbol = renderer.symbol(
613
+ btnOptions.symbol,
614
+ btnOptions.symbolX - (symbolSize / 2),
615
+ btnOptions.symbolY - (symbolSize / 2),
616
+ symbolSize,
617
+ symbolSize
618
+ )
619
+ .attr(extend(symbolAttr, {
620
+ 'stroke-width': btnOptions.symbolStrokeWidth || 1,
621
+ zIndex: 1
622
+ })).add(button);
623
+ }
624
+
625
+ button.add()
626
+ .align(extend(btnOptions, {
627
+ width: button.width,
628
+ x: Highcharts.pick(btnOptions.x, buttonOffset) // #1654
629
+ }), true, 'spacingBox');
630
+
631
+ buttonOffset += (button.width + btnOptions.buttonSpacing) * (btnOptions.align === 'right' ? -1 : 1);
632
+
633
+ chart.exportSVGElements.push(button, symbol);
634
+
635
+ },
636
+
637
+ /**
638
+ * Destroy the buttons.
639
+ */
640
+ destroyExport: function (e) {
641
+ var chart = e.target,
642
+ i,
643
+ elem;
644
+
645
+ // Destroy the extra buttons added
646
+ for (i = 0; i < chart.exportSVGElements.length; i++) {
647
+ elem = chart.exportSVGElements[i];
648
+ // Destroy and null the svg/vml elements
649
+ elem.onclick = elem.ontouchstart = null;
650
+ chart.exportSVGElements[i] = elem.destroy();
651
+ }
652
+
653
+ // Destroy the divs for the menu
654
+ for (i = 0; i < chart.exportDivElements.length; i++) {
655
+ elem = chart.exportDivElements[i];
656
+
657
+ // Remove the event handler
658
+ removeEvent(elem, 'mouseleave');
659
+
660
+ // Remove inline events
661
+ chart.exportDivElements[i] = elem.onmouseout = elem.onmouseover = elem.ontouchstart = elem.onclick = null;
662
+
663
+ // Destroy the div by moving to garbage bin
664
+ discardElement(elem);
665
+ }
666
+ }
667
+ });
668
+
669
+
670
+ symbols.menu = function (x, y, width, height) {
671
+ var arr = [
672
+ M, x, y + 2.5,
673
+ L, x + width, y + 2.5,
674
+ M, x, y + height / 2 + 0.5,
675
+ L, x + width, y + height / 2 + 0.5,
676
+ M, x, y + height - 1.5,
677
+ L, x + width, y + height - 1.5
678
+ ];
679
+ return arr;
680
+ };
681
+
682
+ // Add the buttons on chart load
683
+ Chart.prototype.callbacks.push(function (chart) {
684
+ var n,
685
+ exportingOptions = chart.options.exporting,
686
+ buttons = exportingOptions.buttons;
687
+
688
+ buttonOffset = 0;
689
+
690
+ if (exportingOptions.enabled !== false) {
691
+
692
+ for (n in buttons) {
693
+ chart.addButton(buttons[n]);
694
+ }
695
+
696
+ // Destroy the export elements at chart destroy
697
+ addEvent(chart, 'destroy', chart.destroyExport);
698
+ }
699
+
700
+ });
701
+
702
+
703
+ }(Highcharts));