highcharts-rails 0.1.0
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.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.markdown +40 -0
- data/Rakefile +1 -0
- data/highcharts-rails.gemspec +22 -0
- data/lib/highcharts-rails.rb +1 -0
- data/lib/highcharts/rails.rb +6 -0
- data/lib/highcharts/version.rb +3 -0
- data/vendor/assets/javascripts/highcharts.js +11103 -0
- data/vendor/assets/javascripts/highcharts/adapters/mootools.js +243 -0
- data/vendor/assets/javascripts/highcharts/adapters/prototype.js +284 -0
- data/vendor/assets/javascripts/highcharts/modules/exporting.js +703 -0
- data/vendor/assets/javascripts/highcharts/themes/dark-blue.js +268 -0
- data/vendor/assets/javascripts/highcharts/themes/dark-green.js +268 -0
- data/vendor/assets/javascripts/highcharts/themes/gray.js +262 -0
- data/vendor/assets/javascripts/highcharts/themes/grid.js +97 -0
- metadata +98 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
/**
|
2
|
+
* @license Highcharts JS v2.1.6 (2011-07-08)
|
3
|
+
* MooTools adapter
|
4
|
+
*
|
5
|
+
* (c) 2010-2011 Torstein Hønsi
|
6
|
+
*
|
7
|
+
* License: www.highcharts.com/license
|
8
|
+
*/
|
9
|
+
|
10
|
+
// JSLint options:
|
11
|
+
/*global Highcharts, Fx, $, $extend, $each, $merge, Events, Event */
|
12
|
+
|
13
|
+
(function() {
|
14
|
+
|
15
|
+
var win = window,
|
16
|
+
legacy = !!win.$merge,
|
17
|
+
$extend = win.$extend || function() {
|
18
|
+
return Object.append.apply(Object, arguments)
|
19
|
+
};
|
20
|
+
|
21
|
+
win.HighchartsAdapter = {
|
22
|
+
/**
|
23
|
+
* Initialize the adapter. This is run once as Highcharts is first run.
|
24
|
+
*/
|
25
|
+
init: function() {
|
26
|
+
var fxProto = Fx.prototype,
|
27
|
+
fxStart = fxProto.start,
|
28
|
+
morphProto = Fx.Morph.prototype,
|
29
|
+
morphCompute = morphProto.compute;
|
30
|
+
|
31
|
+
// override Fx.start to allow animation of SVG element wrappers
|
32
|
+
fxProto.start = function(from, to) {
|
33
|
+
var fx = this,
|
34
|
+
elem = fx.element;
|
35
|
+
|
36
|
+
// special for animating paths
|
37
|
+
if (from.d) {
|
38
|
+
//this.fromD = this.element.d.split(' ');
|
39
|
+
fx.paths = Highcharts.pathAnim.init(
|
40
|
+
elem,
|
41
|
+
elem.d,
|
42
|
+
fx.toD
|
43
|
+
);
|
44
|
+
}
|
45
|
+
fxStart.apply(fx, arguments);
|
46
|
+
|
47
|
+
return this; // chainable
|
48
|
+
};
|
49
|
+
|
50
|
+
// override Fx.step to allow animation of SVG element wrappers
|
51
|
+
morphProto.compute = function(from, to, delta) {
|
52
|
+
var fx = this,
|
53
|
+
paths = fx.paths;
|
54
|
+
|
55
|
+
if (paths) {
|
56
|
+
fx.element.attr(
|
57
|
+
'd',
|
58
|
+
Highcharts.pathAnim.step(paths[0], paths[1], delta, fx.toD)
|
59
|
+
);
|
60
|
+
} else {
|
61
|
+
return morphCompute.apply(fx, arguments);
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
},
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Animate a HTML element or SVG element wrapper
|
69
|
+
* @param {Object} el
|
70
|
+
* @param {Object} params
|
71
|
+
* @param {Object} options jQuery-like animation options: duration, easing, callback
|
72
|
+
*/
|
73
|
+
animate: function (el, params, options) {
|
74
|
+
var isSVGElement = el.attr,
|
75
|
+
effect,
|
76
|
+
complete = options && options.complete;
|
77
|
+
|
78
|
+
if (isSVGElement && !el.setStyle) {
|
79
|
+
// add setStyle and getStyle methods for internal use in Moo
|
80
|
+
el.getStyle = el.attr;
|
81
|
+
el.setStyle = function() { // property value is given as array in Moo - break it down
|
82
|
+
var args = arguments;
|
83
|
+
el.attr.call(el, args[0], args[1][0]);
|
84
|
+
}
|
85
|
+
// dirty hack to trick Moo into handling el as an element wrapper
|
86
|
+
el.$family = el.uid = true;
|
87
|
+
}
|
88
|
+
|
89
|
+
// stop running animations
|
90
|
+
HighchartsAdapter.stop(el);
|
91
|
+
|
92
|
+
// define and run the effect
|
93
|
+
effect = new Fx.Morph(
|
94
|
+
isSVGElement ? el : $(el),
|
95
|
+
$extend({
|
96
|
+
transition: Fx.Transitions.Quad.easeInOut
|
97
|
+
}, options)
|
98
|
+
);
|
99
|
+
|
100
|
+
// special treatment for paths
|
101
|
+
if (params.d) {
|
102
|
+
effect.toD = params.d;
|
103
|
+
}
|
104
|
+
|
105
|
+
// jQuery-like events
|
106
|
+
if (complete) {
|
107
|
+
effect.addEvent('complete', complete);
|
108
|
+
}
|
109
|
+
|
110
|
+
// run
|
111
|
+
effect.start(params);
|
112
|
+
|
113
|
+
// record for use in stop method
|
114
|
+
el.fx = effect;
|
115
|
+
},
|
116
|
+
|
117
|
+
/**
|
118
|
+
* MooTool's each function
|
119
|
+
*
|
120
|
+
*/
|
121
|
+
each: function(arr, fn) {
|
122
|
+
return legacy ?
|
123
|
+
$each(arr, fn) :
|
124
|
+
arr.each(fn);
|
125
|
+
},
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Map an array
|
129
|
+
* @param {Array} arr
|
130
|
+
* @param {Function} fn
|
131
|
+
*/
|
132
|
+
map: function (arr, fn){
|
133
|
+
return arr.map(fn);
|
134
|
+
},
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Grep or filter an array
|
138
|
+
* @param {Array} arr
|
139
|
+
* @param {Function} fn
|
140
|
+
*/
|
141
|
+
grep: function(arr, fn) {
|
142
|
+
return arr.filter(fn);
|
143
|
+
},
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Deep merge two objects and return a third
|
147
|
+
*/
|
148
|
+
merge: function() {
|
149
|
+
var args = arguments,
|
150
|
+
args13 = [{}], // MooTools 1.3+
|
151
|
+
i = args.length,
|
152
|
+
ret;
|
153
|
+
|
154
|
+
if (legacy) {
|
155
|
+
ret = $merge.apply(null, args);
|
156
|
+
} else {
|
157
|
+
while (i--) {
|
158
|
+
args13[i + 1] = args[i];
|
159
|
+
}
|
160
|
+
ret = Object.merge.apply(Object, args13);
|
161
|
+
}
|
162
|
+
|
163
|
+
return ret;
|
164
|
+
},
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Add an event listener
|
168
|
+
* @param {Object} el HTML element or custom object
|
169
|
+
* @param {String} type Event type
|
170
|
+
* @param {Function} fn Event handler
|
171
|
+
*/
|
172
|
+
addEvent: function (el, type, fn) {
|
173
|
+
if (typeof type == 'string') { // chart broke due to el being string, type function
|
174
|
+
|
175
|
+
if (type == 'unload') { // Moo self destructs before custom unload events
|
176
|
+
type = 'beforeunload';
|
177
|
+
}
|
178
|
+
|
179
|
+
// if the addEvent method is not defined, el is a custom Highcharts object
|
180
|
+
// like series or point
|
181
|
+
if (!el.addEvent) {
|
182
|
+
if (el.nodeName) {
|
183
|
+
el = $(el); // a dynamically generated node
|
184
|
+
} else {
|
185
|
+
$extend(el, new Events()); // a custom object
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
el.addEvent(type, fn);
|
190
|
+
}
|
191
|
+
},
|
192
|
+
|
193
|
+
removeEvent: function(el, type, fn) {
|
194
|
+
if (type) {
|
195
|
+
if (type == 'unload') { // Moo self destructs before custom unload events
|
196
|
+
type = 'beforeunload';
|
197
|
+
}
|
198
|
+
|
199
|
+
if (defined(fn)) {
|
200
|
+
el.removeEvent(type, fn);
|
201
|
+
} else {
|
202
|
+
el.removeEvents(type);
|
203
|
+
}
|
204
|
+
} else {
|
205
|
+
el.removeEvents();
|
206
|
+
}
|
207
|
+
},
|
208
|
+
|
209
|
+
fireEvent: function(el, event, eventArguments, defaultFunction) {
|
210
|
+
// create an event object that keeps all functions
|
211
|
+
event = new Event({
|
212
|
+
type: event,
|
213
|
+
target: el
|
214
|
+
});
|
215
|
+
event = $extend(event, eventArguments);
|
216
|
+
// override the preventDefault function to be able to use
|
217
|
+
// this for custom events
|
218
|
+
event.preventDefault = function() {
|
219
|
+
defaultFunction = null;
|
220
|
+
};
|
221
|
+
// if fireEvent is not available on the object, there hasn't been added
|
222
|
+
// any events to it above
|
223
|
+
if (el.fireEvent) {
|
224
|
+
el.fireEvent(event.type, event);
|
225
|
+
}
|
226
|
+
|
227
|
+
// fire the default if it is passed and it is not prevented above
|
228
|
+
if (defaultFunction) {
|
229
|
+
defaultFunction(event);
|
230
|
+
}
|
231
|
+
},
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Stop running animations on the object
|
235
|
+
*/
|
236
|
+
stop: function (el) {
|
237
|
+
if (el.fx) {
|
238
|
+
el.fx.cancel();
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
})();
|
@@ -0,0 +1,284 @@
|
|
1
|
+
/**
|
2
|
+
* @license Highcharts JS v2.1.6 (2011-07-08)
|
3
|
+
* Prototype adapter
|
4
|
+
*
|
5
|
+
* @author Michael Nelson, Torstein Hønsi.
|
6
|
+
*
|
7
|
+
* Feel free to use and modify this script.
|
8
|
+
* Highcharts license: www.highcharts.com/license.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/*
|
12
|
+
* Known issues:
|
13
|
+
* - Some grid lines land in wrong position - http://jsfiddle.net/highcharts/jaRhY/28
|
14
|
+
*/
|
15
|
+
|
16
|
+
// JSLint options:
|
17
|
+
/*jslint forin: true */
|
18
|
+
/*global Effect, Class, Highcharts, Event, $, $A */
|
19
|
+
|
20
|
+
// Adapter interface between prototype and the Highcarts charting library
|
21
|
+
var HighchartsAdapter = (function() {
|
22
|
+
|
23
|
+
var hasEffect = typeof Effect != 'undefined';
|
24
|
+
|
25
|
+
return {
|
26
|
+
|
27
|
+
init: function() {
|
28
|
+
|
29
|
+
if (hasEffect) {
|
30
|
+
/**
|
31
|
+
* Animation for Highcharts SVG element wrappers only
|
32
|
+
* @param {Object} element
|
33
|
+
* @param {Object} attribute
|
34
|
+
* @param {Object} to
|
35
|
+
* @param {Object} options
|
36
|
+
*/
|
37
|
+
Effect.HighchartsTransition = Class.create(Effect.Base, {
|
38
|
+
initialize: function(element, attr, to, options){
|
39
|
+
var from,
|
40
|
+
opts;
|
41
|
+
|
42
|
+
this.element = element;
|
43
|
+
|
44
|
+
from = element.attr(attr);
|
45
|
+
|
46
|
+
// special treatment for paths
|
47
|
+
if (attr == 'd') {
|
48
|
+
this.paths = Highcharts.pathAnim.init(
|
49
|
+
element,
|
50
|
+
element.d,
|
51
|
+
to
|
52
|
+
);
|
53
|
+
this.toD = to;
|
54
|
+
|
55
|
+
|
56
|
+
// fake values in order to read relative position as a float in update
|
57
|
+
from = 0;
|
58
|
+
to = 1;
|
59
|
+
}
|
60
|
+
|
61
|
+
opts = Object.extend((options || {}), {
|
62
|
+
from: from,
|
63
|
+
to: to,
|
64
|
+
attribute: attr
|
65
|
+
});
|
66
|
+
this.start(opts);
|
67
|
+
},
|
68
|
+
setup: function(){
|
69
|
+
HighchartsAdapter._extend(this.element);
|
70
|
+
this.element._highchart_animation = this;
|
71
|
+
},
|
72
|
+
update: function(position) {
|
73
|
+
var paths = this.paths;
|
74
|
+
|
75
|
+
if (paths) {
|
76
|
+
position = Highcharts.pathAnim.step(paths[0], paths[1], position, this.toD);
|
77
|
+
}
|
78
|
+
|
79
|
+
this.element.attr(this.options.attribute, position);
|
80
|
+
},
|
81
|
+
finish: function(){
|
82
|
+
this.element._highchart_animation = null;
|
83
|
+
}
|
84
|
+
});
|
85
|
+
}
|
86
|
+
},
|
87
|
+
|
88
|
+
// el needs an event to be attached. el is not necessarily a dom element
|
89
|
+
addEvent: function(el, event, fn) {
|
90
|
+
if (el.addEventListener || el.attachEvent) {
|
91
|
+
Event.observe($(el), event, fn);
|
92
|
+
|
93
|
+
} else {
|
94
|
+
HighchartsAdapter._extend(el);
|
95
|
+
el._highcharts_observe(event, fn);
|
96
|
+
}
|
97
|
+
},
|
98
|
+
|
99
|
+
// motion makes things pretty. use it if effects is loaded, if not... still get to the end result.
|
100
|
+
animate: function(el, params, options) {
|
101
|
+
var key,
|
102
|
+
fx;
|
103
|
+
|
104
|
+
// default options
|
105
|
+
options = options || {};
|
106
|
+
options.delay = 0;
|
107
|
+
options.duration = (options.duration || 500) / 1000;
|
108
|
+
|
109
|
+
// animate wrappers and DOM elements
|
110
|
+
if (hasEffect) {
|
111
|
+
for (key in params) {
|
112
|
+
fx = new Effect.HighchartsTransition($(el), key, params[key], options);
|
113
|
+
}
|
114
|
+
} else {
|
115
|
+
for (key in params) {
|
116
|
+
el.attr(key, params[key]);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
if (!el.attr) {
|
121
|
+
throw 'Todo: implement animate DOM objects';
|
122
|
+
}
|
123
|
+
},
|
124
|
+
|
125
|
+
// this only occurs in higcharts 2.0+
|
126
|
+
stop: function(el){
|
127
|
+
if (el._highcharts_extended && el._highchart_animation) {
|
128
|
+
el._highchart_animation.cancel();
|
129
|
+
}
|
130
|
+
},
|
131
|
+
|
132
|
+
// um.. each
|
133
|
+
each: function(arr, fn){
|
134
|
+
$A(arr).each(fn);
|
135
|
+
},
|
136
|
+
|
137
|
+
// fire an event based on an event name (event) and an object (el).
|
138
|
+
// again, el may not be a dom element
|
139
|
+
fireEvent: function(el, event, eventArguments, defaultFunction){
|
140
|
+
if (event.preventDefault) {
|
141
|
+
defaultFunction = null;
|
142
|
+
}
|
143
|
+
|
144
|
+
if (el.fire) {
|
145
|
+
el.fire(event, eventArguments);
|
146
|
+
} else if (el._highcharts_extended) {
|
147
|
+
el._highcharts_fire(event, eventArguments);
|
148
|
+
}
|
149
|
+
|
150
|
+
if (defaultFunction) {
|
151
|
+
defaultFunction(eventArguments);
|
152
|
+
}
|
153
|
+
},
|
154
|
+
|
155
|
+
removeEvent: function(el, event, handler){
|
156
|
+
if ($(el).stopObserving) {
|
157
|
+
$(el).stopObserving(event, handler);
|
158
|
+
} else {
|
159
|
+
HighchartsAdapter._extend(el);
|
160
|
+
el._highcharts_stop_observing(event, handler);
|
161
|
+
}
|
162
|
+
},
|
163
|
+
|
164
|
+
// um, grep
|
165
|
+
grep: function(arr, fn){
|
166
|
+
return arr.findAll(fn);
|
167
|
+
},
|
168
|
+
|
169
|
+
// um, map
|
170
|
+
map: function(arr, fn){
|
171
|
+
return arr.map(fn);
|
172
|
+
},
|
173
|
+
|
174
|
+
// deep merge. merge({a : 'a', b : {b1 : 'b1', b2 : 'b2'}}, {b : {b2 : 'b2_prime'}, c : 'c'}) => {a : 'a', b : {b1 : 'b1', b2 : 'b2_prime'}, c : 'c'}
|
175
|
+
/*merge: function(){
|
176
|
+
function doCopy(copy, original) {
|
177
|
+
var value,
|
178
|
+
key,
|
179
|
+
undef,
|
180
|
+
nil,
|
181
|
+
same,
|
182
|
+
obj,
|
183
|
+
arr,
|
184
|
+
node;
|
185
|
+
|
186
|
+
for (key in original) {
|
187
|
+
value = original[key];
|
188
|
+
undef = typeof(value) === 'undefined';
|
189
|
+
nil = value === null;
|
190
|
+
same = original === copy[key];
|
191
|
+
|
192
|
+
if (undef || nil || same) {
|
193
|
+
continue;
|
194
|
+
}
|
195
|
+
|
196
|
+
obj = typeof(value) === 'object';
|
197
|
+
arr = value && obj && value.constructor == Array;
|
198
|
+
node = !!value.nodeType;
|
199
|
+
|
200
|
+
if (obj && !arr && !node) {
|
201
|
+
copy[key] = doCopy(typeof copy[key] == 'object' ? copy[key] : {}, value);
|
202
|
+
}
|
203
|
+
else {
|
204
|
+
copy[key] = original[key];
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return copy;
|
208
|
+
}
|
209
|
+
|
210
|
+
var args = arguments, retVal = {};
|
211
|
+
|
212
|
+
for (var i = 0; i < args.length; i++) {
|
213
|
+
retVal = doCopy(retVal, args[i]);
|
214
|
+
}
|
215
|
+
|
216
|
+
return retVal;
|
217
|
+
},*/
|
218
|
+
merge: function() { // the built-in prototype merge function doesn't do deep copy
|
219
|
+
function doCopy(copy, original) {
|
220
|
+
var value;
|
221
|
+
|
222
|
+
for (var key in original) {
|
223
|
+
value = original[key];
|
224
|
+
if (value && typeof value == 'object' && value.constructor != Array &&
|
225
|
+
typeof value.nodeType !== 'number') {
|
226
|
+
copy[key] = doCopy(copy[key] || {}, value); // copy
|
227
|
+
|
228
|
+
} else {
|
229
|
+
copy[key] = original[key];
|
230
|
+
}
|
231
|
+
}
|
232
|
+
return copy;
|
233
|
+
}
|
234
|
+
|
235
|
+
function merge() {
|
236
|
+
var args = arguments,
|
237
|
+
retVal = {};
|
238
|
+
|
239
|
+
for (var i = 0; i < args.length; i++) {
|
240
|
+
retVal = doCopy(retVal, args[i])
|
241
|
+
|
242
|
+
}
|
243
|
+
return retVal;
|
244
|
+
}
|
245
|
+
|
246
|
+
return merge.apply(this, arguments);
|
247
|
+
},
|
248
|
+
|
249
|
+
// extend an object to handle highchart events (highchart objects, not svg elements).
|
250
|
+
// this is a very simple way of handling events but whatever, it works (i think)
|
251
|
+
_extend: function(object){
|
252
|
+
if (!object._highcharts_extended) {
|
253
|
+
Object.extend(object, {
|
254
|
+
_highchart_events: {},
|
255
|
+
_highchart_animation: null,
|
256
|
+
_highcharts_extended: true,
|
257
|
+
_highcharts_observe: function(name, fn){
|
258
|
+
this._highchart_events[name] = [this._highchart_events[name], fn].compact().flatten();
|
259
|
+
},
|
260
|
+
_highcharts_stop_observing: function(name, fn){
|
261
|
+
if (name) {
|
262
|
+
if (fn) {
|
263
|
+
this._highchart_events[name] = [this._highchart_events[name]].compact().flatten().without(fn);
|
264
|
+
} else {
|
265
|
+
delete this._highchart_events[name];
|
266
|
+
}
|
267
|
+
} else {
|
268
|
+
this._highchart_events = {};
|
269
|
+
}
|
270
|
+
},
|
271
|
+
_highcharts_fire: function(name, args){
|
272
|
+
(this._highchart_events[name] || []).each(function(fn){
|
273
|
+
if (args && args.stopped) {
|
274
|
+
return; // "throw $break" wasn't working. i think because of the scope of 'this'.
|
275
|
+
}
|
276
|
+
fn.bind(this)(args);
|
277
|
+
}
|
278
|
+
.bind(this));
|
279
|
+
}
|
280
|
+
});
|
281
|
+
}
|
282
|
+
}
|
283
|
+
};
|
284
|
+
})();
|