Skip to content

Commit

Permalink
[storybook] Updates layer-webgl stories so that they showcase layers …
Browse files Browse the repository at this point in the history
…by default
  • Loading branch information
jacomyal committed Jul 19, 2024
1 parent 9431e83 commit 6c516a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 10 additions & 4 deletions packages/storybook/stories/layer-webgl/contour-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default () => {
checkboxesContainer.style.bottom = "10px";
document.body.append(checkboxesContainer);

communitiesArray.forEach((community) => {
communitiesArray.forEach((community, i) => {
const id = `cb-${community}`;
const checkboxContainer = document.createElement("div");
checkboxContainer.innerHTML += `
Expand All @@ -51,8 +51,7 @@ export default () => {
const checkbox = checkboxesContainer.querySelector(`#${id}`) as HTMLInputElement;

let clean: null | (() => void) = null;

checkbox.addEventListener("click", () => {
const toggle = () => {
if (clean) {
clean();
clean = null;
Expand All @@ -69,7 +68,14 @@ export default () => {
),
);
}
});
};

checkbox.addEventListener("change", toggle);

if (!i) {
checkbox.checked = true;
toggle();
}
});

onStoryDown(() => {
Expand Down
14 changes: 9 additions & 5 deletions packages/storybook/stories/layer-webgl/metaballs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default () => {
louvain.assign(graph, { nodeCommunityAttribute: "community" });
const communities = new Set<string>();
graph.forEachNode((_, attrs) => communities.add(attrs.community));
const communitiesArray = Array.from(communities);

// Retrieve some useful DOM elements:
const container = document.getElementById("sigma-container") as HTMLElement;
Expand All @@ -30,17 +31,15 @@ export default () => {
const select = document.createElement("select");
select.innerHTML =
`<option value="">No community</option>` +
Array.from(communities)
.map((str) => `<option value="${str}">Community ${str}</option>`)
.join("");
communitiesArray.map((str) => `<option value="${str}">Community ${str}</option>`).join("");
select.style.position = "absolute";
select.style.right = "10px";
select.style.bottom = "10px";
document.body.append(select);

// Handle metaballs layer:
let cleanWebGLLayer: null | (() => void) = null;
select.addEventListener("change", () => {
const checkSelectedOption = () => {
if (cleanWebGLLayer) cleanWebGLLayer();

const community = select.value;
Expand All @@ -53,7 +52,12 @@ export default () => {
} else {
cleanWebGLLayer = null;
}
});
};
select.addEventListener("change", checkSelectedOption);

// Select first community:
select.value = communitiesArray[0];
checkSelectedOption();
});

onStoryDown(() => {
Expand Down

0 comments on commit 6c516a0

Please sign in to comment.