Skip to content

Commit

Permalink
fix: config plot axis
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 11, 2024
1 parent 72e0427 commit 049a434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/ConfigProvider/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ export function usePlotConfig<T extends CommonConfig>(
defaultConfig: Partial<T> | ((props: Partial<T>) => Partial<T>),
props: Partial<T>,
): Partial<T> {
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,
};

Expand Down
23 changes: 13 additions & 10 deletions src/utils/plot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUndefined } from 'lodash';
import { get } from 'lodash';

const ADC_ENCODE_FIELDS = new Map([
['x', 'xField'],
Expand Down Expand Up @@ -33,20 +33,23 @@ function visG2Encode2ADCEncode<T extends Record<string, any>>(config: T) {
* 将缩写的 axisTitle 转换为 G2 axis 配置
*/
function axisTitle2G2axis<T extends Record<string, any>>(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;
Expand Down

0 comments on commit 049a434

Please sign in to comment.