-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Sankey and SunburstChart components #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rick-hup
wants to merge
19
commits into
main
Choose a base branch
from
feat/sankey-chart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1d219db
chore(deps): add d3-sankey for Sankey chart
rick-hup 3444637
feat(sankey): add d3-sankey layout helper
rick-hup cac677a
feat(sankey): add Sankey chart with nodes and links
rick-hup 5120c90
test(sankey): cover #node and #link slots and nodeWidth
rick-hup f33e321
test(sankey): cover node/link click event types
rick-hup 399107e
test(sankey): cover tooltip integration for nodes and links
rick-hup a7728df
docs(sankey): add 5 Storybook stories
rick-hup cd54a91
chore(play): add Sankey playground page
rick-hup ae01b3c
docs(sankey): add Sankey chart docs page and demo
rick-hup c9c9fab
feat(sunburst): add layout utility with d3-hierarchy partition
rick-hup 62d993a
feat(sunburst): add SunburstChart component with tooltip support
rick-hup 575c23f
feat(sunburst): export SunburstChart from public API
rick-hup 01f1029
docs(sunburst): add 5 Storybook stories
rick-hup 3b93c19
chore(play): add Sunburst playground page
rick-hup 85291a1
fix(types): widen selectActiveLabel return type to match combineActiv…
rick-hup 4197d16
fix(docs): correct Sankey props table defaults and descriptions
rick-hup 2153b6f
fix(sankey): use linkStroke prop for link path stroke color
rick-hup f0d01e3
fix(sunburst): wire ringPadding and padding props into layout calcula…
rick-hup 1061467
fix(sunburst): use original data indices for tooltipIndex, not sorted…
rick-hup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ dist | |
| .claude/* | ||
| .agents/* | ||
| tasks/ | ||
|
|
||
| .omx/* | ||
| # Docs site generated files | ||
| docs/.nuxt | ||
| docs/.data | ||
|
|
||
56 changes: 56 additions & 0 deletions
56
docs/app/charts/sankey-charts/custom-node-sankey-chart.vue
This file contains hidden or 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,56 @@ | ||
| <script setup> | ||
| import { Sankey, Tooltip } from 'vccs' | ||
|
|
||
| const data = { | ||
| nodes: [ | ||
| { name: 'Coal' }, | ||
| { name: 'Gas' }, | ||
| { name: 'Solar' }, | ||
| { name: 'Electricity' }, | ||
| { name: 'Heat' }, | ||
| { name: 'Industry' }, | ||
| { name: 'Homes' }, | ||
| ], | ||
| links: [ | ||
| { source: 0, target: 3, value: 30 }, | ||
| { source: 1, target: 3, value: 20 }, | ||
| { source: 2, target: 3, value: 15 }, | ||
| { source: 0, target: 4, value: 10 }, | ||
| { source: 1, target: 4, value: 8 }, | ||
| { source: 3, target: 5, value: 35 }, | ||
| { source: 3, target: 6, value: 30 }, | ||
| { source: 4, target: 6, value: 18 }, | ||
| ], | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <Sankey | ||
| :data="data" | ||
| :width="730" | ||
| :height="360" | ||
| link-fill="#06b6d4" | ||
| > | ||
| <template #node="{ x, y, width, height, payload }"> | ||
| <g> | ||
| <rect | ||
| :x="x" | ||
| :y="y" | ||
| :width="width" | ||
| :height="height" | ||
| fill="#f59e0b" | ||
| /> | ||
| <text | ||
| :x="x + width + 6" | ||
| :y="y + height / 2" | ||
| font-size="12" | ||
| dominant-baseline="middle" | ||
| fill="currentColor" | ||
| > | ||
| {{ payload.name }} | ||
| </text> | ||
| </g> | ||
| </template> | ||
| <Tooltip :cursor="false" /> | ||
| </Sankey> | ||
| </template> |
This file contains hidden or 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,34 @@ | ||
| <script setup> | ||
| import { Sankey, Tooltip } from 'vccs' | ||
|
|
||
| const data = { | ||
| nodes: [ | ||
| { name: 'Visit' }, | ||
| { name: 'Sign up' }, | ||
| { name: 'Onboarding' }, | ||
| { name: 'Active' }, | ||
| { name: 'Drop off' }, | ||
| { name: 'Churned' }, | ||
| ], | ||
| links: [ | ||
| { source: 0, target: 1, value: 800 }, | ||
| { source: 0, target: 4, value: 200 }, | ||
| { source: 1, target: 2, value: 600 }, | ||
| { source: 1, target: 4, value: 200 }, | ||
| { source: 2, target: 3, value: 450 }, | ||
| { source: 2, target: 5, value: 150 }, | ||
| ], | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <Sankey | ||
| :data="data" | ||
| :width="730" | ||
| :height="360" | ||
| node-fill="#f97316" | ||
| link-fill="#14b8a6" | ||
| > | ||
| <Tooltip :cursor="false" /> | ||
| </Sankey> | ||
| </template> |
This file contains hidden or 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,66 @@ | ||
| --- | ||
| title: Sankey | ||
| description: Flow diagrams showing the magnitude of flow between nodes | ||
| navigation: | ||
| icon: i-lucide-git-fork | ||
| --- | ||
|
|
||
| Sankey diagrams visualize flow quantities between a set of nodes, where the width of each link is proportional to its value. They are ideal for showing energy flows, user journeys, budget allocations, and similar many-to-many relationships. | ||
|
|
||
| ## Simple Sankey | ||
|
|
||
| A basic Sankey diagram with nodes and weighted links. The layout is computed by `d3-sankey`. | ||
|
|
||
| ::chart-demo{name="Simple Sankey" description="A Sankey diagram of a user funnel flow." src="sankey-charts/simple-sankey-chart"} | ||
| :: | ||
|
|
||
| ## Custom Node | ||
|
|
||
| Use the `#node` slot to fully customize how each node is rendered. The slot receives coordinates, dimensions, and the node payload. | ||
|
|
||
| ::chart-demo{name="Custom Node Sankey" description="A Sankey diagram with custom node rendering showing labels." src="sankey-charts/custom-node-sankey-chart"} | ||
| :: | ||
|
|
||
| ## Sankey props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| |------|------|---------|-------------| | ||
| | `data` | `{ nodes, links }` | **required** | Graph data with `nodes` and `links` arrays. Links use numeric `source`/`target` indices and a `value`. | | ||
| | `width` | `number` | **required** | Chart width in pixels | | ||
| | `height` | `number` | **required** | Chart height in pixels | | ||
| | `nodeWidth` | `number` | `10` | Width of each node rectangle | | ||
| | `nodePadding` | `number` | `10` | Vertical padding between nodes in the same column | | ||
| | `iterations` | `number` | `32` | Number of d3-sankey layout iterations for relaxation | | ||
| | `margin` | `{ top, right, bottom, left }` | `{ top: 5, right: 5, bottom: 5, left: 5 }` | Chart margins | | ||
| | `nodeFill` | `string` | `'#0088fe'` | Default fill color for node rectangles | | ||
| | `nodeStroke` | `string` | `'#fff'` | Stroke color for node rectangles | | ||
| | `linkFill` | `string` | `'#0088fe'` | Default fill color for link paths | | ||
| | `linkStroke` | `string` | `'none'` | Stroke color for link paths | | ||
| | `isAnimationActive` | `boolean` | `true` | Enable entrance animation | | ||
| | `transition` | `AnimationOptions` | `{ duration: 0.8, ease: 'easeOut' }` | Animation timing (motion-v) | | ||
|
|
||
| ## Slots | ||
|
|
||
| | Slot | Props | Description | | ||
| |------|-------|-------------| | ||
| | `#node` | `{ x, y, width, height, index, payload }` | Custom node rendering | | ||
| | `#link` | `{ d, sourceX, targetX, sourceY, targetY, linkWidth, index, payload }` | Custom link path rendering | | ||
| | `default` | — | Place `<Tooltip>` or other child components here. | | ||
|
|
||
| ## Data structure | ||
|
|
||
| ```ts | ||
| const data = { | ||
| nodes: [ | ||
| { name: 'A' }, | ||
| { name: 'B' }, | ||
| { name: 'C' }, | ||
| ], | ||
| links: [ | ||
| { source: 0, target: 1, value: 10 }, | ||
| { source: 1, target: 2, value: 6 }, | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| `source` and `target` are numeric indices into the `nodes` array. `value` determines the link width. Both nodes and links support `<Tooltip>` hover interaction. | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.