Update linear scale + tests

This commit is contained in:
Evert Timberg
2015-11-01 08:45:12 -05:00
parent b823bae63e
commit 8324b35506
2 changed files with 26 additions and 8 deletions

View File

@@ -42,11 +42,21 @@
this.min = null;
this.max = null;
var positiveValues = [];
var negativeValues = [];
if (this.options.stacked) {
var valuesPerType = {};
helpers.each(this.data.datasets, function(dataset) {
if (valuesPerType[dataset.type] === undefined) {
valuesPerType[dataset.type] = {
positiveValues: [],
negativeValues: [],
};
}
// Store these per type
var positiveValues = valuesPerType[dataset.type].positiveValues;
var negativeValues = valuesPerType[dataset.type].negativeValues;
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
@@ -71,9 +81,11 @@
}
}, this);
var values = positiveValues.concat(negativeValues);
this.min = helpers.min(values);
this.max = helpers.max(values);
helpers.each(valuesPerType, function(valuesForType) {
var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
this.min = Math.min(this.min, helpers.min(values));
this.max = Math.max(this.max, helpers.max(values));
}, this);
} else {
helpers.each(this.data.datasets, function(dataset) {

View File

@@ -188,13 +188,19 @@ describe('Linear Scale', function() {
var mockData = {
datasets: [{
yAxisID: scaleID,
data: [10, 5, 0, -5, 78, -100]
data: [10, 5, 0, -5, 78, -100],
type: 'bar'
}, {
yAxisID: 'second scale',
data: [-1000, 1000],
}, {
yAxisID: scaleID,
data: [150, 0, 0, -100, -10, 9]
data: [150, 0, 0, -100, -10, 9],
type: 'bar'
}, {
yAxisID: scaleID,
data: [10, 10, 10, 10, 10, 10],
type: 'line'
}]
};