Skip to content

Commit af64bbc

Browse files
committed
allow datasets with null values
1 parent 5dc21db commit af64bbc

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lib/Axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ var Axes = React.createClass({
437437
this.xAxisMode = this.props.categoryAxisMode;
438438
this.yAxisMode = 'point';
439439
this.xAxisLabels = this.props.categoryLabels;
440-
this.yAxisLabels = this.props.valueLabels || fixedValues.reverse();
440+
this.yAxisLabels = this.props.valueLabels.reverse() || fixedValues.reverse();
441441
this.xAxisUnits = this._getCategoryUnits(props);
442442
this.yAxisUnits = this._getValueUnits(props).reverse();
443443
} else {

lib/LineChart.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ var LineChart = React.createClass({
284284
},
285285

286286
_renderLine: function(value, index, values, dataset) {
287+
if ( value == null ) {
288+
return null;
289+
}
287290
var fromValue = value;
288291
var toValue = values[index + 1];
289292
if (typeof toValue == 'undefined') {
@@ -309,6 +312,9 @@ var LineChart = React.createClass({
309312
},
310313

311314
_renderArea: function(value, index, values, dataset) {
315+
if ( value == null ) {
316+
return null;
317+
}
312318
var fromValue = value;
313319
var toValue = values[index + 1];
314320
if (typeof toValue == 'undefined') {
@@ -364,12 +370,14 @@ var LineChart = React.createClass({
364370

365371
componentWillMount: function() {
366372
var p = this.props;
367-
ensureScaleCoverRange(p.valueScale, p.datasets, false);
373+
// don't ensureScaleCoverRange if datasets has no values
374+
p.datasets.some(d => d.values.some(v => v != null)) && ensureScaleCoverRange(p.valueScale, p.datasets, false);
368375
},
369376

370377
componentWillReceiveProps: function(nextProps) {
371378
var p = nextProps;
372-
ensureScaleCoverRange(p.valueScale, p.datasets, false);
379+
// don't ensureScaleCoverRange if datasets has no values
380+
p.datasets.some(d => d.values.some(v => v != null)) && ensureScaleCoverRange(p.valueScale, p.datasets, false);
373381
},
374382

375383
render: function() {

lib/makeRange.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,25 @@ function makeRange(datasets : Array<Dataset>, totalize: boolean): Range {
3434
dataArray.forEach(function(data, index) {
3535
// min
3636
data.forEach(function(datum, index) {
37-
min = Math.min(min, datum.value);
37+
if ( datum.value != null ) {
38+
min = Math.min(min, datum.value);
39+
}
3840
});
3941
// max
4042
var total = 0;
4143
data.forEach(function(datum, index) {
42-
total += datum.value;
44+
if ( datum.value != null ) {
45+
total += datum.value;
46+
}
4347
});
4448
max = Math.max(max, total);
4549
});
4650
} else {
4751
datasets.forEach(function(dataset, index) {
48-
min = Math.min(min, ...dataset.values);
49-
max = Math.max(max, ...dataset.values);
52+
if ( dataset.values.some(v => v != null) ) {
53+
min = Math.min(min, ...dataset.values);
54+
max = Math.max(max, ...dataset.values);
55+
}
5056
});
5157
}
5258
return { min, max };

0 commit comments

Comments
 (0)