Skip to content

Commit 5576c55

Browse files
committed
wip: tooltip
1 parent 904ea56 commit 5576c55

File tree

3 files changed

+75
-78
lines changed

3 files changed

+75
-78
lines changed

src/components/Graph/GravityGraph.scss

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.3);
1414
border: 1px solid var(--g-color-line-generic);
1515
font-size: var(--g-text-body-short-font-size);
16+
font-family: var(--g-font-family);
1617
line-height: var(--g-text-body-short-line-height);
18+
19+
&[aria-haspopup='dialog'] {
20+
cursor: pointer;
21+
}
1722
}
1823

1924
&__block-id {
@@ -52,10 +57,37 @@
5257
}
5358

5459
&__tooltip-content {
55-
padding: 8px;
60+
padding: 0 8px 8px;
5661
width: 300px;
5762
font-size: var(--g-text-body-short-font-size);
63+
font-family: var(--g-font-family);
5864
line-height: var(--g-text-body-short-line-height);
65+
}
66+
67+
&__tooltip-tabs {
68+
margin-bottom: 8px;
69+
}
70+
71+
&__tooltip-stat-row {
72+
display: grid;
73+
grid-template-columns: 100px auto;
74+
gap: 8px;
75+
margin: 4px 0 0;
76+
77+
span {
78+
overflow: hidden;
79+
text-overflow: ellipsis;
80+
}
81+
span:nth-child(2) {
82+
word-wrap: break-word;
83+
}
84+
}
85+
86+
&__tooltip-stat-group {
87+
margin-top: 8px;
88+
}
5989

90+
&__tooltip-stat-group-name {
91+
font-weight: bold;
6092
}
6193
}

src/components/Graph/GravityGraph.tsx

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,26 @@ const config = {
5353
showConnectionArrows: false,
5454
},
5555
};
56+
57+
const baseElkConfig = {
58+
id: 'root',
59+
layoutOptions: {
60+
'elk.algorithm': 'layered',
61+
'elk.direction': 'DOWN',
62+
// 'elk.spacing.edgeNode': '50',
63+
'elk.layered.spacing.nodeNodeBetweenLayers': '20',
64+
'elk.layered.nodePlacement.bk.fixedAlignment': 'BALANCED',
65+
'elk.layered.nodePlacement.bk.ordering': 'INTERACTIVE',
66+
// 'elk.debugMode': true,
67+
// 'elk.alignment': 'CENTER'
68+
},
69+
};
70+
71+
5672
const elk = new ELK();
5773

5874
const renderBlockFn = (graph, block) => {
59-
// console.log('===', block);
75+
console.log('===', block);
6076

6177
const map = {
6278
query: QueryBlockComponent,
@@ -83,52 +99,7 @@ const renderBlockFn = (graph, block) => {
8399
);
84100
};
85101

86-
// const _blocks: TBlock[] = [
87-
// {
88-
// width: 200,
89-
// height: 160,
90-
// id: 'Left',
91-
// is: 'block-action',
92-
// selected: false,
93-
// name: 'Left block',
94-
// anchors: [],
95-
// },
96-
// {
97-
// width: 200,
98-
// height: 160,
99-
// id: 'Right',
100-
// is: 'block-action',
101-
// selected: false,
102-
// name: 'Right block',
103-
// anchors: [],
104-
// },
105-
// ];
106-
107-
// const _connections = [
108-
// {
109-
// id: 'c1',
110-
// sourceBlockId: 'Left',
111-
// targetBlockId: 'Right',
112-
// },
113-
// ];
114-
115-
const baseElkConfig = {
116-
id: 'root',
117-
layoutOptions: {
118-
'elk.algorithm': 'layered',
119-
'elk.direction': 'DOWN',
120-
// 'elk.spacing.edgeNode': '50',
121-
'elk.layered.spacing.nodeNodeBetweenLayers': '20',
122-
'elk.layered.nodePlacement.bk.fixedAlignment': 'BALANCED',
123-
'elk.layered.nodePlacement.bk.ordering': 'INTERACTIVE',
124-
'elk.debugMode': true,
125-
// 'elk.alignment': 'CENTER'
126-
},
127-
};
128-
129102
export function GravityGraph<T>({data, theme}: Props<T>) {
130-
// console.log('997', data);
131-
132103
const _blocks = useMemo(() => prepareBlocks(data.nodes), [data.nodes]);
133104
const _connections = useMemo(() => prepareConnections(data.links), [data.links]);
134105
const elkConfig = useMemo(
@@ -147,26 +118,15 @@ export function GravityGraph<T>({data, theme}: Props<T>) {
147118
return;
148119
}
149120

150-
// console.log('result', result);
151-
152-
const blocks = _blocks.map((block) => {
153-
return {
154-
...block,
155-
...result.blocks[block.id],
156-
};
157-
});
121+
const blocks = _blocks.map((block) => ({
122+
...block,
123+
...result.blocks[block.id],
124+
}));
158125

159-
const connections = _connections.reduce((acc, connection) => {
160-
if (connection.id in result.edges) {
161-
acc.push({
162-
...connection,
163-
...result.edges[connection.id],
164-
});
165-
}
166-
return acc;
167-
}, []);
168-
169-
// console.log('connections', connections);
126+
const connections = _connections.map((connection) => ({
127+
...connection,
128+
...(connection.id? result.edges[connection.id] : {}),
129+
}));
170130

171131
graph.setEntities({
172132
blocks,

src/components/Graph/TooltipComponent.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@ import React, { useState, useMemo } from 'react';
22
import type { TBlock } from '@gravity-ui/graph';
33
import { Text, Popover, TabProvider, TabList, Tab, TabPanel } from '@gravity-ui/uikit';
44

5+
import {cn} from '../../utils/cn';
6+
const b = cn('ydb-gravity-graph');
57
type Props = {
68
block: TBlock;
79
children: React.ReactNode;
810
};
911

12+
const getStatsContent = (stat) => {
13+
if (!stat.items) {
14+
return <p className={b('tooltip-stat-row')} key={stat.name}><span>{stat.name}:</span><span>{stat.value}</span></p>;
15+
}
16+
17+
return (
18+
<section className={b('tooltip-stat-group')} key={stat.name}>
19+
<div className={b('tooltip-stat-group-name')}>{stat.name}:</div>
20+
{stat.items?.map(({ name, value }) => <p className={b('tooltip-stat-row')} key={name}><span>{name}:</span><span>{value}</span></p>)}
21+
</section>
22+
);
23+
}
24+
1025
const getTooltipContent = (block: TBlock) => {
1126
const [activeTab, setActiveTab] = useState(block?.stats[0]?.group);
1227

1328
return (
1429
<TabProvider value={activeTab} onUpdate={setActiveTab}>
15-
<TabList>
30+
<TabList className={b('tooltip-tabs')}>
1631
{block?.stats?.map((item) => <Tab value={item.group}>{item.group}</Tab>)}
1732
</TabList>
1833
{block?.stats?.map((item) => <TabPanel value={item.group}>
19-
{item.stats?.map((stat) => <div key={stat.name}>
20-
{Boolean(stat.items) &&
21-
<>
22-
<strong>{stat.name}</strong>
23-
{stat.items?.map(({ name, value }) => <div key={value}>{name}: {value}</div>)}
24-
</>
25-
}
26-
{!stat.items && <div>{stat.name}: {stat.value}</div>}
27-
28-
29-
</div>)}
34+
{item.stats?.map(getStatsContent)}
3035
</TabPanel>)}
3136
</TabProvider>
3237
);

0 commit comments

Comments
 (0)