highcharts-rails 4.1.10 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,316 +0,0 @@
1
- /**
2
- * @license Highcharts JS v3.0.10 (2014-03-10)
3
- * MooTools adapter
4
- *
5
- * (c) 2010-2014 Torstein Honsi
6
- *
7
- * License: www.highcharts.com/license
8
- */
9
-
10
- // JSLint options:
11
- /*global Fx, $, $extend, $each, $merge, Events, Event, DOMEvent */
12
-
13
- (function () {
14
-
15
- var win = window,
16
- doc = document,
17
- mooVersion = win.MooTools.version.substring(0, 3), // Get the first three characters of the version number
18
- legacy = mooVersion === '1.2' || mooVersion === '1.1', // 1.1 && 1.2 considered legacy, 1.3 is not.
19
- legacyEvent = legacy || mooVersion === '1.3', // In versions 1.1 - 1.3 the event class is named Event, in newer versions it is named DOMEvent.
20
- $extend = win.$extend || function () {
21
- return Object.append.apply(Object, arguments);
22
- };
23
-
24
- win.HighchartsAdapter = {
25
- /**
26
- * Initialize the adapter. This is run once as Highcharts is first run.
27
- * @param {Object} pathAnim The helper object to do animations across adapters.
28
- */
29
- init: function (pathAnim) {
30
- var fxProto = Fx.prototype,
31
- fxStart = fxProto.start,
32
- morphProto = Fx.Morph.prototype,
33
- morphCompute = morphProto.compute;
34
-
35
- // override Fx.start to allow animation of SVG element wrappers
36
- /*jslint unparam: true*//* allow unused parameters in fx functions */
37
- fxProto.start = function (from, to) {
38
- var fx = this,
39
- elem = fx.element;
40
-
41
- // special for animating paths
42
- if (from.d) {
43
- //this.fromD = this.element.d.split(' ');
44
- fx.paths = pathAnim.init(
45
- elem,
46
- elem.d,
47
- fx.toD
48
- );
49
- }
50
- fxStart.apply(fx, arguments);
51
-
52
- return this; // chainable
53
- };
54
-
55
- // override Fx.step to allow animation of SVG element wrappers
56
- morphProto.compute = function (from, to, delta) {
57
- var fx = this,
58
- paths = fx.paths;
59
-
60
- if (paths) {
61
- fx.element.attr(
62
- 'd',
63
- pathAnim.step(paths[0], paths[1], delta, fx.toD)
64
- );
65
- } else {
66
- return morphCompute.apply(fx, arguments);
67
- }
68
- };
69
- /*jslint unparam: false*/
70
- },
71
-
72
- /**
73
- * Run a general method on the framework, following jQuery syntax
74
- * @param {Object} el The HTML element
75
- * @param {String} method Which method to run on the wrapped element
76
- */
77
- adapterRun: function (el, method) {
78
-
79
- // This currently works for getting inner width and height. If adding
80
- // more methods later, we need a conditional implementation for each.
81
- if (method === 'width' || method === 'height') {
82
- return parseInt(document.id(el).getStyle(method), 10);
83
- }
84
- },
85
-
86
- /**
87
- * Downloads a script and executes a callback when done.
88
- * @param {String} scriptLocation
89
- * @param {Function} callback
90
- */
91
- getScript: function (scriptLocation, callback) {
92
- // We cannot assume that Assets class from mootools-more is available so instead insert a script tag to download script.
93
- var head = doc.getElementsByTagName('head')[0];
94
- var script = doc.createElement('script');
95
-
96
- script.type = 'text/javascript';
97
- script.src = scriptLocation;
98
- script.onload = callback;
99
-
100
- head.appendChild(script);
101
- },
102
-
103
- /**
104
- * Animate a HTML element or SVG element wrapper
105
- * @param {Object} el
106
- * @param {Object} params
107
- * @param {Object} options jQuery-like animation options: duration, easing, callback
108
- */
109
- animate: function (el, params, options) {
110
- var isSVGElement = el.attr,
111
- effect,
112
- complete = options && options.complete;
113
-
114
- if (isSVGElement && !el.setStyle) {
115
- // add setStyle and getStyle methods for internal use in Moo
116
- el.getStyle = el.attr;
117
- el.setStyle = function () { // property value is given as array in Moo - break it down
118
- var args = arguments;
119
- this.attr.call(this, args[0], args[1][0]);
120
- };
121
- // dirty hack to trick Moo into handling el as an element wrapper
122
- el.$family = function () { return true; };
123
- el.getComputedStyle = function () {
124
- return el.element.getComputedStyle.apply(el.element, arguments);
125
- };
126
- }
127
-
128
- // stop running animations
129
- win.HighchartsAdapter.stop(el);
130
-
131
- // define and run the effect
132
- effect = new Fx.Morph(
133
- isSVGElement ? el : document.id(el),
134
- $extend({
135
- transition: Fx.Transitions.Quad.easeInOut
136
- }, options)
137
- );
138
-
139
- // Make sure that the element reference is set when animating svg elements
140
- if (isSVGElement) {
141
- effect.element = el;
142
- }
143
-
144
- // special treatment for paths
145
- if (params.d) {
146
- effect.toD = params.d;
147
- }
148
-
149
- // jQuery-like events
150
- if (complete) {
151
- effect.addEvent('complete', complete);
152
- }
153
-
154
- // run
155
- effect.start(params);
156
-
157
- // record for use in stop method
158
- el.fx = effect;
159
- },
160
-
161
- /**
162
- * MooTool's each function
163
- *
164
- */
165
- each: function (arr, fn) {
166
- return legacy ?
167
- $each(arr, fn) :
168
- Array.each(arr, fn);
169
- },
170
-
171
- /**
172
- * Map an array
173
- * @param {Array} arr
174
- * @param {Function} fn
175
- */
176
- map: function (arr, fn) {
177
- return arr.map(fn);
178
- },
179
-
180
- /**
181
- * Grep or filter an array
182
- * @param {Array} arr
183
- * @param {Function} fn
184
- */
185
- grep: function (arr, fn) {
186
- return arr.filter(fn);
187
- },
188
-
189
- /**
190
- * Return the index of an item in an array, or -1 if not matched
191
- */
192
- inArray: function (item, arr, from) {
193
- return arr ? arr.indexOf(item, from) : -1;
194
- },
195
-
196
- /**
197
- * Get the offset of an element relative to the top left corner of the web page
198
- */
199
- offset: function (el) {
200
- var offsets = el.getPosition(); // #1496
201
- return {
202
- left: offsets.x,
203
- top: offsets.y
204
- };
205
- },
206
-
207
- /**
208
- * Extends an object with Events, if its not done
209
- */
210
- extendWithEvents: function (el) {
211
- // if the addEvent method is not defined, el is a custom Highcharts object
212
- // like series or point
213
- if (!el.addEvent) {
214
- if (el.nodeName) {
215
- el = document.id(el); // a dynamically generated node
216
- } else {
217
- $extend(el, new Events()); // a custom object
218
- }
219
- }
220
- },
221
-
222
- /**
223
- * Add an event listener
224
- * @param {Object} el HTML element or custom object
225
- * @param {String} type Event type
226
- * @param {Function} fn Event handler
227
- */
228
- addEvent: function (el, type, fn) {
229
- if (typeof type === 'string') { // chart broke due to el being string, type function
230
-
231
- if (type === 'unload') { // Moo self destructs before custom unload events
232
- type = 'beforeunload';
233
- }
234
-
235
- win.HighchartsAdapter.extendWithEvents(el);
236
-
237
- el.addEvent(type, fn);
238
- }
239
- },
240
-
241
- removeEvent: function (el, type, fn) {
242
- if (typeof el === 'string') {
243
- // el.removeEvents below apperantly calls this method again. Do not quite understand why, so for now just bail out.
244
- return;
245
- }
246
-
247
- if (el.addEvent) { // If el doesn't have an addEvent method, there are no events to remove
248
- if (type) {
249
- if (type === 'unload') { // Moo self destructs before custom unload events
250
- type = 'beforeunload';
251
- }
252
-
253
- if (fn) {
254
- el.removeEvent(type, fn);
255
- } else if (el.removeEvents) { // #958
256
- el.removeEvents(type);
257
- }
258
- } else {
259
- el.removeEvents();
260
- }
261
- }
262
- },
263
-
264
- fireEvent: function (el, event, eventArguments, defaultFunction) {
265
- var eventArgs = {
266
- type: event,
267
- target: el
268
- };
269
- // create an event object that keeps all functions
270
- event = legacyEvent ? new Event(eventArgs) : new DOMEvent(eventArgs);
271
- event = $extend(event, eventArguments);
272
-
273
- // When running an event on the Chart.prototype, MooTools nests the target in event.event
274
- if (!event.target && event.event) {
275
- event.target = event.event.target;
276
- }
277
-
278
- // override the preventDefault function to be able to use
279
- // this for custom events
280
- event.preventDefault = function () {
281
- defaultFunction = null;
282
- };
283
- // if fireEvent is not available on the object, there hasn't been added
284
- // any events to it above
285
- if (el.fireEvent) {
286
- el.fireEvent(event.type, event);
287
- }
288
-
289
- // fire the default if it is passed and it is not prevented above
290
- if (defaultFunction) {
291
- defaultFunction(event);
292
- }
293
- },
294
-
295
- /**
296
- * Set back e.pageX and e.pageY that MooTools has abstracted away. #1165, #1346.
297
- */
298
- washMouseEvent: function (e) {
299
- if (e.page) {
300
- e.pageX = e.page.x;
301
- e.pageY = e.page.y;
302
- }
303
- return e;
304
- },
305
-
306
- /**
307
- * Stop running animations on the object
308
- */
309
- stop: function (el) {
310
- if (el.fx) {
311
- el.fx.cancel();
312
- }
313
- }
314
- };
315
-
316
- }());
@@ -1,316 +0,0 @@
1
- /**
2
- * @license Highcharts JS v3.0.10 (2014-03-10)
3
- * Prototype adapter
4
- *
5
- * @author Michael Nelson, Torstein Honsi.
6
- *
7
- * Feel free to use and modify this script.
8
- * Highcharts license: www.highcharts.com/license.
9
- */
10
-
11
- // JSLint options:
12
- /*global Effect, Class, Event, Element, $, $$, $A */
13
-
14
- // Adapter interface between prototype and the Highcharts charting library
15
- var HighchartsAdapter = (function () {
16
-
17
- var hasEffect = typeof Effect !== 'undefined';
18
-
19
- return {
20
-
21
- /**
22
- * Initialize the adapter. This is run once as Highcharts is first run.
23
- * @param {Object} pathAnim The helper object to do animations across adapters.
24
- */
25
- init: function (pathAnim) {
26
- if (hasEffect) {
27
- /**
28
- * Animation for Highcharts SVG element wrappers only
29
- * @param {Object} element
30
- * @param {Object} attribute
31
- * @param {Object} to
32
- * @param {Object} options
33
- */
34
- Effect.HighchartsTransition = Class.create(Effect.Base, {
35
- initialize: function (element, attr, to, options) {
36
- var from,
37
- opts;
38
-
39
- this.element = element;
40
- this.key = attr;
41
- from = element.attr ? element.attr(attr) : $(element).getStyle(attr);
42
-
43
- // special treatment for paths
44
- if (attr === 'd') {
45
- this.paths = pathAnim.init(
46
- element,
47
- element.d,
48
- to
49
- );
50
- this.toD = to;
51
-
52
-
53
- // fake values in order to read relative position as a float in update
54
- from = 0;
55
- to = 1;
56
- }
57
-
58
- opts = Object.extend((options || {}), {
59
- from: from,
60
- to: to,
61
- attribute: attr
62
- });
63
- this.start(opts);
64
- },
65
- setup: function () {
66
- HighchartsAdapter._extend(this.element);
67
- // If this is the first animation on this object, create the _highcharts_animation helper that
68
- // contain pointers to the animation objects.
69
- if (!this.element._highchart_animation) {
70
- this.element._highchart_animation = {};
71
- }
72
-
73
- // Store a reference to this animation instance.
74
- this.element._highchart_animation[this.key] = this;
75
- },
76
- update: function (position) {
77
- var paths = this.paths,
78
- element = this.element,
79
- obj;
80
-
81
- if (paths) {
82
- position = pathAnim.step(paths[0], paths[1], position, this.toD);
83
- }
84
-
85
- if (element.attr) { // SVGElement
86
-
87
- if (element.element) { // If not, it has been destroyed (#1405)
88
- element.attr(this.options.attribute, position);
89
- }
90
-
91
- } else { // HTML, #409
92
- obj = {};
93
- obj[this.options.attribute] = position;
94
- $(element).setStyle(obj);
95
- }
96
-
97
- },
98
- finish: function () {
99
- // Delete the property that holds this animation now that it is finished.
100
- // Both canceled animations and complete ones gets a 'finish' call.
101
- if (this.element && this.element._highchart_animation) { // #1405
102
- delete this.element._highchart_animation[this.key];
103
- }
104
- }
105
- });
106
- }
107
- },
108
-
109
- /**
110
- * Run a general method on the framework, following jQuery syntax
111
- * @param {Object} el The HTML element
112
- * @param {String} method Which method to run on the wrapped element
113
- */
114
- adapterRun: function (el, method) {
115
-
116
- // This currently works for getting inner width and height. If adding
117
- // more methods later, we need a conditional implementation for each.
118
- return parseInt($(el).getStyle(method), 10);
119
-
120
- },
121
-
122
- /**
123
- * Downloads a script and executes a callback when done.
124
- * @param {String} scriptLocation
125
- * @param {Function} callback
126
- */
127
- getScript: function (scriptLocation, callback) {
128
- var head = $$('head')[0]; // Returns an array, so pick the first element.
129
- if (head) {
130
- // Append a new 'script' element, set its type and src attributes, add a 'load' handler that calls the callback
131
- head.appendChild(new Element('script', { type: 'text/javascript', src: scriptLocation}).observe('load', callback));
132
- }
133
- },
134
-
135
- /**
136
- * Custom events in prototype needs to be namespaced. This method adds a namespace 'h:' in front of
137
- * events that are not recognized as native.
138
- */
139
- addNS: function (eventName) {
140
- var HTMLEvents = /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
141
- MouseEvents = /^(?:click|mouse(?:down|up|over|move|out))$/;
142
- return (HTMLEvents.test(eventName) || MouseEvents.test(eventName)) ?
143
- eventName :
144
- 'h:' + eventName;
145
- },
146
-
147
- // el needs an event to be attached. el is not necessarily a dom element
148
- addEvent: function (el, event, fn) {
149
- if (el.addEventListener || el.attachEvent) {
150
- Event.observe($(el), HighchartsAdapter.addNS(event), fn);
151
-
152
- } else {
153
- HighchartsAdapter._extend(el);
154
- el._highcharts_observe(event, fn);
155
- }
156
- },
157
-
158
- // motion makes things pretty. use it if effects is loaded, if not... still get to the end result.
159
- animate: function (el, params, options) {
160
- var key,
161
- fx;
162
-
163
- // default options
164
- options = options || {};
165
- options.delay = 0;
166
- options.duration = (options.duration || 500) / 1000;
167
- options.afterFinish = options.complete;
168
-
169
- // animate wrappers and DOM elements
170
- if (hasEffect) {
171
- for (key in params) {
172
- // The fx variable is seemingly thrown away here, but the Effect.setup will add itself to the _highcharts_animation object
173
- // on the element itself so its not really lost.
174
- fx = new Effect.HighchartsTransition($(el), key, params[key], options);
175
- }
176
- } else {
177
- if (el.attr) { // #409 without effects
178
- for (key in params) {
179
- el.attr(key, params[key]);
180
- }
181
- }
182
- if (options.complete) {
183
- options.complete();
184
- }
185
- }
186
-
187
- if (!el.attr) { // HTML element, #409
188
- $(el).setStyle(params);
189
- }
190
- },
191
-
192
- // this only occurs in higcharts 2.0+
193
- stop: function (el) {
194
- var key;
195
- if (el._highcharts_extended && el._highchart_animation) {
196
- for (key in el._highchart_animation) {
197
- // Cancel the animation
198
- // The 'finish' function in the Effect object will remove the reference
199
- el._highchart_animation[key].cancel();
200
- }
201
- }
202
- },
203
-
204
- // um.. each
205
- each: function (arr, fn) {
206
- $A(arr).each(fn);
207
- },
208
-
209
- inArray: function (item, arr, from) {
210
- return arr ? arr.indexOf(item, from) : -1;
211
- },
212
-
213
- /**
214
- * Get the cumulative offset relative to the top left of the page. This method, unlike its
215
- * jQuery and MooTools counterpart, still suffers from issue #208 regarding the position
216
- * of a chart within a fixed container.
217
- */
218
- offset: function (el) {
219
- return $(el).cumulativeOffset();
220
- },
221
-
222
- // fire an event based on an event name (event) and an object (el).
223
- // again, el may not be a dom element
224
- fireEvent: function (el, event, eventArguments, defaultFunction) {
225
- if (el.fire) {
226
- el.fire(HighchartsAdapter.addNS(event), eventArguments);
227
- } else if (el._highcharts_extended) {
228
- eventArguments = eventArguments || {};
229
- el._highcharts_fire(event, eventArguments);
230
- }
231
-
232
- if (eventArguments && eventArguments.defaultPrevented) {
233
- defaultFunction = null;
234
- }
235
-
236
- if (defaultFunction) {
237
- defaultFunction(eventArguments);
238
- }
239
- },
240
-
241
- removeEvent: function (el, event, handler) {
242
- if ($(el).stopObserving) {
243
- if (event) {
244
- event = HighchartsAdapter.addNS(event);
245
- }
246
- $(el).stopObserving(event, handler);
247
- } if (window === el) {
248
- Event.stopObserving(el, event, handler);
249
- } else {
250
- HighchartsAdapter._extend(el);
251
- el._highcharts_stop_observing(event, handler);
252
- }
253
- },
254
-
255
- washMouseEvent: function (e) {
256
- return e;
257
- },
258
-
259
- // um, grep
260
- grep: function (arr, fn) {
261
- return arr.findAll(fn);
262
- },
263
-
264
- // um, map
265
- map: function (arr, fn) {
266
- return arr.map(fn);
267
- },
268
-
269
- // extend an object to handle highchart events (highchart objects, not svg elements).
270
- // this is a very simple way of handling events but whatever, it works (i think)
271
- _extend: function (object) {
272
- if (!object._highcharts_extended) {
273
- Object.extend(object, {
274
- _highchart_events: {},
275
- _highchart_animation: null,
276
- _highcharts_extended: true,
277
- _highcharts_observe: function (name, fn) {
278
- this._highchart_events[name] = [this._highchart_events[name], fn].compact().flatten();
279
- },
280
- _highcharts_stop_observing: function (name, fn) {
281
- if (name) {
282
- if (fn) {
283
- this._highchart_events[name] = [this._highchart_events[name]].compact().flatten().without(fn);
284
- } else {
285
- delete this._highchart_events[name];
286
- }
287
- } else {
288
- this._highchart_events = {};
289
- }
290
- },
291
- _highcharts_fire: function (name, args) {
292
- var target = this;
293
- (this._highchart_events[name] || []).each(function (fn) {
294
- // args is never null here
295
- if (args.stopped) {
296
- return; // "throw $break" wasn't working. i think because of the scope of 'this'.
297
- }
298
-
299
- // Attach a simple preventDefault function to skip default handler if called
300
- args.preventDefault = function () {
301
- args.defaultPrevented = true;
302
- };
303
- args.target = target;
304
-
305
- // If the event handler return false, prevent the default handler from executing
306
- if (fn.bind(this)(args) === false) {
307
- args.preventDefault();
308
- }
309
- }
310
- .bind(this));
311
- }
312
- });
313
- }
314
- }
315
- };
316
- }());