Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/scales/scale.linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ module.exports = function(Chart) {
};

var LinearScale = Chart.LinearScaleBase.extend({

determineDataLimits: function() {
var me = this;
var opts = me.options;
var chart = me.chart;
var data = chart.data;
var datasets = data.datasets;
var isHorizontal = me.isHorizontal();
var DEFAULT_MIN = 0;
var DEFAULT_MAX = 1;

function IDMatches(meta) {
return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
Expand Down Expand Up @@ -121,6 +124,9 @@ module.exports = function(Chart) {
});
}

me.min = isFinite(me.min) ? me.min : DEFAULT_MIN;
me.max = isFinite(me.max) ? me.max : DEFAULT_MAX;

// Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
this.handleTickRangeOptions();
},
Expand Down
43 changes: 43 additions & 0 deletions test/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,47 @@ describe('Linear Scale', function() {
var yScale = chart.scales.yScale0;
expect(yScale.width).toBeCloseToPixel(0);
});

it('max and min value should be valid and finite when charts datasets are hidden', function() {
var barData = {
labels: ['S1', 'S2', 'S3'],
datasets: [{
label: 'Closed',
backgroundColor: '#382765',
data: [2500, 2000, 1500]
}, {
label: 'In Progress',
backgroundColor: '#7BC225',
data: [1000, 2000, 1500]
}, {
label: 'Assigned',
backgroundColor: '#ffC225',
data: [1000, 2000, 1500]
}]
};

var chart = window.acquireChart({
type: 'horizontalBar',
data: barData,
options: {
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true
}]
}
}
});

barData.datasets.forEach(function(data, index) {
var meta = chart.getDatasetMeta(index);
meta.hidden = true;
chart.update();
});

expect(chart.scales['x-axis-0'].min).toEqual(0);
expect(chart.scales['x-axis-0'].max).toEqual(1);
});
});