Skip to content

Commit

Permalink
[storybook] Refines StoryBook site
Browse files Browse the repository at this point in the history
This commit breaks a lot of stories permalinks. They are supposed to be
fixed within sigma.js resources, but might break somewhere else.

Details:
- Upgrades all StoryBook dependencies
- Adds simple documentation homepage as a story
- Reorganizes all stories
- Moves onStoryDown outside the stories, to get less noise in the
  visible stories codesources
- Refines settings, to hide toolbar, only show the "Code" addon, and get
  it more readable by default
- Cleans a lot of unused addons and settings
- Fixes all StoryBook permalinks from READMEs and documentation website
  • Loading branch information
jacomyal committed Sep 25, 2024
1 parent 40c4ed7 commit 7ae0567
Show file tree
Hide file tree
Showing 122 changed files with 755 additions and 4,096 deletions.
4,050 changes: 384 additions & 3,666 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/edge-curve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It also exports:
- `EdgeCurvedArrowProgram`, a program with defaults settings adapted to render edges as curved arrows
- `createEdgeCurveProgram`, the factory to build a `CustomEdgeCurveProgram` with customized settings
- `DEFAULT_EDGE_CURVATURE`, the default curvature value for edges
- `indexParallelEdgesIndex`, a utility function to find parallel edges, and help adapt their `curvature` for display (see the [dedicated example](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/edge-curve/parallel-edges.ts) to see how it works)
- `indexParallelEdgesIndex`, a utility function to find parallel edges, and help adapt their `curvature` for display (see the [dedicated example](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/edge-curve/parallel-edges.ts) to see how it works)

## How to use

Expand All @@ -36,4 +36,4 @@ const sigma = new Sigma(graph, container, {
});
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/edge-curve) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/edge-curve) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/layer-leaflet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ const sigma = new Sigma(graph, container);
bindLeafletLayer(sigma);
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/layer-leaflet) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/layer-leaflet) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/layer-maplibre/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ const sigma = new Sigma(graph, container);
bindMaplibreLayer(sigma);
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/layer-maplibre) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/layer-maplibre) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/layer-webgl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ const renderer = new Sigma(graph, container);
bindWebGLLayer("metaballs", renderer, createContoursProgram(graph.nodes()));
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/layer-webgl) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/layer-webgl) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/node-border/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ const sigma = new Sigma(graph, container, {
});
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/node-border) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/node-border) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/node-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const sigma = new Sigma(graph, container, {
});
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/node-image) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/node-image) for more advanced examples.

## Factory options

