-
Notifications
You must be signed in to change notification settings - Fork 10
/
charter.js
92 lines (70 loc) · 2.62 KB
/
charter.js
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @see README.md
*/
(function($, window) {
'use strict';
var Charter = function() { this.init(); };
$.extend(Charter.prototype, {
init: function() {
$(document.body).css('margin', '0px');
this.constr = 'Chart';
this.container = $('<div />').attr('id', 'chart-container').appendTo(document.body);
// Disable animations
Highcharts.SVGRenderer.prototype.Element.prototype.animate = Highcharts.SVGRenderer.prototype.Element.prototype.attr;
},
setId: function(id) {
this.id = id;
},
pingback: function(callback, msg) {
msg = msg || {};
msg.callback = callback;
msg.id = this.id;
window.callPhantom(msg);
},
runScript: function(code) {
$('<script />')
.attr('type', 'text/javascript')
.html(code)
.appendTo(document.head);
},
setOptions: function(options) {
if (!options.chart) {
options.chart = {};
}
// DOM-target
options.chart.renderTo = this.container.get(0);
// Width/height
options.chart.width = (options.exporting && options.exporting.sourceWidth) || options.chart.width || 600;
options.chart.height = (options.exporting && options.exporting.sourceHeight) || options.chart.height || 400;
this.options = options;
},
setConstructor: function(constr) {
this.constr = constr;
},
onRenderComplete: function() {
this.pingback('onRenderComplete');
},
render: function() {
var context = this, svg;
this.chart = new Highcharts[this.constr](this.options, function() {
// Remove stroke-opacity paths, used by mouse-trackers,
// they turn up as as fully opaque in the PDF/PNG
var node, opacity;
$('*[stroke-opacity]').each(function() {
node = $(this);
opacity = node.attr('stroke-opacity');
node.removeAttr('stroke-opacity');
node.attr('opacity', opacity);
});
this.onRenderComplete();
}.bind(this));
svg = $('svg');
return {
html : this.container.find('.highcharts-container').html(),
width : svg.attr('width'),
height: svg.attr('height')
};
}
});
window.Charter = Charter;
})(jQuery, window);