Skip to content

Commit 6d66e3c

Browse files
committed
Fixes grid scaling
1 parent 7998901 commit 6d66e3c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/components/GraphCaption/LayoutQualityCaption.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isNaN } from "lodash";
12
import { FC } from "react";
23
import { useTranslation } from "react-i18next";
34

@@ -8,6 +9,7 @@ export const LayoutQualityCaption: FC = () => {
89
const { t } = useTranslation();
910
const { quality } = useLayoutState();
1011
const { locale } = usePreferences();
12+
const error = quality.metric?.cMax === undefined || isNaN(quality.metric?.cMax);
1113

1214
if (!quality.enabled) return null;
1315

@@ -21,10 +23,12 @@ export const LayoutQualityCaption: FC = () => {
2123
</div>
2224
</div>
2325
<div className="caption text-center">
24-
{quality.metric?.ePercentOfDeltaMax
25-
? Math.round(quality.metric.ePercentOfDeltaMax * 100).toLocaleString(locale, { compactDisplay: "short" }) +
26-
"%"
27-
: "N/A"}{" "}
26+
{error
27+
? "ERROR"
28+
: quality.metric?.ePercentOfDeltaMax
29+
? Math.round(quality.metric.ePercentOfDeltaMax * 100).toLocaleString(locale, { compactDisplay: "short" }) +
30+
"%"
31+
: "N/A"}{" "}
2832
</div>
2933
</div>
3034
);

src/views/graphPage/controllers/GridController.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useSigma } from "@react-sigma/core";
2+
import { nodeExtent } from "graphology-metrics/graph";
3+
import { mean } from "lodash";
24
import { FC, useCallback, useEffect, useRef } from "react";
35
import { getPixelRatio } from "sigma/utils";
46

@@ -41,11 +43,12 @@ export const GridController: FC<{ size: number; opacity: number; color: string }
4143
const ctx = canvas?.getContext("2d");
4244
if (!ctx) return;
4345

44-
const { angle, ratio } = sigma.getCamera().getState();
45-
const center = sigma.framedGraphToViewport({ x: 0.5, y: 0.5 });
46+
const { angle } = sigma.getCamera().getState();
47+
const { x, y } = nodeExtent(sigma.getGraph(), ["x", "y"]);
48+
const center = sigma.graphToViewport({ x: mean(x), y: mean(y) });
4649
const { width, height } = sigma.getDimensions();
4750
const stageSize = Math.sqrt(width ** 2 + height ** 2) / 2;
48-
const gridSize = slowedSize / ratio;
51+
const gridSize = slowedSize * sigma.getGraphToViewportRatio();
4952

5053
const finalOpacity =
5154
gridSize > MIN_GRID_SIZE ? slowedOpacity : (slowedOpacity * (gridSize - MIN_GRID_SIZE / 2)) / (MIN_GRID_SIZE / 2);

0 commit comments

Comments
 (0)