Expand Down
2 changes: 1 addition & 1 deletion packages/node-piechart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ const sigma = new Sigma(graph, container, {
});
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/node-piechart) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/node-piechart) for more advanced examples.
2 changes: 1 addition & 1 deletion packages/node-square/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ const sigma = new Sigma(graph, container, {
});
```

Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/node-square) for more advanced examples.
Please check the related [Storybook](https://github.com/jacomyal/sigma.js/tree/main/packages/storybook/stories/3-additional-packages/node-square) for more advanced examples.
9 changes: 2 additions & 7 deletions packages/storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import { mergeConfig } from "vite";

/** @type { import('@storybook/html-vite').StorybookConfig } */
const config: StorybookConfig = {
stories: ["../stories/**/stories.ts", "../../**/src/**/*.mdx", "../../**/src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
stories: ["../stories/**/*.mdx", "../stories/**/stories.ts"],
addons: [
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@storybook/addon-interactions"),
{ name: "@storybook/addon-essentials", options: { actions: false, controls: false } },
getAbsolutePath("@storybook/addon-storysource"),
],
framework: getAbsolutePath("@storybook/html-vite"),
typescript: {
check: true,
},
docs: {
autodocs: "tag",
},
core: {
disableTelemetry: true,
},
Expand Down
8 changes: 8 additions & 0 deletions packages/storybook/.storybook/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ document.body.append(image);

addons.setConfig({
theme,
showToolbar: false,
panelPosition: "bottom",
bottomPanelHeight: 380,
sidebar: {
renderLabel(item) {
return item.name.replace(/--/g, "/");
},
},
});
9 changes: 0 additions & 9 deletions packages/storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ const forceReloadDecorator: Preview["decorators"] = (storyFn, context) => {

const preview: Preview = {
decorators: [forceReloadDecorator],
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
2 changes: 1 addition & 1 deletion packages/storybook/.storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create } from "@storybook/theming/create";
import { create } from "@storybook/theming";

export default create({
base: "light",
Expand Down
16 changes: 8 additions & 8 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@storybook/addon-essentials": "^8.0.0",
"@storybook/addon-interactions": "^8.0.0",
"@storybook/addon-links": "^8.0.0",
"@storybook/addon-storysource": "^8.0.0",
"@storybook/html": "^8.0.0",
"@storybook/html-vite": "^8.0.0",
"@storybook/web-components": "^8.0.0",
"storybook": "^8.0.0"
"@storybook/addon-essentials": "^8.3.3",
"@storybook/addon-storysource": "^8.3.3",
"@storybook/html": "^8.3.3",
"@storybook/html-vite": "^8.3.3",
"@storybook/manager-api": "^8.3.3",
"@storybook/theming": "^8.3.3",
"@storybook/web-components": "^8.3.3",
"storybook": "^8.3.3"
},
"scripts": {
"start": "storybook dev -p 6006",
Expand Down
37 changes: 37 additions & 0 deletions packages/storybook/stories/0-docs/introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Meta } from "@storybook/addon-docs";

<Meta title="Introduction" />

![Sigma.js](https://raw.githubusercontent.com/jacomyal/sigma.js/main/packages/website/static/img/logo-sigma-text.png)

**[Website](https://www.sigmajs.org/)** | **[Documentation](https://www.sigmajs.org/docs)** | **[GitHub](https://github.com/jacomyal/sigma.js)** | <strong><a rel="me" href="https://vis.social/@sigmajs">Mastodon</a></strong>

---

This Storybook is designed to help you explore the different features and use cases of sigma.js by showcasing various scenarios. Each story displays the full source code below, allowing you to easily reference and implement these examples in your own projects.

## Core Library

### Features showcases

This section showcases basic scenarios that demonstrate the fundamental features of sigma.js. If you're just getting started, this is a great place to explore and understand the core functionalities.

### Advanced Use Cases

For more advanced use cases, this section delves deeper into sigma.js capabilities. Here, you'll find stories that highlight more complex scenarios and techniques, ideal for experienced users looking to extend sigma.js further.

## Satellite Packages

There are multiple features of sigma.js that are exposed from additional packages. The list of these packages is available [on NPM](https://www.npmjs.com/org/sigma). This section presents stories specific to these additional packages.

---

## Getting Started

You can use the sidebar to navigate the stories.

And if you don't know where to start, here are some cherry-picked entry points:

- [I come from Gephi and I want to display my GEXF graph](./?path=/story/load-gexf-file--story)
- [I have some CSV data and I want to render a network of connections from that file](./?path=/story/csv-to-network-map--story)
- [I have some geo-localized network dataset and I want to render it hover a map background](./?path=/story/sigma-layer-maplibre--story)
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Graph from "graphology";
import { parse } from "graphology-gexf/browser";
import Sigma from "sigma";

import { onStoryDown } from "../utils";

export default () => {
let renderer: Sigma | null = null;

Expand All @@ -27,10 +25,10 @@ export default () => {
const zoomResetBtn = document.getElementById("zoom-reset") as HTMLButtonElement;
const labelsThresholdRange = document.getElementById("labels-threshold") as HTMLInputElement;

// Instanciate sigma:
// Instantiate sigma:
renderer = new Sigma(graph, container, {
minCameraRatio: 0.1,
maxCameraRatio: 10,
minCameraRatio: 0.08,
maxCameraRatio: 3,
});
const camera = renderer.getCamera();

Expand All @@ -54,7 +52,7 @@ export default () => {
labelsThresholdRange.value = renderer.getSetting("labelRenderedSizeThreshold") + "";
});

onStoryDown(() => {
return () => {
renderer?.kill();
});
};
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Meta, StoryObj } from "@storybook/web-components";

import { wrapStory } from "../../utils";
import play from "./index";
import template from "./index.html?raw";
import source from "./index?raw";

const meta: Meta = {
id: "load-gexf-file",
title: "Examples",
title: "Core library/Features showcases",
};
export default meta;

Expand All @@ -15,7 +16,7 @@ type Story = StoryObj;
export const story: Story = {
name: "Load GEXF file",
render: () => template,
play,
play: wrapStory(play),
args: {},
parameters: {
storySource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Graph from "graphology";
import Sigma from "sigma";
import { MouseCoords } from "sigma/types";

import data from "../_data/data.json";
import { onStoryDown } from "../utils";
import data from "../../_data/data.json";

export default () => {
const container = document.getElementById("sigma-container") as HTMLElement;
Expand Down Expand Up @@ -84,7 +83,7 @@ export default () => {
});
});

onStoryDown(() => {
return () => {
renderer.kill();
});
};
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Meta, StoryObj } from "@storybook/web-components";

import { wrapStory } from "../../utils";
import play from "./index";
import template from "./index.html?raw";
import source from "./index?raw";

const meta: Meta = {
id: "events",
title: "Examples",
title: "Core library/Features showcases",
};
export default meta;

Expand All @@ -15,7 +16,7 @@ type Story = StoryObj;
export const story: Story = {
name: "Events",
render: () => template,
play,
play: wrapStory(play),
args: {},
parameters: {
storySource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Sigma from "sigma";
import { PlainObject } from "sigma/types";
import { animateNodes } from "sigma/utils";

import data from "../_data/data.json";
import { onStoryDown } from "../utils";
import data from "../../_data/data.json";

export default () => {
// Initialize the graph object with data
Expand Down Expand Up @@ -119,7 +118,7 @@ export default () => {
/** instantiate sigma into the container **/
const renderer = new Sigma(graph, container);

onStoryDown(() => {
return () => {
renderer.kill();
});
};
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Meta, StoryObj } from "@storybook/web-components";

import { wrapStory } from "../../utils";
import play from "./index";
import template from "./index.html?raw";
import source from "./index?raw";

const meta: Meta = {
id: "layouts",
title: "Examples",
title: "Core library/Features showcases",
};
export default meta;

Expand All @@ -15,7 +16,7 @@ type Story = StoryObj;
export const story: Story = {
name: "Layouts example",
render: () => template,
play,
play: wrapStory(play),
args: {},
parameters: {
storySource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Graph from "graphology";
import Sigma from "sigma";
import { Coordinates, EdgeDisplayData, NodeDisplayData } from "sigma/types";

import data from "../_data/data.json";
import { onStoryDown } from "../utils";
import data from "../../_data/data.json";

export default () => {
// Retrieve some useful DOM elements:
Expand Down Expand Up @@ -178,7 +177,7 @@ export default () => {
return res;
});

onStoryDown(() => {
return () => {
renderer.kill();
});
};
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Meta, StoryObj } from "@storybook/web-components";

import { wrapStory } from "../../utils";
import play from "./index";
import template from "./index.html?raw";
import source from "./index?raw";

const meta: Meta = {
id: "use-reducers",
title: "Examples",
title: "Core library/Features showcases",
};
export default meta;

Expand All @@ -15,7 +16,7 @@ type Story = StoryObj;
export const story: Story = {
name: "Use node and edge reducers",
render: () => template,
play,
play: wrapStory(play),
args: {},
parameters: {
storySource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Graph from "graphology";
import ForceSupervisor from "graphology-layout-force/worker";
import Sigma from "sigma";

import { onStoryDown } from "../utils";
import NodeGradientProgram from "./node-gradient";

export default () => {
Expand Down Expand Up @@ -76,8 +75,8 @@ export default () => {
const layout = new ForceSupervisor(graph);
layout.start();

onStoryDown(() => {
return () => {
layout.kill();
renderer.kill();
});
};
};
Loading

0 comments on commit 7ae0567

Please sign in to comment.