Skip to content

[Optimize-4146] Optimize lineage relationship chart display #4203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dinky-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@ant-design/icons": "^5.3.7",
"@ant-design/pro-components": "^2.7.19",
"@ant-design/use-emotion-css": "^1.0.4",
"@antv/graphin": "^3.0.2",
"@antv/g6-extension-react": "^0.1.7",
"@antv/graphin": "^3.0.4",
"@antv/g6-extension-react": "^0.1.17",
"@antv/g-canvas": "^2.0.20",
"@antv/ava-react": "^3.3.2",
"@antv/g2": "^5.2.7",
Expand Down
122 changes: 77 additions & 45 deletions dinky-web/src/pages/DataStudio/Toolbar/Service/Lineage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
register
} from '@antv/g6';
import { memo, useContext, useEffect, useRef } from 'react';
import { Flex } from 'antd';
import { ReactNode } from '@antv/g6-extension-react';
import { Graphin } from '@antv/graphin';
import { DagreLayout, GridLayout } from '@antv/layout';
Expand Down Expand Up @@ -66,13 +65,13 @@ class RectComboWithExtraButton extends RectCombo {
const { collapsed } = attributes;
const [, height] = this.getKeySize(attributes);
const btnR = 8;
const y = -(height / 2 + btnR);
const y = height / 2 + btnR + 2;
const d = collapsed ? expand(0, y, btnR) : collapse(0, y, btnR);

const hitArea = this.upsert(
'hit-area',
Circle,
{ cy: y, r: 10, fill: '#fff', cursor: 'pointer' },
{ cy: y, r: 10, fill: '#fff', cursor: 'pointer', cx: 0 },
this
);
this.upsert('button', Path, { stroke: '#3d81f7', d, cursor: 'pointer' }, hitArea!!);
Expand All @@ -82,7 +81,7 @@ class RectComboWithExtraButton extends RectCombo {
this.shapeMap['hit-area'].addEventListener('click', () => {
const id = this.id;
const collapsed = !this.attributes.collapsed;
const { graph } = this.attributes.context!!;
const { graph } = this.context;
if (collapsed) graph.collapseElement(id);
else graph.expandElement(id);
});
Expand Down Expand Up @@ -114,14 +113,7 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
observer.observe(element);
return () => observer.unobserve(element);
}, []);
// 把data.tables 的id ,name转成map
const tablesMap = data.tables.reduce(
(acc, item) => {
acc[item.id] = item.name;
return acc;
},
{} as Record<string, string>
);
const tables = data.tables.map((x) => x.name);
return (
<div ref={containerRef} style={{ width: '100%', height: '100%' }}>
<Graphin
Expand All @@ -131,13 +123,42 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
autoResize: true,
theme: theme === 'light' ? theme : 'dark',
data: {
nodes: data.tables.flatMap((item) =>
item.columns.map((column) => ({
id: item.id + column.name,
combo: item.id,
data: { name: column.name }
}))
),
nodes: data.tables.flatMap((item) => {
const lengths = item.columns.map((x) => x.name.length);
const width = Math.max(...lengths) * 10;
const tableSplit = item.name.split('.');
return [
{
id: item.name,
combo: item.id,
data: { name: tableSplit[tableSplit.length - 1], tables: tableSplit },
palette: {
type: 'group',
field: 'name'
},
style: {
fill: '#3c3f41',
radius: [10, 10, 0, 0],
size: [300, 30],
labelFill: 'white'
}
},
...item.columns.map((column) => ({
id: item.id + column.name,
combo: item.id,
data: { name: column.name, width, catalog: item.name },
style: {
fill: 'white',
size: [300, 30],
labelFill: 'black',
// todo
port: false,
ports: [{ placement: 'right' }, { placement: 'left' }],
portR: 3
}
}))
];
}),
edges: data.relations.map((item) => ({
source: item.srcTableId + item.srcTableColName,
target: item.tgtTableId + item.tgtTableColName
Expand All @@ -147,38 +168,35 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
combo: {
type: 'circle-combo-with-extra-button',
style: {
labelText: (d) => tablesMap[d.id]
padding: [0, 0],
fill: '#FFF',
radius: 10
}
},
node: {
type: 'react',
type: 'rect',
style: {
size: [240, 20],
component: (data: { data: { name: string } }) => (
<Flex
justify={'center'}
align={'center'}
style={{
width: '100%',
height: '100%',
background: 'var(--main-background-color)',
borderRadius: 5,
border: '1px solid gray'
}}
vertical
>
{data.data.name}
</Flex>
),
port: true,
ports: [{ placement: 'right' }, { placement: 'left' }]
// iconText: (d: { data: { name: string } }) => d.data.name,
labelText: (d: { data: { name: string } }) => d.data.name,
labelPlacement: 'center'
},
state: {
highlight: {
fill: '#dfe0d9'
}
}
},
edge: {
type: 'cubic-horizontal',
style: {
endArrow: true,
endArrowType: 'vee'
endArrowType: 'vee',
lineDash: 5
},
state: {
highlight: {
lineDash: 0
}
}
},
layout: {
Expand All @@ -187,8 +205,8 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
outerLayout: new DagreLayout({
rankdir: 'LR',
edgeLabelSpace: false,
nodesep: 5,
ranksep: 50
nodesep: 15,
ranksep: 150
})
},
behaviors: [
Expand All @@ -197,7 +215,8 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
'zoom-canvas',
{
type: 'hover-activate',
enable: (event: any) => event.targetType === 'node',
enable: (event: any) =>
event.targetType === 'node' && !tables.find((x) => x === event.target.id),
degree: 1, // 👈🏻 Activate relations.
state: 'highlight',
inactiveState: 'dim',
Expand Down Expand Up @@ -247,7 +266,20 @@ export const Lineage = memo((props: { data: LineageDetailInfo }) => {
backgroundColor: 'var(--btn-background-color)'
}
},
{ key: 'background', type: 'background', background: 'var(--primary-color)' }
{ key: 'background', type: 'background', background: 'var(--primary-color)' },
{
type: 'tooltip',
enable: (event: any) =>
event.targetType === 'node' && tables.find((x) => x === event.target.id),
trigger: 'click',
getContent: (event: any, items: any) => {
const ts = items[0].data.tables;
const catalog = `<h4>catalog: ${ts[0]}</h4>`;
const database = `<h4>database: ${ts[1]}</h4>`;
const table = `<h4>table: ${ts[2]}</h4>`;
return catalog + database + table;
}
}
],
transforms: ['process-parallel-edges'],
autoFit: 'view'
Expand Down
Loading