Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle stacked groups when not adjacent #4937

Merged
merged 2 commits into from Nov 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/controllers/controller.bar.js
Expand Up @@ -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
*/
getStackCount: function(last) {
_getStacks: function(last) {
var me = this;
var chart = me.chart;
var scale = me.getIndexScale();
Expand All @@ -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.
* @param {Number} [datasetIndex] - The dataset index
* @param {String} [name] - The stack name to find
* @returns {Number} The stack index
* @private
*/
getStackIndex: function(datasetIndex) {
return this.getStackCount(datasetIndex) - 1;
getStackIndex: function(datasetIndex, name) {
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;
},

/**
Expand Down Expand Up @@ -312,7 +332,8 @@ module.exports = function(Chart) {
calculateBarIndexPixels: function(datasetIndex, index, ruler) {
var me = this;
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 base = pixels[index];
var length = pixels.length;
Expand Down