Skip to content

Repository files navigation

Graph (@webwriter/graph@1.0.2)

License: MIT | Version: 1.0.2

Visualize graphs, simulate common graph algorithms (Kruskal, Dijkstra, BFS, DFS, etc.), and record your own graph animations.

Snippets

Snippets are examples and templates using the package's widgets.

NameImport Path
People@webwriter/graph/snippets/people.html
Dijkstra@webwriter/graph/snippets/dijkstra.html
Kruskal@webwriter/graph/snippets/kruskal.html

WwGraph (<ww-graph>)

Usage

Use with a CDN (e.g. jsdelivr):

<linkhref="https://cdn.jsdelivr.net/npm/@webwriter/graph/widgets/ww-graph.css" rel="stylesheet"><scripttype="module" src="https://cdn.jsdelivr.net/npm/@webwriter/graph/widgets/ww-graph.js"></script><ww-graph></ww-graph>

Or use with a bundler (e.g. Vite):

npm install @webwriter/graph
<linkhref="@webwriter/graph/widgets/ww-graph.css" rel="stylesheet"><scripttype="module" src="@webwriter/graph/widgets/ww-graph.js"></script><ww-graph></ww-graph>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
graph (graph)iGraphThe graph data, containing labeled nodes and weighted links.-
animation (animation)AnimationStep[]Array of animation steps. Each step can color nodes/links, set node subtexts, or reset previous steps.[]
permissions (permissions)PermissionsTypeControls which features are available to the user (editing, algorithm execution, animation playback).{ general: { play: true, playbackRate: true, }, edit: { enabled: true, addNode: true, addEdge: true, editNode: true, editEdge: true, delNode: true, delEdge: true, }, algorithm: { enabled: true, executable: algorithms.map((a) => a.id), }, animation: { enabled: true, editStep: true, delStep: true, }, }

Fields including properties and attributes define the current state of the widget and offer customization options.

Methods

NameDescriptionParameters
animateStepApplies a single animation step to the graph immediately.step: AnimationStep, signal: AbortSignal
previewStepShows the final state of a single animation step without playing the transition animation. Used when editing steps.step: AnimationStep
resetGraphResets the graph SVG layout by briefly clearing and restoring the graph data, triggering a re-render.-
executeAlgorithmRuns the currently selected algorithm on the graph and starts playing the resulting animation.-
startAnimationStarts or resumes the animation playback from the current position.-

Methods allow programmatic access to the widget.

Editing config

NameValue

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public slots, events, custom CSS properties, or CSS parts.


Generated with @webwriter/build@1.9.1

About

Visualize graphs, simulate common graph algorithms (Kruskal, Dijkstra, BFS, DFS, etc.), and record your own graph animations.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages