From 7a1c600ec559bb86315270728969052b43b0826b Mon Sep 17 00:00:00 2001 From: yvonneyx Date: Tue, 19 Nov 2024 15:49:21 +0800 Subject: [PATCH] feat: graph supports global configuration --- src/ConfigProvider/hooks/useConfig.ts | 4 ++-- src/ConfigProvider/index.md | 15 ++++++++++----- src/types/config.ts | 6 ++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ConfigProvider/hooks/useConfig.ts b/src/ConfigProvider/hooks/useConfig.ts index 102975e..b5ae884 100644 --- a/src/ConfigProvider/hooks/useConfig.ts +++ b/src/ConfigProvider/hooks/useConfig.ts @@ -80,10 +80,10 @@ export function useMapConfig(name: Charts, props: T) { } function useGraphGlobalConfig(name: Charts) { - // TODO: global config + const { graph: graphConfig = {} } = useConfig(); const componentConfig = useComponentGlobalConfig(name); - return componentConfig || {}; + return mergeGraphOptions(graphConfig, componentConfig || {}); } export function useGraphConfig(name: Charts, defaultConfig: T, props: T) { diff --git a/src/ConfigProvider/index.md b/src/ConfigProvider/index.md index aa43d0d..7a4e59c 100644 --- a/src/ConfigProvider/index.md +++ b/src/ConfigProvider/index.md @@ -18,11 +18,12 @@ demo: { cols: 2 } ## API -| 属性 | 类型 | 是否必传 | 默认值 | 说明 | -| ---------- | ------------------------ | -------- | ------ | -------- | -| plot | `PlotGlobalConfig` | 否 | - | 图表配置 | -| map | `MapGlobalConfig` | 否 | - | 地图配置 | -| components | `ComponentsGlobalConfig` | 否 | - | 组件配置 | +| 属性 | 类型 | 是否必传 | 默认值 | 说明 | +| ---------- | ------------------------ | -------- | ------ | ---------- | +| plot | `PlotGlobalConfig` | 否 | - | 图表配置 | +| graph | `GraphGlobalConfig` | 否 | - | 关系图配置 | +| map | `MapGlobalConfig` | 否 | - | 地图配置 | +| components | `ComponentsGlobalConfig` | 否 | - | 组件配置 | ### PlotGlobalConfig @@ -30,6 +31,10 @@ demo: { cols: 2 } | ----- | --------- | -------- | ------ | ---------------------------------------------------------------------------------------------------- | | theme | `G2Theme` | 否 | - | 统计图表主题,详见 [plots theme](https://ant-design-charts.antgroup.com/options/plots/theme/academy) | +### GraphGlobalConfig + +参考 [Ant Design Charts 的关系图配置项](https://ant-design-charts.antgroup.com/options/graphs/overview)。 + ### MapGlobalConfig | 属性 | 类型 | 是否必传 | 默认值 | 说明 | diff --git a/src/types/config.ts b/src/types/config.ts index 3c6091a..239fd60 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -1,3 +1,4 @@ +import type { GraphOptions as ADCGraphOptions } from '@ant-design/graphs'; import type { G2 } from '@ant-design/plots'; import type { Charts } from './chart'; @@ -6,6 +7,10 @@ type PlotGlobalConfig = { [key: string]: any; }; +type GraphGlobalConfig = ADCGraphOptions & { + [key: string]: any; +}; + type MapGlobalConfig = { style?: 'normal' | 'light' | 'dark' | string; token?: string; @@ -18,6 +23,7 @@ type ComponentsGlobalConfig = Partial>>; export type GlobalConfig = { plot?: PlotGlobalConfig; + graph?: GraphGlobalConfig; map?: MapGlobalConfig; components?: ComponentsGlobalConfig; };