-
Notifications
You must be signed in to change notification settings - Fork 118
FE-570: Replace SVG simulation timeline with uPlot #8627
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8b07615
Replace SVG simulation timeline with uPlot
kube 9b03c60
Add hover tooltip and Logic Pro-style ruler to simulation timeline
kube 0552558
Refactor chart component into derived state + focused effects; fix AIβ¦
kube 39d3f1e
Extract focused helpers from buildUPlotOptions for readability
kube c977e01
Fix stacked band rendering and stale store ref; revert frozen scales
kube 0179bc5
Lint
kube 46fdb75
Memoize columnar data and remove dead store length check
kube 30002dd
Remove unused d3-scale dependency
kube c873ab2
Fix y-axis label clipping in simulation timeline
kube 03507fe
Collapse redundant chart wrapper divs
kube 2c90db7
Reserve canvas space for the playhead pin
kube 4b6d979
Fix restart revision bump and separator DPR scaling
kube 3a23cdd
Lint
kube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { useEffect, useRef, useState, type RefObject } from "react"; | ||
|
|
||
| interface ElementSize { | ||
| width: number; | ||
| height: number; | ||
| } | ||
|
|
||
| interface UseElementSizeOptions { | ||
| /** | ||
| * Debounce interval in milliseconds. When set, the returned size only | ||
| * updates at most once per interval, batching rapid resize events. | ||
| * Useful for expensive downstream work (e.g. chart recreation). | ||
| * Defaults to 0 (no debounce β updates on every ResizeObserver callback). | ||
| */ | ||
| debounce?: number; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the content-box size of a DOM element, kept in sync via ResizeObserver. | ||
| * | ||
| * Returns `null` until the element is mounted and the first observation fires. | ||
| * Supports an optional `debounce` interval to throttle updates. | ||
| * | ||
| * @example | ||
| * ```tsx | ||
| * const ref = useRef<HTMLDivElement>(null); | ||
| * const size = useElementSize(ref, { debounce: 100 }); | ||
| * | ||
| * return <div ref={ref}>{size && `${size.width} Γ ${size.height}`}</div>; | ||
| * ``` | ||
| */ | ||
| export function useElementSize( | ||
|
kube marked this conversation as resolved.
|
||
| ref: RefObject<HTMLElement | null>, | ||
| options?: UseElementSizeOptions, | ||
| ): ElementSize | null { | ||
| "use no memo"; // imperative observer + timer management | ||
| const [size, setSize] = useState<ElementSize | null>(null); | ||
| const debounceMs = options?.debounce ?? 0; | ||
| const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const el = ref.current; | ||
| if (!el) { | ||
| return; | ||
| } | ||
|
|
||
| const update = (width: number, height: number) => { | ||
| setSize((prev) => { | ||
|
kube marked this conversation as resolved.
|
||
| if (prev && prev.width === width && prev.height === height) { | ||
| return prev; // avoid spurious re-renders | ||
| } | ||
| return { width, height }; | ||
| }); | ||
| }; | ||
|
|
||
| const ro = new ResizeObserver((entries) => { | ||
| const entry = entries[0]; | ||
| if (!entry) { | ||
| return; | ||
| } | ||
| const { width, height } = entry.contentRect; | ||
| if (debounceMs > 0) { | ||
| if (timerRef.current != null) { | ||
| clearTimeout(timerRef.current); | ||
| } | ||
| timerRef.current = setTimeout(() => { | ||
| update(width, height); | ||
| timerRef.current = null; | ||
| }, debounceMs); | ||
| } else { | ||
| update(width, height); | ||
| } | ||
| }); | ||
|
|
||
| ro.observe(el); | ||
|
|
||
| return () => { | ||
| ro.disconnect(); | ||
| if (timerRef.current != null) { | ||
| clearTimeout(timerRef.current); | ||
| timerRef.current = null; | ||
| } | ||
| }; | ||
| }, [ref, debounceMs]); | ||
|
|
||
| return size; | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.