highcharts-rails 4.1.10 → 4.2.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.
@@ -1,635 +1 @@
1
- /**
2
- * @license Highcharts JS v4.1.10 (2015-12-07)
3
- *
4
- * Standalone Highcharts Framework
5
- *
6
- * License: MIT License
7
- */
8
1
 
9
- (function (root, factory) {
10
- if (typeof module === 'object' && module.exports) {
11
- module.exports = root.document ?
12
- factory(root) :
13
- function (w) {
14
- return factory(w);
15
- };
16
- } else {
17
- root.HighchartsAdapter = factory();
18
- }
19
- }(typeof window !== 'undefined' ? window : this, function (w) {
20
-
21
- var UNDEFINED,
22
- win = w || window,
23
- doc = win.document,
24
- emptyArray = [],
25
- _getStyle,
26
- timers = [],
27
- animSetters = {},
28
- HighchartsAdapter,
29
- Fx;
30
-
31
- Math.easeInOutSine = function (t, b, c, d) {
32
- return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
33
- };
34
-
35
- /**
36
- * Internal method to return CSS value for given element and property
37
- */
38
- _getStyle = function (el, prop) {
39
- var style = win.getComputedStyle(el, undefined);
40
- return style && style.getPropertyValue(prop);
41
- };
42
-
43
-
44
- /**
45
- * Extend given object with custom events
46
- */
47
- function augment(obj) {
48
- function removeOneEvent(el, type, fn) {
49
- el.removeEventListener(type, fn, false);
50
- }
51
-
52
- function IERemoveOneEvent(el, type, fn) {
53
- fn = el.HCProxiedMethods[fn.toString()];
54
- el.detachEvent('on' + type, fn);
55
- }
56
-
57
- function removeAllEvents(el, type) {
58
- var events = el.HCEvents,
59
- remove,
60
- types,
61
- len,
62
- n;
63
-
64
- if (el.removeEventListener) {
65
- remove = removeOneEvent;
66
- } else if (el.attachEvent) {
67
- remove = IERemoveOneEvent;
68
- } else {
69
- return; // break on non-DOM events
70
- }
71
-
72
-
73
- if (type) {
74
- types = {};
75
- types[type] = true;
76
- } else {
77
- types = events;
78
- }
79
-
80
- for (n in types) {
81
- if (events[n]) {
82
- len = events[n].length;
83
- while (len--) {
84
- remove(el, n, events[n][len]);
85
- }
86
- }
87
- }
88
- }
89
-
90
- if (!obj.HCExtended) {
91
- obj.HCExtended = true;
92
-
93
- obj.HCEvents = {};
94
-
95
- obj.bind = function (name, fn) {
96
- var el = this,
97
- events = this.HCEvents,
98
- wrappedFn;
99
-
100
- // handle DOM events in modern browsers
101
- if (el.addEventListener) {
102
- el.addEventListener(name, fn, false);
103
-
104
- // handle old IE implementation
105
- } else if (el.attachEvent) {
106
-
107
- wrappedFn = function (e) {
108
- e.target = e.srcElement || win; // #2820
109
- fn.call(el, e);
110
- };
111
-
112
- if (!el.HCProxiedMethods) {
113
- el.HCProxiedMethods = {};
114
- }
115
-
116
- // link wrapped fn with original fn, so we can get this in removeEvent
117
- el.HCProxiedMethods[fn.toString()] = wrappedFn;
118
-
119
- el.attachEvent('on' + name, wrappedFn);
120
- }
121
-
122
-
123
- if (events[name] === UNDEFINED) {
124
- events[name] = [];
125
- }
126
-
127
- events[name].push(fn);
128
- };
129
-
130
- obj.unbind = function (name, fn) {
131
- var events,
132
- index;
133
-
134
- if (name) {
135
- events = this.HCEvents[name] || [];
136
- if (fn) {
137
- index = HighchartsAdapter.inArray(fn, events);
138
- if (index > -1) {
139
- events.splice(index, 1);
140
- this.HCEvents[name] = events;
141
- }
142
- if (this.removeEventListener) {
143
- removeOneEvent(this, name, fn);
144
- } else if (this.attachEvent) {
145
- IERemoveOneEvent(this, name, fn);
146
- }
147
- } else {
148
- removeAllEvents(this, name);
149
- this.HCEvents[name] = [];
150
- }
151
- } else {
152
- removeAllEvents(this);
153
- this.HCEvents = {};
154
- }
155
- };
156
-
157
- obj.trigger = function (name, args) {
158
- var events = this.HCEvents[name] || [],
159
- target = this,
160
- len = events.length,
161
- i,
162
- preventDefault,
163
- fn;
164
-
165
- // Attach a simple preventDefault function to skip default handler if called
166
- preventDefault = function () {
167
- args.defaultPrevented = true;
168
- };
169
-
170
- for (i = 0; i < len; i++) {
171
- fn = events[i];
172
-
173
- // args is never null here
174
- if (args.stopped) {
175
- return;
176
- }
177
-
178
- args.preventDefault = preventDefault;
179
- args.target = target;
180
-
181
- // If the type is not set, we're running a custom event (#2297). If it is set,
182
- // we're running a browser event, and setting it will cause en error in
183
- // IE8 (#2465).
184
- if (!args.type) {
185
- args.type = name;
186
- }
187
-
188
-
189
-
190
- // If the event handler return false, prevent the default handler from executing
191
- if (fn.call(this, args) === false) {
192
- args.preventDefault();
193
- }
194
- }
195
- };
196
- }
197
-
198
- return obj;
199
- }
200
-
201
-
202
- HighchartsAdapter = {
203
-
204
- /**
205
- * Initialize the adapter. This is run once as Highcharts is first run.
206
- */
207
- init: function (pathAnim) {
208
-
209
- /**
210
- * Compatibility section to add support for legacy IE. This can be removed if old IE
211
- * support is not needed.
212
- */
213
- if (!doc.defaultView) {
214
- _getStyle = function (el, prop) {
215
- var val;
216
- if (el.style[prop]) {
217
- return el.style[prop];
218
- }
219
- if (prop === 'opacity') {
220
- prop = 'filter';
221
- }
222
-
223
- val = el.currentStyle[prop.replace(/\-(\w)/g, function (a, b) {
224
- return b.toUpperCase();
225
- })];
226
- if (prop === 'filter') {
227
- val = val.replace(
228
- /alpha\(opacity=([0-9]+)\)/,
229
- function (a, b) {
230
- return b / 100;
231
- }
232
- );
233
- }
234
-
235
- return val === '' ? 1 : val;
236
- };
237
- this.adapterRun = function (elem, method) {
238
- var alias = { width: 'clientWidth', height: 'clientHeight' }[method];
239
-
240
- if (alias) {
241
- elem.style.zoom = 1;
242
- return elem[alias] - 2 * parseInt(_getStyle(elem, 'padding'), 10);
243
- }
244
- };
245
- }
246
-
247
- if (!Array.prototype.forEach) {
248
- this.each = function (arr, fn) { // legacy
249
- var i = 0,
250
- len = arr.length;
251
- for (; i < len; i++) {
252
- if (fn.call(arr[i], arr[i], i, arr) === false) {
253
- return i;
254
- }
255
- }
256
- };
257
- }
258
-
259
- if (!Array.prototype.indexOf) {
260
- this.inArray = function (item, arr) {
261
- var len,
262
- i = 0;
263
-
264
- if (arr) {
265
- len = arr.length;
266
-
267
- for (; i < len; i++) {
268
- if (arr[i] === item) {
269
- return i;
270
- }
271
- }
272
- }
273
-
274
- return -1;
275
- };
276
- }
277
-
278
- if (!Array.prototype.filter) {
279
- this.grep = function (elements, fn) {
280
- var ret = [],
281
- i = 0,
282
- length = elements.length;
283
-
284
- for (; i < length; i++) {
285
- if (!!fn(elements[i], i)) {
286
- ret.push(elements[i]);
287
- }
288
- }
289
-
290
- return ret;
291
- };
292
- }
293
-
294
- //--- End compatibility section ---
295
-
296
-
297
- /**
298
- * Start of animation specific code
299
- */
300
- Fx = function (elem, options, prop) {
301
- this.options = options;
302
- this.elem = elem;
303
- this.prop = prop;
304
- };
305
- Fx.prototype = {
306
-
307
- update: function () {
308
- var styles,
309
- paths = this.paths,
310
- elem = this.elem,
311
- elemelem = elem.element,
312
- prop; // if destroyed, it is null
313
-
314
- // Animation setter defined from outside
315
- if (animSetters[this.prop]) {
316
- animSetters[this.prop](this);
317
-
318
- // Animating a path definition on SVGElement
319
- } else if (paths && elemelem) {
320
- elem.attr('d', pathAnim.step(paths[0], paths[1], this.now, this.toD));
321
-
322
- // Other animations on SVGElement
323
- } else if (elem.attr) {
324
- if (elemelem) {
325
- elem.attr(this.prop, this.now);
326
- }
327
-
328
- // HTML styles, raw HTML content like container size
329
- } else {
330
- styles = {};
331
- styles[this.prop] = this.now + this.unit;
332
- for (prop in styles) {
333
- elem.style[prop] = styles[prop];
334
- }
335
- }
336
-
337
- if (this.options.step) {
338
- this.options.step.call(this.elem, this.now, this);
339
- }
340
-
341
- },
342
- custom: function (from, to, unit) {
343
- var self = this,
344
- t = function (gotoEnd) {
345
- return self.step(gotoEnd);
346
- },
347
- i;
348
-
349
- this.startTime = +new Date();
350
- this.start = from;
351
- this.end = to;
352
- this.unit = unit;
353
- this.now = this.start;
354
- this.pos = this.state = 0;
355
-
356
- t.elem = this.elem;
357
-
358
- if (t() && timers.push(t) === 1) {
359
- t.timerId = setInterval(function () {
360
-
361
- for (i = 0; i < timers.length; i++) {
362
- if (!timers[i]()) {
363
- timers.splice(i--, 1);
364
- }
365
- }
366
-
367
- if (!timers.length) {
368
- clearInterval(t.timerId);
369
- }
370
- }, 13);
371
- }
372
- },
373
-
374
- step: function (gotoEnd) {
375
- var t = +new Date(),
376
- ret,
377
- done,
378
- options = this.options,
379
- elem = this.elem,
380
- i;
381
-
382
- if (elem.attr && !elem.element) { // #2616, element including flag is destroyed
383
- ret = false;
384
-
385
- } else if (gotoEnd || t >= options.duration + this.startTime) {
386
- this.now = this.end;
387
- this.pos = this.state = 1;
388
- this.update();
389
-
390
- this.options.curAnim[this.prop] = true;
391
-
392
- done = true;
393
- for (i in options.curAnim) {
394
- if (options.curAnim[i] !== true) {
395
- done = false;
396
- }
397
- }
398
-
399
- if (done) {
400
- if (options.complete) {
401
- options.complete.call(elem);
402
- }
403
- }
404
- ret = false;
405
-
406
- } else {
407
- var n = t - this.startTime;
408
- this.state = n / options.duration;
409
- this.pos = options.easing(n, 0, 1, options.duration);
410
- this.now = this.start + ((this.end - this.start) * this.pos);
411
- this.update();
412
- ret = true;
413
- }
414
- return ret;
415
- }
416
- };
417
-
418
- /**
419
- * The adapter animate method
420
- */
421
- this.animate = function (el, prop, opt) {
422
- var start,
423
- unit = '',
424
- end,
425
- fx,
426
- args,
427
- name,
428
- key,
429
- PX = 'px';
430
-
431
- if (typeof opt !== 'object' || opt === null) {
432
- args = arguments;
433
- opt = {
434
- duration: args[2],
435
- easing: args[3],
436
- complete: args[4]
437
- };
438
- }
439
- if (typeof opt.duration !== 'number') {
440
- opt.duration = 400;
441
- }
442
- opt.easing = Math[opt.easing] || Math.easeInOutSine;
443
- opt.curAnim = {};
444
- for (key in prop) {
445
- opt.curAnim[key] = prop[key];
446
- }
447
-
448
- for (name in prop) {
449
- fx = new Fx(el, opt, name);
450
- end = null;
451
-
452
- if (name === 'd') {
453
- fx.paths = pathAnim.init(
454
- el,
455
- el.d,
456
- prop.d
457
- );
458
- fx.toD = prop.d;
459
- start = 0;
460
- end = 1;
461
- } else if (el.attr) {
462
- start = el.attr(name);
463
- } else {
464
- start = parseFloat(_getStyle(el, name)) || 0;
465
- if (name !== 'opacity') {
466
- unit = PX;
467
- }
468
- }
469
-
470
- if (!end) {
471
- end = prop[name];
472
- }
473
- if (end.match && end.match(PX)) {
474
- end = end.replace(/px/g, ''); // #4351
475
- }
476
- fx.custom(start, end, unit);
477
- }
478
- };
479
- },
480
-
481
- /**
482
- * Add an animation setter for a specific property
483
- */
484
- addAnimSetter: function (prop, fn) {
485
- animSetters[prop] = fn;
486
- },
487
-
488
- /**
489
- * Downloads a script and executes a callback when done.
490
- * @param {String} scriptLocation
491
- * @param {Function} callback
492
- */
493
- getScript: function (scriptLocation, callback) {
494
- // We cannot assume that Assets class from mootools-more is available so instead insert a script tag to download script.
495
- var head = doc.getElementsByTagName('head')[0],
496
- script = doc.createElement('script');
497
-
498
- script.type = 'text/javascript';
499
- script.src = scriptLocation;
500
- script.onload = callback;
501
-
502
- head.appendChild(script);
503
- },
504
-
505
- /**
506
- * Return the index of an item in an array, or -1 if not found
507
- */
508
- inArray: function (item, arr) {
509
- return arr.indexOf ? arr.indexOf(item) : emptyArray.indexOf.call(arr, item);
510
- },
511
-
512
-
513
- /**
514
- * A direct link to adapter methods
515
- */
516
- adapterRun: function (elem, method) {
517
- return parseInt(_getStyle(elem, method), 10);
518
- },
519
-
520
- /**
521
- * Filter an array
522
- */
523
- grep: function (elements, callback) {
524
- return emptyArray.filter.call(elements, callback);
525
- },
526
-
527
- /**
528
- * Map an array
529
- */
530
- map: function (arr, fn) {
531
- var results = [], i = 0, len = arr.length;
532
-
533
- for (; i < len; i++) {
534
- results[i] = fn.call(arr[i], arr[i], i, arr);
535
- }
536
-
537
- return results;
538
- },
539
-
540
- /**
541
- * Get the element's offset position, corrected by overflow:auto. Loosely based on jQuery's offset method.
542
- */
543
- offset: function (el) {
544
- var docElem = document.documentElement,
545
- box = el.getBoundingClientRect();
546
-
547
- return {
548
- top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0),
549
- left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)
550
- };
551
- },
552
-
553
- /**
554
- * Add an event listener
555
- */
556
- addEvent: function (el, type, fn) {
557
- augment(el).bind(type, fn);
558
- },
559
-
560
- /**
561
- * Remove event added with addEvent
562
- */
563
- removeEvent: function (el, type, fn) {
564
- augment(el).unbind(type, fn);
565
- },
566
-
567
- /**
568
- * Fire an event on a custom object
569
- */
570
- fireEvent: function (el, type, eventArguments, defaultFunction) {
571
- var e,
572
- key;
573
-
574
- if (doc.createEvent && (el.dispatchEvent || el.fireEvent)) {
575
- e = doc.createEvent('Events');
576
- e.initEvent(type, true, true);
577
- e.target = el;
578
-
579
- for (key in eventArguments) {
580
- e[key] = eventArguments[key];
581
- }
582
-
583
- if (el.dispatchEvent) {
584
- el.dispatchEvent(e);
585
- } else {
586
- el.fireEvent(type, e);
587
- }
588
-
589
- } else if (el.HCExtended === true) {
590
- eventArguments = eventArguments || {};
591
- el.trigger(type, eventArguments);
592
- }
593
-
594
- if (eventArguments && eventArguments.defaultPrevented) {
595
- defaultFunction = null;
596
- }
597
-
598
- if (defaultFunction) {
599
- defaultFunction(eventArguments);
600
- }
601
- },
602
-
603
- washMouseEvent: function (e) {
604
- return e;
605
- },
606
-
607
-
608
- /**
609
- * Stop running animation
610
- */
611
- stop: function (el) {
612
-
613
- var i = timers.length,
614
- timer;
615
-
616
- // Remove timers related to this element (#4519)
617
- while (i--) {
618
- timer = timers[i];
619
- if (timer.elem === el) {
620
- timers.splice(i, 1);
621
- }
622
- }
623
- },
624
-
625
- /**
626
- * Utility for iterating over an array. Parameters are reversed compared to jQuery.
627
- * @param {Array} arr
628
- * @param {Function} fn
629
- */
630
- each: function (arr, fn) { // modern browsers
631
- return Array.prototype.forEach.call(arr, fn);
632
- }
633
- };
634
- return HighchartsAdapter;
635
- }));