highcharts-rails 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,26 +5,7 @@ var UNDEFINED,
5
5
  ALLOWED_SHAPES,
6
6
  Chart = Highcharts.Chart,
7
7
  extend = Highcharts.extend,
8
- each = Highcharts.each,
9
- defaultOptions;
10
-
11
- defaultOptions = {
12
- xAxis: 0,
13
- yAxis: 0,
14
- title: {
15
- style: {},
16
- text: "",
17
- x: 0,
18
- y: 0
19
- },
20
- shape: {
21
- params: {
22
- stroke: "#000000",
23
- fill: "transparent",
24
- strokeWidth: 2
25
- }
26
- }
27
- };
8
+ each = Highcharts.each;
28
9
 
29
10
  ALLOWED_SHAPES = ["path", "rect", "circle"];
30
11
 
@@ -42,6 +23,44 @@ ALIGN_FACTOR = {
42
23
  var inArray = HighchartsAdapter.inArray,
43
24
  merge = Highcharts.merge;
44
25
 
26
+ function defaultOptions(shapeType) {
27
+ var shapeOptions,
28
+ options;
29
+
30
+ options = {
31
+ xAxis: 0,
32
+ yAxis: 0,
33
+ title: {
34
+ style: {},
35
+ text: "",
36
+ x: 0,
37
+ y: 0
38
+ },
39
+ shape: {
40
+ params: {
41
+ stroke: "#000000",
42
+ fill: "transparent",
43
+ strokeWidth: 2
44
+ }
45
+ }
46
+ };
47
+
48
+ shapeOptions = {
49
+ circle: {
50
+ params: {
51
+ x: 0,
52
+ y: 0
53
+ }
54
+ }
55
+ };
56
+
57
+ if (shapeOptions[shapeType]) {
58
+ options.shape = merge(options.shape, shapeOptions[shapeType]);
59
+ }
60
+
61
+ return options;
62
+ }
63
+
45
64
  function isArray(obj) {
46
65
  return Object.prototype.toString.call(obj) === '[object Array]';
47
66
  }
@@ -54,6 +73,23 @@ function defined(obj) {
54
73
  return obj !== UNDEFINED && obj !== null;
55
74
  }
56
75
 
76
+ function translatePath(d, xAxis, yAxis, xOffset, yOffset) {
77
+ var len = d.length,
78
+ i = 0;
79
+
80
+ while (i < len) {
81
+ if (typeof d[i] === 'number' && typeof d[i + 1] === 'number') {
82
+ d[i] = xAxis.toPixels(d[i]) - xOffset;
83
+ d[i + 1] = yAxis.toPixels(d[i + 1]) - yOffset;
84
+ i += 2;
85
+ } else {
86
+ i += 1;
87
+ }
88
+ }
89
+
90
+ return d;
91
+ }
92
+
57
93
 
58
94
  // Define annotation prototype
59
95
  var Annotation = function () {
@@ -64,8 +100,10 @@ Annotation.prototype = {
64
100
  * Initialize the annotation
65
101
  */
66
102
  init: function (chart, options) {
103
+ var shapeType = options.shape && options.shape.type;
104
+
67
105
  this.chart = chart;
68
- this.options = merge({}, defaultOptions, options);
106
+ this.options = merge({}, defaultOptions(shapeType), options);
69
107
  },
70
108
 
71
109
  /*
@@ -86,16 +124,17 @@ Annotation.prototype = {
86
124
  group = annotation.group = renderer.g();
87
125
  }
88
126
 
89
- if (!title && titleOptions) {
90
- title = annotation.title = renderer.label(titleOptions);
91
- title.add(group);
92
- }
93
127
 
94
128
  if (!shape && shapeOptions && inArray(shapeOptions.type, ALLOWED_SHAPES) !== -1) {
95
129
  shape = annotation.shape = renderer[options.shape.type](shapeOptions.params);
96
130
  shape.add(group);
97
131
  }
98
132
 
133
+ if (!title && titleOptions) {
134
+ title = annotation.title = renderer.label(titleOptions);
135
+ title.add(group);
136
+ }
137
+
99
138
  group.add(chart.annotations.group);
100
139
 
101
140
  // link annotations to point or series
@@ -152,10 +191,9 @@ Annotation.prototype = {
152
191
 
153
192
 
154
193
  // Based on given options find annotation pixel position
155
- x = (defined(options.xValue) ? xAxis.toPixels(options.xValue + xAxis.minPointOffset) : options.x) - xAxis.minPixelPadding;
194
+ x = (defined(options.xValue) ? xAxis.toPixels(options.xValue + xAxis.minPointOffset) - xAxis.minPixelPadding : options.x);
156
195
  y = defined(options.yValue) ? yAxis.toPixels(options.yValue) : options.y;
157
196
 
158
-
159
197
  if (isNaN(x) || isNaN(y) || !isNumber(x) || !isNumber(y)) {
160
198
  return;
161
199
  }
@@ -187,6 +225,15 @@ Annotation.prototype = {
187
225
  shapeParams.x += xAxis.minPixelPadding;
188
226
  }
189
227
 
228
+ if (options.shape.type === 'path') {
229
+ translatePath(shapeParams.d, xAxis, yAxis, x, y);
230
+ }
231
+ }
232
+
233
+ // move the center of the circle to shape x/y
234
+ if (options.shape.type === 'circle') {
235
+ shapeParams.x += shapeParams.r;
236
+ shapeParams.y += shapeParams.r;
190
237
  }
191
238
 
192
239
  resetBBox = true;
@@ -2908,7 +2908,7 @@ if (CanvasRenderingContext2D) {
2908
2908
  });
2909
2909
  }
2910
2910
  }/**
2911
- * @license Highcharts JS v3.0.2 (2013-06-05)
2911
+ * @license Highcharts JS v3.0.3 (2013-07-31)
2912
2912
  * CanVGRenderer Extension module
2913
2913
  *
2914
2914
  * (c) 2011-2012 Torstein Hønsi, Erik Olsson
@@ -2,7 +2,7 @@
2
2
  * @license Data plugin for Highcharts
3
3
  *
4
4
  * (c) 2012-2013 Torstein Hønsi
5
- * Last revision 2012-11-27
5
+ * Last revision 2013-06-07
6
6
  *
7
7
  * License: www.highcharts.com/license
8
8
  */
@@ -87,8 +87,8 @@
87
87
 
88
88
 
89
89
  // The Data constructor
90
- var Data = function (options) {
91
- this.init(options);
90
+ var Data = function (dataOptions, chartOptions) {
91
+ this.init(dataOptions, chartOptions);
92
92
  };
93
93
 
94
94
  // Set the prototype properties
@@ -97,8 +97,9 @@
97
97
  /**
98
98
  * Initialize the Data object with the given options
99
99
  */
100
- init: function (options) {
100
+ init: function (options, chartOptions) {
101
101
  this.options = options;
102
+ this.chartOptions = chartOptions;
102
103
  this.columns = options.columns || this.rowsToColumns(options.rows) || [];
103
104
 
104
105
  // No need to parse or interpret anything
@@ -120,6 +121,30 @@
120
121
 
121
122
  },
122
123
 
124
+ /**
125
+ * Get the column distribution. For example, a line series takes a single column for
126
+ * Y values. A range series takes two columns for low and high values respectively,
127
+ * and an OHLC series takes four columns.
128
+ */
129
+ getColumnDistribution: function () {
130
+ var chartOptions = this.chartOptions,
131
+ getValueCount = function (type) {
132
+ return (Highcharts.seriesTypes[type || 'line'].prototype.pointArrayMap || [0]).length;
133
+ },
134
+ globalType = chartOptions && chartOptions.chart && chartOptions.chart.type,
135
+ individualCounts = [];
136
+
137
+ each((chartOptions && chartOptions.series) || [], function (series) {
138
+ individualCounts.push(getValueCount(series.type || globalType));
139
+ });
140
+
141
+ this.valueCount = {
142
+ global: getValueCount(globalType),
143
+ individual: individualCounts
144
+ };
145
+ },
146
+
147
+
123
148
  dataFound: function () {
124
149
  // Interpret the values into right types
125
150
  this.parseTypes();
@@ -436,19 +461,20 @@
436
461
  complete: function () {
437
462
 
438
463
  var columns = this.columns,
439
- hasXData,
440
- categories,
441
464
  firstCol,
442
465
  type,
443
466
  options = this.options,
467
+ valueCount,
444
468
  series,
445
469
  data,
446
- name,
447
470
  i,
448
- j;
471
+ j,
472
+ seriesIndex;
449
473
 
450
474
 
451
475
  if (options.complete) {
476
+
477
+ this.getColumnDistribution();
452
478
 
453
479
  // Use first column for X data or categories?
454
480
  if (columns.length > 1) {
@@ -457,42 +483,61 @@
457
483
  firstCol.shift(); // remove the first cell
458
484
  }
459
485
 
460
- // Use the first column for categories or X values
461
- hasXData = firstCol.isNumeric || firstCol.isDatetime;
462
- if (!hasXData) { // means type is neither datetime nor linear
463
- categories = firstCol;
464
- }
465
486
 
466
487
  if (firstCol.isDatetime) {
467
488
  type = 'datetime';
489
+ } else if (!firstCol.isNumeric) {
490
+ type = 'category';
468
491
  }
469
492
  }
470
-
471
- // Use the next columns for series
472
- series = [];
493
+
494
+ // Get the names and shift the top row
473
495
  for (i = 0; i < columns.length; i++) {
474
496
  if (this.headerRow === 0) {
475
- name = columns[i].shift();
497
+ columns[i].name = columns[i].shift();
476
498
  }
499
+ }
500
+
501
+ // Use the next columns for series
502
+ series = [];
503
+ for (i = 0, seriesIndex = 0; i < columns.length; seriesIndex++) {
504
+
505
+ // This series' value count
506
+ valueCount = Highcharts.pick(this.valueCount.individual[seriesIndex], this.valueCount.global);
507
+
508
+ // Iterate down the cells of each column and add data to the series
477
509
  data = [];
478
510
  for (j = 0; j < columns[i].length; j++) {
479
- data[j] = columns[i][j] !== undefined ?
480
- (hasXData ?
481
- [firstCol[j], columns[i][j]] :
482
- columns[i][j]
483
- ) :
484
- null;
511
+ data[j] = [
512
+ firstCol[j],
513
+ columns[i][j] !== undefined ? columns[i][j] : null
514
+ ];
515
+ if (valueCount > 1) {
516
+ data[j].push(columns[i + 1][j] !== undefined ? columns[i + 1][j] : null);
517
+ }
518
+ if (valueCount > 2) {
519
+ data[j].push(columns[i + 2][j] !== undefined ? columns[i + 2][j] : null);
520
+ }
521
+ if (valueCount > 3) {
522
+ data[j].push(columns[i + 3][j] !== undefined ? columns[i + 3][j] : null);
523
+ }
524
+ if (valueCount > 4) {
525
+ data[j].push(columns[i + 4][j] !== undefined ? columns[i + 4][j] : null);
526
+ }
485
527
  }
486
- series[i] = {
487
- name: name,
528
+
529
+ // Add the series
530
+ series[seriesIndex] = {
531
+ name: columns[i].name,
488
532
  data: data
489
533
  };
534
+
535
+ i += valueCount;
490
536
  }
491
537
 
492
538
  // Do the callback
493
539
  options.complete({
494
540
  xAxis: {
495
- categories: categories,
496
541
  type: type
497
542
  },
498
543
  series: series
@@ -503,8 +548,8 @@
503
548
 
504
549
  // Register the Data prototype and data function on Highcharts
505
550
  Highcharts.Data = Data;
506
- Highcharts.data = function (options) {
507
- return new Data(options);
551
+ Highcharts.data = function (options, chartOptions) {
552
+ return new Data(options, chartOptions);
508
553
  };
509
554
 
510
555
  // Extend Chart.init so that the Chart constructor accepts a new configuration
@@ -528,7 +573,7 @@
528
573
 
529
574
  proceed.call(chart, userOptions, callback);
530
575
  }
531
- }));
576
+ }), userOptions);
532
577
  } else {
533
578
  proceed.call(chart, userOptions, callback);
534
579
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Highcharts JS v3.0.2 (2013-06-05)
2
+ * @license Highcharts JS v3.0.3 (2013-07-31)
3
3
  * Exporting module
4
4
  *
5
5
  * (c) 2010-2013 Torstein Hønsi
@@ -269,7 +269,7 @@ extend(Chart.prototype, {
269
269
  userMin = extremes.userMin,
270
270
  userMax = extremes.userMax;
271
271
 
272
- if (userMin !== UNDEFINED || userMax !== UNDEFINED) {
272
+ if (axisCopy && (userMin !== UNDEFINED || userMax !== UNDEFINED)) {
273
273
  axisCopy.setExtremes(userMin, userMax, true, false);
274
274
  }
275
275
  });
@@ -319,9 +319,6 @@ extend(Chart.prototype, {
319
319
  // IE9 beta bugs with innerHTML. Test again with final IE9.
320
320
  svg = svg.replace(/(url\(#highcharts-[0-9]+)&quot;/g, '$1')
321
321
  .replace(/&quot;/g, "'");
322
- if (svg.match(/ xmlns="/g).length === 2) {
323
- svg = svg.replace(/xmlns="[^"]+"/, '');
324
- }
325
322
 
326
323
  return svg;
327
324
  },
@@ -342,8 +339,8 @@ extend(Chart.prototype, {
342
339
  chartOptions,
343
340
  {
344
341
  exporting: {
345
- sourceWidth: options.sourceWidth || chartExportingOptions.sourceWidth, // docs: option and parameter in exportChart()
346
- sourceHeight: options.sourceHeight || chartExportingOptions.sourceHeight // docs
342
+ sourceWidth: options.sourceWidth || chartExportingOptions.sourceWidth,
343
+ sourceHeight: options.sourceHeight || chartExportingOptions.sourceHeight
347
344
  }
348
345
  }
349
346
  ));
@@ -519,7 +516,7 @@ extend(Chart.prototype, {
519
516
  menuStyle.left = (x - menuPadding) + PX;
520
517
  }
521
518
  // if outside bottom, bottom align it
522
- if (y + height + chart.exportMenuHeight > chartHeight) {
519
+ if (y + height + chart.exportMenuHeight > chartHeight && button.alignOptions.verticalAlign !== 'top') {
523
520
  menuStyle.bottom = (chartHeight - y - menuPadding) + PX;
524
521
  } else {
525
522
  menuStyle.top = (y + height - menuPadding) + PX;
@@ -94,7 +94,7 @@ seriesTypes.funnel = Highcharts.extendClass(seriesTypes.pie, {
94
94
 
95
95
  // Return the width at a specific y coordinate
96
96
  series.getWidthAt = getWidthAt = function (y) {
97
- return y > height - neckHeight ?
97
+ return y > height - neckHeight || height === neckHeight ?
98
98
  neckWidth :
99
99
  neckWidth + (width - neckWidth) * ((height - neckHeight - y) / (height - neckHeight));
100
100
  };
@@ -137,7 +137,7 @@ seriesTypes.funnel = Highcharts.extendClass(seriesTypes.pie, {
137
137
  // set start and end positions
138
138
  y5 = null;
139
139
  fraction = sum ? point.y / sum : 0;
140
- y1 = cumulative * height;
140
+ y1 = centerY - height / 2 + cumulative * height;
141
141
  y3 = y1 + fraction * height;
142
142
  //tempWidth = neckWidth + (width - neckWidth) * ((height - neckHeight - y1) / (height - neckHeight));
143
143
  tempWidth = getWidthAt(y1);
@@ -0,0 +1,57 @@
1
+ (function (Highcharts) {
2
+ var seriesTypes = Highcharts.seriesTypes,
3
+ each = Highcharts.each;
4
+
5
+ seriesTypes.heatmap = Highcharts.extendClass(seriesTypes.map, {
6
+ colorKey: 'z',
7
+ pointArrayMap: ['y', 'z'],
8
+ translate: function () {
9
+ var series = this,
10
+ options = series.options,
11
+ dataMin = Number.MAX_VALUE,
12
+ dataMax = Number.MIN_VALUE,
13
+ opacity,
14
+ minOpacity = options.minOpacity,
15
+ path,
16
+ color;
17
+
18
+
19
+ series.generatePoints();
20
+
21
+ each(series.data, function (point) {
22
+ var x = point.x,
23
+ y = point.y,
24
+ value = point.z,
25
+ xPad = (series.options.colsize || 1) / 2,
26
+ yPad = (series.options.rowsize || 1) / 2;
27
+
28
+ point.path = [
29
+ 'M', x - xPad, y - yPad,
30
+ 'L', x + xPad, y - yPad,
31
+ 'L', x + xPad, y + yPad,
32
+ 'L', x - xPad, y + yPad,
33
+ 'Z'
34
+ ];
35
+
36
+ point.shapeType = 'path';
37
+ point.shapeArgs = {
38
+ d: series.translatePath(point.path)
39
+ };
40
+
41
+ if (typeof value === 'number') {
42
+ if (value > dataMax) {
43
+ dataMax = value;
44
+ } else if (value < dataMin) {
45
+ dataMin = value;
46
+ }
47
+ }
48
+ });
49
+
50
+ series.translateColors(dataMin, dataMax);
51
+ },
52
+
53
+ getBox: function () {}
54
+
55
+ });
56
+
57
+ }(Highcharts));