[vislib/handler/area] only warn if any chart has more than 1 series

This commit is contained in:
Spencer Alger 2015-02-06 10:45:20 -07:00
parent 44dd2fc1ca
commit cc0fdbfda0
2 changed files with 17 additions and 1 deletions

View file

@ -622,6 +622,18 @@ define(function (require) {
return extents;
};
/**
* Get the maximum number of series, considering each chart
* individually.
*
* @return {number} - the largest number of series from all charts
*/
Data.prototype.maxNumberOfSeries = function () {
return this.chartData().reduce(function (max, chart) {
return Math.max(max, chart.series.length);
}, 0);
};
return Data;
};
});

View file

@ -67,7 +67,11 @@ define(function (require) {
msg: 'Positive and negative values are not accurately represented by stacked ' +
'area charts. The line chart is better suited for this type of data.',
test: function (vis, data) {
return vis._attr.mode === 'stacked' && data.gitYMax(data._getY) > 0 && data.gitYMin(data._getY) < 0;
if (!data.shouldBeStacked() || data.maxNumberOfSeries() < 2) return;
var hasPos = data.getYMax(data._getY) > 0;
var hasNeg = data.getYMin(data._getY) < 0;
return (hasPos && hasNeg);
}
}
]