Skip to content

Commit 70da0b8

Browse files
committed
wip: custom blocks
1 parent 2c4cf39 commit 70da0b8

File tree

8 files changed

+151
-8
lines changed

8 files changed

+151
-8
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {TBlock} from '@gravity-ui/graph';
2+
3+
type Props = {
4+
block: TBlock;
5+
className: string;
6+
};
7+
8+
export const ConnectionBlockComponent = ({className, block}: Props) => {
9+
return (
10+
<div className={className}>
11+
{block.operators ? block.operators.join('') : block.name} #{block.id}
12+
</div>
13+
);
14+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Props = {
2+
className: string;
3+
};
4+
5+
export const QueryBlockComponent = ({className}: Props) => {
6+
return <div className={className} />;
7+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type {TBlock} from '@gravity-ui/graph';
2+
3+
type Props = {
4+
block: TBlock;
5+
className: string;
6+
};
7+
8+
export const ResultBlockComponent = ({className, block}: Props) => {
9+
return <div className={className}>{block.name}</div>;
10+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {TBlock} from '@gravity-ui/graph';
2+
3+
type Props = {
4+
block: TBlock;
5+
className: string;
6+
};
7+
8+
export const StageBlockComponent = ({className, block}: Props) => {
9+
return (
10+
<div className={className}>
11+
{block.operators ? block.operators.join('') : block.name} #{block.id}
12+
</div>
13+
);
14+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.ydb-gravity-graph {
2+
&__block {
3+
background: none;
4+
border: none;
5+
cursor: auto;
6+
}
7+
8+
&__block-content {
9+
width: 100%;
10+
height: 100%;
11+
padding: 8px 12px;
12+
background: var(--g-color-base-float);
13+
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.3);
14+
border: 1px solid var(--g-color-line-generic);
15+
}
16+
17+
&__block-content.query {
18+
border-radius: 50%;
19+
}
20+
21+
&__block-content.result {
22+
display: flex;
23+
align-items: center;
24+
justify-content: center;
25+
}
26+
27+
&__block-content.stage {
28+
border-radius: 6px;
29+
}
30+
31+
&__block-content.connection {
32+
border-radius: 6px;
33+
box-shadow: none;
34+
background: var(--g-color-base-info-light);
35+
border: 1px solid var(--g-color-line-info);
36+
}
37+
}

src/components/Graph/GravityGraph.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ import {
2323
parseCustomPropertyValue,
2424
} from './utils';
2525

26+
import {cn} from '../../utils/cn';
27+
28+
import './GravityGraph.scss';
29+
30+
const b = cn('ydb-gravity-graph');
31+
2632
import {QueryBlockView} from './BlockComponents/QueryBlockView';
33+
import {QueryBlockComponent} from './BlockComponents/QueryBlockComponent';
34+
import {ResultBlockComponent} from './BlockComponents/ResultBlockComponent';
35+
import {StageBlockComponent} from './BlockComponents/StageBlockComponent';
36+
import {ConnectionBlockComponent} from './BlockComponents/ConnectionBlockComponent';
2737
import {graphColorsConfig} from './colorsConfig';
2838

2939
interface Props<T> {
@@ -35,7 +45,7 @@ const config = {
3545
settings: {
3646
connection: MultipointConnection,
3747
blockComponents: {
38-
Query: QueryBlockView,
48+
query: QueryBlockView,
3949
},
4050
// canDragCamera: true,
4151
// canZoomCamera: false,
@@ -46,9 +56,24 @@ const config = {
4656
const elk = new ELK();
4757

4858
const renderBlockFn = (graph, block) => {
59+
console.log('===', block);
60+
61+
const map = {
62+
query: QueryBlockComponent,
63+
result: ResultBlockComponent,
64+
stage: StageBlockComponent,
65+
connection: ConnectionBlockComponent,
66+
};
67+
68+
const Component = map[block.is];
69+
4970
return (
50-
<GraphBlock graph={graph} block={block}>
51-
{block.id}
71+
<GraphBlock graph={graph} block={block} className={b('block')}>
72+
{Component ? (
73+
<Component graph={graph} block={block} className={b('block-content', block.is)} />
74+
) : (
75+
block.id
76+
)}
5277
</GraphBlock>
5378
);
5479
};
@@ -88,7 +113,7 @@ const baseElkConfig = {
88113
'elk.algorithm': 'layered',
89114
'elk.direction': 'DOWN',
90115
// 'elk.spacing.edgeNode': '50',
91-
'elk.layered.spacing.nodeNodeBetweenLayers': '50',
116+
'elk.layered.spacing.nodeNodeBetweenLayers': '20',
92117
'elk.layered.nodePlacement.bk.fixedAlignment': 'BALANCED',
93118
'elk.layered.nodePlacement.bk.ordering': 'INTERACTIVE',
94119
'elk.debugMode': true,
@@ -151,6 +176,10 @@ export function GravityGraph<T>({data, theme}: Props<T>) {
151176
useGraphEvent(graph, 'state-change', ({state}) => {
152177
if (state === GraphState.ATTACHED) {
153178
console.log('start');
179+
graph.cameraService.set({
180+
scale: 1,
181+
scaleMax: 1.5,
182+
});
154183
start();
155184
// graph.zoomTo("center", { padding: 300 });
156185
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type {ExplainPlanNodeData} from '@gravity-ui/paranoid';
2+
3+
type Props = {
4+
width: number;
5+
height: number;
6+
};
7+
8+
type SizeConfig = Record<ExplainPlanNodeData['type'], Props>;
9+
10+
export const graphSizesConfig: SizeConfig = {
11+
query: {
12+
width: 40,
13+
height: 40,
14+
},
15+
result: {
16+
width: 112,
17+
height: 40,
18+
},
19+
stage: {
20+
width: 248,
21+
height: 40,
22+
},
23+
connection: {
24+
width: 112,
25+
height: 40,
26+
},
27+
materialize: {
28+
width: 190,
29+
height: 40,
30+
},
31+
};

src/components/Graph/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {TBlock, TConnection, TGraphConfig} from '@gravity-ui/graph';
22
import type {Data, GraphNode, Options, Shapes} from '@gravity-ui/paranoid';
33
import type {ElkExtendedEdge, ElkNode} from 'elkjs';
44
import type {AbstractGraphColorsConfig} from './colorsConfig';
5+
import {graphSizesConfig} from './sizesConfig';
56

67
export const prepareChildren = (blocks: TGraphConfig['blocks']) => {
78
return blocks?.map((b) => {
@@ -37,12 +38,12 @@ export const prepareEdges = (connections: TGraphConfig['connections'], skipLabel
3738
};
3839

3940
export const prepareBlocks = (nodes: Data['nodes']): TBlock[] => {
40-
return nodes?.map(({data: {id, name, ...rest}}) => ({
41+
return nodes?.map(({data: {id, name, type, ...rest}}) => ({
4142
id: String(id),
42-
is: name,
43+
is: type,
4344
name,
44-
width: 200,
45-
height: 100,
45+
width: graphSizesConfig[type]?.width || 100,
46+
height: graphSizesConfig[type]?.height || 40,
4647
...rest,
4748
}));
4849
};

0 commit comments

Comments
 (0)