mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Correctly handle stacked groups when not adjacent (#4937)
Only the dataset index was used for indexing the stack
This commit is contained in:
parent
683e86e549
commit
447ca40a7f
@ -201,10 +201,12 @@ module.exports = function(Chart) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the effective number of stacks based on groups and bar visibility.
|
* Returns the stacks based on groups and bar visibility.
|
||||||
|
* @param {Number} [last] - The dataset index
|
||||||
|
* @returns {Array} The stack list
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
getStackCount: function(last) {
|
_getStacks: function(last) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var chart = me.chart;
|
var chart = me.chart;
|
||||||
var scale = me.getIndexScale();
|
var scale = me.getIndexScale();
|
||||||
@ -223,15 +225,33 @@ module.exports = function(Chart) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stacks.length;
|
return stacks;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the effective number of stacks based on groups and bar visibility.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
getStackCount: function() {
|
||||||
|
return this._getStacks().length;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the stack index for the given dataset based on groups and bar visibility.
|
* Returns the stack index for the given dataset based on groups and bar visibility.
|
||||||
|
* @param {Number} [datasetIndex] - The dataset index
|
||||||
|
* @param {String} [name] - The stack name to find
|
||||||
|
* @returns {Number} The stack index
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
getStackIndex: function(datasetIndex) {
|
getStackIndex: function(datasetIndex, name) {
|
||||||
return this.getStackCount(datasetIndex) - 1;
|
var stacks = this._getStacks(datasetIndex);
|
||||||
|
var index = (name !== undefined)
|
||||||
|
? stacks.indexOf(name)
|
||||||
|
: -1; // indexOf returns -1 if element is not present
|
||||||
|
|
||||||
|
return (index === -1)
|
||||||
|
? stacks.length - 1
|
||||||
|
: index;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,7 +332,8 @@ module.exports = function(Chart) {
|
|||||||
calculateBarIndexPixels: function(datasetIndex, index, ruler) {
|
calculateBarIndexPixels: function(datasetIndex, index, ruler) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var options = ruler.scale.options;
|
var options = ruler.scale.options;
|
||||||
var stackIndex = me.getStackIndex(datasetIndex);
|
var meta = me.getMeta();
|
||||||
|
var stackIndex = me.getStackIndex(datasetIndex, meta.stack);
|
||||||
var pixels = ruler.pixels;
|
var pixels = ruler.pixels;
|
||||||
var base = pixels[index];
|
var base = pixels[index];
|
||||||
var length = pixels.length;
|
var length = pixels.length;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user