Skip to content
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

feat(sankey): add @visx/sankey #1880

Merged
merged 29 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f235e4e
initialize package
jacksonhardaker Sep 25, 2024
6a0fc55
add `Sankey` component
jacksonhardaker Sep 25, 2024
f6b1495
add exports
jacksonhardaker Sep 25, 2024
eacc1e9
add default color
jacksonhardaker Sep 25, 2024
ad0e4c4
add docs page
jacksonhardaker Sep 25, 2024
4a36269
fix package
jacksonhardaker Sep 25, 2024
afd0826
fix import and tsconfig
jacksonhardaker Sep 25, 2024
c1ee24d
extract to types
jacksonhardaker Sep 25, 2024
560120d
add example
jacksonhardaker Sep 25, 2024
5ea7cfd
change version to 1.0.0
jacksonhardaker Sep 26, 2024
ff3d5c7
add to visx-visx
jacksonhardaker Sep 26, 2024
dc8a980
pin version
jacksonhardaker Sep 26, 2024
31d4d6e
add controls to sankey example
jacksonhardaker Sep 26, 2024
5affdce
add sankey tile
jacksonhardaker Sep 26, 2024
726ea17
add styles to example
jacksonhardaker Sep 26, 2024
71208f7
add example tile to docs page
jacksonhardaker Sep 26, 2024
057267a
add usage to readme
jacksonhardaker Sep 26, 2024
70546d6
remove console.log
jacksonhardaker Sep 26, 2024
dd8595b
add class names
jacksonhardaker Sep 26, 2024
8a2e81a
add tests
jacksonhardaker Sep 27, 2024
0cd4c44
fix readme
jacksonhardaker Sep 27, 2024
1c4b2d2
add tooltip to example
jacksonhardaker Sep 27, 2024
2fe3b62
update references
jacksonhardaker Sep 30, 2024
979dbec
pin d3-shape version d3-sankey dep
jacksonhardaker Sep 30, 2024
c9068b8
revert automatically applied demo tsconfig changes
jacksonhardaker Oct 2, 2024
ff039e1
remove newline
jacksonhardaker Oct 2, 2024
73eaace
build sizes
jacksonhardaker Oct 2, 2024
71649a3
remove console.log
jacksonhardaker Nov 6, 2024
be8b3df
format
jacksonhardaker Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add styles to example
  • Loading branch information
jacksonhardaker committed Sep 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 726ea173fd8b9adf96c84311200b69651f2c5950
9 changes: 8 additions & 1 deletion packages/visx-demo/src/components/Gallery/SankeyTile.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React from 'react';
import Sankey, { SankeyDemoProps } from '../../sandboxes/visx-sankey/Example';
import Sankey, { SankeyDemoProps, background, color } from '../../sandboxes/visx-sankey/Example';
import GalleryTile from '../GalleryTile';

export { default as packageJson } from '../../sandboxes/visx-sankey/package.json';

const tileStyles = { background };
const detailsStyles = { color };
const exampleProps = { showControls: false };

export default function SankeyTile() {
return (
<GalleryTile<SankeyDemoProps>
title="Sankey"
description="<Sankey.Sankey />"
exampleProps={exampleProps}
exampleRenderer={Sankey}
exampleUrl="/sankey"
tileStyles={tileStyles}
detailsStyles={detailsStyles}
/>
);
}
103 changes: 67 additions & 36 deletions packages/visx-demo/src/sandboxes/visx-sankey/Example.tsx
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ console.log({ energy });

const controlStyles = { fontSize: 10 };

export const background = '#84dccf';
export const color = '#392f5a';

type NodeDatum = { name: string };
type LinkDatum = {};

@@ -16,58 +19,86 @@ const nodeAlignments = {
sankeyRight,
} as const;

const defaultMargin = { top: 10, left: 10, right: 10, bottom: 10 };

export type SankeyDemoProps = {
width: number;
height: number;
showControls?: boolean;
margin?: { top: number; right: number; bottom: number; left: number };
};

export default function SankeyDemo({ width, height }) {
export default function SankeyDemo({
width,
height,
showControls = true,
margin = defaultMargin,
}: SankeyDemoProps) {
const xMax = width - margin.left - margin.right;
const yMax = height - margin.top - margin.bottom;

const [nodeAlignment, setTileMethod] = useState<keyof typeof nodeAlignments>('sankeyCenter');
const [nodePadding, setNodePadding] = useState(10);
const [nodeWidth, setNodeWidth] = useState(10);

if (width < 10) return null;

return (
<div>
<div style={controlStyles}>
<label>
node alignment{' '}
<select
onClick={(e) => e.stopPropagation()}
onChange={(e) => setTileMethod(e.target.value as keyof typeof nodeAlignments)}
value={nodeAlignment}
>
{Object.keys(nodeAlignments).map((alignment) => (
<option key={alignment} value={alignment}>
{alignment}
</option>
))}
</select>
</label>{' '}
<label>
node padding{' '}
<input
type="number"
value={nodePadding}
onChange={(e) => setNodePadding(Number(e.target.value))}
/>
</label>{' '}
<label>
node width{' '}
<input
type="number"
value={nodeWidth}
onChange={(e) => setNodeWidth(Number(e.target.value))}
/>
</label>
</div>
<div>
<div style={{}}>
{showControls && (
<div style={controlStyles}>
<label>
node alignment{' '}
<select
onClick={(e) => e.stopPropagation()}
onChange={(e) => setTileMethod(e.target.value as keyof typeof nodeAlignments)}
value={nodeAlignment}
>
{Object.keys(nodeAlignments).map((alignment) => (
<option key={alignment} value={alignment}>
{alignment}
</option>
))}
</select>
</label>{' '}
<label>
node padding{' '}
<input
type="number"
value={nodePadding}
onChange={(e) => setNodePadding(Number(e.target.value))}
/>
</label>{' '}
<label>
node width{' '}
<input
type="number"
value={nodeWidth}
onChange={(e) => setNodeWidth(Number(e.target.value))}
/>
</label>
</div>
)}
<div
style={{
background,
padding: `${margin.top}px ${margin.right}px ${margin.bottom}px ${margin.left}px`,
borderRadius: 5,
}}
>
<svg width={width} height={height}>
<Sankey<NodeDatum, LinkDatum>
root={energy}
nodeWidth={nodeWidth}
size={[width, height]}
size={[xMax, yMax]}
nodePadding={nodePadding}
nodeAlign={nodeAlignments[nodeAlignment]}
nodeProps={{
fill: color,
}}
linkProps={{
stroke: color,
}}
/>
</svg>
</div>