mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
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:
parent
ba6e041713
commit
074ab2aa87
@ -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();
|
||||
},
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user