-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes #1423. Details: - Adds (un)?register(Node|Edge)Program methods - Updates handleSettingsUpdate so that it can take an oldSettings input, and check when programs are updated - Updates updateSetting to use setSetting internally - Updates setSetting to give handleSettingsUpdate an oldSettings input - Adds some unit tests for settings management
- Loading branch information
Showing
2 changed files
with
160 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Graph from "graphology"; | ||
import Sigma from "sigma"; | ||
import { NodePointProgram } from "sigma/rendering"; | ||
import { createElement } from "sigma/utils"; | ||
import { afterEach, beforeEach, describe, expect, test } from "vitest"; | ||
|
||
interface SigmaTestContext { | ||
sigma: Sigma; | ||
} | ||
|
||
beforeEach<SigmaTestContext>(async (context) => { | ||
const graph = new Graph(); | ||
graph.addNode("a", { type: "circle", x: 0, y: 0 }); | ||
graph.addNode("b", { type: "circle", x: 10, y: 10 }); | ||
graph.addEdge("a", "b", { type: "arrow" }); | ||
const container = createElement("div", { width: "100px", height: "100px" }); | ||
document.body.append(container); | ||
context.sigma = new Sigma(graph, container); | ||
}); | ||
|
||
afterEach<SigmaTestContext>(async ({ sigma }) => { | ||
sigma.kill(); | ||
sigma.getContainer().remove(); | ||
}); | ||
|
||
describe("Sigma settings management", () => { | ||
test<SigmaTestContext>("it should refresh when settings are updated", async ({ sigma }) => { | ||
let count = 0; | ||
sigma.on("beforeRender", () => count++); | ||
|
||
expect(count).toEqual(0); | ||
sigma.setSetting("minEdgeThickness", 10); | ||
await new Promise((resolve) => window.setTimeout(resolve, 0)); | ||
|
||
expect(count).toEqual(1); | ||
}); | ||
|
||
test<SigmaTestContext>("it should update programs when they're updated", ({ sigma }) => { | ||
sigma.setSetting("nodeProgramClasses", { point: NodePointProgram }); | ||
expect(() => sigma.refresh()).toThrow(); | ||
|
||
const graph = sigma.getGraph(); | ||
graph.forEachNode((node) => graph.setNodeAttribute(node, "type", "point")); | ||
expect(() => sigma.refresh()).not.toThrow(); | ||
}); | ||
}); |