Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix up "inconsistent" example; only check series lengths when stacking

  • Loading branch information...
commit 318f1372ed0ca3881d23882e78d784c72490bf21 1 parent 5dc77c4
@dchester dchester authored
Showing with 25 additions and 12 deletions.
  1. +5 −5 examples/inconsistent.html
  2. +20 −7 src/js/Rickshaw.Graph.js
View
10 examples/inconsistent.html
@@ -16,23 +16,23 @@
var graph = new Rickshaw.Graph( {
element: document.getElementById("chart"),
- renderer: 'area',
+ renderer: 'line',
interpolation: 'cardinal',
series: [
{
- data: [ { x: 0, y: 19 }, { x: 1, y: 30 }, { x: 2, y: 22 }, { x: 3, y: 29 }, { x: 4, y: 21 }, { x: 5, y: 29 } ],
+ data: [ { x: 0, y: 19 }, { x: 1, y: 30 }, { x: 2, y: 22 }, { x: 3, y: 29 }, { x: 4, y: 26 }, { x: 5, y: 35 } ],
name: 'new york',
color: palette.color()
}, {
- data: [ { x: 0, y: 19 }, { x: 1, y: 29 }, { x: 2, y: 22 }, { x: 3, y: 27 }, { x: 4, y: 21 }, { x: 5, y: 29 } ],
+ data: [ { x: 0, y: 49 }, { x: 1, y: 35 }, { x: 2, y: 32 }, { x: 3, y: 38 }, { x: 4, y: 37 } ],
name: 'boston',
color: palette.color()
}, {
- data: [ { x: 0, y: 19 }, { x: 1, y: 22 }, { x: 2, y: 10 }, { x: 4, y: 21 }, { x: 5, y: 29 } ],
+ data: [ { x: 0, y: 19 }, { x: 1, y: 22 }, { x: 2, y: 10 }, { x: 4, y: 21 }, { x: 5, y: 17 } ],
name: 'los angeles',
color: palette.color()
}, {
- data: [ { x: 0, y: 19 }, { x: 1, y: 10 }, { x: 2, y: 22 }, { x: 4, y: 21 }, { x: 5, y: 29 } ],
+ data: [ { x: 1, y: 9 }, { x: 2, y: 3 }, { x: 3, y: 8 }, { x: 4, y: 14 }, { x: 5, y: 13 } ],
name: 'san francisco',
color: palette.color()
}
View
27 src/js/Rickshaw.Graph.js
@@ -74,13 +74,6 @@ Rickshaw.Graph = function(args) {
throw "series data is not an array: " + JSON.stringify(s.data);
}
- pointsCount = pointsCount || s.data.length;
-
- if (pointsCount && s.data.length != pointsCount) {
- throw "series cannot have differing numbers of points: " +
- pointsCount + " vs " + s.data.length + "; see Rickshaw.Series.fill()";
- }
-
var x = s.data[0].x;
var y = s.data[0].y;
@@ -141,6 +134,9 @@ Rickshaw.Graph = function(args) {
var stackedData;
if (!this.renderer.unstack) {
+
+ this._validateStackable();
+
var layout = d3.layout.stack();
layout.offset( self.offset );
stackedData = layout(data);
@@ -162,6 +158,23 @@ Rickshaw.Graph = function(args) {
return stackedData;
};
+ this._validateStackable = function() {
+
+ var series = this.series;
+ var pointsCount;
+
+ series.forEach( function(s) {
+
+ pointsCount = pointsCount || s.data.length;
+
+ if (pointsCount && s.data.length != pointsCount) {
+ throw "stacked series cannot have differing numbers of points: " +
+ pointsCount + " vs " + s.data.length + "; see Rickshaw.Series.fill()";
+ }
+
+ }, this );
+ };
+
this.stackData.hooks = { data: [], after: [] };
this._slice = function(d) {
Please sign in to comment.
Something went wrong with that request. Please try again.