-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor main graph to d3.js #6159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
apata
wants to merge
30
commits into
main-graph-v2-backend
Choose a base branch
from
main-graph-to-api-v2--double-headed
base: main-graph-v2-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5a82ec4
Add generic graph component and use it for main graph
apata e05fdaa
Remove superfluous mobile related code
apata a312c3c
Add isTouchDevice state and touch-device specific zoom instructions
apata 3faf67b
Move useMainGraphWidth
apata 31745c4
Center tooltip
apata edb2faa
Adjust tooltip position
apata 93e9a9f
Clarify pointerup
apata d3ca930
Extract fetching main graph and remapping main graph data
apata d694cf5
Unify BE and FE change calculations
apata ae2272a
Stop wrapping change arrow, unify with ComparisonTooltipContent
apata dd75d4a
Exports
apata ffc7127
Attempt partial logic
apata 16452d7
Draw dashed partial periods at the start and end of main series
apata ea8f640
Simplify
apata 1fa6945
Clarify series
apata 578ef76
Better types
apata 7e97655
Make remapAndFillData take accessors
apata 6d79540
Get metric label using utility
apata 83708f2
Refactor value and comparisonValue to numericValue and comparisonNume…
apata 67b83ba
Refactor outerValue and comparisoOuterValue to value and comparisonValue
apata 3fcda54
Fix format
apata fbbaf4d
Fix type error in test
apata c631892
No need to assert isPartial
apata 6a3120a
Fix issue with full crash when switching between periods while tooltip
apata 0c4d397
Add necessary types
apata 4f27cde
Handle comparison_partial_time_labels
apata 59f92e9
Handle [null] style result items
apata f058ae2
Hint expected tick count to y axis nicing
apata 6add2b9
Remove old line graph
apata 66d2ceb
Clarify graph inputs
apata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import React, { ReactNode, useLayoutEffect, useRef, useState } from 'react' | ||
| import { Transition } from '@headlessui/react' | ||
|
|
||
| export const GraphTooltipWrapper = ({ | ||
| x, | ||
| y, | ||
| maxX, | ||
| minWidth, | ||
| children, | ||
| className, | ||
| onClick, | ||
| isTouchDevice | ||
| }: { | ||
| x: number | ||
| y: number | ||
| maxX: number | ||
| minWidth: number | ||
| children: ReactNode | ||
| className?: string | ||
| onClick?: () => void | ||
| isTouchDevice?: boolean | ||
| }) => { | ||
| const ref = useRef<HTMLDivElement>(null) | ||
| // bigger on mobile to have room between thumb and tooltip | ||
| const xOffsetFromCursor = isTouchDevice ? 24 : 12 | ||
| const yOffsetFromCursor = isTouchDevice ? 48 : 24 | ||
| const [measuredWidth, setMeasuredWidth] = useState(minWidth) | ||
| // center tooltip above the cursor, clamped to prevent left/right overflow | ||
| const rawLeft = x + xOffsetFromCursor | ||
| const tooltipLeft = Math.max(0, Math.min(rawLeft, maxX - measuredWidth)) | ||
|
|
||
| useLayoutEffect(() => { | ||
| if (!ref.current) { | ||
| return | ||
| } | ||
| setMeasuredWidth(ref.current.offsetWidth) | ||
| }, [children, className, minWidth]) | ||
|
|
||
| return ( | ||
| <Transition | ||
| as={React.Fragment} | ||
| appear | ||
| show | ||
| // enter delay on mobile is needed to prevent the tooltip from entering when the user starts to y-pan | ||
| // but the y-pan is not yet certain | ||
| enter={isTouchDevice ? 'transition-opacity duration-0 delay-150' : ''} | ||
| enterFrom={isTouchDevice ? 'opacity-0' : ''} | ||
| enterTo={isTouchDevice ? 'opacity-100' : ''} | ||
| > | ||
| <div | ||
| ref={ref} | ||
| className={className} | ||
| onClick={onClick} | ||
| style={{ | ||
| minWidth, | ||
| left: tooltipLeft, | ||
| top: y, | ||
| transform: `translateY(-100%) translateY(-${yOffsetFromCursor}px)` | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| </Transition> | ||
| ) | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice improvement on mobile! Holding a finger a bit longer on the graph is quite intuitive and it's much better to not let any tooltips show up to just disturb the experience.
The only thing that's bothering me a bit is that text outside the graph container (precisely the Channels tab text) gets selected when I tap-and-hold inside the graph container, which in turn makes the OS render a magnifying glass for text selection right next to my finger (instead of the actual tooltip). When I move my finger a bit, it displays the tooltip though.
^ something to fix another day I guess. Nice work!