@@ -44,7 +44,7 @@ import GlobalModel from '../../model/Global';
4444import ExtensionAPI from '../../core/ExtensionAPI' ;
4545import { Dictionary } from 'zrender/src/core/types' ;
4646import { CoordinateSystemMaster } from '../CoordinateSystem' ;
47- import { NullUndefined , ScaleDataValue } from '../../util/types' ;
47+ import { NullUndefined , ScaleDataValue , SeriesOption } from '../../util/types' ;
4848import SeriesData from '../../data/SeriesData' ;
4949import OrdinalScale from '../../scale/Ordinal' ;
5050import {
@@ -81,6 +81,8 @@ type AxesMap = {
8181
8282type ParsedOuterBoundsContain = 'all' | 'axisLabel' ;
8383
84+ type MarkerTypes = 'markPoint' | 'markLine' | 'markArea' ;
85+
8486// margin is [top, right, bottom, left]
8587const XY_TO_MARGIN_IDX = [
8688 [ 3 , 1 ] , // xyIdx 0 => 'x'
@@ -542,6 +544,16 @@ class Grid implements CoordinateSystemMaster {
542544
543545 unionExtent ( data , xAxis ) ;
544546 unionExtent ( data , yAxis ) ;
547+
548+ // 处理 markPoint、markLine、markArea
549+ const markerTypes : MarkerTypes [ ] = [ 'markPoint' , 'markLine' , 'markArea' ] ;
550+
551+ markerTypes . forEach ( markerType => {
552+ const markerOpt = seriesModel . get ( markerType as keyof SeriesOption ) ;
553+ if ( markerOpt && markerOpt . data ) {
554+ unionMarkerExtent ( markerOpt . data , xAxis , yAxis ) ;
555+ }
556+ } ) ;
545557 }
546558 } , this ) ;
547559
@@ -550,6 +562,48 @@ class Grid implements CoordinateSystemMaster {
550562 axis . scale . unionExtentFromData ( data , dim ) ;
551563 } ) ;
552564 }
565+
566+ function UnionExtentForAxisByValue (
567+ value : any ,
568+ axis : Axis2D ,
569+ axisType : string ,
570+ ) : void {
571+ if ( value != null && typeof value !== 'string' && axisType !== 'category' ) {
572+ const val = axis . scale . parse ( value ) ;
573+ if ( ! isNaN ( val ) ) {
574+ axis . scale . _innerUnionExtent ( [ val , val ] ) ;
575+ }
576+ }
577+ }
578+
579+ function unionMarkerExtent (
580+ markerData : any [ ] ,
581+ xAxis : Axis2D ,
582+ yAxis : Axis2D ,
583+ ) : void {
584+ each ( markerData , function ( item ) {
585+ if ( ! item ) {
586+ return ;
587+ }
588+ const items = isObject ( item ) && ! item . coord && ! item . xAxis && ! item . yAxis
589+ ? ( Array . isArray ( item ) ? item : [ item ] )
590+ : [ item ] ;
591+
592+ each ( items , function ( markerItem ) {
593+ if ( ! markerItem ) {
594+ return ;
595+ }
596+
597+ UnionExtentForAxisByValue ( markerItem . xAxis , xAxis , xAxis . type ) ;
598+ UnionExtentForAxisByValue ( markerItem . yAxis , yAxis , yAxis . type ) ;
599+
600+ if ( markerItem . coord && Array . isArray ( markerItem . coord ) ) {
601+ UnionExtentForAxisByValue ( markerItem . coord [ 0 ] , xAxis , xAxis . type ) ;
602+ UnionExtentForAxisByValue ( markerItem . coord [ 1 ] , yAxis , yAxis . type ) ;
603+ }
604+ } ) ;
605+ } ) ;
606+ }
553607 }
554608
555609 /**
0 commit comments