Skip to content

Commit c050653

Browse files
committed
wip: controls
1 parent eec1fe7 commit c050653

File tree

6 files changed

+220
-110
lines changed

6 files changed

+220
-110
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type {Graph} from '@gravity-ui/graph';
2+
import MagnifierMinusIcon from '@gravity-ui/icons/svgs/magnifier-minus.svg';
3+
import MagnifierPlusIcon from '@gravity-ui/icons/svgs/magnifier-plus.svg';
4+
import {Button, Icon} from '@gravity-ui/uikit';
5+
6+
import {cn} from '../../utils/cn';
7+
const b = cn('ydb-gravity-graph');
8+
9+
const ZOOM_STEP = 1.25;
10+
11+
interface Props {
12+
graph: Graph;
13+
}
14+
15+
export const GraphControls = ({graph}: Props) => {
16+
const onZoomInClick = () => {
17+
const cameraScale = graph.cameraService.getCameraScale();
18+
graph.zoom({scale: cameraScale * ZOOM_STEP});
19+
};
20+
21+
const onZoomOutClick = () => {
22+
const cameraScale = graph.cameraService.getCameraScale();
23+
graph.zoom({scale: cameraScale / ZOOM_STEP});
24+
};
25+
26+
const onResetZoomClick = () => {
27+
graph.zoom({scale: 1});
28+
};
29+
30+
return (
31+
<div className={b('zoom-controls')}>
32+
<Button
33+
view="raised"
34+
onClick={onZoomInClick}
35+
>
36+
<Icon data={MagnifierPlusIcon} size={16} />
37+
</Button>
38+
<Button
39+
view="raised"
40+
onClick={onZoomOutClick}
41+
>
42+
<Icon data={MagnifierMinusIcon} size={16} />
43+
</Button>
44+
<Button
45+
view="raised"
46+
onClick={onResetZoomClick}
47+
>
48+
1:1
49+
</Button>
50+
</div>
51+
);
52+
};
53+

src/components/Graph/GravityGraph.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
overflow: hidden;
7979
text-overflow: ellipsis;
8080
}
81+
span:nth-child(1) {
82+
color: var(--g-color-text-secondary);
83+
}
8184
span:nth-child(2) {
8285
word-wrap: break-word;
8386
}
@@ -86,8 +89,22 @@
8689
&__tooltip-stat-group {
8790
margin-top: 8px;
8891
}
92+
93+
&__tooltip-stat-group + &__tooltip-stat-group {
94+
padding-top: 8px;
95+
border-top: 1px dotted var(--g-color-line-generic);
96+
}
8997

9098
&__tooltip-stat-group-name {
9199
font-weight: bold;
92100
}
101+
102+
&__zoom-controls {
103+
position: absolute;
104+
top: 8px;
105+
right: 50px;
106+
z-index: 999;
107+
display: flex;
108+
gap: 2px;
109+
}
93110
}

src/components/Graph/GravityGraph.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,25 @@ import './GravityGraph.scss';
2929

3030
const b = cn('ydb-gravity-graph');
3131

32-
import {QueryBlockView} from './BlockComponents/QueryBlockView';
32+
// import {QueryBlockView} from './BlockComponents/QueryBlockView';
3333
import {QueryBlockComponent} from './BlockComponents/QueryBlockComponent';
3434
import {ResultBlockComponent} from './BlockComponents/ResultBlockComponent';
3535
import {StageBlockComponent} from './BlockComponents/StageBlockComponent';
3636
import {ConnectionBlockComponent} from './BlockComponents/ConnectionBlockComponent';
3737
import {graphColorsConfig} from './colorsConfig';
38+
import { GraphControls } from './GraphControls';
3839

3940
interface Props<T> {
4041
data: Data<T>;
4142
theme?: string;
4243
}
4344

44-
const config = {
45+
const config: TGraphConfig = {
4546
settings: {
4647
connection: MultipointConnection,
47-
blockComponents: {
48-
query: QueryBlockView,
49-
},
48+
// blockComponents: {
49+
// query: QueryBlockView,
50+
// },
5051
// canDragCamera: true,
5152
// canZoomCamera: false,
5253
// useBezierConnections: false,
@@ -72,7 +73,7 @@ const baseElkConfig = {
7273
const elk = new ELK();
7374

7475
const renderBlockFn = (graph, block) => {
75-
console.log('===', block);
76+
// console.log('===', block);
7677

7778
const map = {
7879
query: QueryBlockComponent,
@@ -140,15 +141,27 @@ export function GravityGraph<T>({data, theme}: Props<T>) {
140141

141142
useGraphEvent(graph, 'state-change', ({state}) => {
142143
if (state === GraphState.ATTACHED) {
143-
console.log('start');
144144
graph.cameraService.set({
145145
scale: 1,
146146
scaleMax: 1.5,
147+
scaleMin: 0.5,
148+
});
149+
graph.setConstants({
150+
block: {
151+
SCALES: [0.125, 0.225, 0.5] // Detailed view stays until zoom = 0.5
152+
}
147153
});
148154
start();
149155
// graph.zoomTo("center", { padding: 300 });
150156
}
151157
});
152158

153-
return <GraphCanvas graph={graph} renderBlock={renderBlockFn} />;
159+
// useGraphEvent(graph, 'connection-selection-change', (event) => {
160+
// console.log('connection-click', event);
161+
// });
162+
163+
return <>
164+
<GraphCanvas graph={graph} renderBlock={renderBlockFn} />
165+
<GraphControls graph={graph} />
166+
</>;
154167
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {MultipointConnection} from '@gravity-ui/graph/react';
2+
3+
/**
4+
* Кастомный класс соединения, который отключает визуальное выделение
5+
* Наследуется от MultipointConnection и переопределяет поведение
6+
*/
7+
export class NonSelectableConnection extends MultipointConnection {
8+
// Переопределяем метод для предотвращения выделения при клике
9+
public override onClick() {
10+
// Ничего не делаем при клике - блокируем выделение
11+
return;
12+
}
13+
14+
// Переопределяем метод для отключения hover эффектов
15+
public override onPointerEnter() {
16+
// Ничего не делаем при наведении
17+
return;
18+
}
19+
20+
public override onPointerLeave() {
21+
// Ничего не делаем при уходе курсора
22+
return;
23+
}
24+
}

0 commit comments

Comments
 (0)