@@ -201,10 +201,12 @@ module.exports = function(Chart) {
201201 } ,
202202
203203 /**
204- * Returns the effective number of stacks based on groups and bar visibility.
204+ * Returns the stacks based on groups and bar visibility.
205+ * @param {Number } [last] - The dataset index
206+ * @returns {Array } The stack list
205207 * @private
206208 */
207- getStackCount : function ( last ) {
209+ _getStacks : function ( last ) {
208210 var me = this ;
209211 var chart = me . chart ;
210212 var scale = me . getIndexScale ( ) ;
@@ -223,15 +225,33 @@ module.exports = function(Chart) {
223225 }
224226 }
225227
226- return stacks . length ;
228+ return stacks ;
229+ } ,
230+
231+ /**
232+ * Returns the effective number of stacks based on groups and bar visibility.
233+ * @private
234+ */
235+ getStackCount : function ( ) {
236+ return this . _getStacks ( ) . length ;
227237 } ,
228238
229239 /**
230240 * Returns the stack index for the given dataset based on groups and bar visibility.
241+ * @param {Number } [datasetIndex] - The dataset index
242+ * @param {String } [name] - The stack name to find
243+ * @returns {Number } The stack index
231244 * @private
232245 */
233- getStackIndex : function ( datasetIndex ) {
234- return this . getStackCount ( datasetIndex ) - 1 ;
246+ getStackIndex : function ( datasetIndex , name ) {
247+ var stacks = this . _getStacks ( datasetIndex ) ;
248+ var index = ( name !== undefined )
249+ ? stacks . indexOf ( name )
250+ : - 1 ; // indexOf returns -1 if element is not present
251+
252+ return ( index === - 1 )
253+ ? stacks . length - 1
254+ : index ;
235255 } ,
236256
237257 /**
@@ -312,7 +332,8 @@ module.exports = function(Chart) {
312332 calculateBarIndexPixels : function ( datasetIndex , index , ruler ) {
313333 var me = this ;
314334 var options = ruler . scale . options ;
315- var stackIndex = me . getStackIndex ( datasetIndex ) ;
335+ var meta = me . getMeta ( ) ;
336+ var stackIndex = me . getStackIndex ( datasetIndex , meta . stack ) ;
316337 var pixels = ruler . pixels ;
317338 var base = pixels [ index ] ;
318339 var length = pixels . length ;
0 commit comments