Fixed HorizontalBar: stacked axis, displays NaN when all legends

unselected (#3770)

added ability to take snapshot of chart limits in order to be used
when max and min value is not finite

added ignore files
This commit is contained in:
Jerry Chang 2017-01-13 08:39:03 -08:00 committed by Evert Timberg
parent ba6e041713
commit 074ab2aa87
2 changed files with 49 additions and 0 deletions

View File

@ -12,6 +12,7 @@ module.exports = function(Chart) {
};
var LinearScale = Chart.LinearScaleBase.extend({
determineDataLimits: function() {
var me = this;
var opts = me.options;
@ -19,6 +20,8 @@ module.exports = function(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;
@ -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();
},

View File

@ -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);
});
});