Skip to content

Commit

Permalink
refactor: adjust default values for graph options
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Dec 10, 2024
1 parent d8abaac commit 8b8208d
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { GraphOptions } from '../../types';
const { TextNode } = RCNode;

export const DEFAULT_OPTIONS: GraphOptions = {
padding: [20, 0, 0, 50],
node: {
type: 'react',
style: {
Expand Down Expand Up @@ -34,8 +33,9 @@ export const DEFAULT_OPTIONS: GraphOptions = {
},
},
layout: {
type: 'antv-dagre',
type: 'dagre',
rankdir: 'LR',
animation: false,
},
transforms: ['translate-react-node-origin'],
};
1 change: 0 additions & 1 deletion packages/graphs/src/components/flow-graph/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { FlowGraphOptions } from './types';
const { TextNode } = RCNode;

export const DEFAULT_OPTIONS: FlowGraphOptions = {
padding: [20, 0, 0, 50],
node: {
type: 'react',
style: {
Expand Down
25 changes: 10 additions & 15 deletions packages/graphs/src/components/indented-tree/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export const getIndentedTreeOptions = ({
};
return <TextNode {...props} />;
},
size: (data: NodeData) =>
getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
size: (data: NodeData) => getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
},
},
edge: {
Expand All @@ -129,8 +128,7 @@ export const getIndentedTreeOptions = ({
type: 'indented',
indent: (node) => getIndent(node, 20),
getWidth: (data) => getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[0],
getHeight: (data) =>
getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getHeight: (data) => getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getVGap: () => 14,
},
};
Expand All @@ -152,21 +150,20 @@ export const getIndentedTreeOptions = ({
depth === 0
? { type: 'filled', color: '#f1f4f5', style: { color: '#252525' } }
: {
type: 'underlined',
style: { textAlign: getNodeTextAlign(this as unknown as Graph, data) },
},
type: 'underlined',
style: { textAlign: getNodeTextAlign(this as unknown as Graph, data) },
},
);
return <TextNode {...props} />;
},
size: (data: NodeData) =>
getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
size: (data: NodeData) => getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
ports: function (data: NodeData) {
const side = getNodeSide(this as unknown as Graph, data);
return side === 'left'
? [{ placement: 'bottom' }, { placement: 'bottom-right' }]
: side === 'center'
? [{ placement: 'bottom' }]
: [{ placement: 'bottom' }, { placement: 'bottom-left' }];
? [{ placement: 'bottom' }]
: [{ placement: 'bottom' }, { placement: 'bottom-left' }];
},
},
},
Expand All @@ -181,10 +178,8 @@ export const getIndentedTreeOptions = ({
layout: {
type: 'indented',
indent: (node) => getIndent(node, 20),
getWidth: (data) =>
getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[0],
getHeight: (data) =>
getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getWidth: (data) => getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[0],
getHeight: (data) => getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getVGap: () => 12,
},
transforms: (prev) => [
Expand Down
29 changes: 15 additions & 14 deletions packages/graphs/src/components/mind-map/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ export function getMindMapOptions({
depth === 0
? { type: 'filled', color: '#f1f4f5', style: { color: '#252525' } }
: depth === 1
? { type: 'filled' }
: { type: 'outlined' },
? { type: 'filled' }
: { type: 'outlined' },
);
return <TextNode {...props} />;
},
size: (data: NodeData) =>
getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
size: (data: NodeData) => getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
dx: function (data: NodeData) {
const side = getNodeSide(this as unknown as Graph, data);
const size = getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size;
Expand All @@ -134,8 +133,7 @@ export function getMindMapOptions({
],
layout: {
type: 'mindmap',
getHeight: (data) =>
getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getHeight: (data) => getBoxedTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getVGap: () => 14,
},
};
Expand All @@ -157,19 +155,22 @@ export function getMindMapOptions({
depth === 0
? { type: 'filled', color: '#f1f4f5', style: { color: '#252525' } }
: {
type: 'underlined',
style: side === 'left' ? { textAlign: 'right' } : side === 'center' ? { textAlign: 'center' } : {},
},
type: 'underlined',
style: side === 'left' ? { textAlign: 'right' } : side === 'center' ? { textAlign: 'center' } : {},
},
);
return <TextNode {...props} />;
},
size: (data: NodeData) =>
getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
size: (data: NodeData) => getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size,
dx: function (data: NodeData) {
const side = getNodeSide(this as unknown as Graph, data);
const size = getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size;
return side === 'left' ? -size[0] : side === 'center' ? -size[0] / 2 : 0;
},
dy: function (data: NodeData) {
const size = getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size;
return size[1] / 2;
},
ports: function (data: NodeData) {
const side = getNodeSide(this as unknown as Graph, data);
return side === 'center'
Expand All @@ -187,8 +188,7 @@ export function getMindMapOptions({
},
layout: {
type: 'mindmap',
getHeight: (data) =>
getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getHeight: (data) => getLinearTextNodeStyle(idOf(data), minWidth, maxWidth, data.depth as number).size[1],
getVGap: () => 12,
},
transforms: (prev) => [
Expand All @@ -211,7 +211,8 @@ export function getMindMapOptions({

if (direction) {
options.layout ||= {} as SingleLayoutOptions;
(options.layout as SingleLayoutOptions).direction = direction === 'alternate' ? 'H' : direction === 'left' ? 'RL' : 'LR';
(options.layout as SingleLayoutOptions).direction =
direction === 'alternate' ? 'H' : direction === 'left' ? 'RL' : 'LR';
}

return options;
Expand Down
7 changes: 2 additions & 5 deletions packages/graphs/src/components/organization-chart/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { OrganizationChartOptions } from './types';
const { TextNode } = RCNode;

export const DEFAULT_OPTIONS: OrganizationChartOptions = {
padding: [20, 0, 0, 50],
node: {
type: 'react',
style: {
Expand All @@ -27,14 +26,12 @@ export const DEFAULT_OPTIONS: OrganizationChartOptions = {
type: 'polyline',
style: {
lineWidth: 2,
router: {
type: 'orth',
},
router: { type: 'orth' },
},
animation: false,
},
layout: {
type: 'antv-dagre',
type: 'dagre',
},
transforms: ['translate-react-node-origin'],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/graphs/tests/demos/flow-graph-task-scheduling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const TaskNode: React.FC<{

export const FlowGraphTaskScheduling = () => {
const options: FlowGraphOptions = {
autoFit: 'center',
autoFit: 'view',
data,
node: {
style: {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphs/tests/demos/flow-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { TextNode } = RCNode;

export const FlowGraph = () => {
const options: FlowGraphOptions = {
autoFit: 'center',
autoFit: 'view',
data,
node: {
style: {
Expand Down
3 changes: 2 additions & 1 deletion packages/graphs/tests/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Dendrogram } from './dendrogram';
export { FishboneDefault } from './fishbone-default';
export { FlowGraph } from './flow-graph';
export { FlowGraphProductLaunch } from './flow-graph-product-launch';
export { FlowGraphTaskScheduling } from './flow-graph-task-scheduling';
Expand All @@ -12,5 +13,5 @@ export { MindMapLinear } from './mind-map-linear';
export { NetworkGraph } from './network-graph';
export { OrganizationChart } from './organization-chart';
export { OrganizationChart2 } from './organization-chart2';
export { UserFlowDirectionDefault } from './user-flow-direction-default';
export { UserFlowDirectionGraph } from './user-flow-direction-graph';
export { FishboneDefault } from './fishbone-default';
10 changes: 1 addition & 9 deletions packages/graphs/tests/demos/organization-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { OrganizationChart as OrganizationChartComponent, type OrganizationChartOptions } from '@ant-design/graphs';
import { Graph } from '@antv/g6';
import React, { useEffect, useState } from 'react';

export const OrganizationChart = () => {
const [graph, setGraph] = useState<Graph | null>(null);
const [data, setData] = useState(undefined);

useEffect(() => {
Expand All @@ -17,11 +15,5 @@ export const OrganizationChart = () => {
data,
};

useEffect(() => {
if (graph) {
console.log(graph);
}
}, [graph]);

return <OrganizationChartComponent ref={setGraph} {...options} />;
return <OrganizationChartComponent {...options} />;
};
1 change: 0 additions & 1 deletion packages/graphs/tests/demos/organization-chart2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const OrganizationChart2 = () => {

const options: OrganizationChartOptions = {
data,
padding: [40, 0, 0, 120],
autoFit: 'view',
node: {
style: {
Expand Down
13 changes: 13 additions & 0 deletions packages/graphs/tests/demos/user-flow-direction-default.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { GraphOptions } from '@ant-design/graphs';
import { FlowDirectionGraph } from '@ant-design/graphs';
import React from 'react';
import data from '../datasets/user-flow.json';

export const UserFlowDirectionDefault = () => {
const options: GraphOptions = {
autoFit: 'view',
data,
};

return <FlowDirectionGraph {...options} />;
};
1 change: 0 additions & 1 deletion packages/graphs/tests/demos/user-flow-direction-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const transformData = (data) => {
export const UserFlowDirectionGraph = () => {
const options: GraphOptions = {
autoFit: 'view',
padding: 20,
data: transformData(data),
node: {
style: {
Expand Down
1 change: 1 addition & 0 deletions packages/graphs/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
body {
margin: 0;
padding: 0;
background-color: #F6F8FA;
}
</style>
</head>
Expand Down
2 changes: 1 addition & 1 deletion packages/graphs/tests/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const App = () => {
const match = useMatch('/*');

return (
<Flex vertical style={{ height: '100vh' }}>
<Flex vertical style={{ width: '500px', height: '500px', backgroundColor: '#fff' }}>
<Select
value={match?.params['*'] || Object.keys(demos)[0]}
options={Object.keys(demos).map((label) => ({ label, value: label }))}
Expand Down

0 comments on commit 8b8208d

Please sign in to comment.