highcharts-rails 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,449 @@
1
- (function(e){function q(b,a,c){return"rgba("+[Math.round(b[0]+(a[0]-b[0])*c),Math.round(b[1]+(a[1]-b[1])*c),Math.round(b[2]+(a[2]-b[2])*c),b[3]+(a[3]-b[3])*c].join(",")+")"}var m=function(){},j=e.getOptions(),g=e.each,n=e.extend,o=e.wrap,h=e.Chart,i=e.seriesTypes,k=i.pie,l=i.column,r=HighchartsAdapter.fireEvent;n(j.lang,{drillUpText:"◁ Back to {series.name}"});j.drilldown={activeAxisLabelStyle:{cursor:"pointer",color:"#039",fontWeight:"bold",textDecoration:"underline"},activeDataLabelStyle:{cursor:"pointer",
2
- color:"#039",fontWeight:"bold",textDecoration:"underline"},animation:{duration:500},drillUpButton:{position:{align:"right",x:-10,y:10}}};e.SVGRenderer.prototype.Element.prototype.fadeIn=function(){this.attr({opacity:0.1,visibility:"visible"}).animate({opacity:1},{duration:250})};h.prototype.drilldownLevels=[];h.prototype.addSeriesAsDrilldown=function(b,a){var c=b.series,d=c.xAxis,f=c.yAxis,e;e=b.color||c.color;var g,a=n({color:e},a);g=HighchartsAdapter.inArray(this,c.points);this.drilldownLevels.push({seriesOptions:c.userOptions,
3
- shapeArgs:b.shapeArgs,bBox:b.graphic.getBBox(),color:e,newSeries:a,pointOptions:c.options.data[g],pointIndex:g,oldExtremes:{xMin:d&&d.userMin,xMax:d&&d.userMax,yMin:f&&f.userMin,yMax:f&&f.userMax}});e=this.addSeries(a,!1);if(d)d.oldPos=d.pos,d.userMin=d.userMax=null,f.userMin=f.userMax=null;if(c.type===e.type)e.animate=e.animateDrilldown||m,e.options.animation=!0;c.remove(!1);this.redraw();this.showDrillUpButton()};h.prototype.getDrilldownBackText=function(){return this.options.lang.drillUpText.replace("{series.name}",
4
- this.drilldownLevels[this.drilldownLevels.length-1].seriesOptions.name)};h.prototype.showDrillUpButton=function(){var b=this,a=this.getDrilldownBackText(),c=b.options.drilldown.drillUpButton;this.drillUpButton?this.drillUpButton.attr({text:a}).align():this.drillUpButton=this.renderer.button(a,null,null,function(){b.drillUp()}).attr(n({align:c.position.align,zIndex:9},c.theme)).add().align(c.position,!1,c.relativeTo||"plotBox")};h.prototype.drillUp=function(){var b=this.drilldownLevels.pop(),a=this.series[0],
5
- c=b.oldExtremes,d=this.addSeries(b.seriesOptions,!1);r(this,"drillup",{seriesOptions:b.seriesOptions});if(d.type===a.type)d.drilldownLevel=b,d.animate=d.animateDrillupTo||m,d.options.animation=!0,a.animateDrillupFrom&&a.animateDrillupFrom(b);a.remove(!1);d.xAxis&&(d.xAxis.setExtremes(c.xMin,c.xMax,!1),d.yAxis.setExtremes(c.yMin,c.yMax,!1));this.redraw();this.drilldownLevels.length===0?this.drillUpButton=this.drillUpButton.destroy():this.drillUpButton.attr({text:this.getDrilldownBackText()}).align()};
6
- k.prototype.animateDrilldown=function(b){var a=this.chart.drilldownLevels[this.chart.drilldownLevels.length-1],c=this.chart.options.drilldown.animation,d=a.shapeArgs,f=d.start,s=(d.end-f)/this.points.length,h=e.Color(a.color).rgba;b||g(this.points,function(a,b){var g=e.Color(a.color).rgba;a.graphic.attr(e.merge(d,{start:f+b*s,end:f+(b+1)*s})).animate(a.shapeArgs,e.merge(c,{step:function(a,d){d.prop==="start"&&this.attr({fill:q(h,g,d.pos)})}}))})};k.prototype.animateDrillupTo=l.prototype.animateDrillupTo=
7
- function(b){if(!b){var a=this,c=a.drilldownLevel;g(this.points,function(a){a.graphic.hide();a.dataLabel&&a.dataLabel.hide();a.connector&&a.connector.hide()});setTimeout(function(){g(a.points,function(a,b){var e=b===c.pointIndex?"show":"fadeIn";a.graphic[e]();if(a.dataLabel)a.dataLabel[e]();if(a.connector)a.connector[e]()})},Math.max(this.chart.options.drilldown.animation.duration-50,0));this.animate=m}};l.prototype.animateDrilldown=function(b){var a=this.chart.drilldownLevels[this.chart.drilldownLevels.length-
8
- 1].shapeArgs,c=this.chart.options.drilldown.animation;b||(a.x+=this.xAxis.oldPos-this.xAxis.pos,g(this.points,function(b){b.graphic.attr(a).animate(b.shapeArgs,c)}))};l.prototype.animateDrillupFrom=k.prototype.animateDrillupFrom=function(b){var a=this.chart.options.drilldown.animation,c=this.group;delete this.group;g(this.points,function(d){var f=d.graphic,g=e.Color(d.color).rgba;delete d.graphic;f.animate(b.shapeArgs,e.merge(a,{step:function(a,c){c.prop==="start"&&this.attr({fill:q(g,e.Color(b.color).rgba,
9
- c.pos)})},complete:function(){f.destroy();c&&(c=c.destroy())}}))})};e.Point.prototype.doDrilldown=function(){for(var b=this.series.chart,a=b.options.drilldown,c=a.series.length,d;c--&&!d;)a.series[c].id===this.drilldown&&(d=a.series[c]);r(b,"drilldown",{point:this,seriesOptions:d});d&&b.addSeriesAsDrilldown(this,d)};o(e.Point.prototype,"init",function(b,a,c,d){var f=b.call(this,a,c,d),b=a.chart,a=(a=a.xAxis&&a.xAxis.ticks[d])&&a.label;if(f.drilldown){if(e.addEvent(f,"click",function(){f.doDrilldown()}),
10
- a){if(!a._basicStyle)a._basicStyle=a.element.getAttribute("style");a.addClass("highcharts-drilldown-axis-label").css(b.options.drilldown.activeAxisLabelStyle).on("click",function(){f.doDrilldown&&f.doDrilldown()})}}else a&&a._basicStyle&&a.element.setAttribute("style",a._basicStyle);return f});o(e.Series.prototype,"drawDataLabels",function(b){var a=this.chart.options.drilldown.activeDataLabelStyle;b.call(this);g(this.points,function(b){if(b.drilldown&&b.dataLabel)b.dataLabel.attr({"class":"highcharts-drilldown-data-label"}).css(a).on("click",
11
- function(){b.doDrilldown()})})});l.prototype.supportsDrilldown=!0;k.prototype.supportsDrilldown=!0;var p,j=function(b){b.call(this);g(this.points,function(a){a.drilldown&&a.graphic&&a.graphic.attr({"class":"highcharts-drilldown-point"}).css({cursor:"pointer"})})};for(p in i)i[p].prototype.supportsDrilldown&&o(i[p].prototype,"drawTracker",j)})(Highcharts);
1
+ /**
2
+ * Highcharts Drilldown plugin
3
+ *
4
+ * Author: Torstein Honsi
5
+ * Last revision: 2013-02-18
6
+ * License: MIT License
7
+ *
8
+ * Demo: http://jsfiddle.net/highcharts/Vf3yT/
9
+ */
10
+
11
+ /*global HighchartsAdapter*/
12
+ (function (H) {
13
+
14
+ "use strict";
15
+
16
+ var noop = function () {},
17
+ defaultOptions = H.getOptions(),
18
+ each = H.each,
19
+ extend = H.extend,
20
+ wrap = H.wrap,
21
+ Chart = H.Chart,
22
+ seriesTypes = H.seriesTypes,
23
+ PieSeries = seriesTypes.pie,
24
+ ColumnSeries = seriesTypes.column,
25
+ fireEvent = HighchartsAdapter.fireEvent,
26
+ inArray = HighchartsAdapter.inArray;
27
+
28
+ // Utilities
29
+ function tweenColors(startColor, endColor, pos) {
30
+ var rgba = [
31
+ Math.round(startColor[0] + (endColor[0] - startColor[0]) * pos),
32
+ Math.round(startColor[1] + (endColor[1] - startColor[1]) * pos),
33
+ Math.round(startColor[2] + (endColor[2] - startColor[2]) * pos),
34
+ startColor[3] + (endColor[3] - startColor[3]) * pos
35
+ ];
36
+ return 'rgba(' + rgba.join(',') + ')';
37
+ }
38
+
39
+ // Add language
40
+ extend(defaultOptions.lang, {
41
+ drillUpText: '◁ Back to {series.name}'
42
+ });
43
+ defaultOptions.drilldown = {
44
+ activeAxisLabelStyle: {
45
+ cursor: 'pointer',
46
+ color: '#039',
47
+ fontWeight: 'bold',
48
+ textDecoration: 'underline'
49
+ },
50
+ activeDataLabelStyle: {
51
+ cursor: 'pointer',
52
+ color: '#039',
53
+ fontWeight: 'bold',
54
+ textDecoration: 'underline'
55
+ },
56
+ animation: {
57
+ duration: 500
58
+ },
59
+ drillUpButton: {
60
+ position: {
61
+ align: 'right',
62
+ x: -10,
63
+ y: 10
64
+ }
65
+ // relativeTo: 'plotBox'
66
+ // theme
67
+ }
68
+ };
69
+
70
+ /**
71
+ * A general fadeIn method
72
+ */
73
+ H.SVGRenderer.prototype.Element.prototype.fadeIn = function () {
74
+ this
75
+ .attr({
76
+ opacity: 0.1,
77
+ visibility: 'visible'
78
+ })
79
+ .animate({
80
+ opacity: 1
81
+ }, {
82
+ duration: 250
83
+ });
84
+ };
85
+
86
+ // Extend the Chart prototype
87
+ Chart.prototype.drilldownLevels = [];
88
+
89
+ Chart.prototype.addSeriesAsDrilldown = function (point, ddOptions) {
90
+ var oldSeries = point.series,
91
+ xAxis = oldSeries.xAxis,
92
+ yAxis = oldSeries.yAxis,
93
+ newSeries,
94
+ color = point.color || oldSeries.color,
95
+ pointIndex,
96
+ level;
97
+
98
+ ddOptions = extend({
99
+ color: color
100
+ }, ddOptions);
101
+ pointIndex = inArray(point, oldSeries.points);
102
+
103
+ level = {
104
+ seriesOptions: oldSeries.userOptions,
105
+ shapeArgs: point.shapeArgs,
106
+ bBox: point.graphic.getBBox(),
107
+ color: color,
108
+ newSeries: ddOptions,
109
+ pointOptions: oldSeries.options.data[pointIndex],
110
+ pointIndex: pointIndex,
111
+ oldExtremes: {
112
+ xMin: xAxis && xAxis.userMin,
113
+ xMax: xAxis && xAxis.userMax,
114
+ yMin: yAxis && yAxis.userMin,
115
+ yMax: yAxis && yAxis.userMax
116
+ }
117
+ };
118
+
119
+ this.drilldownLevels.push(level);
120
+
121
+ newSeries = this.addSeries(ddOptions, false);
122
+ if (xAxis) {
123
+ xAxis.oldPos = xAxis.pos;
124
+ xAxis.userMin = xAxis.userMax = null;
125
+ yAxis.userMin = yAxis.userMax = null;
126
+ }
127
+
128
+ // Run fancy cross-animation on supported and equal types
129
+ if (oldSeries.type === newSeries.type) {
130
+ newSeries.animate = newSeries.animateDrilldown || noop;
131
+ newSeries.options.animation = true;
132
+ }
133
+
134
+ oldSeries.remove(false);
135
+
136
+ this.redraw();
137
+ this.showDrillUpButton();
138
+ };
139
+
140
+ Chart.prototype.getDrilldownBackText = function () {
141
+ var lastLevel = this.drilldownLevels[this.drilldownLevels.length - 1];
142
+
143
+ return this.options.lang.drillUpText.replace('{series.name}', lastLevel.seriesOptions.name);
144
+
145
+ };
146
+
147
+ Chart.prototype.showDrillUpButton = function () {
148
+ var chart = this,
149
+ backText = this.getDrilldownBackText(),
150
+ buttonOptions = chart.options.drilldown.drillUpButton;
151
+
152
+
153
+ if (!this.drillUpButton) {
154
+ this.drillUpButton = this.renderer.button(
155
+ backText,
156
+ null,
157
+ null,
158
+ function () {
159
+ chart.drillUp();
160
+ }
161
+ )
162
+ .attr(extend({
163
+ align: buttonOptions.position.align,
164
+ zIndex: 9
165
+ }, buttonOptions.theme))
166
+ .add()
167
+ .align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
168
+ } else {
169
+ this.drillUpButton.attr({
170
+ text: backText
171
+ })
172
+ .align();
173
+ }
174
+ };
175
+
176
+ Chart.prototype.drillUp = function () {
177
+ var chart = this,
178
+ level = chart.drilldownLevels.pop(),
179
+ oldSeries = chart.series[0],
180
+ oldExtremes = level.oldExtremes,
181
+ newSeries = chart.addSeries(level.seriesOptions, false);
182
+
183
+ fireEvent(chart, 'drillup', { seriesOptions: level.seriesOptions });
184
+
185
+ if (newSeries.type === oldSeries.type) {
186
+ newSeries.drilldownLevel = level;
187
+ newSeries.animate = newSeries.animateDrillupTo || noop;
188
+ newSeries.options.animation = true;
189
+
190
+ if (oldSeries.animateDrillupFrom) {
191
+ oldSeries.animateDrillupFrom(level);
192
+ }
193
+ }
194
+
195
+ oldSeries.remove(false);
196
+
197
+ // Reset the zoom level of the upper series
198
+ if (newSeries.xAxis) {
199
+ newSeries.xAxis.setExtremes(oldExtremes.xMin, oldExtremes.xMax, false);
200
+ newSeries.yAxis.setExtremes(oldExtremes.yMin, oldExtremes.yMax, false);
201
+ }
202
+
203
+
204
+ this.redraw();
205
+
206
+ if (this.drilldownLevels.length === 0) {
207
+ this.drillUpButton = this.drillUpButton.destroy();
208
+ } else {
209
+ this.drillUpButton.attr({
210
+ text: this.getDrilldownBackText()
211
+ })
212
+ .align();
213
+ }
214
+ };
215
+
216
+ PieSeries.prototype.animateDrilldown = function (init) {
217
+ var level = this.chart.drilldownLevels[this.chart.drilldownLevels.length - 1],
218
+ animationOptions = this.chart.options.drilldown.animation,
219
+ animateFrom = level.shapeArgs,
220
+ start = animateFrom.start,
221
+ angle = animateFrom.end - start,
222
+ startAngle = angle / this.points.length,
223
+ startColor = H.Color(level.color).rgba;
224
+
225
+ if (!init) {
226
+ each(this.points, function (point, i) {
227
+ var endColor = H.Color(point.color).rgba;
228
+
229
+ /*jslint unparam: true*/
230
+ point.graphic
231
+ .attr(H.merge(animateFrom, {
232
+ start: start + i * startAngle,
233
+ end: start + (i + 1) * startAngle
234
+ }))
235
+ .animate(point.shapeArgs, H.merge(animationOptions, {
236
+ step: function (val, fx) {
237
+ if (fx.prop === 'start') {
238
+ this.attr({
239
+ fill: tweenColors(startColor, endColor, fx.pos)
240
+ });
241
+ }
242
+ }
243
+ }));
244
+ /*jslint unparam: false*/
245
+ });
246
+ }
247
+ };
248
+
249
+
250
+ /**
251
+ * When drilling up, keep the upper series invisible until the lower series has
252
+ * moved into place
253
+ */
254
+ PieSeries.prototype.animateDrillupTo =
255
+ ColumnSeries.prototype.animateDrillupTo = function (init) {
256
+ if (!init) {
257
+ var newSeries = this,
258
+ level = newSeries.drilldownLevel;
259
+
260
+ each(this.points, function (point) {
261
+ point.graphic.hide();
262
+ if (point.dataLabel) {
263
+ point.dataLabel.hide();
264
+ }
265
+ if (point.connector) {
266
+ point.connector.hide();
267
+ }
268
+ });
269
+
270
+
271
+ // Do dummy animation on first point to get to complete
272
+ setTimeout(function () {
273
+ each(newSeries.points, function (point, i) {
274
+ // Fade in other points
275
+ var verb = i === level.pointIndex ? 'show' : 'fadeIn';
276
+ point.graphic[verb]();
277
+ if (point.dataLabel) {
278
+ point.dataLabel[verb]();
279
+ }
280
+ if (point.connector) {
281
+ point.connector[verb]();
282
+ }
283
+ });
284
+ }, Math.max(this.chart.options.drilldown.animation.duration - 50, 0));
285
+
286
+ // Reset
287
+ this.animate = noop;
288
+ }
289
+
290
+ };
291
+
292
+ ColumnSeries.prototype.animateDrilldown = function (init) {
293
+ var animateFrom = this.chart.drilldownLevels[this.chart.drilldownLevels.length - 1].shapeArgs,
294
+ animationOptions = this.chart.options.drilldown.animation;
295
+
296
+ if (!init) {
297
+
298
+ animateFrom.x += (this.xAxis.oldPos - this.xAxis.pos);
299
+
300
+ each(this.points, function (point) {
301
+ point.graphic
302
+ .attr(animateFrom)
303
+ .animate(point.shapeArgs, animationOptions);
304
+ });
305
+ }
306
+
307
+ };
308
+
309
+ /**
310
+ * When drilling up, pull out the individual point graphics from the lower series
311
+ * and animate them into the origin point in the upper series.
312
+ */
313
+ ColumnSeries.prototype.animateDrillupFrom =
314
+ PieSeries.prototype.animateDrillupFrom =
315
+ function (level) {
316
+ var animationOptions = this.chart.options.drilldown.animation,
317
+ group = this.group;
318
+
319
+ delete this.group;
320
+ each(this.points, function (point) {
321
+ var graphic = point.graphic,
322
+ startColor = H.Color(point.color).rgba;
323
+
324
+ delete point.graphic;
325
+
326
+ /*jslint unparam: true*/
327
+ graphic.animate(level.shapeArgs, H.merge(animationOptions, {
328
+
329
+ step: function (val, fx) {
330
+ if (fx.prop === 'start') {
331
+ this.attr({
332
+ fill: tweenColors(startColor, H.Color(level.color).rgba, fx.pos)
333
+ });
334
+ }
335
+ },
336
+ complete: function () {
337
+ graphic.destroy();
338
+ if (group) {
339
+ group = group.destroy();
340
+ }
341
+ }
342
+ }));
343
+ /*jslint unparam: false*/
344
+ });
345
+ };
346
+
347
+ H.Point.prototype.doDrilldown = function () {
348
+ var series = this.series,
349
+ chart = series.chart,
350
+ drilldown = chart.options.drilldown,
351
+ i = drilldown.series.length,
352
+ seriesOptions;
353
+
354
+ while (i-- && !seriesOptions) {
355
+ if (drilldown.series[i].id === this.drilldown) {
356
+ seriesOptions = drilldown.series[i];
357
+ }
358
+ }
359
+
360
+ // Fire the event. If seriesOptions is undefined, the implementer can check for
361
+ // seriesOptions, and call addSeriesAsDrilldown async if necessary.
362
+ fireEvent(chart, 'drilldown', {
363
+ point: this,
364
+ seriesOptions: seriesOptions
365
+ });
366
+
367
+ if (seriesOptions) {
368
+ chart.addSeriesAsDrilldown(this, seriesOptions);
369
+ }
370
+
371
+ };
372
+
373
+ wrap(H.Point.prototype, 'init', function (proceed, series, options, x) {
374
+ var point = proceed.call(this, series, options, x),
375
+ chart = series.chart,
376
+ tick = series.xAxis && series.xAxis.ticks[x],
377
+ tickLabel = tick && tick.label;
378
+
379
+ if (point.drilldown) {
380
+
381
+ // Add the click event to the point label
382
+ H.addEvent(point, 'click', function () {
383
+ point.doDrilldown();
384
+ });
385
+
386
+ // Make axis labels clickable
387
+ if (tickLabel) {
388
+ if (!tickLabel._basicStyle) {
389
+ tickLabel._basicStyle = tickLabel.element.getAttribute('style');
390
+ }
391
+ tickLabel
392
+ .addClass('highcharts-drilldown-axis-label')
393
+ .css(chart.options.drilldown.activeAxisLabelStyle)
394
+ .on('click', function () {
395
+ if (point.doDrilldown) {
396
+ point.doDrilldown();
397
+ }
398
+ });
399
+
400
+ }
401
+ } else if (tickLabel && tickLabel._basicStyle) {
402
+ tickLabel.element.setAttribute('style', tickLabel._basicStyle);
403
+ }
404
+
405
+ return point;
406
+ });
407
+
408
+ wrap(H.Series.prototype, 'drawDataLabels', function (proceed) {
409
+ var css = this.chart.options.drilldown.activeDataLabelStyle;
410
+
411
+ proceed.call(this);
412
+
413
+ each(this.points, function (point) {
414
+ if (point.drilldown && point.dataLabel) {
415
+ point.dataLabel
416
+ .attr({
417
+ 'class': 'highcharts-drilldown-data-label'
418
+ })
419
+ .css(css)
420
+ .on('click', function () {
421
+ point.doDrilldown();
422
+ });
423
+ }
424
+ });
425
+ });
426
+
427
+ // Mark the trackers with a pointer
428
+ ColumnSeries.prototype.supportsDrilldown = true;
429
+ PieSeries.prototype.supportsDrilldown = true;
430
+ var type,
431
+ drawTrackerWrapper = function (proceed) {
432
+ proceed.call(this);
433
+ each(this.points, function (point) {
434
+ if (point.drilldown && point.graphic) {
435
+ point.graphic
436
+ .attr({
437
+ 'class': 'highcharts-drilldown-point'
438
+ })
439
+ .css({ cursor: 'pointer' });
440
+ }
441
+ });
442
+ };
443
+ for (type in seriesTypes) {
444
+ if (seriesTypes[type].prototype.supportsDrilldown) {
445
+ wrap(seriesTypes[type].prototype, 'drawTracker', drawTrackerWrapper);
446
+ }
447
+ }
448
+
449
+ }(Highcharts));