@epilot/spark-ui 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/accordion.cjs +3 -6
- package/dist/components/accordion.cjs.map +1 -1
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +3 -6
- package/dist/components/accordion.js.map +1 -1
- package/dist/components/alert-dialog.cjs +2 -5
- package/dist/components/alert-dialog.cjs.map +1 -1
- package/dist/components/alert-dialog.js +2 -5
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/bar-chart.cjs +1 -1
- package/dist/components/bar-chart.js +2 -2
- package/dist/components/battery-progress-row.cjs +14 -11
- package/dist/components/battery-progress-row.cjs.map +1 -1
- package/dist/components/battery-progress-row.d.cts +2 -10
- package/dist/components/battery-progress-row.d.ts +2 -10
- package/dist/components/battery-progress-row.js +14 -11
- package/dist/components/battery-progress-row.js.map +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.cjs +6 -6
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.d.cts +3 -3
- package/dist/components/button.d.ts +3 -3
- package/dist/components/button.js +6 -6
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.cjs +4 -5
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.js +4 -5
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.cjs +18 -14
- package/dist/components/callout.cjs.map +1 -1
- package/dist/components/callout.d.cts +10 -4
- package/dist/components/callout.d.ts +10 -4
- package/dist/components/callout.js +18 -15
- package/dist/components/callout.js.map +1 -1
- package/dist/components/device-card.cjs +2 -6
- package/dist/components/device-card.cjs.map +1 -1
- package/dist/components/device-card.d.cts +3 -3
- package/dist/components/device-card.d.ts +3 -3
- package/dist/components/device-card.js +2 -6
- package/dist/components/device-card.js.map +1 -1
- package/dist/components/dialog.cjs +2 -5
- package/dist/components/dialog.cjs.map +1 -1
- package/dist/components/dialog.js +2 -5
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/dropdown-menu.cjs +4 -13
- package/dist/components/dropdown-menu.cjs.map +1 -1
- package/dist/components/dropdown-menu.js +4 -13
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/empty-state.cjs +5 -5
- package/dist/components/empty-state.cjs.map +1 -1
- package/dist/components/empty-state.d.cts +3 -3
- package/dist/components/empty-state.d.ts +3 -3
- package/dist/components/empty-state.js +5 -5
- package/dist/components/empty-state.js.map +1 -1
- package/dist/components/icon.cjs +2 -3
- package/dist/components/icon.cjs.map +1 -1
- package/dist/components/icon.d.cts +0 -3
- package/dist/components/icon.d.ts +0 -3
- package/dist/components/icon.js +2 -3
- package/dist/components/icon.js.map +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/input-otp.cjs +1 -1
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input.cjs +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/line-chart.cjs +3 -3
- package/dist/components/line-chart.js +4 -4
- package/dist/components/list.cjs.map +1 -1
- package/dist/components/list.js.map +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/message-scroller.cjs +3 -3
- package/dist/components/message-scroller.cjs.map +1 -1
- package/dist/components/message-scroller.js +3 -3
- package/dist/components/message-scroller.js.map +1 -1
- package/dist/components/metering-row.cjs +3 -3
- package/dist/components/metering-row.cjs.map +1 -1
- package/dist/components/metering-row.d.cts +3 -3
- package/dist/components/metering-row.d.ts +3 -3
- package/dist/components/metering-row.js +3 -3
- package/dist/components/metering-row.js.map +1 -1
- package/dist/components/money-saved-block.cjs +2 -5
- package/dist/components/money-saved-block.cjs.map +1 -1
- package/dist/components/money-saved-block.js +2 -5
- package/dist/components/money-saved-block.js.map +1 -1
- package/dist/components/on-off-button.cjs +2 -5
- package/dist/components/on-off-button.cjs.map +1 -1
- package/dist/components/on-off-button.js +2 -5
- package/dist/components/on-off-button.js.map +1 -1
- package/dist/components/page-header.cjs +2 -2
- package/dist/components/page-header.cjs.map +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/page-header.js +2 -2
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/period-tabs.cjs +3 -6
- package/dist/components/period-tabs.cjs.map +1 -1
- package/dist/components/period-tabs.js +3 -6
- package/dist/components/period-tabs.js.map +1 -1
- package/dist/components/pill.cjs +2 -5
- package/dist/components/pill.cjs.map +1 -1
- package/dist/components/pill.js +2 -5
- package/dist/components/pill.js.map +1 -1
- package/dist/components/power-history-chart.cjs +3 -3
- package/dist/components/power-history-chart.js +4 -4
- package/dist/components/power-history.cjs +1 -1
- package/dist/components/power-history.js +1 -1
- package/dist/components/power-network.cjs +2 -5
- package/dist/components/power-network.cjs.map +1 -1
- package/dist/components/power-network.js +2 -5
- package/dist/components/power-network.js.map +1 -1
- package/dist/components/sankey-chart.cjs +56 -71
- package/dist/components/sankey-chart.cjs.map +1 -1
- package/dist/components/sankey-chart.js +56 -71
- package/dist/components/sankey-chart.js.map +1 -1
- package/dist/components/schedule-list.cjs +3 -9
- package/dist/components/schedule-list.cjs.map +1 -1
- package/dist/components/schedule-list.js +3 -9
- package/dist/components/schedule-list.js.map +1 -1
- package/dist/components/select.cjs +6 -18
- package/dist/components/select.cjs.map +1 -1
- package/dist/components/select.js +6 -18
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.cjs +2 -5
- package/dist/components/sheet.cjs.map +1 -1
- package/dist/components/sheet.js +2 -5
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/slider.cjs +9 -3
- package/dist/components/slider.cjs.map +1 -1
- package/dist/components/slider.js +9 -3
- package/dist/components/slider.js.map +1 -1
- package/dist/components/smart-toggle-button.cjs +2 -5
- package/dist/components/smart-toggle-button.cjs.map +1 -1
- package/dist/components/smart-toggle-button.js +2 -5
- package/dist/components/smart-toggle-button.js.map +1 -1
- package/dist/components/solar-forecast-chart.cjs +8 -9
- package/dist/components/solar-forecast-chart.cjs.map +1 -1
- package/dist/components/solar-forecast-chart.d.cts +2 -2
- package/dist/components/solar-forecast-chart.d.ts +2 -2
- package/dist/components/solar-forecast-chart.js +9 -10
- package/dist/components/solar-forecast-chart.js.map +1 -1
- package/dist/components/stepper.cjs +3 -9
- package/dist/components/stepper.cjs.map +1 -1
- package/dist/components/stepper.js +3 -9
- package/dist/components/stepper.js.map +1 -1
- package/dist/components/tabs.cjs +2 -2
- package/dist/components/tabs.cjs.map +1 -1
- package/dist/components/tabs.js +2 -2
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/textarea.cjs +1 -1
- package/dist/components/textarea.js +1 -1
- package/dist/components/toast.cjs +9 -12
- package/dist/components/toast.cjs.map +1 -1
- package/dist/components/toast.js +9 -12
- package/dist/components/toast.js.map +1 -1
- package/dist/components/tooltip.cjs +2 -5
- package/dist/components/tooltip.cjs.map +1 -1
- package/dist/components/tooltip.js +2 -5
- package/dist/components/tooltip.js.map +1 -1
- package/dist/styles/index.css +0 -2
- package/package.json +3 -10
- package/dist/icons/index.cjs +0 -7
- package/dist/icons/index.d.cts +0 -4
- package/dist/icons/index.d.ts +0 -4
- package/dist/icons/index.js +0 -3
- package/dist/icons/material-symbol.cjs +0 -106
- package/dist/icons/material-symbol.cjs.map +0 -1
- package/dist/icons/material-symbol.d.cts +0 -21
- package/dist/icons/material-symbol.d.ts +0 -21
- package/dist/icons/material-symbol.js +0 -102
- package/dist/icons/material-symbol.js.map +0 -1
- package/dist/styles/material-symbol.css +0 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"power-network.js","names":[],"sources":["../../src/components/power-network.tsx"],"sourcesContent":["import {\n createContext,\n type ReactElement,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { useReducedMotion } from '../hooks/use-reduced-motion'\nimport { MaterialSymbol } from '../icons/material-symbol'\nimport { cn } from '../utils/cn'\nimport NumberFlow from './number-flow'\nimport { Skeleton } from './skeleton'\nimport { SectionTitle } from './typography'\n\n// --- Variants -----------------------------------------------------------\n\nexport type PowerSourceVariant = 'grid' | 'solar' | 'battery' | 'neutral'\n\ninterface SourceVariantStyles {\n activeClassName: string\n flowStroke: string\n initialDashGap: number\n}\n\nconst SOURCE_VARIANTS: Record<PowerSourceVariant, SourceVariantStyles> = {\n grid: {\n activeClassName: 'border-blue-a9 bg-blue-a1 shadow-blue-a4',\n flowStroke: 'var(--blue-11)',\n initialDashGap: 10,\n },\n solar: {\n activeClassName: 'border-orange-a9 bg-orange-a1 shadow-orange-a3',\n flowStroke: 'var(--orange-a9)',\n initialDashGap: 5,\n },\n battery: {\n activeClassName: 'border-green-a9 bg-green-a1 shadow-green-a3',\n flowStroke: 'var(--green-a9)',\n initialDashGap: 7,\n },\n neutral: {\n activeClassName: 'border-gray-a9 bg-gray-a1 shadow-gray-a3',\n flowStroke: 'var(--neutral-a9)',\n initialDashGap: 9,\n },\n}\n\nconst DEVICE_FLOW_STROKE = 'var(--neutral-a9)'\nconst DEVICE_INITIAL_DASH_GAP = 9\n\n// Drawn under every connector and revealed when nothing flows, so a 0 W node\n// still reads as wired up and online rather than disconnected.\nconst IDLE_STROKE = 'var(--neutral-a6)'\nconst SKELETON_STROKE = 'var(--neutral-a6)'\nconst STROKE_WIDTH = 2\nconst STRAIGHT_TOLERANCE_PX = 3\nconst SOURCE_HOME_OFFSET_STEP_PX = 10\nconst DEVICE_HOME_OFFSET_STEP_PX = 10\n\n// --- Flow animation parameters ------------------------------------------\n\nconst FLOW_DASH_SOLID = 1\nconst FLOW_GAP_MAX = 14\nconst FLOW_GAP_MIN = 5\nconst FLOW_SPEED_MIN = 10\nconst FLOW_SPEED_MAX = 56\nconst FLOW_SMOOTHING = 5.5\n\ninterface FlowVisual {\n gap: number\n speed: number\n opacity: number\n}\n\ninterface FlowAnimationState extends FlowVisual {\n offset: number\n}\n\n// --- Context ------------------------------------------------------------\n\ntype NodeKind = 'source' | 'device' | 'home'\n\ninterface RegisteredNode {\n id: string\n kind: NodeKind\n variant?: PowerSourceVariant\n watts: number\n element: HTMLDivElement | null\n}\n\ninterface PowerNetworkContextValue {\n loading: boolean\n register: (node: RegisteredNode) => void\n unregister: (id: string) => void\n totalSourceWatts: number\n}\n\nconst PowerNetworkContext = createContext<PowerNetworkContextValue | null>(null)\n\nfunction usePowerNetwork(): PowerNetworkContextValue {\n const ctx = useContext(PowerNetworkContext)\n if (!ctx) {\n throw new Error(\n 'Power network sub-components must be used inside <PowerNetworkDiagram>.',\n )\n }\n return ctx\n}\n\n// --- Geometry helpers ---------------------------------------------------\n\ninterface Point {\n x: number\n y: number\n}\n\nfunction anchorTop(rect: DOMRect, containerRect: DOMRect): Point {\n return {\n x: rect.left + rect.width / 2 - containerRect.left,\n y: rect.top - containerRect.top,\n }\n}\n\nfunction anchorBottom(rect: DOMRect, containerRect: DOMRect): Point {\n return {\n x: rect.left + rect.width / 2 - containerRect.left,\n y: rect.bottom - containerRect.top,\n }\n}\n\nfunction buildAdaptivePath(from: Point, to: Point): string {\n if (Math.abs(from.x - to.x) < STRAIGHT_TOLERANCE_PX) {\n return `M ${from.x} ${from.y} L ${to.x} ${to.y}`\n }\n const dy = to.y - from.y\n const c1y = from.y + dy * 0.56\n const c2y = to.y - dy * 0.58\n return `M ${from.x} ${from.y} C ${from.x} ${c1y} ${to.x} ${c2y} ${to.x} ${to.y}`\n}\n\n// --- PowerNetworkDiagram ------------------------------------------------\n\nexport interface PowerNetworkDiagramProps {\n title?: string\n loading?: boolean\n className?: string\n children?: ReactNode\n}\n\ninterface ConnectorPath {\n id: string\n d: string\n kind: NodeKind\n variant?: PowerSourceVariant\n reversed: boolean\n}\n\nfunction connectorPathsEqual(a: ConnectorPath[], b: ConnectorPath[]): boolean {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n const ap = a[i]\n const bp = b[i]\n if (!ap || !bp) return false\n if (\n ap.id !== bp.id ||\n ap.d !== bp.d ||\n ap.variant !== bp.variant ||\n ap.kind !== bp.kind ||\n ap.reversed !== bp.reversed\n ) {\n return false\n }\n }\n return true\n}\n\nexport function PowerNetworkDiagram({\n title,\n loading = false,\n className,\n children,\n}: PowerNetworkDiagramProps): ReactElement {\n const containerRef = useRef<HTMLDivElement>(null)\n const reducedMotion = useReducedMotion()\n const [nodes, setNodes] = useState<Map<string, RegisteredNode>>(\n () => new Map(),\n )\n const [connectorPaths, setConnectorPaths] = useState<ConnectorPath[]>([])\n const connectorPathsRef = useRef<ConnectorPath[]>([])\n const flowPathRefs = useRef<Record<string, SVGPathElement | null>>({})\n const idlePathRefs = useRef<Record<string, SVGPathElement | null>>({})\n const currentFlowVisualsRef = useRef<Record<string, FlowAnimationState>>({})\n const targetFlowVisualsRef = useRef<Record<string, FlowVisual>>({})\n\n const register = useCallback((node: RegisteredNode) => {\n setNodes((prev) => {\n const existing = prev.get(node.id)\n if (\n existing &&\n existing.kind === node.kind &&\n existing.variant === node.variant &&\n existing.watts === node.watts &&\n existing.element === node.element\n ) {\n return prev\n }\n const next = new Map(prev)\n next.set(node.id, node)\n return next\n })\n }, [])\n\n const unregister = useCallback((id: string) => {\n setNodes((prev) => {\n if (!prev.has(id)) return prev\n const next = new Map(prev)\n next.delete(id)\n return next\n })\n }, [])\n\n const totalSourceWatts = useMemo(() => {\n let total = 0\n for (const node of nodes.values()) {\n if (node.kind === 'source') total += node.watts\n }\n return total\n }, [nodes])\n\n useEffect(() => {\n const container = containerRef.current\n if (!container) return\n\n let homeNode: RegisteredNode | undefined\n const sources: RegisteredNode[] = []\n const devices: RegisteredNode[] = []\n for (const node of nodes.values()) {\n if (node.kind === 'home') {\n homeNode = node\n } else if (node.element) {\n if (node.kind === 'source') sources.push(node)\n else devices.push(node)\n }\n }\n\n const updatePaths = () => {\n if (!homeNode || !homeNode.element) {\n setConnectorPaths((prev) => (prev.length === 0 ? prev : []))\n return\n }\n const containerRect = container.getBoundingClientRect()\n const homeRect = homeNode.element.getBoundingClientRect()\n const homeTop = anchorTop(homeRect, containerRect)\n const homeBottom = anchorBottom(homeRect, containerRect)\n const next: ConnectorPath[] = []\n\n const sourceCount = sources.length\n const deviceCount = devices.length\n\n sources.forEach((source, index) => {\n if (!source.element) return\n const from = anchorBottom(\n source.element.getBoundingClientRect(),\n containerRect,\n )\n const offsetX =\n SOURCE_HOME_OFFSET_STEP_PX * (index - (sourceCount - 1) / 2)\n const to = { x: homeTop.x + offsetX, y: homeTop.y }\n next.push({\n id: source.id,\n d: buildAdaptivePath(from, to),\n kind: 'source',\n variant: source.variant,\n reversed: source.watts < 0,\n })\n })\n\n devices.forEach((device, index) => {\n if (!device.element) return\n const to = anchorTop(\n device.element.getBoundingClientRect(),\n containerRect,\n )\n const offsetX =\n DEVICE_HOME_OFFSET_STEP_PX * (index - (deviceCount - 1) / 2)\n const from = { x: homeBottom.x + offsetX, y: homeBottom.y }\n next.push({\n id: device.id,\n d: buildAdaptivePath(from, to),\n kind: 'device',\n reversed: false,\n })\n })\n\n setConnectorPaths((prev) =>\n connectorPathsEqual(prev, next) ? prev : next,\n )\n }\n\n updatePaths()\n\n const resizeObserver = new ResizeObserver(updatePaths)\n resizeObserver.observe(container)\n for (const node of nodes.values()) {\n if (node.element) resizeObserver.observe(node.element)\n }\n window.addEventListener('resize', updatePaths)\n\n return () => {\n resizeObserver.disconnect()\n window.removeEventListener('resize', updatePaths)\n }\n }, [nodes])\n\n useEffect(() => {\n connectorPathsRef.current = connectorPaths\n }, [connectorPaths])\n\n useEffect(() => {\n const targets: Record<string, FlowVisual> = {}\n const homeWatts = totalSourceWatts\n for (const node of nodes.values()) {\n if (node.kind === 'home') continue\n const watts = node.watts\n const relative =\n homeWatts > 0\n ? Math.max(0, Math.min(1, Math.abs(watts) / homeWatts))\n : 0\n targets[node.id] = {\n gap: FLOW_GAP_MAX - (FLOW_GAP_MAX - FLOW_GAP_MIN) * relative,\n speed: FLOW_SPEED_MIN + (FLOW_SPEED_MAX - FLOW_SPEED_MIN) * relative,\n opacity: Math.abs(watts) > 0 ? 1 : 0,\n }\n }\n targetFlowVisualsRef.current = targets\n }, [nodes, totalSourceWatts])\n\n useEffect(() => {\n if (loading || reducedMotion) return\n let frameId = 0\n let lastFrameTime = performance.now()\n\n const animate = (now: number) => {\n const deltaSeconds = Math.max(0.001, (now - lastFrameTime) / 1000)\n lastFrameTime = now\n const smoothing = 1 - Math.exp(-FLOW_SMOOTHING * deltaSeconds)\n\n for (const connectorPath of connectorPathsRef.current) {\n const id = connectorPath.id\n const target = targetFlowVisualsRef.current[id]\n const pathElement = flowPathRefs.current[id]\n if (!target || !pathElement) continue\n\n const current = currentFlowVisualsRef.current[id] ?? {\n gap: target.gap,\n offset: 0,\n speed: target.speed,\n opacity: target.opacity,\n }\n\n current.gap += (target.gap - current.gap) * smoothing\n current.speed += (target.speed - current.speed) * smoothing\n current.opacity += (target.opacity - current.opacity) * smoothing\n\n const dashCycle = FLOW_DASH_SOLID + Math.max(0.001, current.gap)\n const direction = connectorPath.reversed ? 1 : -1\n const nextOffset =\n current.offset + direction * current.speed * deltaSeconds\n const wrappedOffset = ((nextOffset % dashCycle) + dashCycle) % dashCycle\n current.offset = wrappedOffset - dashCycle\n\n pathElement.setAttribute(\n 'stroke-dasharray',\n `${FLOW_DASH_SOLID} ${current.gap.toFixed(3)}`,\n )\n pathElement.setAttribute('stroke-dashoffset', current.offset.toFixed(3))\n pathElement.setAttribute('opacity', current.opacity.toFixed(3))\n idlePathRefs.current[id]?.setAttribute(\n 'opacity',\n (1 - current.opacity).toFixed(3),\n )\n\n currentFlowVisualsRef.current[id] = current\n }\n\n frameId = window.requestAnimationFrame(animate)\n }\n\n frameId = window.requestAnimationFrame(animate)\n return () => window.cancelAnimationFrame(frameId)\n }, [loading, reducedMotion])\n\n // Reduced motion: freeze the marching dashes but keep the dash gap tracking\n // live magnitude, and let opacity fade in/out via the CSS transition on each\n // flow path (see the flow <path> style below).\n useEffect(() => {\n if (loading || !reducedMotion) return\n for (const connectorPath of connectorPathsRef.current) {\n const target = targetFlowVisualsRef.current[connectorPath.id]\n const pathElement = flowPathRefs.current[connectorPath.id]\n if (!target || !pathElement) continue\n pathElement.setAttribute(\n 'stroke-dasharray',\n `${FLOW_DASH_SOLID} ${target.gap.toFixed(3)}`,\n )\n pathElement.setAttribute('stroke-dashoffset', '0')\n pathElement.setAttribute('opacity', target.opacity.toFixed(3))\n idlePathRefs.current[connectorPath.id]?.setAttribute(\n 'opacity',\n (1 - target.opacity).toFixed(3),\n )\n }\n }, [loading, reducedMotion, nodes, totalSourceWatts])\n\n const contextValue = useMemo<PowerNetworkContextValue>(\n () => ({ loading, register, unregister, totalSourceWatts }),\n [loading, register, unregister, totalSourceWatts],\n )\n\n return (\n <PowerNetworkContext.Provider value={contextValue}>\n <div\n ref={containerRef}\n className={cn('@container relative flex flex-col', className)}\n >\n {title && <SectionTitle>{title}</SectionTitle>}\n {connectorPaths.length > 0 && (\n <svg className=\"pointer-events-none absolute inset-0 size-full\">\n {connectorPaths.map((path) => {\n if (loading) {\n return (\n <path\n key={path.id}\n d={path.d}\n fill=\"none\"\n stroke={SKELETON_STROKE}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n />\n )\n }\n\n const flowStroke =\n path.kind === 'source' && path.variant\n ? SOURCE_VARIANTS[path.variant].flowStroke\n : DEVICE_FLOW_STROKE\n const initialDashGap =\n path.kind === 'source' && path.variant\n ? SOURCE_VARIANTS[path.variant].initialDashGap\n : DEVICE_INITIAL_DASH_GAP\n\n return (\n <g key={path.id}>\n <path\n d={path.d}\n fill=\"none\"\n stroke={IDLE_STROKE}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n ref={(el) => {\n idlePathRefs.current[path.id] = el\n }}\n opacity={1}\n style={\n reducedMotion\n ? { transition: 'opacity 300ms ease' }\n : undefined\n }\n />\n <path\n d={path.d}\n fill=\"none\"\n stroke={flowStroke}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n ref={(el) => {\n flowPathRefs.current[path.id] = el\n }}\n strokeDasharray={`${FLOW_DASH_SOLID} ${initialDashGap}`}\n strokeDashoffset={0}\n opacity={0}\n style={\n reducedMotion\n ? { transition: 'opacity 300ms ease' }\n : undefined\n }\n />\n </g>\n )\n })}\n </svg>\n )}\n <div className=\"flex flex-col gap-y-14\">{children}</div>\n </div>\n </PowerNetworkContext.Provider>\n )\n}\n\n// --- Row containers -----------------------------------------------------\n\nexport interface PowerNetworkRowProps {\n className?: string\n children?: ReactNode\n}\n\nexport function PowerNetworkSources({\n className,\n children,\n}: PowerNetworkRowProps): ReactElement {\n return (\n <div\n className={cn(\n 'flex items-center justify-center gap-[clamp(1.5rem,10cqw,4rem)]',\n className,\n )}\n >\n {children}\n </div>\n )\n}\n\nexport function PowerNetworkDevices({\n className,\n children,\n}: PowerNetworkRowProps): ReactElement {\n return (\n <div\n className={cn(\n 'flex items-center justify-center gap-[clamp(1.5rem,10cqw,4rem)]',\n className,\n )}\n >\n {children}\n </div>\n )\n}\n\n// --- PowerSource --------------------------------------------------------\n\nexport interface PowerSourceProps {\n id?: string\n watts: number\n icon: ReactNode\n variant?: PowerSourceVariant\n className?: string\n /**\n * Optional 0–100 progress (e.g. battery SoC). When set, a thin colored arc\n * is drawn around the icon circle as a non-intrusive indicator.\n */\n progress?: number\n /** Keeps the variant colors at 0 W, for a source that is online but idle. */\n standby?: boolean\n}\n\nexport function PowerSource({\n id: idProp,\n watts,\n icon,\n variant = 'neutral',\n className,\n progress,\n standby = false,\n}: PowerSourceProps): ReactElement {\n const autoId = useId()\n const id = idProp ?? autoId\n const { register, unregister, loading } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n\n useEffect(() => {\n if (!element) return\n register({ id, kind: 'source', variant, watts, element })\n }, [element, register, id, variant, watts])\n\n useEffect(() => {\n return () => unregister(id)\n }, [unregister, id])\n\n if (loading) {\n return <SourceSkeleton anchorRef={setElement} />\n }\n\n const isActive = watts !== 0\n const isColored = isActive || standby\n const variantStyles = SOURCE_VARIANTS[variant]\n const clampedProgress =\n progress == null ? null : Math.max(0, Math.min(100, progress))\n const showRing = clampedProgress != null\n const RING_RADIUS = 48\n const RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS\n const ringDash =\n clampedProgress != null ? (clampedProgress / 100) * RING_CIRCUMFERENCE : 0\n\n return (\n <div\n className={cn(\n 'flex flex-col items-center justify-center gap-1 transition-opacity duration-500',\n !isColored && 'opacity-45',\n className,\n )}\n >\n <NumberFlow\n value={Math.abs(watts)}\n suffix=\"W\"\n className=\"mt-1 text-sm leading-none font-medium\"\n />\n <div\n ref={setElement}\n className={cn(\n 'relative flex aspect-square items-center justify-center rounded-full border p-4 shadow-sm',\n isColored\n ? variantStyles.activeClassName\n : 'border-gray bg-gray-a3 shadow-gray-a4 saturate-0',\n )}\n >\n {showRing && (\n <svg\n className=\"pointer-events-none absolute inset-0 size-full -rotate-90\"\n viewBox=\"0 0 100 100\"\n aria-hidden=\"true\"\n >\n <circle\n cx=\"50\"\n cy=\"50\"\n r={RING_RADIUS}\n fill=\"none\"\n stroke={variantStyles.flowStroke}\n strokeWidth=\"4\"\n strokeLinecap=\"round\"\n strokeDasharray={`${ringDash} ${RING_CIRCUMFERENCE}`}\n opacity={isColored ? 1 : 0.5}\n />\n </svg>\n )}\n {icon}\n </div>\n </div>\n )\n}\n\nfunction SourceSkeleton({\n anchorRef,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n}): ReactElement {\n return (\n <div className=\"flex flex-col items-center justify-center gap-1\">\n <Skeleton className=\"h-3.5 w-10\" />\n <div\n ref={anchorRef}\n className=\"flex aspect-square animate-pulse items-center justify-center rounded-full border border-gray bg-base-gray-soft p-4 motion-reduce:animate-none\"\n >\n <div className=\"size-7\" />\n </div>\n </div>\n )\n}\n\n// --- PowerDevice --------------------------------------------------------\n\nexport interface PowerDeviceProps {\n id?: string\n watts: number\n icon: ReactNode\n className?: string\n}\n\nexport function PowerDevice({\n id: idProp,\n watts,\n icon,\n className,\n}: PowerDeviceProps): ReactElement {\n const autoId = useId()\n const id = idProp ?? autoId\n const { register, unregister, loading } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n\n useEffect(() => {\n if (!element) return\n register({ id, kind: 'device', watts, element })\n }, [element, register, id, watts])\n\n useEffect(() => {\n return () => unregister(id)\n }, [unregister, id])\n\n if (loading) {\n return <DeviceSkeleton anchorRef={setElement} />\n }\n\n return (\n <div\n className={cn(\n 'flex flex-col items-center justify-center gap-1',\n className,\n )}\n >\n <div\n ref={setElement}\n className=\"flex aspect-square items-center justify-center rounded-full border border-gray bg-gray-a1 p-4\"\n >\n {icon}\n </div>\n <NumberFlow\n value={watts}\n suffix=\"W\"\n className=\"text-sm font-medium tabular-nums\"\n />\n </div>\n )\n}\n\nfunction DeviceSkeleton({\n anchorRef,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n}): ReactElement {\n return (\n <div className=\"flex flex-col items-center justify-center gap-1\">\n <div\n ref={anchorRef}\n className=\"flex aspect-square animate-pulse items-center justify-center rounded-full border border-gray bg-base-gray-soft p-4 motion-reduce:animate-none\"\n >\n <div className=\"size-5\" />\n </div>\n <Skeleton className=\"h-3.5 w-10\" />\n </div>\n )\n}\n\n// --- PowerNetworkHome ---------------------------------------------------\n\nexport interface PowerNetworkHomeProps {\n /** Override total power. Defaults to the sum of registered source watts. */\n watts?: number\n /** Self-sufficiency ratio in 0..1. Renders a green ring when provided. */\n autarky?: number\n className?: string\n}\n\nexport function PowerNetworkHome({\n watts,\n autarky,\n className,\n}: PowerNetworkHomeProps): ReactElement {\n const autoId = useId()\n const { register, unregister, loading, totalSourceWatts } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const effectiveWatts = watts ?? totalSourceWatts\n\n useEffect(() => {\n if (!element) return\n register({ id: autoId, kind: 'home', watts: effectiveWatts, element })\n }, [element, register, autoId, effectiveWatts])\n\n useEffect(() => {\n return () => unregister(autoId)\n }, [unregister, autoId])\n\n if (loading) {\n return <HomeSkeleton anchorRef={setElement} className={className} />\n }\n\n return (\n <HomeSection\n anchorRef={setElement}\n autarky={autarky ?? null}\n watts={effectiveWatts}\n className={className}\n />\n )\n}\n\nfunction HomeSection({\n anchorRef,\n autarky,\n className,\n watts,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n autarky: number | null\n className?: string\n watts: number\n}): ReactElement {\n const reducedMotion = useReducedMotion()\n const targetAutarky =\n autarky == null ? 0 : Math.max(0, Math.min(100, autarky * 100))\n const [animatedAutarky, setAnimatedAutarky] = useState(targetAutarky)\n const animatedAutarkyRef = useRef(animatedAutarky)\n const nodeSize = 78\n const ringStrokeWidth = 2\n const radius = (nodeSize - ringStrokeWidth) / 2\n const circumference = 2 * Math.PI * radius\n const progressLength = (animatedAutarky / 100) * circumference\n\n useEffect(() => {\n animatedAutarkyRef.current = animatedAutarky\n }, [animatedAutarky])\n\n useEffect(() => {\n if (reducedMotion) {\n animatedAutarkyRef.current = targetAutarky\n setAnimatedAutarky(targetAutarky)\n return\n }\n\n let frameId = 0\n let lastTime = performance.now()\n\n const animate = (now: number) => {\n const deltaSeconds = Math.max(0.001, (now - lastTime) / 1000)\n lastTime = now\n const smoothing = 1 - Math.exp(-7 * deltaSeconds)\n const next =\n animatedAutarkyRef.current +\n (targetAutarky - animatedAutarkyRef.current) * smoothing\n\n animatedAutarkyRef.current = next\n setAnimatedAutarky(next)\n\n if (Math.abs(targetAutarky - next) > 0.05) {\n frameId = window.requestAnimationFrame(animate)\n } else {\n animatedAutarkyRef.current = targetAutarky\n setAnimatedAutarky(targetAutarky)\n }\n }\n\n frameId = window.requestAnimationFrame(animate)\n return () => window.cancelAnimationFrame(frameId)\n }, [targetAutarky, reducedMotion])\n\n return (\n <div\n ref={anchorRef}\n className={cn('relative mx-auto size-[78px]', className)}\n >\n {autarky != null && (\n <svg\n className=\"absolute inset-0 size-full -rotate-90\"\n viewBox={`0 0 ${nodeSize} ${nodeSize}`}\n >\n <circle\n cx={nodeSize / 2}\n cy={nodeSize / 2}\n r={radius}\n fill=\"none\"\n stroke=\"var(--neutral-a5)\"\n strokeWidth={ringStrokeWidth}\n />\n {progressLength > 0 && (\n <circle\n cx={nodeSize / 2}\n cy={nodeSize / 2}\n r={radius}\n fill=\"none\"\n stroke=\"var(--green-a9)\"\n strokeLinecap=\"round\"\n strokeWidth={ringStrokeWidth}\n strokeDasharray={`${progressLength} ${circumference}`}\n />\n )}\n </svg>\n )}\n <div className=\"absolute inset-0 flex flex-col items-center justify-center rounded-full border border-gray-a5 shadow-sm shadow-gray-a1\">\n <MaterialSymbol className=\"text-[14px]\" name=\"home\" />\n <NumberFlow\n value={watts}\n suffix=\"W\"\n className=\"mt-1 text-sm leading-none font-medium\"\n />\n </div>\n </div>\n )\n}\n\nfunction HomeSkeleton({\n anchorRef,\n className,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n className?: string\n}): ReactElement {\n return (\n <div\n ref={anchorRef}\n className={cn(\n 'mx-auto size-[78px] animate-pulse rounded-full border border-gray motion-reduce:animate-none',\n className,\n )}\n />\n )\n}\n"],"mappings":";;;;;;;;;;AA6BA,MAAM,kBAAmE;CACvE,MAAM;EACJ,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;CAClB;CACA,OAAO;EACL,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;CAClB;CACA,SAAS;EACP,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;CAClB;CACA,SAAS;EACP,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;CAClB;AACF;AAEA,MAAM,qBAAqB;AAC3B,MAAM,0BAA0B;AAIhC,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AAInC,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,e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,iBAAiB,GAAG,eAAe,GAAG;GACvC,CAAA,CAEA;MAEP,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,oBAAC,gBAAD;IAAgB,WAAU;IAAc,MAAK;GAAQ,CAAA,GACrD,oBAAC,YAAD;IACE,OAAO;IACP,QAAO;IACP,WAAU;GACX,CAAA,CACE;IACF;;AAET;AAEA,SAAS,aAAa,EACpB,WACA,aAIe;CACf,OACE,oBAAC,OAAD;EACE,KAAK;EACL,WAAW,GACT,gGACA,SACF;CACD,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"power-network.js","names":[],"sources":["../../src/components/power-network.tsx"],"sourcesContent":["import { Home } from '@epilot/spark-icons'\nimport {\n createContext,\n type ReactElement,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { useReducedMotion } from '../hooks/use-reduced-motion'\nimport { cn } from '../utils/cn'\nimport NumberFlow from './number-flow'\nimport { Skeleton } from './skeleton'\nimport { SectionTitle } from './typography'\n\n// --- Variants -----------------------------------------------------------\n\nexport type PowerSourceVariant = 'grid' | 'solar' | 'battery' | 'neutral'\n\ninterface SourceVariantStyles {\n activeClassName: string\n flowStroke: string\n initialDashGap: number\n}\n\nconst SOURCE_VARIANTS: Record<PowerSourceVariant, SourceVariantStyles> = {\n grid: {\n activeClassName: 'border-blue-a9 bg-blue-a1 shadow-blue-a4',\n flowStroke: 'var(--blue-11)',\n initialDashGap: 10,\n },\n solar: {\n activeClassName: 'border-orange-a9 bg-orange-a1 shadow-orange-a3',\n flowStroke: 'var(--orange-a9)',\n initialDashGap: 5,\n },\n battery: {\n activeClassName: 'border-green-a9 bg-green-a1 shadow-green-a3',\n flowStroke: 'var(--green-a9)',\n initialDashGap: 7,\n },\n neutral: {\n activeClassName: 'border-gray-a9 bg-gray-a1 shadow-gray-a3',\n flowStroke: 'var(--neutral-a9)',\n initialDashGap: 9,\n },\n}\n\nconst DEVICE_FLOW_STROKE = 'var(--neutral-a9)'\nconst DEVICE_INITIAL_DASH_GAP = 9\n\n// Drawn under every connector and revealed when nothing flows, so a 0 W node\n// still reads as wired up and online rather than disconnected.\nconst IDLE_STROKE = 'var(--neutral-a6)'\nconst SKELETON_STROKE = 'var(--neutral-a6)'\nconst STROKE_WIDTH = 2\nconst STRAIGHT_TOLERANCE_PX = 3\nconst SOURCE_HOME_OFFSET_STEP_PX = 10\nconst DEVICE_HOME_OFFSET_STEP_PX = 10\n\n// --- Flow animation parameters ------------------------------------------\n\nconst FLOW_DASH_SOLID = 1\nconst FLOW_GAP_MAX = 14\nconst FLOW_GAP_MIN = 5\nconst FLOW_SPEED_MIN = 10\nconst FLOW_SPEED_MAX = 56\nconst FLOW_SMOOTHING = 5.5\n\ninterface FlowVisual {\n gap: number\n speed: number\n opacity: number\n}\n\ninterface FlowAnimationState extends FlowVisual {\n offset: number\n}\n\n// --- Context ------------------------------------------------------------\n\ntype NodeKind = 'source' | 'device' | 'home'\n\ninterface RegisteredNode {\n id: string\n kind: NodeKind\n variant?: PowerSourceVariant\n watts: number\n element: HTMLDivElement | null\n}\n\ninterface PowerNetworkContextValue {\n loading: boolean\n register: (node: RegisteredNode) => void\n unregister: (id: string) => void\n totalSourceWatts: number\n}\n\nconst PowerNetworkContext = createContext<PowerNetworkContextValue | null>(null)\n\nfunction usePowerNetwork(): PowerNetworkContextValue {\n const ctx = useContext(PowerNetworkContext)\n if (!ctx) {\n throw new Error(\n 'Power network sub-components must be used inside <PowerNetworkDiagram>.',\n )\n }\n return ctx\n}\n\n// --- Geometry helpers ---------------------------------------------------\n\ninterface Point {\n x: number\n y: number\n}\n\nfunction anchorTop(rect: DOMRect, containerRect: DOMRect): Point {\n return {\n x: rect.left + rect.width / 2 - containerRect.left,\n y: rect.top - containerRect.top,\n }\n}\n\nfunction anchorBottom(rect: DOMRect, containerRect: DOMRect): Point {\n return {\n x: rect.left + rect.width / 2 - containerRect.left,\n y: rect.bottom - containerRect.top,\n }\n}\n\nfunction buildAdaptivePath(from: Point, to: Point): string {\n if (Math.abs(from.x - to.x) < STRAIGHT_TOLERANCE_PX) {\n return `M ${from.x} ${from.y} L ${to.x} ${to.y}`\n }\n const dy = to.y - from.y\n const c1y = from.y + dy * 0.56\n const c2y = to.y - dy * 0.58\n return `M ${from.x} ${from.y} C ${from.x} ${c1y} ${to.x} ${c2y} ${to.x} ${to.y}`\n}\n\n// --- PowerNetworkDiagram ------------------------------------------------\n\nexport interface PowerNetworkDiagramProps {\n title?: string\n loading?: boolean\n className?: string\n children?: ReactNode\n}\n\ninterface ConnectorPath {\n id: string\n d: string\n kind: NodeKind\n variant?: PowerSourceVariant\n reversed: boolean\n}\n\nfunction connectorPathsEqual(a: ConnectorPath[], b: ConnectorPath[]): boolean {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n const ap = a[i]\n const bp = b[i]\n if (!ap || !bp) return false\n if (\n ap.id !== bp.id ||\n ap.d !== bp.d ||\n ap.variant !== bp.variant ||\n ap.kind !== bp.kind ||\n ap.reversed !== bp.reversed\n ) {\n return false\n }\n }\n return true\n}\n\nexport function PowerNetworkDiagram({\n title,\n loading = false,\n className,\n children,\n}: PowerNetworkDiagramProps): ReactElement {\n const containerRef = useRef<HTMLDivElement>(null)\n const reducedMotion = useReducedMotion()\n const [nodes, setNodes] = useState<Map<string, RegisteredNode>>(\n () => new Map(),\n )\n const [connectorPaths, setConnectorPaths] = useState<ConnectorPath[]>([])\n const connectorPathsRef = useRef<ConnectorPath[]>([])\n const flowPathRefs = useRef<Record<string, SVGPathElement | null>>({})\n const idlePathRefs = useRef<Record<string, SVGPathElement | null>>({})\n const currentFlowVisualsRef = useRef<Record<string, FlowAnimationState>>({})\n const targetFlowVisualsRef = useRef<Record<string, FlowVisual>>({})\n\n const register = useCallback((node: RegisteredNode) => {\n setNodes((prev) => {\n const existing = prev.get(node.id)\n if (\n existing &&\n existing.kind === node.kind &&\n existing.variant === node.variant &&\n existing.watts === node.watts &&\n existing.element === node.element\n ) {\n return prev\n }\n const next = new Map(prev)\n next.set(node.id, node)\n return next\n })\n }, [])\n\n const unregister = useCallback((id: string) => {\n setNodes((prev) => {\n if (!prev.has(id)) return prev\n const next = new Map(prev)\n next.delete(id)\n return next\n })\n }, [])\n\n const totalSourceWatts = useMemo(() => {\n let total = 0\n for (const node of nodes.values()) {\n if (node.kind === 'source') total += node.watts\n }\n return total\n }, [nodes])\n\n useEffect(() => {\n const container = containerRef.current\n if (!container) return\n\n let homeNode: RegisteredNode | undefined\n const sources: RegisteredNode[] = []\n const devices: RegisteredNode[] = []\n for (const node of nodes.values()) {\n if (node.kind === 'home') {\n homeNode = node\n } else if (node.element) {\n if (node.kind === 'source') sources.push(node)\n else devices.push(node)\n }\n }\n\n const updatePaths = () => {\n if (!homeNode || !homeNode.element) {\n setConnectorPaths((prev) => (prev.length === 0 ? prev : []))\n return\n }\n const containerRect = container.getBoundingClientRect()\n const homeRect = homeNode.element.getBoundingClientRect()\n const homeTop = anchorTop(homeRect, containerRect)\n const homeBottom = anchorBottom(homeRect, containerRect)\n const next: ConnectorPath[] = []\n\n const sourceCount = sources.length\n const deviceCount = devices.length\n\n sources.forEach((source, index) => {\n if (!source.element) return\n const from = anchorBottom(\n source.element.getBoundingClientRect(),\n containerRect,\n )\n const offsetX =\n SOURCE_HOME_OFFSET_STEP_PX * (index - (sourceCount - 1) / 2)\n const to = { x: homeTop.x + offsetX, y: homeTop.y }\n next.push({\n id: source.id,\n d: buildAdaptivePath(from, to),\n kind: 'source',\n variant: source.variant,\n reversed: source.watts < 0,\n })\n })\n\n devices.forEach((device, index) => {\n if (!device.element) return\n const to = anchorTop(\n device.element.getBoundingClientRect(),\n containerRect,\n )\n const offsetX =\n DEVICE_HOME_OFFSET_STEP_PX * (index - (deviceCount - 1) / 2)\n const from = { x: homeBottom.x + offsetX, y: homeBottom.y }\n next.push({\n id: device.id,\n d: buildAdaptivePath(from, to),\n kind: 'device',\n reversed: false,\n })\n })\n\n setConnectorPaths((prev) =>\n connectorPathsEqual(prev, next) ? prev : next,\n )\n }\n\n updatePaths()\n\n const resizeObserver = new ResizeObserver(updatePaths)\n resizeObserver.observe(container)\n for (const node of nodes.values()) {\n if (node.element) resizeObserver.observe(node.element)\n }\n window.addEventListener('resize', updatePaths)\n\n return () => {\n resizeObserver.disconnect()\n window.removeEventListener('resize', updatePaths)\n }\n }, [nodes])\n\n useEffect(() => {\n connectorPathsRef.current = connectorPaths\n }, [connectorPaths])\n\n useEffect(() => {\n const targets: Record<string, FlowVisual> = {}\n const homeWatts = totalSourceWatts\n for (const node of nodes.values()) {\n if (node.kind === 'home') continue\n const watts = node.watts\n const relative =\n homeWatts > 0\n ? Math.max(0, Math.min(1, Math.abs(watts) / homeWatts))\n : 0\n targets[node.id] = {\n gap: FLOW_GAP_MAX - (FLOW_GAP_MAX - FLOW_GAP_MIN) * relative,\n speed: FLOW_SPEED_MIN + (FLOW_SPEED_MAX - FLOW_SPEED_MIN) * relative,\n opacity: Math.abs(watts) > 0 ? 1 : 0,\n }\n }\n targetFlowVisualsRef.current = targets\n }, [nodes, totalSourceWatts])\n\n useEffect(() => {\n if (loading || reducedMotion) return\n let frameId = 0\n let lastFrameTime = performance.now()\n\n const animate = (now: number) => {\n const deltaSeconds = Math.max(0.001, (now - lastFrameTime) / 1000)\n lastFrameTime = now\n const smoothing = 1 - Math.exp(-FLOW_SMOOTHING * deltaSeconds)\n\n for (const connectorPath of connectorPathsRef.current) {\n const id = connectorPath.id\n const target = targetFlowVisualsRef.current[id]\n const pathElement = flowPathRefs.current[id]\n if (!target || !pathElement) continue\n\n const current = currentFlowVisualsRef.current[id] ?? {\n gap: target.gap,\n offset: 0,\n speed: target.speed,\n opacity: target.opacity,\n }\n\n current.gap += (target.gap - current.gap) * smoothing\n current.speed += (target.speed - current.speed) * smoothing\n current.opacity += (target.opacity - current.opacity) * smoothing\n\n const dashCycle = FLOW_DASH_SOLID + Math.max(0.001, current.gap)\n const direction = connectorPath.reversed ? 1 : -1\n const nextOffset =\n current.offset + direction * current.speed * deltaSeconds\n const wrappedOffset = ((nextOffset % dashCycle) + dashCycle) % dashCycle\n current.offset = wrappedOffset - dashCycle\n\n pathElement.setAttribute(\n 'stroke-dasharray',\n `${FLOW_DASH_SOLID} ${current.gap.toFixed(3)}`,\n )\n pathElement.setAttribute('stroke-dashoffset', current.offset.toFixed(3))\n pathElement.setAttribute('opacity', current.opacity.toFixed(3))\n idlePathRefs.current[id]?.setAttribute(\n 'opacity',\n (1 - current.opacity).toFixed(3),\n )\n\n currentFlowVisualsRef.current[id] = current\n }\n\n frameId = window.requestAnimationFrame(animate)\n }\n\n frameId = window.requestAnimationFrame(animate)\n return () => window.cancelAnimationFrame(frameId)\n }, [loading, reducedMotion])\n\n // Reduced motion: freeze the marching dashes but keep the dash gap tracking\n // live magnitude, and let opacity fade in/out via the CSS transition on each\n // flow path (see the flow <path> style below).\n useEffect(() => {\n if (loading || !reducedMotion) return\n for (const connectorPath of connectorPathsRef.current) {\n const target = targetFlowVisualsRef.current[connectorPath.id]\n const pathElement = flowPathRefs.current[connectorPath.id]\n if (!target || !pathElement) continue\n pathElement.setAttribute(\n 'stroke-dasharray',\n `${FLOW_DASH_SOLID} ${target.gap.toFixed(3)}`,\n )\n pathElement.setAttribute('stroke-dashoffset', '0')\n pathElement.setAttribute('opacity', target.opacity.toFixed(3))\n idlePathRefs.current[connectorPath.id]?.setAttribute(\n 'opacity',\n (1 - target.opacity).toFixed(3),\n )\n }\n }, [loading, reducedMotion, nodes, totalSourceWatts])\n\n const contextValue = useMemo<PowerNetworkContextValue>(\n () => ({ loading, register, unregister, totalSourceWatts }),\n [loading, register, unregister, totalSourceWatts],\n )\n\n return (\n <PowerNetworkContext.Provider value={contextValue}>\n <div\n ref={containerRef}\n className={cn('@container relative flex flex-col', className)}\n >\n {title && <SectionTitle>{title}</SectionTitle>}\n {connectorPaths.length > 0 && (\n <svg className=\"pointer-events-none absolute inset-0 size-full\">\n {connectorPaths.map((path) => {\n if (loading) {\n return (\n <path\n key={path.id}\n d={path.d}\n fill=\"none\"\n stroke={SKELETON_STROKE}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n />\n )\n }\n\n const flowStroke =\n path.kind === 'source' && path.variant\n ? SOURCE_VARIANTS[path.variant].flowStroke\n : DEVICE_FLOW_STROKE\n const initialDashGap =\n path.kind === 'source' && path.variant\n ? SOURCE_VARIANTS[path.variant].initialDashGap\n : DEVICE_INITIAL_DASH_GAP\n\n return (\n <g key={path.id}>\n <path\n d={path.d}\n fill=\"none\"\n stroke={IDLE_STROKE}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n ref={(el) => {\n idlePathRefs.current[path.id] = el\n }}\n opacity={1}\n style={\n reducedMotion\n ? { transition: 'opacity 300ms ease' }\n : undefined\n }\n />\n <path\n d={path.d}\n fill=\"none\"\n stroke={flowStroke}\n strokeWidth={STROKE_WIDTH}\n strokeLinecap=\"round\"\n ref={(el) => {\n flowPathRefs.current[path.id] = el\n }}\n strokeDasharray={`${FLOW_DASH_SOLID} ${initialDashGap}`}\n strokeDashoffset={0}\n opacity={0}\n style={\n reducedMotion\n ? { transition: 'opacity 300ms ease' }\n : undefined\n }\n />\n </g>\n )\n })}\n </svg>\n )}\n <div className=\"flex flex-col gap-y-14\">{children}</div>\n </div>\n </PowerNetworkContext.Provider>\n )\n}\n\n// --- Row containers -----------------------------------------------------\n\nexport interface PowerNetworkRowProps {\n className?: string\n children?: ReactNode\n}\n\nexport function PowerNetworkSources({\n className,\n children,\n}: PowerNetworkRowProps): ReactElement {\n return (\n <div\n className={cn(\n 'flex items-center justify-center gap-[clamp(1.5rem,10cqw,4rem)]',\n className,\n )}\n >\n {children}\n </div>\n )\n}\n\nexport function PowerNetworkDevices({\n className,\n children,\n}: PowerNetworkRowProps): ReactElement {\n return (\n <div\n className={cn(\n 'flex items-center justify-center gap-[clamp(1.5rem,10cqw,4rem)]',\n className,\n )}\n >\n {children}\n </div>\n )\n}\n\n// --- PowerSource --------------------------------------------------------\n\nexport interface PowerSourceProps {\n id?: string\n watts: number\n icon: ReactNode\n variant?: PowerSourceVariant\n className?: string\n /**\n * Optional 0–100 progress (e.g. battery SoC). When set, a thin colored arc\n * is drawn around the icon circle as a non-intrusive indicator.\n */\n progress?: number\n /** Keeps the variant colors at 0 W, for a source that is online but idle. */\n standby?: boolean\n}\n\nexport function PowerSource({\n id: idProp,\n watts,\n icon,\n variant = 'neutral',\n className,\n progress,\n standby = false,\n}: PowerSourceProps): ReactElement {\n const autoId = useId()\n const id = idProp ?? autoId\n const { register, unregister, loading } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n\n useEffect(() => {\n if (!element) return\n register({ id, kind: 'source', variant, watts, element })\n }, [element, register, id, variant, watts])\n\n useEffect(() => {\n return () => unregister(id)\n }, [unregister, id])\n\n if (loading) {\n return <SourceSkeleton anchorRef={setElement} />\n }\n\n const isActive = watts !== 0\n const isColored = isActive || standby\n const variantStyles = SOURCE_VARIANTS[variant]\n const clampedProgress =\n progress == null ? null : Math.max(0, Math.min(100, progress))\n const showRing = clampedProgress != null\n const RING_RADIUS = 48\n const RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS\n const ringDash =\n clampedProgress != null ? (clampedProgress / 100) * RING_CIRCUMFERENCE : 0\n\n return (\n <div\n className={cn(\n 'flex flex-col items-center justify-center gap-1 transition-opacity duration-500',\n !isColored && 'opacity-45',\n className,\n )}\n >\n <NumberFlow\n value={Math.abs(watts)}\n suffix=\"W\"\n className=\"mt-1 text-sm leading-none font-medium\"\n />\n <div\n ref={setElement}\n className={cn(\n 'relative flex aspect-square items-center justify-center rounded-full border p-4 shadow-sm',\n isColored\n ? variantStyles.activeClassName\n : 'border-gray bg-gray-a3 shadow-gray-a4 saturate-0',\n )}\n >\n {showRing && (\n <svg\n className=\"pointer-events-none absolute inset-0 size-full -rotate-90\"\n viewBox=\"0 0 100 100\"\n aria-hidden=\"true\"\n >\n <circle\n cx=\"50\"\n cy=\"50\"\n r={RING_RADIUS}\n fill=\"none\"\n stroke={variantStyles.flowStroke}\n strokeWidth=\"4\"\n strokeLinecap=\"round\"\n strokeDasharray={`${ringDash} ${RING_CIRCUMFERENCE}`}\n opacity={isColored ? 1 : 0.5}\n />\n </svg>\n )}\n {icon}\n </div>\n </div>\n )\n}\n\nfunction SourceSkeleton({\n anchorRef,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n}): ReactElement {\n return (\n <div className=\"flex flex-col items-center justify-center gap-1\">\n <Skeleton className=\"h-3.5 w-10\" />\n <div\n ref={anchorRef}\n className=\"flex aspect-square animate-pulse items-center justify-center rounded-full border border-gray bg-base-gray-soft p-4 motion-reduce:animate-none\"\n >\n <div className=\"size-7\" />\n </div>\n </div>\n )\n}\n\n// --- PowerDevice --------------------------------------------------------\n\nexport interface PowerDeviceProps {\n id?: string\n watts: number\n icon: ReactNode\n className?: string\n}\n\nexport function PowerDevice({\n id: idProp,\n watts,\n icon,\n className,\n}: PowerDeviceProps): ReactElement {\n const autoId = useId()\n const id = idProp ?? autoId\n const { register, unregister, loading } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n\n useEffect(() => {\n if (!element) return\n register({ id, kind: 'device', watts, element })\n }, [element, register, id, watts])\n\n useEffect(() => {\n return () => unregister(id)\n }, [unregister, id])\n\n if (loading) {\n return <DeviceSkeleton anchorRef={setElement} />\n }\n\n return (\n <div\n className={cn(\n 'flex flex-col items-center justify-center gap-1',\n className,\n )}\n >\n <div\n ref={setElement}\n className=\"flex aspect-square items-center justify-center rounded-full border border-gray bg-gray-a1 p-4\"\n >\n {icon}\n </div>\n <NumberFlow\n value={watts}\n suffix=\"W\"\n className=\"text-sm font-medium tabular-nums\"\n />\n </div>\n )\n}\n\nfunction DeviceSkeleton({\n anchorRef,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n}): ReactElement {\n return (\n <div className=\"flex flex-col items-center justify-center gap-1\">\n <div\n ref={anchorRef}\n className=\"flex aspect-square animate-pulse items-center justify-center rounded-full border border-gray bg-base-gray-soft p-4 motion-reduce:animate-none\"\n >\n <div className=\"size-5\" />\n </div>\n <Skeleton className=\"h-3.5 w-10\" />\n </div>\n )\n}\n\n// --- PowerNetworkHome ---------------------------------------------------\n\nexport interface PowerNetworkHomeProps {\n /** Override total power. Defaults to the sum of registered source watts. */\n watts?: number\n /** Self-sufficiency ratio in 0..1. Renders a green ring when provided. */\n autarky?: number\n className?: string\n}\n\nexport function PowerNetworkHome({\n watts,\n autarky,\n className,\n}: PowerNetworkHomeProps): ReactElement {\n const autoId = useId()\n const { register, unregister, loading, totalSourceWatts } = usePowerNetwork()\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const effectiveWatts = watts ?? totalSourceWatts\n\n useEffect(() => {\n if (!element) return\n register({ id: autoId, kind: 'home', watts: effectiveWatts, element })\n }, [element, register, autoId, effectiveWatts])\n\n useEffect(() => {\n return () => unregister(autoId)\n }, [unregister, autoId])\n\n if (loading) {\n return <HomeSkeleton anchorRef={setElement} className={className} />\n }\n\n return (\n <HomeSection\n anchorRef={setElement}\n autarky={autarky ?? null}\n watts={effectiveWatts}\n className={className}\n />\n )\n}\n\nfunction HomeSection({\n anchorRef,\n autarky,\n className,\n watts,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n autarky: number | null\n className?: string\n watts: number\n}): ReactElement {\n const reducedMotion = useReducedMotion()\n const targetAutarky =\n autarky == null ? 0 : Math.max(0, Math.min(100, autarky * 100))\n const [animatedAutarky, setAnimatedAutarky] = useState(targetAutarky)\n const animatedAutarkyRef = useRef(animatedAutarky)\n const nodeSize = 78\n const ringStrokeWidth = 2\n const radius = (nodeSize - ringStrokeWidth) / 2\n const circumference = 2 * Math.PI * radius\n const progressLength = (animatedAutarky / 100) * circumference\n\n useEffect(() => {\n animatedAutarkyRef.current = animatedAutarky\n }, [animatedAutarky])\n\n useEffect(() => {\n if (reducedMotion) {\n animatedAutarkyRef.current = targetAutarky\n setAnimatedAutarky(targetAutarky)\n return\n }\n\n let frameId = 0\n let lastTime = performance.now()\n\n const animate = (now: number) => {\n const deltaSeconds = Math.max(0.001, (now - lastTime) / 1000)\n lastTime = now\n const smoothing = 1 - Math.exp(-7 * deltaSeconds)\n const next =\n animatedAutarkyRef.current +\n (targetAutarky - animatedAutarkyRef.current) * smoothing\n\n animatedAutarkyRef.current = next\n setAnimatedAutarky(next)\n\n if (Math.abs(targetAutarky - next) > 0.05) {\n frameId = window.requestAnimationFrame(animate)\n } else {\n animatedAutarkyRef.current = targetAutarky\n setAnimatedAutarky(targetAutarky)\n }\n }\n\n frameId = window.requestAnimationFrame(animate)\n return () => window.cancelAnimationFrame(frameId)\n }, [targetAutarky, reducedMotion])\n\n return (\n <div\n ref={anchorRef}\n className={cn('relative mx-auto size-[78px]', className)}\n >\n {autarky != null && (\n <svg\n className=\"absolute inset-0 size-full -rotate-90\"\n viewBox={`0 0 ${nodeSize} ${nodeSize}`}\n >\n <circle\n cx={nodeSize / 2}\n cy={nodeSize / 2}\n r={radius}\n fill=\"none\"\n stroke=\"var(--neutral-a5)\"\n strokeWidth={ringStrokeWidth}\n />\n {progressLength > 0 && (\n <circle\n cx={nodeSize / 2}\n cy={nodeSize / 2}\n r={radius}\n fill=\"none\"\n stroke=\"var(--green-a9)\"\n strokeLinecap=\"round\"\n strokeWidth={ringStrokeWidth}\n strokeDasharray={`${progressLength} ${circumference}`}\n />\n )}\n </svg>\n )}\n <div className=\"absolute inset-0 flex flex-col items-center justify-center rounded-full border border-gray-a5 shadow-sm shadow-gray-a1\">\n <Home className=\"[--spark-icon-size:14px]\" />\n <NumberFlow\n value={watts}\n suffix=\"W\"\n className=\"mt-1 text-sm leading-none font-medium\"\n />\n </div>\n </div>\n )\n}\n\nfunction HomeSkeleton({\n anchorRef,\n className,\n}: {\n anchorRef: (element: HTMLDivElement | null) => void\n className?: string\n}): ReactElement {\n return (\n <div\n ref={anchorRef}\n className={cn(\n 'mx-auto size-[78px] animate-pulse rounded-full border border-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AAmB,UAAU;IAC7B,mBAAmB,aAAa;GAClC;EACF;EAEA,UAAU,OAAO,sBAAsB,OAAO;EAC9C,aAAa,OAAO,qBAAqB,OAAO;CAClD,GAAG,CAAC,eAAe,aAAa,CAAC;CAEjC,OACE,qBAAC,OAAD;EACE,KAAK;EACL,WAAW,GAAG,gCAAgC,SAAS;YAFzD,CAIG,WAAW,QACV,qBAAC,OAAD;GACE,WAAU;GACV,SAAS,OAAO,SAAS,GAAG;aAF9B,CAIE,oBAAC,UAAD;IACE,IAAI,WAAW;IACf,IAAI,WAAW;IACf,GAAG;IACH,MAAK;IACL,QAAO;IACP,aAAa;GACd,CAAA,GACA,iBAAiB,KAChB,oBAAC,UAAD;IACE,IAAI,WAAW;IACf,IAAI,WAAW;IACf,GAAG;IACH,MAAK;IACL,QAAO;IACP,eAAc;IACd,aAAa;IACb,iBAAiB,GAAG,eAAe,GAAG;GACvC,CAAA,CAEA;MAEP,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,oBAAC,MAAD,EAAM,WAAU,2BAA4B,CAAA,GAC5C,oBAAC,YAAD;IACE,OAAO;IACP,QAAO;IACP,WAAU;GACX,CAAA,CACE;IACF;;AAET;AAEA,SAAS,aAAa,EACpB,WACA,aAIe;CACf,OACE,oBAAC,OAAD;EACE,KAAK;EACL,WAAW,GACT,gGACA,SACF;CACD,CAAA;AAEL"}
|
|
@@ -24,13 +24,7 @@ const DEFAULT_LABEL_PADDING = 96;
|
|
|
24
24
|
const LEFT_INSET = 4;
|
|
25
25
|
const TOP_INSET = 8;
|
|
26
26
|
const LABEL_GAP = 8;
|
|
27
|
-
|
|
28
|
-
const LABEL_NAME_HEIGHT = 11;
|
|
29
|
-
/** Vertical offset of the value box relative to the name baseline. Negative pulls
|
|
30
|
-
* the value up toward the name to tighten the gap between them. */
|
|
31
|
-
const LABEL_VALUE_GAP = -4;
|
|
32
|
-
/** Height of the value box rendered below the node name. */
|
|
33
|
-
const VALUE_HEIGHT = 16;
|
|
27
|
+
const LABEL_STACK_HEIGHT = 26;
|
|
34
28
|
const DEFAULT_COLOR = "var(--neutral-a9)";
|
|
35
29
|
function resolveNodeColor(node, categoryColors, defaultColor) {
|
|
36
30
|
if (node.color) return node.color;
|
|
@@ -86,27 +80,31 @@ function SankeyChart({ nodes, links, categoryColors = SANKEY_CATEGORY_COLORS, de
|
|
|
86
80
|
}, [keepAtDepthIds]);
|
|
87
81
|
const innerWidth = Math.max(0, width - labelPadding - LEFT_INSET);
|
|
88
82
|
const innerHeight = Math.max(0, height - TOP_INSET * 2);
|
|
83
|
+
const halfLabelStack = LABEL_STACK_HEIGHT / 2;
|
|
84
|
+
const labelWidth = Math.max(40, labelPadding - LABEL_GAP - 4);
|
|
89
85
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
90
86
|
className: (0, cnfast.cn)("flex w-full flex-col gap-2 py-2", className),
|
|
91
87
|
children: [title && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_typography.SectionTitle, { children: title }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
92
88
|
ref: containerRef,
|
|
93
|
-
className: "w-full",
|
|
89
|
+
className: "relative w-full",
|
|
94
90
|
style: { height },
|
|
95
|
-
children: width > 0 && innerWidth > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
children: width > 0 && innerWidth > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_sankey.Sankey, {
|
|
92
|
+
root: graph,
|
|
93
|
+
size: [innerWidth, innerHeight],
|
|
94
|
+
nodeWidth,
|
|
95
|
+
nodePadding,
|
|
96
|
+
nodeAlign,
|
|
97
|
+
nodeId: (node) => node.id,
|
|
98
|
+
nodeSort,
|
|
99
|
+
children: ({ graph: laidOut, createPath }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
100
|
+
"aria-hidden": "true",
|
|
101
|
+
className: "block",
|
|
102
|
+
height,
|
|
103
|
+
width,
|
|
104
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_visx_group.Group, {
|
|
105
|
+
left: LEFT_INSET,
|
|
106
|
+
top: TOP_INSET,
|
|
107
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_group.Group, {
|
|
110
108
|
className: "visx-sankey-links",
|
|
111
109
|
children: laidOut.links.map((link, index) => {
|
|
112
110
|
const sourceId = typeof link.source === "object" ? link.source.id : String(link.source);
|
|
@@ -126,56 +124,43 @@ function SankeyChart({ nodes, links, categoryColors = SANKEY_CATEGORY_COLORS, de
|
|
|
126
124
|
const w = node.x1 - node.x0;
|
|
127
125
|
const h = node.y1 - node.y0;
|
|
128
126
|
const fill = colorById.get(node.id) ?? defaultColor;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
138
|
-
x: node.x0,
|
|
139
|
-
y: node.y0,
|
|
140
|
-
width: w,
|
|
141
|
-
height: Math.max(1, h),
|
|
142
|
-
fill,
|
|
143
|
-
rx: 2
|
|
144
|
-
}),
|
|
145
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
146
|
-
x: labelX,
|
|
147
|
-
y: labelY + primaryDy,
|
|
148
|
-
textAnchor: labelAnchor,
|
|
149
|
-
dominantBaseline: "alphabetic",
|
|
150
|
-
fontSize: 11,
|
|
151
|
-
fontWeight: 600,
|
|
152
|
-
fill: "var(--neutral-a12)",
|
|
153
|
-
children: node.label
|
|
154
|
-
}),
|
|
155
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("foreignObject", {
|
|
156
|
-
x: labelX,
|
|
157
|
-
y: valueY,
|
|
158
|
-
width: valueWidth,
|
|
159
|
-
height: valueHeight,
|
|
160
|
-
style: { overflow: "visible" },
|
|
161
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
162
|
-
style: {
|
|
163
|
-
lineHeight: 1.2,
|
|
164
|
-
overflow: "visible"
|
|
165
|
-
},
|
|
166
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_number_flow, {
|
|
167
|
-
value: node.value ?? 0,
|
|
168
|
-
...valueSuffix !== void 0 && { suffix: valueSuffix },
|
|
169
|
-
...valueFormat !== void 0 && { format: valueFormat },
|
|
170
|
-
className: "text-[10px] text-gray-light tabular-nums"
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
] }, `sankey-node-${index}`);
|
|
127
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
128
|
+
x: node.x0,
|
|
129
|
+
y: node.y0,
|
|
130
|
+
width: w,
|
|
131
|
+
height: Math.max(1, h),
|
|
132
|
+
fill,
|
|
133
|
+
rx: 2
|
|
134
|
+
}, `sankey-node-${index}`);
|
|
175
135
|
})
|
|
176
|
-
})]
|
|
136
|
+
})]
|
|
177
137
|
})
|
|
178
|
-
})
|
|
138
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
139
|
+
className: "pointer-events-none absolute inset-0 [-webkit-text-size-adjust:100%] [text-size-adjust:100%]",
|
|
140
|
+
children: laidOut.nodes.map((node, index) => {
|
|
141
|
+
if (node.x0 === void 0 || node.x1 === void 0 || node.y0 === void 0 || node.y1 === void 0) return null;
|
|
142
|
+
const h = node.y1 - node.y0;
|
|
143
|
+
const nodeCenterY = TOP_INSET + node.y0 + h / 2;
|
|
144
|
+
const labelCenterY = Math.min(Math.max(nodeCenterY, halfLabelStack), height - halfLabelStack);
|
|
145
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
146
|
+
className: "absolute flex -translate-y-1/2 flex-col items-start gap-1",
|
|
147
|
+
style: {
|
|
148
|
+
left: LEFT_INSET + node.x1 + LABEL_GAP,
|
|
149
|
+
top: labelCenterY,
|
|
150
|
+
width: labelWidth
|
|
151
|
+
},
|
|
152
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
153
|
+
className: "text-[11px] leading-none font-semibold whitespace-nowrap text-gray",
|
|
154
|
+
children: node.label
|
|
155
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_number_flow, {
|
|
156
|
+
value: node.value ?? 0,
|
|
157
|
+
...valueSuffix !== void 0 && { suffix: valueSuffix },
|
|
158
|
+
...valueFormat !== void 0 && { format: valueFormat },
|
|
159
|
+
className: "block min-h-[10px] text-[10px] leading-none text-gray-light tabular-nums"
|
|
160
|
+
})]
|
|
161
|
+
}, `sankey-label-${node.id ?? index}`);
|
|
162
|
+
})
|
|
163
|
+
})] })
|
|
179
164
|
})
|
|
180
165
|
})]
|
|
181
166
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sankey-chart.cjs","names":["SectionTitle","Group","Sankey","NumberFlow"],"sources":["../../src/components/sankey-chart.tsx"],"sourcesContent":["import { Group } from '@visx/group'\nimport {\n Sankey,\n sankeyJustify,\n type SankeyLink,\n type SankeyNode,\n} from '@visx/sankey'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport { cn } from '../utils/cn'\nimport NumberFlow, { type Format } from './number-flow'\nimport { SectionTitle } from './typography'\n\nconst SANKEY_CATEGORY_COLORS: Record<string, string> = {\n solar: 'var(--orange-a9)',\n battery: 'var(--green-a9)',\n grid: 'var(--blue-9)',\n gridFeedIn: 'var(--blue-7)',\n home: 'var(--spark-9)',\n floor: 'var(--neutral-a9)',\n device: 'var(--neutral-a8)',\n}\n\nexport interface SankeyChartNode {\n id: string\n label: string\n /** Optional category — used to colour the node and any outgoing links. */\n category?: string\n /** Override the colour resolved from `category`. */\n color?: string\n}\n\nexport interface SankeyChartLink {\n source: string\n target: string\n value: number\n /** Override the colour of the link. Defaults to the source node colour. */\n color?: string\n}\n\nexport interface SankeyChartProps {\n nodes: SankeyChartNode[]\n links: SankeyChartLink[]\n /** Resolves a category to a colour. */\n categoryColors?: Record<string, string>\n /** Fallback colour for nodes/links without a category. */\n defaultColor?: string\n /** Suffix appended to each animated value label (e.g. \" W\"). */\n valueSuffix?: string\n /** NumberFlow `format` for value labels. */\n valueFormat?: Format\n height?: number\n nodeWidth?: number\n nodePadding?: number\n /** Reserved horizontal space on the right for labels. */\n labelPadding?: number\n /**\n * Node ids kept at their natural (computed) column instead of being pushed to\n * the last column. By default `sankeyJustify` sends every node with no\n * outgoing link to the right edge; use this to hold a terminal node (e.g. grid\n * feed-in) in a middle column alongside its siblings.\n */\n keepAtDepthIds?: readonly string[]\n title?: string\n className?: string\n}\n\ntype SankeyDatumNode = SankeyChartNode & {\n /** Computed by d3-sankey; present after layout. */\n}\n\ntype SankeyDatumLink = SankeyChartLink\n\nconst DEFAULT_HEIGHT = 260\nconst DEFAULT_NODE_WIDTH = 12\nconst DEFAULT_NODE_PADDING = 10\nconst DEFAULT_LABEL_PADDING = 96\nconst LEFT_INSET = 4\nconst TOP_INSET = 8\nconst LABEL_GAP = 8\n/** Approx. cap/ascender height of the node name above its alphabetic baseline. */\nconst LABEL_NAME_HEIGHT = 11\n/** Vertical offset of the value box relative to the name baseline. Negative pulls\n * the value up toward the name to tighten the gap between them. */\nconst LABEL_VALUE_GAP = -4\n/** Height of the value box rendered below the node name. */\nconst VALUE_HEIGHT = 16\nconst DEFAULT_COLOR = 'var(--neutral-a9)'\n\nfunction resolveNodeColor(\n node: SankeyChartNode,\n categoryColors: Record<string, string> | undefined,\n defaultColor: string,\n) {\n if (node.color) return node.color\n if (node.category && categoryColors?.[node.category]) {\n return categoryColors[node.category] as string\n }\n return defaultColor\n}\n\nfunction SankeyChart({\n nodes,\n links,\n categoryColors = SANKEY_CATEGORY_COLORS,\n defaultColor = DEFAULT_COLOR,\n valueSuffix,\n valueFormat,\n height = DEFAULT_HEIGHT,\n nodeWidth = DEFAULT_NODE_WIDTH,\n nodePadding = DEFAULT_NODE_PADDING,\n labelPadding = DEFAULT_LABEL_PADDING,\n keepAtDepthIds,\n title,\n className,\n}: SankeyChartProps): React.ReactElement {\n const containerRef = useRef<HTMLDivElement>(null)\n const [width, setWidth] = useState(0)\n\n useEffect(() => {\n const element = containerRef.current\n if (!element) return\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n setWidth(entry.contentRect.width)\n })\n\n resizeObserver.observe(element)\n return () => resizeObserver.disconnect()\n }, [])\n\n const nodeIds = useMemo(() => new Set(nodes.map((node) => node.id)), [nodes])\n\n // Drop zero-value links and any whose endpoints aren't in the current node\n // set (a stale link referencing a removed node makes d3-sankey throw\n // `missing: <id>`).\n const visibleLinks = useMemo(\n () =>\n links.filter(\n (link) =>\n link.value > 0 &&\n nodeIds.has(link.source) &&\n nodeIds.has(link.target),\n ),\n [links, nodeIds],\n )\n\n const visibleNodes = useMemo(() => {\n const referencedIds = new Set<string>()\n for (const link of visibleLinks) {\n referencedIds.add(link.source)\n referencedIds.add(link.target)\n }\n return nodes.filter((node) => referencedIds.has(node.id))\n }, [nodes, visibleLinks])\n\n const colorById = useMemo(() => {\n const map = new Map<string, string>()\n for (const node of nodes) {\n map.set(node.id, resolveNodeColor(node, categoryColors, defaultColor))\n }\n return map\n }, [categoryColors, defaultColor, nodes])\n\n const orderById = useMemo(() => {\n const map = new Map<string, number>()\n visibleNodes.forEach((node, index) => map.set(node.id, index))\n return map\n }, [visibleNodes])\n\n const nodeSort = useMemo(\n () =>\n (\n a: SankeyNode<SankeyDatumNode, SankeyDatumLink>,\n b: SankeyNode<SankeyDatumNode, SankeyDatumLink>,\n ) =>\n (orderById.get(a.id) ?? 0) - (orderById.get(b.id) ?? 0),\n [orderById],\n )\n\n const graph = useMemo(\n () => ({\n nodes: visibleNodes.map((node) => ({ ...node })),\n links: visibleLinks.map((link) => ({ ...link })),\n }),\n [visibleNodes, visibleLinks],\n )\n\n const nodeAlign = useMemo(() => {\n const keep = new Set(keepAtDepthIds)\n return (node: SankeyNode<SankeyDatumNode, SankeyDatumLink>, n: number) =>\n keep.has(node.id) ? (node.depth ?? 0) : sankeyJustify(node, n)\n }, [keepAtDepthIds])\n\n const innerWidth = Math.max(0, width - labelPadding - LEFT_INSET)\n const innerHeight = Math.max(0, height - TOP_INSET * 2)\n\n return (\n <div className={cn('flex w-full flex-col gap-2 py-2', className)}>\n {title && <SectionTitle>{title}</SectionTitle>}\n\n <div ref={containerRef} className=\"w-full\" style={{ height }}>\n {width > 0 && innerWidth > 0 && (\n <svg width={width} height={height}>\n <Group left={LEFT_INSET} top={TOP_INSET}>\n <Sankey<SankeyDatumNode, SankeyDatumLink>\n root={graph}\n size={[innerWidth, innerHeight]}\n nodeWidth={nodeWidth}\n nodePadding={nodePadding}\n nodeAlign={nodeAlign}\n nodeId={(node) => node.id}\n nodeSort={nodeSort}\n >\n {({ graph: laidOut, createPath }) => (\n <>\n <Group className=\"visx-sankey-links\">\n {laidOut.links.map((link, index) => {\n const sourceId =\n typeof link.source === 'object'\n ? (\n link.source as SankeyNode<\n SankeyDatumNode,\n SankeyDatumLink\n >\n ).id\n : String(link.source)\n const stroke =\n link.color ?? colorById.get(sourceId) ?? defaultColor\n\n return (\n <path\n key={`sankey-link-${index}`}\n d={createPath(link) ?? ''}\n fill=\"none\"\n stroke={stroke}\n strokeOpacity={0.32}\n strokeWidth={Math.max(1, link.width ?? 0)}\n />\n )\n })}\n </Group>\n\n <Group className=\"visx-sankey-nodes\">\n {laidOut.nodes.map((node, index) => {\n if (\n node.x0 === undefined ||\n node.x1 === undefined ||\n node.y0 === undefined ||\n node.y1 === undefined\n ) {\n return null\n }\n\n const w = node.x1 - node.x0\n const h = node.y1 - node.y0\n const fill = colorById.get(node.id) ?? defaultColor\n\n const labelX = node.x1 + LABEL_GAP\n // Center the name+value label on the node, then clamp it\n // vertically so a node flush against an edge (e.g. a tiny\n // \"grid\" node at the top) doesn't push its name past the\n // chart bounds and get clipped. The name's ascenders sit\n // above labelY; the value box sits below it.\n const labelY = Math.min(\n Math.max(\n node.y0 + h / 2 - 4,\n LABEL_NAME_HEIGHT - TOP_INSET,\n ),\n innerHeight + TOP_INSET - VALUE_HEIGHT,\n )\n const labelAnchor = 'start' as const\n const primaryDy = 0\n const valueWidth = Math.max(\n 40,\n labelPadding - LABEL_GAP - 4,\n )\n const valueHeight = VALUE_HEIGHT\n const valueY = labelY + LABEL_VALUE_GAP\n\n return (\n <Group key={`sankey-node-${index}`}>\n <rect\n x={node.x0}\n y={node.y0}\n width={w}\n height={Math.max(1, h)}\n fill={fill}\n rx={2}\n />\n <text\n x={labelX}\n y={labelY + primaryDy}\n textAnchor={labelAnchor}\n dominantBaseline=\"alphabetic\"\n fontSize={11}\n fontWeight={600}\n fill=\"var(--neutral-a12)\"\n >\n {node.label}\n </text>\n <foreignObject\n x={labelX}\n y={valueY}\n width={valueWidth}\n height={valueHeight}\n style={{ overflow: 'visible' }}\n >\n <div\n style={{\n lineHeight: 1.2,\n overflow: 'visible',\n }}\n >\n <NumberFlow\n value={node.value ?? 0}\n {...(valueSuffix !== undefined && {\n suffix: valueSuffix,\n })}\n {...(valueFormat !== undefined && {\n format: valueFormat,\n })}\n className=\"text-[10px] text-gray-light tabular-nums\"\n />\n </div>\n </foreignObject>\n </Group>\n )\n })}\n </Group>\n </>\n )}\n </Sankey>\n </Group>\n </svg>\n )}\n </div>\n </div>\n )\n}\n\nexport type { SankeyLink, SankeyNode }\nexport { SankeyChart, SANKEY_CATEGORY_COLORS }\n"],"mappings":";;;;;;;;;;AAYA,MAAM,yBAAiD;CACrD,OAAO;CACP,SAAS;CACT,MAAM;CACN,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CAAA;QACV,EAAA,GA7CK,eAAe,OA6CpB;OAEX,CAAC;MACI,CAAA,CACP,EAAA,CAAA;KAEE,CAAA;IACH,CAAA;GACJ,CAAA;EAEJ,CAAA,CACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"sankey-chart.cjs","names":["SectionTitle","Sankey","Group","NumberFlow"],"sources":["../../src/components/sankey-chart.tsx"],"sourcesContent":["import { Group } from '@visx/group'\nimport {\n Sankey,\n sankeyJustify,\n type SankeyLink,\n type SankeyNode,\n} from '@visx/sankey'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport { cn } from '../utils/cn'\nimport NumberFlow, { type Format } from './number-flow'\nimport { SectionTitle } from './typography'\n\nconst SANKEY_CATEGORY_COLORS: Record<string, string> = {\n solar: 'var(--orange-a9)',\n battery: 'var(--green-a9)',\n grid: 'var(--blue-9)',\n gridFeedIn: 'var(--blue-7)',\n home: 'var(--spark-9)',\n floor: 'var(--neutral-a9)',\n device: 'var(--neutral-a8)',\n}\n\nexport interface SankeyChartNode {\n id: string\n label: string\n /** Optional category — used to colour the node and any outgoing links. */\n category?: string\n /** Override the colour resolved from `category`. */\n color?: string\n}\n\nexport interface SankeyChartLink {\n source: string\n target: string\n value: number\n /** Override the colour of the link. Defaults to the source node colour. */\n color?: string\n}\n\nexport interface SankeyChartProps {\n nodes: SankeyChartNode[]\n links: SankeyChartLink[]\n /** Resolves a category to a colour. */\n categoryColors?: Record<string, string>\n /** Fallback colour for nodes/links without a category. */\n defaultColor?: string\n /** Suffix appended to each animated value label (e.g. \" W\"). */\n valueSuffix?: string\n /** NumberFlow `format` for value labels. */\n valueFormat?: Format\n height?: number\n nodeWidth?: number\n nodePadding?: number\n /** Reserved horizontal space on the right for labels. */\n labelPadding?: number\n /**\n * Node ids kept at their natural (computed) column instead of being pushed to\n * the last column. By default `sankeyJustify` sends every node with no\n * outgoing link to the right edge; use this to hold a terminal node (e.g. grid\n * feed-in) in a middle column alongside its siblings.\n */\n keepAtDepthIds?: readonly string[]\n title?: string\n className?: string\n}\n\ntype SankeyDatumNode = SankeyChartNode & {\n /** Computed by d3-sankey; present after layout. */\n}\n\ntype SankeyDatumLink = SankeyChartLink\n\nconst DEFAULT_HEIGHT = 260\nconst DEFAULT_NODE_WIDTH = 12\nconst DEFAULT_NODE_PADDING = 10\nconst DEFAULT_LABEL_PADDING = 96\nconst LEFT_INSET = 4\nconst TOP_INSET = 8\nconst LABEL_GAP = 8\nconst LABEL_STACK_HEIGHT = 26\nconst DEFAULT_COLOR = 'var(--neutral-a9)'\n\nfunction resolveNodeColor(\n node: SankeyChartNode,\n categoryColors: Record<string, string> | undefined,\n defaultColor: string,\n) {\n if (node.color) return node.color\n if (node.category && categoryColors?.[node.category]) {\n return categoryColors[node.category] as string\n }\n return defaultColor\n}\n\nfunction SankeyChart({\n nodes,\n links,\n categoryColors = SANKEY_CATEGORY_COLORS,\n defaultColor = DEFAULT_COLOR,\n valueSuffix,\n valueFormat,\n height = DEFAULT_HEIGHT,\n nodeWidth = DEFAULT_NODE_WIDTH,\n nodePadding = DEFAULT_NODE_PADDING,\n labelPadding = DEFAULT_LABEL_PADDING,\n keepAtDepthIds,\n title,\n className,\n}: SankeyChartProps): React.ReactElement {\n const containerRef = useRef<HTMLDivElement>(null)\n const [width, setWidth] = useState(0)\n\n useEffect(() => {\n const element = containerRef.current\n if (!element) return\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0]\n if (!entry) return\n setWidth(entry.contentRect.width)\n })\n\n resizeObserver.observe(element)\n return () => resizeObserver.disconnect()\n }, [])\n\n const nodeIds = useMemo(() => new Set(nodes.map((node) => node.id)), [nodes])\n\n // Drop zero-value links and any whose endpoints aren't in the current node\n // set (a stale link referencing a removed node makes d3-sankey throw\n // `missing: <id>`).\n const visibleLinks = useMemo(\n () =>\n links.filter(\n (link) =>\n link.value > 0 &&\n nodeIds.has(link.source) &&\n nodeIds.has(link.target),\n ),\n [links, nodeIds],\n )\n\n const visibleNodes = useMemo(() => {\n const referencedIds = new Set<string>()\n for (const link of visibleLinks) {\n referencedIds.add(link.source)\n referencedIds.add(link.target)\n }\n return nodes.filter((node) => referencedIds.has(node.id))\n }, [nodes, visibleLinks])\n\n const colorById = useMemo(() => {\n const map = new Map<string, string>()\n for (const node of nodes) {\n map.set(node.id, resolveNodeColor(node, categoryColors, defaultColor))\n }\n return map\n }, [categoryColors, defaultColor, nodes])\n\n const orderById = useMemo(() => {\n const map = new Map<string, number>()\n visibleNodes.forEach((node, index) => map.set(node.id, index))\n return map\n }, [visibleNodes])\n\n const nodeSort = useMemo(\n () =>\n (\n a: SankeyNode<SankeyDatumNode, SankeyDatumLink>,\n b: SankeyNode<SankeyDatumNode, SankeyDatumLink>,\n ) =>\n (orderById.get(a.id) ?? 0) - (orderById.get(b.id) ?? 0),\n [orderById],\n )\n\n const graph = useMemo(\n () => ({\n nodes: visibleNodes.map((node) => ({ ...node })),\n links: visibleLinks.map((link) => ({ ...link })),\n }),\n [visibleNodes, visibleLinks],\n )\n\n const nodeAlign = useMemo(() => {\n const keep = new Set(keepAtDepthIds)\n return (node: SankeyNode<SankeyDatumNode, SankeyDatumLink>, n: number) =>\n keep.has(node.id) ? (node.depth ?? 0) : sankeyJustify(node, n)\n }, [keepAtDepthIds])\n\n const innerWidth = Math.max(0, width - labelPadding - LEFT_INSET)\n const innerHeight = Math.max(0, height - TOP_INSET * 2)\n const halfLabelStack = LABEL_STACK_HEIGHT / 2\n const labelWidth = Math.max(40, labelPadding - LABEL_GAP - 4)\n\n return (\n <div className={cn('flex w-full flex-col gap-2 py-2', className)}>\n {title && <SectionTitle>{title}</SectionTitle>}\n\n <div ref={containerRef} className=\"relative w-full\" style={{ height }}>\n {width > 0 && innerWidth > 0 && (\n <Sankey<SankeyDatumNode, SankeyDatumLink>\n root={graph}\n size={[innerWidth, innerHeight]}\n nodeWidth={nodeWidth}\n nodePadding={nodePadding}\n nodeAlign={nodeAlign}\n nodeId={(node) => node.id}\n nodeSort={nodeSort}\n >\n {({ graph: laidOut, createPath }) => (\n <>\n <svg\n aria-hidden=\"true\"\n className=\"block\"\n height={height}\n width={width}\n >\n <Group left={LEFT_INSET} top={TOP_INSET}>\n <Group className=\"visx-sankey-links\">\n {laidOut.links.map((link, index) => {\n const sourceId =\n typeof link.source === 'object'\n ? (\n link.source as SankeyNode<\n SankeyDatumNode,\n SankeyDatumLink\n >\n ).id\n : String(link.source)\n const stroke =\n link.color ?? colorById.get(sourceId) ?? defaultColor\n\n return (\n <path\n key={`sankey-link-${index}`}\n d={createPath(link) ?? ''}\n fill=\"none\"\n stroke={stroke}\n strokeOpacity={0.32}\n strokeWidth={Math.max(1, link.width ?? 0)}\n />\n )\n })}\n </Group>\n\n <Group className=\"visx-sankey-nodes\">\n {laidOut.nodes.map((node, index) => {\n if (\n node.x0 === undefined ||\n node.x1 === undefined ||\n node.y0 === undefined ||\n node.y1 === undefined\n ) {\n return null\n }\n\n const w = node.x1 - node.x0\n const h = node.y1 - node.y0\n const fill = colorById.get(node.id) ?? defaultColor\n\n return (\n <rect\n key={`sankey-node-${index}`}\n x={node.x0}\n y={node.y0}\n width={w}\n height={Math.max(1, h)}\n fill={fill}\n rx={2}\n />\n )\n })}\n </Group>\n </Group>\n </svg>\n\n <div className=\"pointer-events-none absolute inset-0 [-webkit-text-size-adjust:100%] [text-size-adjust:100%]\">\n {laidOut.nodes.map((node, index) => {\n if (\n node.x0 === undefined ||\n node.x1 === undefined ||\n node.y0 === undefined ||\n node.y1 === undefined\n ) {\n return null\n }\n\n const h = node.y1 - node.y0\n const nodeCenterY = TOP_INSET + node.y0 + h / 2\n const labelCenterY = Math.min(\n Math.max(nodeCenterY, halfLabelStack),\n height - halfLabelStack,\n )\n\n return (\n <div\n key={`sankey-label-${node.id ?? index}`}\n className=\"absolute flex -translate-y-1/2 flex-col items-start gap-1\"\n style={{\n left: LEFT_INSET + node.x1 + LABEL_GAP,\n top: labelCenterY,\n width: labelWidth,\n }}\n >\n <span className=\"text-[11px] leading-none font-semibold whitespace-nowrap text-gray\">\n {node.label}\n </span>\n <NumberFlow\n value={node.value ?? 0}\n {...(valueSuffix !== undefined && {\n suffix: valueSuffix,\n })}\n {...(valueFormat !== undefined && {\n format: valueFormat,\n })}\n className=\"block min-h-[10px] text-[10px] leading-none text-gray-light tabular-nums\"\n />\n </div>\n )\n })}\n </div>\n </>\n )}\n </Sankey>\n )}\n </div>\n </div>\n )\n}\n\nexport type { SankeyLink, SankeyNode }\nexport { SankeyChart, SANKEY_CATEGORY_COLORS }\n"],"mappings":";;;;;;;;;;AAYA,MAAM,yBAAiD;CACrD,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;CACZ,MAAM;CACN,OAAO;CACP,QAAQ;AACV;AAoDA,MAAM,iBAAiB;AACvB,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAC7B,MAAM,wBAAwB;AAC9B,MAAM,aAAa;AACnB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;AAEtB,SAAS,iBACP,MACA,gBACA,cACA;CACA,IAAI,KAAK,OAAO,OAAO,KAAK;CAC5B,IAAI,KAAK,YAAY,iBAAiB,KAAK,WACzC,OAAO,eAAe,KAAK;CAE7B,OAAO;AACT;AAEA,SAAS,YAAY,EACnB,OACA,OACA,iBAAiB,wBACjB,eAAe,eACf,aACA,aACA,SAAS,gBACT,YAAY,oBACZ,cAAc,sBACd,eAAe,uBACf,gBACA,OACA,aACuC;CACvC,MAAM,gBAAA,GAAA,MAAA,QAAsC,IAAI;CAChD,MAAM,CAAC,OAAO,aAAA,GAAA,MAAA,UAAqB,CAAC;CAEpC,CAAA,GAAA,MAAA,iBAAgB;EACd,MAAM,UAAU,aAAa;EAC7B,IAAI,CAAC,SAAS;EAEd,MAAM,iBAAiB,IAAI,gBAAgB,YAAY;GACrD,MAAM,QAAQ,QAAQ;GACtB,IAAI,CAAC,OAAO;GACZ,SAAS,MAAM,YAAY,KAAK;EAClC,CAAC;EAED,eA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,OACE,iBAAA,GAAA,kBAAA,MAAC,OAAD;OAEE,WAAU;OACV,OAAO;QACL,MAAM,aAAa,KAAK,KAAK;QAC7B,KAAK;QACL,OAAO;OACT;iBAPF,CASE,iBAAA,GAAA,kBAAA,KAAC,QAAD;QAAM,WAAU;kBACb,KAAK;OACF,CAAA,GACN,iBAAA,GAAA,kBAAA,KAACC,gCAAD;QACE,OAAO,KAAK,SAAS;QACrB,GAAK,gBAAgB,KAAA,KAAa,EAChC,QAAQ,YACV;QACA,GAAK,gBAAgB,KAAA,KAAa,EAChC,QAAQ,YACV;QACA,WAAU;OACX,CAAA,CACE;SArBE,gBAAgB,KAAK,MAAM,OAqB7B;KAET,CAAC;IACE,CAAA,CACL,EAAA,CAAA;GAEE,CAAA;EAEP,CAAA,CACF;;AAET"}
|
|
@@ -23,13 +23,7 @@ const DEFAULT_LABEL_PADDING = 96;
|
|
|
23
23
|
const LEFT_INSET = 4;
|
|
24
24
|
const TOP_INSET = 8;
|
|
25
25
|
const LABEL_GAP = 8;
|
|
26
|
-
|
|
27
|
-
const LABEL_NAME_HEIGHT = 11;
|
|
28
|
-
/** Vertical offset of the value box relative to the name baseline. Negative pulls
|
|
29
|
-
* the value up toward the name to tighten the gap between them. */
|
|
30
|
-
const LABEL_VALUE_GAP = -4;
|
|
31
|
-
/** Height of the value box rendered below the node name. */
|
|
32
|
-
const VALUE_HEIGHT = 16;
|
|
26
|
+
const LABEL_STACK_HEIGHT = 26;
|
|
33
27
|
const DEFAULT_COLOR = "var(--neutral-a9)";
|
|
34
28
|
function resolveNodeColor(node, categoryColors, defaultColor) {
|
|
35
29
|
if (node.color) return node.color;
|
|
@@ -85,27 +79,31 @@ function SankeyChart({ nodes, links, categoryColors = SANKEY_CATEGORY_COLORS, de
|
|
|
85
79
|
}, [keepAtDepthIds]);
|
|
86
80
|
const innerWidth = Math.max(0, width - labelPadding - LEFT_INSET);
|
|
87
81
|
const innerHeight = Math.max(0, height - TOP_INSET * 2);
|
|
82
|
+
const halfLabelStack = LABEL_STACK_HEIGHT / 2;
|
|
83
|
+
const labelWidth = Math.max(40, labelPadding - LABEL_GAP - 4);
|
|
88
84
|
return /* @__PURE__ */ jsxs("div", {
|
|
89
85
|
className: cn("flex w-full flex-col gap-2 py-2", className),
|
|
90
86
|
children: [title && /* @__PURE__ */ jsx(SectionTitle, { children: title }), /* @__PURE__ */ jsx("div", {
|
|
91
87
|
ref: containerRef,
|
|
92
|
-
className: "w-full",
|
|
88
|
+
className: "relative w-full",
|
|
93
89
|
style: { height },
|
|
94
|
-
children: width > 0 && innerWidth > 0 && /* @__PURE__ */ jsx(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
children: width > 0 && innerWidth > 0 && /* @__PURE__ */ jsx(Sankey, {
|
|
91
|
+
root: graph,
|
|
92
|
+
size: [innerWidth, innerHeight],
|
|
93
|
+
nodeWidth,
|
|
94
|
+
nodePadding,
|
|
95
|
+
nodeAlign,
|
|
96
|
+
nodeId: (node) => node.id,
|
|
97
|
+
nodeSort,
|
|
98
|
+
children: ({ graph: laidOut, createPath }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("svg", {
|
|
99
|
+
"aria-hidden": "true",
|
|
100
|
+
className: "block",
|
|
101
|
+
height,
|
|
102
|
+
width,
|
|
103
|
+
children: /* @__PURE__ */ jsxs(Group, {
|
|
104
|
+
left: LEFT_INSET,
|
|
105
|
+
top: TOP_INSET,
|
|
106
|
+
children: [/* @__PURE__ */ jsx(Group, {
|
|
109
107
|
className: "visx-sankey-links",
|
|
110
108
|
children: laidOut.links.map((link, index) => {
|
|
111
109
|
const sourceId = typeof link.source === "object" ? link.source.id : String(link.source);
|
|
@@ -125,56 +123,43 @@ function SankeyChart({ nodes, links, categoryColors = SANKEY_CATEGORY_COLORS, de
|
|
|
125
123
|
const w = node.x1 - node.x0;
|
|
126
124
|
const h = node.y1 - node.y0;
|
|
127
125
|
const fill = colorById.get(node.id) ?? defaultColor;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/* @__PURE__ */ jsx("rect", {
|
|
137
|
-
x: node.x0,
|
|
138
|
-
y: node.y0,
|
|
139
|
-
width: w,
|
|
140
|
-
height: Math.max(1, h),
|
|
141
|
-
fill,
|
|
142
|
-
rx: 2
|
|
143
|
-
}),
|
|
144
|
-
/* @__PURE__ */ jsx("text", {
|
|
145
|
-
x: labelX,
|
|
146
|
-
y: labelY + primaryDy,
|
|
147
|
-
textAnchor: labelAnchor,
|
|
148
|
-
dominantBaseline: "alphabetic",
|
|
149
|
-
fontSize: 11,
|
|
150
|
-
fontWeight: 600,
|
|
151
|
-
fill: "var(--neutral-a12)",
|
|
152
|
-
children: node.label
|
|
153
|
-
}),
|
|
154
|
-
/* @__PURE__ */ jsx("foreignObject", {
|
|
155
|
-
x: labelX,
|
|
156
|
-
y: valueY,
|
|
157
|
-
width: valueWidth,
|
|
158
|
-
height: valueHeight,
|
|
159
|
-
style: { overflow: "visible" },
|
|
160
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
161
|
-
style: {
|
|
162
|
-
lineHeight: 1.2,
|
|
163
|
-
overflow: "visible"
|
|
164
|
-
},
|
|
165
|
-
children: /* @__PURE__ */ jsx(NumberFlow, {
|
|
166
|
-
value: node.value ?? 0,
|
|
167
|
-
...valueSuffix !== void 0 && { suffix: valueSuffix },
|
|
168
|
-
...valueFormat !== void 0 && { format: valueFormat },
|
|
169
|
-
className: "text-[10px] text-gray-light tabular-nums"
|
|
170
|
-
})
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
] }, `sankey-node-${index}`);
|
|
126
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
127
|
+
x: node.x0,
|
|
128
|
+
y: node.y0,
|
|
129
|
+
width: w,
|
|
130
|
+
height: Math.max(1, h),
|
|
131
|
+
fill,
|
|
132
|
+
rx: 2
|
|
133
|
+
}, `sankey-node-${index}`);
|
|
174
134
|
})
|
|
175
|
-
})]
|
|
135
|
+
})]
|
|
176
136
|
})
|
|
177
|
-
})
|
|
137
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
138
|
+
className: "pointer-events-none absolute inset-0 [-webkit-text-size-adjust:100%] [text-size-adjust:100%]",
|
|
139
|
+
children: laidOut.nodes.map((node, index) => {
|
|
140
|
+
if (node.x0 === void 0 || node.x1 === void 0 || node.y0 === void 0 || node.y1 === void 0) return null;
|
|
141
|
+
const h = node.y1 - node.y0;
|
|
142
|
+
const nodeCenterY = TOP_INSET + node.y0 + h / 2;
|
|
143
|
+
const labelCenterY = Math.min(Math.max(nodeCenterY, halfLabelStack), height - halfLabelStack);
|
|
144
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
145
|
+
className: "absolute flex -translate-y-1/2 flex-col items-start gap-1",
|
|
146
|
+
style: {
|
|
147
|
+
left: LEFT_INSET + node.x1 + LABEL_GAP,
|
|
148
|
+
top: labelCenterY,
|
|
149
|
+
width: labelWidth
|
|
150
|
+
},
|
|
151
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
152
|
+
className: "text-[11px] leading-none font-semibold whitespace-nowrap text-gray",
|
|
153
|
+
children: node.label
|
|
154
|
+
}), /* @__PURE__ */ jsx(NumberFlow, {
|
|
155
|
+
value: node.value ?? 0,
|
|
156
|
+
...valueSuffix !== void 0 && { suffix: valueSuffix },
|
|
157
|
+
...valueFormat !== void 0 && { format: valueFormat },
|
|
158
|
+
className: "block min-h-[10px] text-[10px] leading-none text-gray-light tabular-nums"
|
|
159
|
+
})]
|
|
160
|
+
}, `sankey-label-${node.id ?? index}`);
|
|
161
|
+
})
|
|
162
|
+
})] })
|
|
178
163
|
})
|
|
179
164
|
})]
|
|
180
165
|
});
|