-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor stories: Destroy Cosmos when switching stories
- Loading branch information
Showing
9 changed files
with
84 additions
and
56 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
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
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,21 @@ | ||
import { Graph } from '@cosmograph/cosmos' | ||
import type { StoryObj } from '@storybook/html' | ||
import { CosmosStoryProps } from '@/graph/stories/create-cosmos' | ||
|
||
export type Story = StoryObj<CosmosStoryProps & { graph: Graph }>; | ||
|
||
export const createStory: (storyFunction: () => { | ||
graph: Graph; | ||
div: HTMLDivElement; | ||
}) => Story = (storyFunction) => ({ | ||
async beforeEach (d): Promise<() => void> { | ||
return (): void => { | ||
d.args.graph?.destroy() | ||
} | ||
}, | ||
render: (args): HTMLDivElement => { | ||
const story = storyFunction() | ||
args.graph = story.graph | ||
return story.div | ||
}, | ||
}) |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Graph } from '@cosmograph/cosmos' | ||
import { createCosmos } from '../create-cosmos' | ||
import { generateMeshData } from '../generate-mesh-data' | ||
|
||
export const FullMeshStory = (): HTMLDivElement => { | ||
export const FullMeshStory = (): { graph: Graph; div: HTMLDivElement} => { | ||
const { pointPositions, links, pointColors } = generateMeshData(40, 30, 15, 1.0) | ||
const { div } = createCosmos({ | ||
|
||
return createCosmos({ | ||
pointPositions, | ||
links, | ||
pointColors, | ||
}) | ||
|
||
return div | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Graph } from '@cosmograph/cosmos' | ||
import { createCosmos } from '../create-cosmos' | ||
import { generateMeshData } from '../generate-mesh-data' | ||
|
||
export const MeshWithHolesStory = (): HTMLDivElement => { | ||
export const MeshWithHolesStory = (): { graph: Graph; div: HTMLDivElement} => { | ||
const { pointPositions, links, pointColors } = generateMeshData(40, 80, 15, 0.8) | ||
const { div } = createCosmos({ | ||
|
||
return createCosmos({ | ||
pointPositions, | ||
links, | ||
pointColors, | ||
}) | ||
|
||
return div | ||
} |