Skip to content

Commit f841d3b

Browse files
committed
fix(Dagre): fixed centering computation error
- Fixed an error in the centering computing where the wrong scaling variable was used, and the internal measurment were not properly scaled Signed-off-by: Jean-Baptiste Bianchi <[email protected]>
1 parent 5537bd2 commit f841d3b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/Neuroglia.Blazor.Dagre/DagreGraph.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
{
306306
if (this.graph == null)
307307
return;
308-
var position = await this.JSRuntime.InvokeAsync<BoundingBox>("neuroglia.blazor.getCenter", this.graphReference);
308+
var position = await this.JSRuntime.InvokeAsync<BoundingBox>("neuroglia.blazor.getCenter", this.graph.Scale, this.graphReference);
309309
this.graph.X = position.X;
310310
this.graph.Y = position.Y;
311311
this.isDirty = true;
@@ -315,7 +315,7 @@
315315
{
316316
if (this.graph == null)
317317
return;
318-
var position = await this.JSRuntime.InvokeAsync<BoundingBox>("neuroglia.blazor.getCenter", this.graphReference, node);
318+
var position = await this.JSRuntime.InvokeAsync<BoundingBox>("neuroglia.blazor.getCenter", this.graph.Scale, this.graphReference, node);
319319
this.graph.X = position.X;
320320
this.graph.Y = position.Y;
321321
this.isDirty = true;

src/Neuroglia.Blazor.Dagre/wwwroot/neuroglia-blazor-dagre-interop.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@
3434
window.neuroglia.blazor.preventScroll = (graphElement) => {
3535
graphElement.addEventListener("wheel", e => e.preventDefault(), { passive: false });
3636
}
37-
window.neuroglia.blazor.getCenter = (graphElement, node) => {
38-
const scale = window.neuroglia.blazor.getScale(graphElement);
37+
window.neuroglia.blazor.getCenter = (scale, graphElement, node) => {
3938
const svgBounds = graphElement.getBoundingClientRect();
4039
const graphBounds = graphElement.getBBox();
41-
const center = {
42-
x: (((svgBounds.width / scale) - graphBounds.width) / 2),
43-
y: (((svgBounds.height / scale) - graphBounds.height) / 2)
40+
let center = {
41+
x: (((svgBounds.width) - graphBounds.width) / 2),
42+
y: (((svgBounds.height) - graphBounds.height) / 2)
4443
};
45-
if (!node) return center;
44+
if (node) {
45+
center = {
46+
x: center.x + ((graphBounds.width / 2) - (node.x * scale)),
47+
y: center.y + ((graphBounds.height / 2) - (node.y * scale)),
48+
};
49+
}
4650
return {
47-
x: center.x + ((graphBounds.width / 2) - node.x),
48-
y: center.y + ((graphBounds.height / 2) - node.y),
49-
};
51+
x: center.x / scale,
52+
y: center.y / scale
53+
}
5054
}
5155
window.neuroglia.blazor.getScale = (graphElement) => {
5256
const svgBounds = graphElement.getBoundingClientRect();

0 commit comments

Comments
 (0)