Skip to content

Commit

Permalink
feat: graph supports global configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Nov 19, 2024
1 parent 04175c3 commit 7a1c600
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ConfigProvider/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export function useMapConfig<T extends MapProps>(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<T extends GraphOptions>(name: Charts, defaultConfig: T, props: T) {
Expand Down
15 changes: 10 additions & 5 deletions src/ConfigProvider/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ demo: { cols: 2 }

## API

| 属性 | 类型 | 是否必传 | 默认值 | 说明 |
| ---------- | ------------------------ | -------- | ------ | -------- |
| plot | `PlotGlobalConfig` || - | 图表配置 |
| map | `MapGlobalConfig` || - | 地图配置 |
| components | `ComponentsGlobalConfig` || - | 组件配置 |
| 属性 | 类型 | 是否必传 | 默认值 | 说明 |
| ---------- | ------------------------ | -------- | ------ | ---------- |
| plot | `PlotGlobalConfig` || - | 图表配置 |
| graph | `GraphGlobalConfig` || - | 关系图配置 |
| map | `MapGlobalConfig` || - | 地图配置 |
| components | `ComponentsGlobalConfig` || - | 组件配置 |

### PlotGlobalConfig

| 属性 | 类型 | 是否必传 | 默认值 | 说明 |
| ----- | --------- | -------- | ------ | ---------------------------------------------------------------------------------------------------- |
| 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

| 属性 | 类型 | 是否必传 | 默认值 | 说明 |
Expand Down
6 changes: 6 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -6,6 +7,10 @@ type PlotGlobalConfig = {
[key: string]: any;
};

type GraphGlobalConfig = ADCGraphOptions & {
[key: string]: any;
};

type MapGlobalConfig = {
style?: 'normal' | 'light' | 'dark' | string;
token?: string;
Expand All @@ -18,6 +23,7 @@ type ComponentsGlobalConfig = Partial<Record<Charts, Record<string, any>>>;

export type GlobalConfig = {
plot?: PlotGlobalConfig;
graph?: GraphGlobalConfig;
map?: MapGlobalConfig;
components?: ComponentsGlobalConfig;
};

0 comments on commit 7a1c600

Please sign in to comment.