@@ -486,6 +486,27 @@ export default class BarController extends DatasetController {
486
486
return this . _getStacks ( undefined , index ) . length ;
487
487
}
488
488
489
+ _getAxisCount ( ) {
490
+ return this . _getAxis ( ) . length ;
491
+ }
492
+
493
+ getFirstScaleIdForIndexAxis ( ) {
494
+ const scales = this . chart . scales ;
495
+ const indexScaleId = this . chart . options . indexAxis ;
496
+ return Object . keys ( scales ) . filter ( key => scales [ key ] . axis === indexScaleId ) . shift ( ) ;
497
+ }
498
+
499
+ _getAxis ( ) {
500
+ const axis = { } ;
501
+ const firstScaleAxisId = this . getFirstScaleIdForIndexAxis ( ) ;
502
+ for ( const dataset of this . chart . data . datasets ) {
503
+ axis [ valueOrDefault (
504
+ this . chart . options . indexAxis === 'x' ? dataset . xAxisID : dataset . yAxisID , firstScaleAxisId
505
+ ) ] = true ;
506
+ }
507
+ return Object . keys ( axis ) ;
508
+ }
509
+
489
510
/**
490
511
* Returns the stack index for the given dataset based on groups and bar visibility.
491
512
* @param {number } [datasetIndex] - The dataset index
@@ -618,13 +639,15 @@ export default class BarController extends DatasetController {
618
639
const skipNull = options . skipNull ;
619
640
const maxBarThickness = valueOrDefault ( options . maxBarThickness , Infinity ) ;
620
641
let center , size ;
642
+ const axisCount = this . _getAxisCount ( ) ;
621
643
if ( ruler . grouped ) {
622
644
const stackCount = skipNull ? this . _getStackCount ( index ) : ruler . stackCount ;
623
645
const range = options . barThickness === 'flex'
624
- ? computeFlexCategoryTraits ( index , ruler , options , stackCount )
625
- : computeFitCategoryTraits ( index , ruler , options , stackCount ) ;
626
-
627
- const stackIndex = this . _getStackIndex ( this . index , this . _cachedMeta . stack , skipNull ? index : undefined ) ;
646
+ ? computeFlexCategoryTraits ( index , ruler , options , stackCount * axisCount )
647
+ : computeFitCategoryTraits ( index , ruler , options , stackCount * axisCount ) ;
648
+ const axisID = this . chart . options . indexAxis === 'x' ? this . getDataset ( ) . xAxisID : this . getDataset ( ) . yAxisID ;
649
+ const axisNumber = this . _getAxis ( ) . indexOf ( valueOrDefault ( axisID , this . getFirstScaleIdForIndexAxis ( ) ) ) ;
650
+ const stackIndex = this . _getStackIndex ( this . index , this . _cachedMeta . stack , skipNull ? index : undefined ) + axisNumber ;
628
651
center = range . start + ( range . chunk * stackIndex ) + ( range . chunk / 2 ) ;
629
652
size = Math . min ( maxBarThickness , range . chunk * range . ratio ) ;
630
653
} else {
@@ -633,6 +656,7 @@ export default class BarController extends DatasetController {
633
656
size = Math . min ( maxBarThickness , ruler . min * ruler . ratio ) ;
634
657
}
635
658
659
+
636
660
return {
637
661
base : center - size / 2 ,
638
662
head : center + size / 2 ,
0 commit comments