Skip to content

Commit

Permalink
refactor: adjust graph config priority
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Dec 12, 2024
1 parent 72e0427 commit acaa5f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,52 @@
"publish-package": "pnpm build && changeset publish"
},
"dependencies": {
"@ant-design/graphs": "^2.0.1",
"@ant-design/icons": "^5.4.0",
"@ant-design/plots": "^2.2.5",
"@antv/l7": "^2.22.0",
"@ant-design/graphs": "^2.0.2",
"@ant-design/icons": "^5.5.2",
"@ant-design/plots": "^2.3.2",
"@antv/l7": "^2.22.3",
"@antv/larkmap": "^1.5.1",
"@babel/runtime": "^7.18.0",
"@babel/runtime": "^7.26.0",
"lodash": "^4.17.21",
"react-markdown": "^9.0.1",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"styled-components": "^6.0.7"
"styled-components": "^6.1.13"
},
"devDependencies": {
"@ant-design/x": "^1.0.1",
"@ant-design/x": "^1.0.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@changesets/cli": "^2.27.10",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.13",
"@types/react": "^18.0.0",
"@types/react": "^18.3.16",
"@types/webpack-bundle-analyzer": "^4.7.0",
"antd": "^5.0.0",
"dumi": "^2.4.13",
"eslint": "^9.14.0",
"antd": "^5.22.4",
"dumi": "^2.4.16",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-hooks": "^5.1.0",
"father": "^4.5.1",
"gh-pages": "^6.2.0",
"globals": "^15.12.0",
"husky": "^9.1.6",
"globals": "^15.13.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"limit-size": "^0.1.4",
"lint-staged": "^15.2.10",
"lint-staged": "^15.2.11",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"react": "^18.0.0",
"react": "^18.3.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0",
"webpack-bundle-analyzer": "^4.10.2"
},
"peerDependencies": {
Expand Down
8 changes: 6 additions & 2 deletions src/ConfigProvider/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ function useGraphGlobalConfig(name: Charts) {
return mergeGraphOptions(graphConfig, componentConfig || {});
}

export function useGraphConfig<T extends GraphOptions>(name: Charts, ...configs: Partial<T>[]) {
export function useGraphConfig<T extends GraphOptions>(
name: Charts,
defaultConfig: Partial<T>,
props: Partial<T>,
) {
const globalConfig = useGraphGlobalConfig(name);

return mergeGraphOptions(globalConfig, ...configs);
return mergeGraphOptions(defaultConfig, globalConfig, props);
}
8 changes: 3 additions & 5 deletions src/FlowDiagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FlowGraph as ADCFlowGraph, RCNode } from '@ant-design/graphs';
import React, { useMemo } from 'react';
import { useGraphConfig } from '../ConfigProvider/hooks';
import type { GraphProps } from '../types';
import { mergeGraphOptions } from '../utils/config';
import { visGraphData2GraphData } from '../utils/graph';
import { getGraphOptionsByData } from './helper';

Expand All @@ -12,7 +13,7 @@ export interface FlowDiagramProps extends GraphProps {}

const defaultConfig: FlowGraphOptions = {
autoResize: true,
autoFit: 'center',
autoFit: 'view',
node: {
style: {
component: (d: G6.NodeData) => {
Expand All @@ -32,7 +33,6 @@ const defaultConfig: FlowGraphOptions = {
},
size: [140, 32],
},
animation: { enter: false },
},
edge: {
style: {
Expand All @@ -49,7 +49,6 @@ const defaultConfig: FlowGraphOptions = {
stroke: '#001f98',
},
},
animation: { enter: false },
},
behaviors: (prev) => [
...prev,
Expand All @@ -72,8 +71,7 @@ const FlowDiagram: React.FC<FlowDiagramProps> = (props) => {

const config = useGraphConfig<FlowGraphOptions>(
'FlowDiagram',
defaultConfig,
getGraphOptionsByData(data),
mergeGraphOptions(defaultConfig, getGraphOptionsByData(data)),
restProps,
);

Expand Down

0 comments on commit acaa5f5

Please sign in to comment.