ganglia_js_charts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ /*
2
+ Highcharts JS v2.1.2 (2011-01-12)
3
+ Exporting module
4
+
5
+ (c) 2010 Torstein H?nsi
6
+
7
+ License: www.highcharts.com/license
8
+ */
9
+ (function(){var j=Highcharts,y=j.Chart,C=j.addEvent,r=j.createElement,z=j.discardElement,u=j.css,w=j.merge,s=j.each,p=j.extend,D=Math.max,q=document,E=window,A="ontouchstart"in q.documentElement,B=j.setOptions({lang:{downloadPNG:"Download PNG image",downloadJPEG:"Download JPEG image",downloadPDF:"Download PDF document",downloadSVG:"Download SVG vector image",exportButtonTitle:"Export to raster or vector image",printButtonTitle:"Print the chart"}});B.navigation={menuStyle:{border:"1px solid #A0A0A0",
10
+ background:"#FFFFFF"},menuItemStyle:{padding:"0 5px",background:"none",color:"#303030",fontSize:A?"14px":"11px"},menuItemHoverStyle:{background:"#4572A5",color:"#FFFFFF"},buttonOptions:{align:"right",backgroundColor:{linearGradient:[0,0,0,20],stops:[[0.4,"#F7F7F7"],[0.6,"#E3E3E3"]]},borderColor:"#B0B0B0",borderRadius:3,borderWidth:1,height:20,hoverBorderColor:"#909090",hoverSymbolFill:"#81A7CF",hoverSymbolStroke:"#4572A5",symbolFill:"#E0E0E0",symbolStroke:"#A0A0A0",symbolX:11.5,symbolY:10.5,verticalAlign:"top",
11
+ width:24,y:10}};B.exporting={type:"image/png",url:"http://export.highcharts.com/",width:800,buttons:{exportButton:{symbol:"exportIcon",x:-10,symbolFill:"#A8BF77",hoverSymbolFill:"#768F3E",_titleKey:"exportButtonTitle",menuItems:[{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"})}}]},
12
+ printButton:{symbol:"printIcon",x:-36,symbolFill:"#B5C9DF",hoverSymbolFill:"#779ABF",_titleKey:"printButtonTitle",onclick:function(){this.print()}}}};p(y.prototype,{getSVG:function(b){var c=this,a,e,d,k,f,h,i=w(c.options,b);if(!q.createElementNS)q.createElementNS=function(l,g){var n=q.createElement(g);n.getBBox=function(){return c.renderer.Element.prototype.getBBox.apply({element:n})};return n};a=r("div",null,{position:"absolute",top:"-9999em",width:c.chartWidth+"px",height:c.chartHeight+"px"},q.body);
13
+ p(i.chart,{renderTo:a,renderer:"SVG"});i.exporting.enabled=false;i.chart.plotBackgroundImage=null;i.series=[];s(c.series,function(l){d=l.options;d.animation=false;d.showCheckbox=false;if(d&&d.marker&&/^url\(/.test(d.marker.symbol))d.marker.symbol="circle";d.data=[];s(l.data,function(g){k=g.config;f=p(typeof k=="object"&&k.constructor!=Array&&g.config,{x:g.x,y:g.y,name:g.name});d.data.push(f);(h=g.config&&g.config.marker)&&/^url\(/.test(h.symbol)&&delete h.symbol});i.series.push(d)});b=new Highcharts.Chart(i);
14
+ e=b.container.innerHTML;i=null;b.destroy();z(a);e=e.replace(/zIndex="[^"]+"/g,"").replace(/isShadow="[^"]+"/g,"").replace(/symbolName="[^"]+"/g,"").replace(/jQuery[0-9]+="[^"]+"/g,"").replace(/isTracker="[^"]+"/g,"").replace(/url\([^#]+#/g,"url(#").replace(/id=([^" >]+)/g,'id="$1"').replace(/class=([^" ]+)/g,'class="$1"').replace(/ transform /g," ").replace(/:(path|rect)/g,"$1").replace(/style="([^"]+)"/g,function(l){return l.toLowerCase()});e=e.replace(/(url\(#highcharts-[0-9]+)"/g,"$1").replace(/"/g,
15
+ "'");if(e.match(/ xmlns="/g).length==2)e=e.replace(/xmlns="[^"]+"/,"");return e},exportChart:function(b,c){var a,e=this.getSVG(c);b=w(this.options.exporting,b);a=r("form",{method:"post",action:b.url},{display:"none"},q.body);s(["filename","type","width","svg"],function(d){r("input",{type:"hidden",name:d,value:{filename:b.filename||"chart",type:b.type,width:b.width,svg:e}[d]},null,a)});a.submit();z(a)},print:function(){var b=this,c=b.container,a=[],e=c.parentNode,d=q.body,k=d.childNodes;if(!b.isPrinting){b.isPrinting=
16
+ true;s(k,function(f,h){if(f.nodeType==1){a[h]=f.style.display;f.style.display="none"}});d.appendChild(c);E.print();setTimeout(function(){e.appendChild(c);s(k,function(f,h){if(f.nodeType==1)f.style.display=a[h]});b.isPrinting=false},1E3)}},contextMenu:function(b,c,a,e,d,k){var f=this,h=f.options.navigation,i=h.menuItemStyle,l=f.chartWidth,g=f.chartHeight,n="cache-"+b,m=f[n],o=D(d,k),t,x;if(!m){f[n]=m=r("div",{className:"highcharts-"+b},{position:"absolute",zIndex:1E3,padding:o+"px"},f.container);t=
17
+ r("div",null,p({MozBoxShadow:"3px 3px 10px #888",WebkitBoxShadow:"3px 3px 10px #888",boxShadow:"3px 3px 10px #888"},h.menuStyle),m);x=function(){u(m,{display:"none"})};C(m,"mouseleave",x);s(c,function(v){if(v)r("div",{onmouseover:function(){u(this,h.menuItemHoverStyle)},onmouseout:function(){u(this,i)},innerHTML:v.text||j.getOptions().lang[v.textKey]},p({cursor:"pointer"},i),t)[A?"ontouchstart":"onclick"]=function(){x();v.onclick.apply(f,arguments)}});f.exportMenuWidth=m.offsetWidth;f.exportMenuHeight=
18
+ m.offsetHeight}b={display:"block"};if(a+f.exportMenuWidth>l)b.right=l-a-d-o+"px";else b.left=a-o+"px";if(e+k+f.exportMenuHeight>g)b.bottom=g-e-o+"px";else b.top=e+k-o+"px";u(m,b)},addButton:function(b){function c(){g.attr(o);l.attr(m)}var a=this,e=a.renderer,d=w(a.options.navigation.buttonOptions,b),k=d.onclick,f=d.menuItems,h=d.width,i=d.height,l,g,n;b=d.borderWidth;var m={stroke:d.borderColor},o={stroke:d.symbolStroke,fill:d.symbolFill};if(d.enabled!==false){l=e.rect(0,0,h,i,d.borderRadius,b).align(d,
19
+ true).attr(p({fill:d.backgroundColor,"stroke-width":b,zIndex:19},m)).add();n=e.rect(0,0,h,i,0).align(d).attr({fill:"rgba(255, 255, 255, 0.001)",title:j.getOptions().lang[d._titleKey],zIndex:21}).css({cursor:"pointer"}).on("mouseover",function(){g.attr({stroke:d.hoverSymbolStroke,fill:d.hoverSymbolFill});l.attr({stroke:d.hoverBorderColor})}).on("mouseout",c).on("click",c).add();if(f)k=function(){c();var t=n.getBBox();a.contextMenu("export-menu",f,t.x,t.y,h,i)};n.on("click",function(){k.apply(a,arguments)});
20
+ g=e.symbol(d.symbol,d.symbolX,d.symbolY,(d.symbolSize||12)/2).align(d,true).attr(p(o,{"stroke-width":d.symbolStrokeWidth||1,zIndex:20})).add()}}});j.Renderer.prototype.symbols.exportIcon=function(b,c,a){return["M",b-a,c+a,"L",b+a,c+a,b+a,c+a*0.5,b-a,c+a*0.5,"Z","M",b,c+a*0.5,"L",b-a*0.5,c-a/3,b-a/6,c-a/3,b-a/6,c-a,b+a/6,c-a,b+a/6,c-a/3,b+a*0.5,c-a/3,"Z"]};j.Renderer.prototype.symbols.printIcon=function(b,c,a){return["M",b-a,c+a*0.5,"L",b+a,c+a*0.5,b+a,c-a/3,b-a,c-a/3,"Z","M",b-a*0.5,c-a/3,"L",b-a*
21
+ 0.5,c-a,b+a*0.5,c-a,b+a*0.5,c-a/3,"Z","M",b-a*0.5,c+a*0.5,"L",b-a*0.75,c+a,b+a*0.75,c+a,b+a*0.5,c+a*0.5,"Z"]};y.prototype.callbacks.push(function(b){var c,a=b.options.exporting,e=a.buttons;if(a.enabled!==false)for(c in e)b.addButton(e[c])})})();
@@ -0,0 +1,671 @@
1
+ /**
2
+ * @license Highcharts JS v2.1.2 (2011-01-12)
3
+ * Exporting module
4
+ *
5
+ * (c) 2010 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() { // encapsulate
14
+
15
+ // create shortcuts
16
+ var HC = Highcharts,
17
+ Chart = HC.Chart,
18
+ addEvent = HC.addEvent,
19
+ createElement = HC.createElement,
20
+ discardElement = HC.discardElement,
21
+ css = HC.css,
22
+ merge = HC.merge,
23
+ each = HC.each,
24
+ extend = HC.extend,
25
+ math = Math,
26
+ mathMax = math.max,
27
+ doc = document,
28
+ win = window,
29
+ hasTouch = 'ontouchstart' in doc.documentElement,
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
+
39
+
40
+
41
+ // Add language and get the defaultOptions
42
+ defaultOptions = HC.setOptions({
43
+ lang: {
44
+ downloadPNG: 'Download PNG image',
45
+ downloadJPEG: 'Download JPEG image',
46
+ downloadPDF: 'Download PDF document',
47
+ downloadSVG: 'Download SVG vector image',
48
+ exportButtonTitle: 'Export to raster or vector image',
49
+ printButtonTitle: 'Print the chart'
50
+ }
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
+ },
60
+ menuItemStyle: {
61
+ padding: '0 5px',
62
+ background: NONE,
63
+ color: '#303030',
64
+ fontSize: hasTouch ? '14px' : '11px'
65
+ },
66
+ menuItemHoverStyle: {
67
+ background: '#4572A5',
68
+ color: '#FFFFFF'
69
+ },
70
+
71
+ buttonOptions: {
72
+ align: 'right',
73
+ backgroundColor: {
74
+ linearGradient: [0, 0, 0, 20],
75
+ stops: [
76
+ [0.4, '#F7F7F7'],
77
+ [0.6, '#E3E3E3']
78
+ ]
79
+ },
80
+ borderColor: '#B0B0B0',
81
+ borderRadius: 3,
82
+ borderWidth: 1,
83
+ //enabled: true,
84
+ height: 20,
85
+ hoverBorderColor: '#909090',
86
+ hoverSymbolFill: '#81A7CF',
87
+ hoverSymbolStroke: '#4572A5',
88
+ symbolFill: '#E0E0E0',
89
+ //symbolSize: 12,
90
+ symbolStroke: '#A0A0A0',
91
+ //symbolStrokeWidth: 1,
92
+ symbolX: 11.5,
93
+ symbolY: 10.5,
94
+ verticalAlign: 'top',
95
+ width: 24,
96
+ y: 10
97
+ }
98
+ };
99
+
100
+
101
+
102
+ // Add the export related options
103
+ defaultOptions.exporting = {
104
+ //enabled: true,
105
+ //filename: 'chart',
106
+ type: 'image/png',
107
+ url: 'http://export.highcharts.com/',
108
+ width: 800,
109
+ buttons: {
110
+ exportButton: {
111
+ //enabled: true,
112
+ symbol: 'exportIcon',
113
+ x: -10,
114
+ symbolFill: '#A8BF77',
115
+ hoverSymbolFill: '#768F3E',
116
+ _titleKey: 'exportButtonTitle',
117
+ menuItems: [{
118
+ textKey: 'downloadPNG',
119
+ onclick: function() {
120
+ this.exportChart();
121
+ }
122
+ }, {
123
+ textKey: 'downloadJPEG',
124
+ onclick: function() {
125
+ this.exportChart({
126
+ type: 'image/jpeg'
127
+ });
128
+ }
129
+ }, {
130
+ textKey: 'downloadPDF',
131
+ onclick: function() {
132
+ this.exportChart({
133
+ type: 'application/pdf'
134
+ });
135
+ }
136
+ }, {
137
+ textKey: 'downloadSVG',
138
+ onclick: function() {
139
+ this.exportChart({
140
+ type: 'image/svg+xml'
141
+ });
142
+ }
143
+ }/*, {
144
+ text: 'View SVG',
145
+ onclick: function() {
146
+ var svg = this.getSVG()
147
+ .replace(/</g, '\n&lt;')
148
+ .replace(/>/g, '&gt;');
149
+
150
+ doc.body.innerHTML = '<pre>'+ svg +'</pre>';
151
+ }
152
+ }*/]
153
+
154
+ },
155
+ printButton: {
156
+ //enabled: true,
157
+ symbol: 'printIcon',
158
+ x: -36,
159
+ symbolFill: '#B5C9DF',
160
+ hoverSymbolFill: '#779ABF',
161
+ _titleKey: 'printButtonTitle',
162
+ onclick: function() {
163
+ this.print();
164
+ }
165
+ }
166
+ }
167
+ };
168
+
169
+
170
+
171
+ extend(Chart.prototype, {
172
+ /**
173
+ * Return an SVG representation of the chart
174
+ *
175
+ * @param additionalOptions {Object} Additional chart options for the generated SVG representation
176
+ */
177
+ getSVG: function(additionalOptions) {
178
+ var chart = this,
179
+ chartCopy,
180
+ sandbox,
181
+ svg,
182
+ seriesOptions,
183
+ config,
184
+ pointOptions,
185
+ pointMarker,
186
+ options = merge(chart.options, additionalOptions); // copy the options and add extra options
187
+
188
+ // IE compatibility hack for generating SVG content that it doesn't really understand
189
+ if (!doc.createElementNS) {
190
+ doc.createElementNS = function(ns, tagName) {
191
+ var elem = doc.createElement(tagName);
192
+ elem.getBBox = function() {
193
+ return chart.renderer.Element.prototype.getBBox.apply({ element: elem });
194
+ };
195
+ return elem;
196
+ };
197
+ }
198
+
199
+ // create a sandbox where a new chart will be generated
200
+ sandbox = createElement(DIV, null, {
201
+ position: ABSOLUTE,
202
+ top: '-9999em',
203
+ width: chart.chartWidth + PX,
204
+ height: chart.chartHeight + PX
205
+ }, doc.body);
206
+
207
+ // override some options
208
+ extend(options.chart, {
209
+ renderTo: sandbox,
210
+ renderer: 'SVG'
211
+ });
212
+ options.exporting.enabled = false; // hide buttons in print
213
+ options.chart.plotBackgroundImage = null; // the converter doesn't handle images
214
+ // prepare for replicating the chart
215
+ options.series = [];
216
+ each(chart.series, function(serie) {
217
+ seriesOptions = serie.options;
218
+
219
+ seriesOptions.animation = false; // turn off animation
220
+ seriesOptions.showCheckbox = false;
221
+
222
+ // remove image markers
223
+ if (seriesOptions && seriesOptions.marker && /^url\(/.test(seriesOptions.marker.symbol)) {
224
+ seriesOptions.marker.symbol = 'circle';
225
+ }
226
+
227
+ seriesOptions.data = [];
228
+
229
+ each(serie.data, function(point) {
230
+ /*pointOptions = point.config === null || typeof point.config == 'number' ?
231
+ { y: point.y } :
232
+ point.config;
233
+ pointOptions.x = point.x;*/
234
+
235
+ // extend the options by those values that can be expressed in a number or array config
236
+ config = point.config;
237
+ pointOptions = extend(
238
+ typeof config == 'object' && config.constructor != Array && point.config, {
239
+ x: point.x,
240
+ y: point.y,
241
+ name: point.name
242
+ }
243
+ );
244
+ seriesOptions.data.push(pointOptions); // copy fresh updated data
245
+
246
+ // remove image markers
247
+ pointMarker = point.config && point.config.marker;
248
+ if (pointMarker && /^url\(/.test(pointMarker.symbol)) {
249
+ delete pointMarker.symbol;
250
+ }
251
+ });
252
+
253
+ options.series.push(seriesOptions);
254
+ });
255
+
256
+ // generate the chart copy
257
+ chartCopy = new Highcharts.Chart(options);
258
+
259
+ // get the SVG from the container's innerHTML
260
+ svg = chartCopy.container.innerHTML;
261
+
262
+ // free up memory
263
+ options = null;
264
+ chartCopy.destroy();
265
+ discardElement(sandbox);
266
+
267
+ // sanitize
268
+ svg = svg
269
+ .replace(/zIndex="[^"]+"/g, '')
270
+ .replace(/isShadow="[^"]+"/g, '')
271
+ .replace(/symbolName="[^"]+"/g, '')
272
+ .replace(/jQuery[0-9]+="[^"]+"/g, '')
273
+ .replace(/isTracker="[^"]+"/g, '')
274
+ .replace(/url\([^#]+#/g, 'url(#')
275
+ /* This fails in IE < 8
276
+ .replace(/([0-9]+)\.([0-9]+)/g, function(s1, s2, s3) { // round off to save weight
277
+ return s2 +'.'+ s3[0];
278
+ })*/
279
+
280
+ // IE specific
281
+ .replace(/id=([^" >]+)/g, 'id="$1"')
282
+ .replace(/class=([^" ]+)/g, 'class="$1"')
283
+ .replace(/ transform /g, ' ')
284
+ .replace(/:(path|rect)/g, '$1')
285
+ .replace(/style="([^"]+)"/g, function(s) {
286
+ return s.toLowerCase();
287
+ });
288
+
289
+ // IE9 beta bugs with innerHTML. Test again with final IE9.
290
+ svg = svg.replace(/(url\(#highcharts-[0-9]+)&quot;/g, '$1')
291
+ .replace(/&quot;/g, "'");
292
+ if (svg.match(/ xmlns="/g).length == 2) {
293
+ svg = svg.replace(/xmlns="[^"]+"/, '');
294
+ }
295
+
296
+ return svg;
297
+ },
298
+
299
+ /**
300
+ * Submit the SVG representation of the chart to the server
301
+ * @param {Object} options Exporting options. Possible members are url, type and width.
302
+ * @param {Object} chartOptions Additional chart options for the SVG representation of the chart
303
+ */
304
+ exportChart: function(options, chartOptions) {
305
+ var form,
306
+ chart = this,
307
+ svg = chart.getSVG(chartOptions);
308
+
309
+ // merge the options
310
+ options = merge(chart.options.exporting, options);
311
+
312
+ // create the form
313
+ form = createElement('form', {
314
+ method: 'post',
315
+ action: options.url
316
+ }, {
317
+ display: NONE
318
+ }, doc.body);
319
+
320
+ // add the values
321
+ each(['filename', 'type', 'width', 'svg'], function(name) {
322
+ createElement('input', {
323
+ type: HIDDEN,
324
+ name: name,
325
+ value: {
326
+ filename: options.filename || 'chart',
327
+ type: options.type,
328
+ width: options.width,
329
+ svg: svg
330
+ }[name]
331
+ }, null, form);
332
+ });
333
+
334
+ // submit
335
+ form.submit();
336
+
337
+ // clean up
338
+ discardElement(form);
339
+ },
340
+
341
+ /**
342
+ * Print the chart
343
+ */
344
+ print: function() {
345
+
346
+ var chart = this,
347
+ container = chart.container,
348
+ origDisplay = [],
349
+ origParent = container.parentNode,
350
+ body = doc.body,
351
+ childNodes = body.childNodes;
352
+
353
+ if (chart.isPrinting) { // block the button while in printing mode
354
+ return;
355
+ }
356
+
357
+ chart.isPrinting = true;
358
+
359
+ // hide all body content
360
+ each(childNodes, function(node, i) {
361
+ if (node.nodeType == 1) {
362
+ origDisplay[i] = node.style.display;
363
+ node.style.display = NONE;
364
+ }
365
+ });
366
+
367
+ // pull out the chart
368
+ body.appendChild(container);
369
+
370
+ // print
371
+ win.print();
372
+
373
+ // allow the browser to prepare before reverting
374
+ setTimeout(function() {
375
+
376
+ // put the chart back in
377
+ origParent.appendChild(container);
378
+
379
+ // restore all body content
380
+ each(childNodes, function(node, i) {
381
+ if (node.nodeType == 1) {
382
+ node.style.display = origDisplay[i];
383
+ }
384
+ });
385
+
386
+ chart.isPrinting = false;
387
+
388
+ }, 1000);
389
+
390
+ },
391
+
392
+ /**
393
+ * Display a popup menu for choosing the export type
394
+ *
395
+ * @param {String} name An identifier for the menu
396
+ * @param {Array} items A collection with text and onclicks for the items
397
+ * @param {Number} x The x position of the opener button
398
+ * @param {Number} y The y position of the opener button
399
+ * @param {Number} width The width of the opener button
400
+ * @param {Number} height The height of the opener button
401
+ */
402
+ contextMenu: function(name, items, x, y, width, height) {
403
+ var chart = this,
404
+ navOptions = chart.options.navigation,
405
+ menuItemStyle = navOptions.menuItemStyle,
406
+ chartWidth = chart.chartWidth,
407
+ chartHeight = chart.chartHeight,
408
+ cacheName = 'cache-'+ name,
409
+ menu = chart[cacheName],
410
+ menuPadding = mathMax(width, height), // for mouse leave detection
411
+ boxShadow = '3px 3px 10px #888',
412
+ innerMenu,
413
+ hide,
414
+ menuStyle;
415
+
416
+ // create the menu only the first time
417
+ if (!menu) {
418
+
419
+ // create a HTML element above the SVG
420
+ chart[cacheName] = menu = createElement(DIV, {
421
+ className: PREFIX + name
422
+ }, {
423
+ position: ABSOLUTE,
424
+ zIndex: 1000,
425
+ padding: menuPadding + PX
426
+ }, chart.container);
427
+
428
+ innerMenu = createElement(DIV, null,
429
+ extend({
430
+ MozBoxShadow: boxShadow,
431
+ WebkitBoxShadow: boxShadow,
432
+ boxShadow: boxShadow
433
+ }, navOptions.menuStyle) , menu);
434
+
435
+ // hide on mouse out
436
+ hide = function() {
437
+ css(menu, { display: NONE });
438
+ };
439
+
440
+ addEvent(menu, 'mouseleave', hide);
441
+
442
+
443
+ // create the items
444
+ each(items, function(item) {
445
+ if (item) {
446
+ var div = createElement(DIV, {
447
+ onmouseover: function() {
448
+ css(this, navOptions.menuItemHoverStyle);
449
+ },
450
+ onmouseout: function() {
451
+ css(this, menuItemStyle);
452
+ },
453
+ innerHTML: item.text || HC.getOptions().lang[item.textKey]
454
+ }, extend({
455
+ cursor: 'pointer'
456
+ }, menuItemStyle), innerMenu);
457
+
458
+ div[hasTouch ? 'ontouchstart' : 'onclick'] = function() {
459
+ hide();
460
+ item.onclick.apply(chart, arguments);
461
+ };
462
+
463
+ }
464
+ });
465
+
466
+ chart.exportMenuWidth = menu.offsetWidth;
467
+ chart.exportMenuHeight = menu.offsetHeight;
468
+ }
469
+
470
+ menuStyle = { display: 'block' };
471
+
472
+ // if outside right, right align it
473
+ if (x + chart.exportMenuWidth > chartWidth) {
474
+ menuStyle.right = (chartWidth - x - width - menuPadding) + PX;
475
+ } else {
476
+ menuStyle.left = (x - menuPadding) + PX;
477
+ }
478
+ // if outside bottom, bottom align it
479
+ if (y + height + chart.exportMenuHeight > chartHeight) {
480
+ menuStyle.bottom = (chartHeight - y - menuPadding) + PX;
481
+ } else {
482
+ menuStyle.top = (y + height - menuPadding) + PX;
483
+ }
484
+
485
+ css(menu, menuStyle);
486
+ },
487
+
488
+ /**
489
+ * Add the export button to the chart
490
+ */
491
+ addButton: function(options) {
492
+ var chart = this,
493
+ renderer = chart.renderer,
494
+ btnOptions = merge(chart.options.navigation.buttonOptions, options),
495
+ onclick = btnOptions.onclick,
496
+ menuItems = btnOptions.menuItems,
497
+ /*position = chart.getAlignment(btnOptions),
498
+ buttonLeft = position.x,
499
+ buttonTop = position.y,*/
500
+ buttonWidth = btnOptions.width,
501
+ buttonHeight = btnOptions.height,
502
+ box,
503
+ symbol,
504
+ button,
505
+ borderWidth = btnOptions.borderWidth,
506
+ boxAttr = {
507
+ stroke: btnOptions.borderColor
508
+
509
+ },
510
+ symbolAttr = {
511
+ stroke: btnOptions.symbolStroke,
512
+ fill: btnOptions.symbolFill
513
+ };
514
+
515
+ if (btnOptions.enabled === false) {
516
+ return;
517
+ }
518
+
519
+ // element to capture the click
520
+ function revert() {
521
+ symbol.attr(symbolAttr);
522
+ box.attr(boxAttr);
523
+ }
524
+
525
+ // the box border
526
+ box = renderer.rect(
527
+ 0,
528
+ 0,
529
+ buttonWidth,
530
+ buttonHeight,
531
+ btnOptions.borderRadius,
532
+ borderWidth
533
+ )
534
+ //.translate(buttonLeft, buttonTop) // to allow gradients
535
+ .align(btnOptions, true)
536
+ .attr(extend({
537
+ fill: btnOptions.backgroundColor,
538
+ 'stroke-width': borderWidth,
539
+ zIndex: 19
540
+ }, boxAttr)).add();
541
+
542
+ // the invisible element to track the clicks
543
+ button = renderer.rect(
544
+ 0,
545
+ 0,
546
+ buttonWidth,
547
+ buttonHeight,
548
+ 0
549
+ )
550
+ .align(btnOptions)
551
+ .attr({
552
+ fill: 'rgba(255, 255, 255, 0.001)',
553
+ title: HC.getOptions().lang[btnOptions._titleKey],
554
+ zIndex: 21
555
+ }).css({
556
+ cursor: 'pointer'
557
+ })
558
+ .on('mouseover', function() {
559
+ symbol.attr({
560
+ stroke: btnOptions.hoverSymbolStroke,
561
+ fill: btnOptions.hoverSymbolFill
562
+ });
563
+ box.attr({
564
+ stroke: btnOptions.hoverBorderColor
565
+ });
566
+ })
567
+ .on('mouseout', revert)
568
+ .on('click', revert)
569
+ .add();
570
+
571
+ //addEvent(button.element, 'click', revert);
572
+
573
+ // add the click event
574
+ if (menuItems) {
575
+ onclick = function(e) {
576
+ revert();
577
+ var bBox = button.getBBox();
578
+ chart.contextMenu('export-menu', menuItems, bBox.x, bBox.y, buttonWidth, buttonHeight);
579
+ };
580
+ }
581
+ /*addEvent(button.element, 'click', function() {
582
+ onclick.apply(chart, arguments);
583
+ });*/
584
+ button.on('click', function() {
585
+ onclick.apply(chart, arguments);
586
+ });
587
+
588
+ // the icon
589
+ symbol = renderer.symbol(
590
+ btnOptions.symbol,
591
+ btnOptions.symbolX,
592
+ btnOptions.symbolY,
593
+ (btnOptions.symbolSize || 12) / 2
594
+ )
595
+ .align(btnOptions, true)
596
+ .attr(extend(symbolAttr, {
597
+ 'stroke-width': btnOptions.symbolStrokeWidth || 1,
598
+ zIndex: 20
599
+ })).add();
600
+
601
+
602
+
603
+ }
604
+ });
605
+
606
+ // Create the export icon
607
+ HC.Renderer.prototype.symbols.exportIcon = function(x, y, radius) {
608
+ return [
609
+ M, // the disk
610
+ x - radius, y + radius,
611
+ L,
612
+ x + radius, y + radius,
613
+ x + radius, y + radius * 0.5,
614
+ x - radius, y + radius * 0.5,
615
+ 'Z',
616
+ M, // the arrow
617
+ x, y + radius * 0.5,
618
+ L,
619
+ x - radius * 0.5, y - radius / 3,
620
+ x - radius / 6, y - radius / 3,
621
+ x - radius / 6, y - radius,
622
+ x + radius / 6, y - radius,
623
+ x + radius / 6, y - radius / 3,
624
+ x + radius * 0.5, y - radius / 3,
625
+ 'Z'
626
+ ];
627
+ };
628
+ // Create the print icon
629
+ HC.Renderer.prototype.symbols.printIcon = function(x, y, radius) {
630
+ return [
631
+ M, // the printer
632
+ x - radius, y + radius * 0.5,
633
+ L,
634
+ x + radius, y + radius * 0.5,
635
+ x + radius, y - radius / 3,
636
+ x - radius, y - radius / 3,
637
+ 'Z',
638
+ M, // the upper sheet
639
+ x - radius * 0.5, y - radius / 3,
640
+ L,
641
+ x - radius * 0.5, y - radius,
642
+ x + radius * 0.5, y - radius,
643
+ x + radius * 0.5, y - radius / 3,
644
+ 'Z',
645
+ M, // the lower sheet
646
+ x - radius * 0.5, y + radius * 0.5,
647
+ L,
648
+ x - radius * 0.75, y + radius,
649
+ x + radius * 0.75, y + radius,
650
+ x + radius * 0.5, y + radius * 0.5,
651
+ 'Z'
652
+ ];
653
+ };
654
+
655
+
656
+ // Add the buttons on chart load
657
+ Chart.prototype.callbacks.push(function(chart) {
658
+ var n,
659
+ exportingOptions = chart.options.exporting,
660
+ buttons = exportingOptions.buttons;
661
+
662
+ if (exportingOptions.enabled !== false) {
663
+
664
+ for (n in buttons) {
665
+ chart.addButton(buttons[n]);
666
+ }
667
+ }
668
+ });
669
+
670
+
671
+ })();