Skip to content

Commit 0b1eac5

Browse files
committed
wip: styles
1 parent 70da0b8 commit 0b1eac5

File tree

6 files changed

+89
-40
lines changed

6 files changed

+89
-40
lines changed
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import type {TBlock} from '@gravity-ui/graph';
2+
import { Icon } from '@gravity-ui/uikit';
3+
import {CodeMerge, Shuffle, VectorCircle, MapPin, BroadcastSignal} from '@gravity-ui/icons';
24

35
type Props = {
46
block: TBlock;
57
className: string;
68
};
79

10+
const getIcon = (name: string) => {
11+
switch (name) {
12+
case 'Merge':
13+
return CodeMerge;
14+
case 'UnionAll':
15+
return VectorCircle;
16+
case 'HashShuffle':
17+
return Shuffle;
18+
case 'Map':
19+
return MapPin;
20+
case 'Broadcast':
21+
return BroadcastSignal;
22+
}
23+
}
24+
825
export const ConnectionBlockComponent = ({className, block}: Props) => {
26+
const icon = getIcon(block.name);
927
return (
1028
<div className={className}>
11-
{block.operators ? block.operators.join('') : block.name} #{block.id}
29+
{icon && <Icon data={icon}/>} {block.name}
1230
</div>
1331
);
1432
};

src/components/Graph/BlockComponents/StageBlockComponent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {TBlock} from '@gravity-ui/graph';
2+
import { Text } from '@gravity-ui/uikit';
23

34
type Props = {
45
block: TBlock;
@@ -8,7 +9,8 @@ type Props = {
89
export const StageBlockComponent = ({className, block}: Props) => {
910
return (
1011
<div className={className}>
11-
{block.operators ? block.operators.join('') : block.name} #{block.id}
12+
{block.operators ? block.operators.map((item) => <div key={item}>{item}</div>) : block.name}
13+
{block.tables ? <div><Text color='secondary'>Tables: </Text>{block.tables.join(', ')}</div> : null}
1214
</div>
1315
);
1416
};

src/components/Graph/GravityGraph.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@
77

88
&__block-content {
99
width: 100%;
10-
height: 100%;
10+
// height: 100%;
1111
padding: 8px 12px;
1212
background: var(--g-color-base-float);
1313
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.3);
1414
border: 1px solid var(--g-color-line-generic);
15+
font-size: var(--g-text-body-short-font-size);
16+
line-height: var(--g-text-body-short-line-height);
1517
}
1618

19+
&__block-id {
20+
position: absolute;
21+
top: 4px;
22+
right: 4px;
23+
color: var(--g-color-text-secondary);
24+
font-size: 10px;
25+
line-height: 1;
26+
}
27+
1728
&__block-content.query {
1829
border-radius: 50%;
30+
height: 100%;
1931
}
2032

2133
&__block-content.result {
@@ -33,5 +45,6 @@
3345
box-shadow: none;
3446
background: var(--g-color-base-info-light);
3547
border: 1px solid var(--g-color-line-info);
48+
color: var(--g-color-text-info-heavy);
3649
}
3750
}

src/components/Graph/GravityGraph.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ const renderBlockFn = (graph, block) => {
7070
return (
7171
<GraphBlock graph={graph} block={block} className={b('block')}>
7272
{Component ? (
73-
<Component graph={graph} block={block} className={b('block-content', block.is)} />
73+
<>
74+
<Component graph={graph} block={block} className={b('block-content', block.is)} />
75+
{block.id !== 'undefined' && block.is !== 'result' && <div className={b('block-id')}>
76+
#{block.id}
77+
</div>}
78+
</>
7479
) : (
7580
block.id
7681
)}

src/components/Graph/sizesConfig.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/components/Graph/utils.ts

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

76
export const prepareChildren = (blocks: TGraphConfig['blocks']) => {
87
return blocks?.map((b) => {
@@ -37,13 +36,56 @@ export const prepareEdges = (connections: TGraphConfig['connections'], skipLabel
3736
});
3837
};
3938

39+
const BLOCK_TOP_PADDING = 8;
40+
const BLOCK_LINE_HEIGHT = 16;
41+
const BORDER_HEIGHT = 2;
42+
43+
const getBlockSize = (block: ExplainPlanNodeData) => {
44+
const ONE_LINE_HEIGHT = BLOCK_TOP_PADDING * 2 + BLOCK_LINE_HEIGHT + BORDER_HEIGHT;
45+
46+
switch (block.type) {
47+
case 'query':
48+
return {
49+
width: 40,
50+
height: 40,
51+
};
52+
case 'result':
53+
return {
54+
width: 112,
55+
height: ONE_LINE_HEIGHT,
56+
};
57+
case 'stage':
58+
const operatorsLength = block.operators?.length ?? 1;
59+
const tablesLength = block.tables?.length ?? 0;
60+
61+
return {
62+
width: 248,
63+
height: BORDER_HEIGHT + BLOCK_TOP_PADDING * 2 + (operatorsLength + tablesLength) * BLOCK_LINE_HEIGHT,
64+
};
65+
case 'connection':
66+
return {
67+
width: 122,
68+
height: ONE_LINE_HEIGHT,
69+
};
70+
case 'materialize':
71+
return {
72+
width: 190,
73+
height: ONE_LINE_HEIGHT,
74+
};
75+
default:
76+
return {
77+
width: 100,
78+
height: ONE_LINE_HEIGHT,
79+
};
80+
}
81+
}
82+
4083
export const prepareBlocks = (nodes: Data['nodes']): TBlock[] => {
41-
return nodes?.map(({data: {id, name, type, ...rest}}) => ({
84+
return nodes?.map(({data: {id, name, type, ...rest}, data}) => ({
4285
id: String(id),
4386
is: type,
4487
name,
45-
width: graphSizesConfig[type]?.width || 100,
46-
height: graphSizesConfig[type]?.height || 40,
88+
...getBlockSize(data),
4789
...rest,
4890
}));
4991
};

0 commit comments

Comments
 (0)