@@ -25,6 +25,8 @@ import SeriesModel from '../../model/Series';
2525import { CoordinateSystemHostModel } from '../../coord/CoordinateSystem' ;
2626import { AxisBaseModel } from '../../coord/AxisBaseModel' ;
2727import type AxisProxy from './AxisProxy' ;
28+ import { getCachePerECPrepare , GlobalModelCachePerECPrepare , makeInner } from '../../util/model' ;
29+ import type ComponentModel from '../../model/Component' ;
2830
2931
3032export interface DataZoomPayloadBatchItem {
@@ -37,17 +39,13 @@ export interface DataZoomPayloadBatchItem {
3739
3840export interface DataZoomReferCoordSysInfo {
3941 model : CoordinateSystemHostModel ;
40- // Notice: if two dataZooms refer the same coordinamte system model,
41- // (1) The axis they refered may different
42+ // Notice: if two dataZooms refer the same coordinate system model,
43+ // (1) The axis they referred may different
4244 // (2) The sequence the axisModels matters, may different in
4345 // different dataZooms.
4446 axisModels : AxisBaseModel [ ] ;
4547}
4648
47- export type DataZoomExtendedAxisBaseModel = AxisBaseModel & {
48- __dzAxisProxy : AxisProxy
49- } ;
50-
5149export const DATA_ZOOM_AXIS_DIMENSIONS = [
5250 'x' , 'y' , 'radius' , 'angle' , 'single'
5351] as const ;
@@ -61,6 +59,12 @@ type DataZoomAxisIdPropName =
6159 'xAxisId' | 'yAxisId' | 'radiusAxisId' | 'angleAxisId' | 'singleAxisId' ;
6260export type DataZoomCoordSysMainType = 'polar' | 'grid' | 'singleAxis' ;
6361
62+ const ecModelCacheInner = makeInner < {
63+ axisProxyMap : AxisProxyMap ;
64+ } , GlobalModelCachePerECPrepare > ( ) ;
65+
66+ type AxisProxyMap = HashMap < AxisProxy , ComponentModel [ 'uid' ] > ;
67+
6468// Supported coords.
6569// FIXME: polar has been broken (but rarely used).
6670const SERIES_COORDS = [ 'cartesian2d' , 'polar' , 'singleAxis' ] as const ;
@@ -211,8 +215,28 @@ export function collectReferCoordSysModelInfo(dataZoomModel: DataZoomModel): {
211215 return coordSysInfoWrap ;
212216}
213217
214- export function getAxisProxyFromModel ( axisModel : AxisBaseModel ) : AxisProxy | NullUndefined {
215- return axisModel && ( axisModel as DataZoomExtendedAxisBaseModel ) . __dzAxisProxy ;
218+ function ensureAxisProxyMap ( ecModel : GlobalModel ) : AxisProxyMap {
219+ // Consider some axes may be deleted, and dataZoom options may be changed at and only at each run of
220+ // "ec prepare", we save axis proxies to a cache that is auto-cleared for each run of "ec prepare".
221+ const store = ecModelCacheInner ( getCachePerECPrepare ( ecModel ) ) ;
222+ return store . axisProxyMap || ( store . axisProxyMap = createHashMap ( ) ) ;
223+ }
224+
225+ export function getAxisProxyFromModel ( axisModel : AxisBaseModel | NullUndefined ) : AxisProxy | NullUndefined {
226+ if ( ! axisModel ) {
227+ return ;
228+ }
229+ if ( __DEV__ ) {
230+ assert ( axisModel . ecModel ) ;
231+ }
232+ return ensureAxisProxyMap ( axisModel . ecModel ) . get ( axisModel . uid ) ;
233+ }
234+
235+ export function setAxisProxyToModel ( axisModel : AxisBaseModel , axisProxy : AxisProxy ) : void {
236+ if ( __DEV__ ) {
237+ assert ( axisModel . ecModel ) ;
238+ }
239+ ensureAxisProxyMap ( axisModel . ecModel ) . set ( axisModel . uid , axisProxy ) ;
216240}
217241
218242/**
@@ -221,7 +245,7 @@ export function getAxisProxyFromModel(axisModel: AxisBaseModel): AxisProxy | Nul
221245 * then do not input it into `AxisProxy#reset`.
222246 */
223247export function getAlignTo ( dataZoomModel : DataZoomModel , axisProxy : AxisProxy ) : AxisProxy | NullUndefined {
224- const alignToAxis = axisProxy . getAxisModel ( ) . axis . alignTo ;
248+ const alignToAxis = axisProxy . getAxisModel ( ) . axis . __alignTo ;
225249 return (
226250 alignToAxis && dataZoomModel . getAxisProxy (
227251 alignToAxis . dim as DataZoomAxisDimension ,
0 commit comments