Skip to content

Commit 1e563f9

Browse files
authored
fix: enable pan/zoom in dependency graph (#36)
1 parent 7661566 commit 1e563f9

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/main/js/dashboard-frontend/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"dependencies": {
66
"@cloudscape-design/collection-hooks": "^1.0.23",
7-
"@cloudscape-design/components": "^3.0.388",
87
"@cloudscape-design/component-toolkit": "^1.0.0-beta.24",
8+
"@cloudscape-design/components": "^3.0.388",
99
"@cloudscape-design/design-tokens": "^3.0.28",
1010
"@cloudscape-design/global-styles": "^1.0.12",
1111
"ace-builds": "^1.4.12",
@@ -19,7 +19,7 @@
1919
"react-scripts": "^5.0.1",
2020
"react-tabs": "^3.2.3",
2121
"react-virtualized": "^9.21.2",
22-
"sass": "^1.60.0",
22+
"sass": "^1.69.5",
2323
"typescript": "^4.3.2",
2424
"use-persisted-state": "^0.3.3",
2525
"ws": "^7.4.6"

src/main/js/dashboard-frontend/src/components/details/DependencyGraph.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,24 @@ class DependencyGraph extends Component<
126126
}
127127

128128
drawGraph() {
129-
let svg = d3.select(this.svg.current);
129+
let svg = d3.select(this.svg.current!) as unknown as d3.Selection<Element, unknown, any, any>;
130130
let inner: any = d3.select(this.innerG.current);
131+
131132
this.d3render(inner, this.g);
132-
inner.attr("transform", `translate(20, 20)`);
133-
svg.attr("height", this.g.graph().height + 40);
133+
134+
// Enable pan/zoom
135+
const zoom = d3.zoom()
136+
.on("zoom", () => {
137+
inner.attr("transform", d3.event.transform);
138+
});
139+
svg.call(zoom);
140+
141+
const { width, height } = inner.node().getBBox();
142+
// Scale to fit, but no bigger than 2x
143+
const scale = Math.min(Math.min(this.svg.current!.clientWidth / width, this.svg.current!.clientHeight / height) * 0.95, 2);
144+
zoom.scaleTo(svg, scale);
145+
// Center horizontally
146+
zoom.translateTo(svg, width / 2, 0);
134147
}
135148
async componentDidMount() {
136149
await SERVER.initConnections();
@@ -165,7 +178,7 @@ class DependencyGraph extends Component<
165178
disableContentPaddings={true}
166179
>
167180
<div className="holder">
168-
<svg height="100" style={{width: "100%"}} ref={this.svg}>
181+
<svg height="100" style={{width: "100%", height: "500px"}} ref={this.svg}>
169182
<g ref={this.innerG} />
170183
</svg>
171184
</div>

0 commit comments

Comments
 (0)