Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable pan/zoom in dependency graph #36

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/js/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"dependencies": {
"@cloudscape-design/collection-hooks": "^1.0.23",
"@cloudscape-design/components": "^3.0.388",
"@cloudscape-design/component-toolkit": "^1.0.0-beta.24",
"@cloudscape-design/components": "^3.0.388",
"@cloudscape-design/design-tokens": "^3.0.28",
"@cloudscape-design/global-styles": "^1.0.12",
"ace-builds": "^1.4.12",
Expand All @@ -19,7 +19,7 @@
"react-scripts": "^5.0.1",
"react-tabs": "^3.2.3",
"react-virtualized": "^9.21.2",
"sass": "^1.60.0",
"sass": "^1.69.5",
"typescript": "^4.3.2",
"use-persisted-state": "^0.3.3",
"ws": "^7.4.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,24 @@ class DependencyGraph extends Component<
}

drawGraph() {
let svg = d3.select(this.svg.current);
let svg = d3.select(this.svg.current!) as unknown as d3.Selection<Element, unknown, any, any>;
let inner: any = d3.select(this.innerG.current);

this.d3render(inner, this.g);
inner.attr("transform", `translate(20, 20)`);
svg.attr("height", this.g.graph().height + 40);

// Enable pan/zoom
const zoom = d3.zoom()
.on("zoom", () => {
inner.attr("transform", d3.event.transform);
});
svg.call(zoom);

const { width, height } = inner.node().getBBox();
// Scale to fit, but no bigger than 2x
const scale = Math.min(Math.min(this.svg.current!.clientWidth / width, this.svg.current!.clientHeight / height) * 0.95, 2);
zoom.scaleTo(svg, scale);
// Center horizontally
zoom.translateTo(svg, width / 2, 0);
}
async componentDidMount() {
await SERVER.initConnections();
Expand Down Expand Up @@ -165,7 +178,7 @@ class DependencyGraph extends Component<
disableContentPaddings={true}
>
<div className="holder">
<svg height="100" style={{width: "100%"}} ref={this.svg}>
<svg height="100" style={{width: "100%", height: "500px"}} ref={this.svg}>
<g ref={this.innerG} />
</svg>
</div>
Expand Down
Loading