@@ -29,6 +29,9 @@ import {
2929import GlobalModel from '../../model/Global' ;
3030import Cartesian2D from '../../coord/cartesian/Cartesian2D' ;
3131import SeriesData from '../../data/SeriesData' ;
32+ import { dimPermutations } from '../../component/marker/MarkAreaView' ;
33+ import { each } from 'zrender/src/core/util' ;
34+ import type Axis2D from '../../coord/cartesian/Axis2D' ;
3235
3336
3437export interface BaseBarSeriesOption < StateOption , ExtraStateOption = DefaultStatesMixin >
@@ -82,16 +85,34 @@ class BaseBarSeriesModel<Opts extends BaseBarSeriesOption<unknown> = BaseBarSeri
8285 return createSeriesData ( null , this , { useEncodeDefaulter : true } ) ;
8386 }
8487
85- getMarkerPosition ( value : ScaleDataValue [ ] ) {
88+ getMarkerPosition ( value : ScaleDataValue [ ] , dims ?: typeof dimPermutations [ number ] , startingAtTick : boolean = false ) {
8689 const coordSys = this . coordinateSystem ;
8790 if ( coordSys && coordSys . clampData ) {
8891 // PENDING if clamp ?
8992 const pt = coordSys . dataToPoint ( coordSys . clampData ( value ) ) ;
90- const data = this . getData ( ) ;
91- const offset = data . getLayout ( 'offset' ) ;
92- const size = data . getLayout ( 'size' ) ;
93- const offsetIndex = ( coordSys as Cartesian2D ) . getBaseAxis ( ) . isHorizontal ( ) ? 0 : 1 ;
94- pt [ offsetIndex ] += offset + size / 2 ;
93+ if ( startingAtTick ) {
94+ each ( coordSys . getAxes ( ) , function ( axis : Axis2D , idx : number ) {
95+ //If axis type is category, use tick coords instead
96+ if ( axis . type === 'category' ) {
97+ const tickCoords = axis . getTicksCoords ( ) ;
98+ let tickIdx = coordSys . clampData ( value ) [ idx ] ;
99+ //The index of rightmost tick of markArea is 1 larger than x1/y1 index
100+ if ( dims && ( dims [ idx ] === 'x1' || dims [ idx ] === 'y1' ) ) {
101+ tickIdx += 1 ;
102+ }
103+ ( tickIdx > tickCoords . length - 1 ) && ( tickIdx = tickCoords . length - 1 ) ;
104+ ( tickIdx < 0 ) && ( tickIdx = 0 ) ;
105+ tickCoords [ tickIdx ] && ( pt [ idx ] = axis . toGlobalCoord ( tickCoords [ tickIdx ] . coord ) ) ;
106+ }
107+ } ) ;
108+ }
109+ else {
110+ const data = this . getData ( ) ;
111+ const offset = data . getLayout ( 'offset' ) ;
112+ const size = data . getLayout ( 'size' ) ;
113+ const offsetIndex = ( coordSys as Cartesian2D ) . getBaseAxis ( ) . isHorizontal ( ) ? 0 : 1 ;
114+ pt [ offsetIndex ] += offset + size / 2 ;
115+ }
95116 return pt ;
96117 }
97118 return [ NaN , NaN ] ;
0 commit comments