@@ -518,18 +518,14 @@ class Bar {
518518 let barXPosition
519519
520520 if ( w . globals . isXNumeric ) {
521- let sxI = realIndex
522- if ( ! w . globals . seriesX [ realIndex ] . length ) {
523- sxI = w . globals . maxValsInArrayIndex
524- }
525- if ( w . globals . seriesX [ sxI ] [ j ] ) {
526- x =
527- ( w . globals . seriesX [ sxI ] [ j ] - w . globals . minX ) / this . xRatio -
528- ( barWidth * this . seriesLen ) / 2
529- }
530-
531- // re-calc barXPosition as x changed
532- barXPosition = x + barWidth * this . visibleI
521+ const xForNumericX = this . getBarXForNumericXAxis ( {
522+ x,
523+ j,
524+ realIndex,
525+ barWidth,
526+ } )
527+ x = xForNumericX . x
528+ barXPosition = xForNumericX . barXPosition
533529 } else {
534530 if ( w . config . plotOptions . bar . hideZeroBarsWhenGrouped ) {
535531 const { nonZeroColumns, zeroEncounters } =
@@ -584,6 +580,24 @@ class Bar {
584580 }
585581 }
586582
583+ getBarXForNumericXAxis ( { x, barWidth, realIndex, j } ) {
584+ const w = this . w
585+ let sxI = realIndex
586+ if ( ! w . globals . seriesX [ realIndex ] . length ) {
587+ sxI = w . globals . maxValsInArrayIndex
588+ }
589+ if ( w . globals . seriesX [ sxI ] [ j ] ) {
590+ x =
591+ ( w . globals . seriesX [ sxI ] [ j ] - w . globals . minX ) / this . xRatio -
592+ ( barWidth * this . seriesLen ) / 2
593+ }
594+
595+ return {
596+ barXPosition : x + barWidth * this . visibleI ,
597+ x,
598+ }
599+ }
600+
587601 /** getPreviousPath is a common function for bars/columns which is used to get previous paths when data changes.
588602 * @memberof Bar
589603 * @param {int } realIndex - current iterating i
0 commit comments