Skip to content

Commit 86177a6

Browse files
committed
improve visual settings
1 parent 50a1b7d commit 86177a6

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

src/lib/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const DEFAULT_EDGE_SIZE_RATIO = 1;
4545
export const EDGE_SIZE_RATIO_STEP = 0.001;
4646

4747
export const MIN_LABEL_SIZE = 5;
48-
export const MAX_LABEL_SIZE = 50;
48+
export const MAX_LABEL_SIZE = 30;
4949
export const DEFAULT_LABEL_SIZE = 14;
5050
export const LABEL_SIZE_STEP = 1;
5151

src/lib/graph.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export function applyNodeLabelSizes(
4545
const minSize = typeof minLabelSize === "number" ? minLabelSize : DEFAULT_LABEL_SIZE;
4646
const maxSize = typeof maxLabelSize === "number" ? maxLabelSize : DEFAULT_LABEL_SIZE;
4747
const extentDelta = nodeSizeExtents[1] - nodeSizeExtents[0];
48-
const factor = (maxSize - minSize) / (extentDelta || 1);
48+
// Guard against tiny ranges to avoid blowing up the factor
49+
const safeDelta = Math.max(extentDelta, 1e-6);
4950
graph.forEachNode((node, nodeData) => {
5051
let nodeSize: number;
5152
if (nodeSizeField === "pagerank") {
@@ -57,7 +58,13 @@ export function applyNodeLabelSizes(
5758
} else {
5859
nodeSize = nodeData.rawSize;
5960
}
60-
graph.setNodeAttribute(node, "labelSize", minSize + (nodeSize - nodeSizeExtents[0]) * factor);
61+
// Normalize to [0, 1]
62+
const tRaw = (nodeSize - nodeSizeExtents[0]) / safeDelta;
63+
const t = Math.max(0, Math.min(1, tRaw));
64+
// Smoothstep easing for gradual change
65+
const eased = t * t * (3 - 2 * t);
66+
const label = minSize + (maxSize - minSize) * eased;
67+
graph.setNodeAttribute(node, "labelSize", label);
6168
});
6269
}
6370

src/utils/threshold.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ export function stateToInputThreshold(v: number): number {
99
export function inputToStateThreshold(v: number): number {
1010
if (v <= MIN_LABEL_THRESHOLD) return Infinity;
1111
if (v >= MAX_LABEL_THRESHOLD) return 0;
12-
return 6 / v;
12+
// Create a smooth, continuous mapping from slider value to threshold
13+
// Map [MIN_LABEL_THRESHOLD, MAX_LABEL_THRESHOLD] to [Infinity, 0.1]
14+
const normalized = (v - MIN_LABEL_THRESHOLD) / (MAX_LABEL_THRESHOLD - MIN_LABEL_THRESHOLD);
15+
// Use smoothstep easing for gradual, natural-feeling control
16+
const eased = normalized * normalized * (3 - 2 * normalized);
17+
// Map to a reasonable threshold range: Infinity -> 20 -> 10 -> 5 -> 2 -> 0.1
18+
const threshold = Math.max(0.1, 20 * Math.pow(0.5, eased * 4));
19+
return threshold;
1320
}

src/views/Settings.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cx from "classnames";
22
import { isEqual, keyBy, uniqBy } from "lodash";
33
import Slider, { SliderProps } from "rc-slider";
4-
import React, { FC, useContext, useState, useMemo } from "react";
4+
import React, { FC, useContext, useState, useMemo, useEffect } from "react";
55
import { FaTimes, FaUndo } from "react-icons/fa";
66
import { FaGear, FaNetworkWired } from "react-icons/fa6";
77
import { VscSettings } from "react-icons/vsc";
@@ -38,6 +38,21 @@ const Settings: FC = () => {
3838
const maxLabelSize = typeof navState.maxLabelSize === "number" ? navState.maxLabelSize : DEFAULT_LABEL_SIZE;
3939
const labelThresholdRatio =
4040
typeof navState.labelThresholdRatio === "number" ? navState.labelThresholdRatio : DEFAULT_LABEL_THRESHOLD;
41+
// Local UI state for smoother sliders
42+
const [localMinLabelSize, setLocalMinLabelSize] = useState<number>(minLabelSize);
43+
const [localMaxLabelSize, setLocalMaxLabelSize] = useState<number>(maxLabelSize);
44+
const [localLabelThresholdRatio, setLocalLabelThresholdRatio] = useState<number>(labelThresholdRatio);
45+
46+
// Keep local slider values in sync if navState changes elsewhere
47+
useEffect(() => {
48+
setLocalMinLabelSize(minLabelSize);
49+
}, [minLabelSize]);
50+
useEffect(() => {
51+
setLocalMaxLabelSize(maxLabelSize);
52+
}, [maxLabelSize]);
53+
useEffect(() => {
54+
setLocalLabelThresholdRatio(labelThresholdRatio);
55+
}, [labelThresholdRatio]);
4156

4257
const { fields, fieldsIndex } = data;
4358

@@ -170,21 +185,27 @@ const Settings: FC = () => {
170185
<div className="pb-3">
171186
<Slider
172187
range
173-
value={[minLabelSize, maxLabelSize]}
188+
value={[localMinLabelSize, localMaxLabelSize]}
174189
min={MIN_LABEL_SIZE}
175190
max={MAX_LABEL_SIZE}
176191
step={LABEL_SIZE_STEP}
177192
marks={{
178193
[MIN_LABEL_SIZE]: MIN_LABEL_SIZE,
179194
[MAX_LABEL_SIZE]: MAX_LABEL_SIZE,
180-
[minLabelSize]: minLabelSize,
181-
[maxLabelSize]: maxLabelSize,
195+
[localMinLabelSize]: localMinLabelSize,
196+
[localMaxLabelSize]: localMaxLabelSize,
182197
}}
183198
onChange={
184-
(([minLabelSize, maxLabelSize]: number[]) => {
185-
setNavState({ ...navState, minLabelSize, maxLabelSize });
199+
(([minValue, maxValue]: number[]) => {
200+
setLocalMinLabelSize(minValue);
201+
setLocalMaxLabelSize(maxValue);
186202
}) as SliderProps["onChange"]
187203
}
204+
onAfterChange={
205+
(([minValue, maxValue]: number[]) => {
206+
setNavState({ ...navState, minLabelSize: minValue, maxLabelSize: maxValue });
207+
}) as SliderProps["onAfterChange"]
208+
}
188209
// Styles:
189210
{...RANGE_STYLE}
190211
/>
@@ -279,7 +300,7 @@ const Settings: FC = () => {
279300
</h3>
280301
<div className="pb-3">
281302
<Slider
282-
value={labelThresholdRatio}
303+
value={localLabelThresholdRatio}
283304
min={MIN_LABEL_THRESHOLD}
284305
max={MAX_LABEL_THRESHOLD}
285306
step={LABEL_THRESHOLD_STEP}
@@ -300,6 +321,8 @@ const Settings: FC = () => {
300321
}}
301322
onChange={
302323
((v: number) => {
324+
setLocalLabelThresholdRatio(v);
325+
// Update graph in real-time for better responsiveness
303326
setNavState({ ...navState, labelThresholdRatio: v });
304327
}) as SliderProps["onChange"]
305328
}

0 commit comments

Comments
 (0)