diff --git a/src/ConfigProvider/hooks/useConfig.ts b/src/ConfigProvider/hooks/useConfig.ts index 1134a9d..6f2ec95 100644 --- a/src/ConfigProvider/hooks/useConfig.ts +++ b/src/ConfigProvider/hooks/useConfig.ts @@ -36,16 +36,15 @@ export function usePlotConfig( defaultConfig: Partial | ((props: Partial) => Partial), props: Partial, ): Partial { - const transformedProps = transform2ADCProps(props); + const globalConfig = usePlotGlobalConfig(name); + const mergedProps = { ...globalConfig, ...props }; + const transformedProps = transform2ADCProps(mergedProps); const _defaultConfig = typeof defaultConfig === 'function' ? defaultConfig(transformedProps) : defaultConfig; - const globalConfig = usePlotGlobalConfig(name); - const config = { ..._defaultConfig, - ...globalConfig, ...transformedProps, }; diff --git a/src/utils/plot.ts b/src/utils/plot.ts index f7a65fb..e06f986 100644 --- a/src/utils/plot.ts +++ b/src/utils/plot.ts @@ -1,4 +1,4 @@ -import { isUndefined } from 'lodash'; +import { get } from 'lodash'; const ADC_ENCODE_FIELDS = new Map([ ['x', 'xField'], @@ -33,20 +33,23 @@ function visG2Encode2ADCEncode>(config: T) { * 将缩写的 axisTitle 转换为 G2 axis 配置 */ function axisTitle2G2axis>(config: T) { - const { axisXTitle, axisYTitle, axis } = config; - - if (!isUndefined(axis)) return config; - - const _config = { axis: {}, ...config }; + const { axisXTitle, axisYTitle } = config; + const _config: T = { axis: {}, ...config }; if (axisXTitle) { - // @ts-expect-error - _config.axis.x = { title: axisXTitle }; + if (get(_config, 'axis.x')) { + _config.axis.x.title = axisXTitle; + } else { + _config.axis.x = { title: axisXTitle }; + } } if (axisYTitle) { - // @ts-expect-error - _config.axis.y = { title: axisYTitle }; + if (get(_config, 'axis.y')) { + _config.axis.y.title = axisYTitle; + } else { + _config.axis.y = { title: axisYTitle }; + } } return _config;