-
Notifications
You must be signed in to change notification settings - Fork 129
feat: graph events #84
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,7 +184,34 @@ Example: | |
| ``` | ||
|
|
||
| See this [example `<SelectionDot />` component](./example/src/components/CustomSelectionDot.tsx). | ||
| ### `events` | ||
| An array of events to be marked in the graph. The position is calculated based on the `date` property of each event relatively to `points` of the graph. | ||
|
|
||
| ### `EventComponent` | ||
| A component that is used to render an event. | ||
|
|
||
| ### `EventTooltipComponent` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create some default component EventTooltip and link it here as example (same asi SelectionDot)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default component created in the fixup 5ff9fd7. |
||
| An additional event component that is rendered if the `SelectionDot` overlaps an `Event`. | ||
|
|
||
| ### `onEventHover` | ||
This comment was marked as outdated.
Sorry, something went wrong.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The library does not work with any tap gestures so far. The only user interaction so far is created by the pan gesture which is also the gesture that enables the new event functionality of this PR. I would prefer to not add this functionality to not make the PR too big. The |
||
| Callback called when an `Event` is hovered on. | ||
|
|
||
| > Events related props require `animated` and `enablePanGesture` to be `true`. | ||
|
|
||
| Example: | ||
|
|
||
| <img src="./img/events.png" align="right" height="200" /> | ||
|
||
|
|
||
| ```jsx | ||
| <LineGraph | ||
| points={priceHistory} | ||
| color="#4484B2" | ||
| animated={true} | ||
| enablePanGesture={true} | ||
| events={transactionEvents} | ||
| EventComponent={DefaultEventComponent} | ||
| /> | ||
| ``` | ||
| ## Sponsor | ||
|
|
||
| <img src="./img/pinkpanda.png" align="right" height="50"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import React, { useEffect } from 'react' | ||
| import { | ||
| useDerivedValue, | ||
| useSharedValue, | ||
| withSpring, | ||
| withTiming, | ||
| } from 'react-native-reanimated' | ||
|
|
||
| import { Circle, Group } from '@shopify/react-native-skia' | ||
|
|
||
| import { EventComponentProps } from './LineGraphProps' | ||
|
|
||
| const EVENT_SIZE = 6 | ||
| const ACTIVE_EVENT_SIZE = 8 | ||
| const ENTERING_ANIMATION_DURATION = 750 | ||
|
|
||
| export function DefaultGraphEvent({ | ||
| isGraphActive, | ||
| fingerX, | ||
| eventX, | ||
| eventY, | ||
| color, | ||
| }: EventComponentProps) { | ||
| const isEventActive = useDerivedValue( | ||
| () => | ||
| isGraphActive.value && | ||
| Math.abs(fingerX.value - eventX) < ACTIVE_EVENT_SIZE | ||
| ) | ||
|
|
||
| const dotRadius = useDerivedValue(() => | ||
| withSpring(isEventActive.value ? ACTIVE_EVENT_SIZE : EVENT_SIZE) | ||
| ) | ||
|
|
||
| const animatedOpacity = useSharedValue(0) | ||
|
|
||
| useEffect(() => { | ||
| // Entering opacity animation triggered on the first render. | ||
| animatedOpacity.value = withTiming(1, { | ||
| duration: ENTERING_ANIMATION_DURATION, | ||
| }) | ||
| }, [animatedOpacity]) | ||
|
|
||
| return ( | ||
| <Group opacity={animatedOpacity}> | ||
| <Circle cx={eventX} cy={eventY} r={dotRadius} color={color} /> | ||
| </Group> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| import React from 'react' | ||
|
|
||
| import { AnimatedLineGraph } from './AnimatedLineGraph' | ||
| import type { LineGraphProps } from './LineGraphProps' | ||
| import { StaticLineGraph } from './StaticLineGraph' | ||
|
|
||
| function LineGraphImpl(props: LineGraphProps): React.ReactElement { | ||
| if (props.animated) return <AnimatedLineGraph {...props} /> | ||
| else return <StaticLineGraph {...props} /> | ||
| export function LineGraphImpl<TEventPayload extends object>( | ||
| props: LineGraphProps<TEventPayload> | ||
| ): React.ReactElement { | ||
| if (props.animated) return <AnimatedLineGraph<TEventPayload> {...props} /> | ||
| return <StaticLineGraph {...props} /> | ||
| } | ||
|
|
||
| export const LineGraph = React.memo(LineGraphImpl) | ||
| export const LineGraph = React.memo(LineGraphImpl) as typeof LineGraphImpl | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? This should be typed |
||
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.
Link EventComponent file here as example (same as SelectionDot)
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.
Linked in the fixup 5ff9fd7.