-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): refactor burndown chart and add tooltip (#343)
<div class='graphite__hidden'> <div>🎥 Video uploaded on Graphite:</div> <a href="https://app.graphite.dev/media/video/1VEKR8FQ1Qa5iAiqVGqF/40fe0194-c226-4583-aa62-e79f6aa537e5.mp4"> <img src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/1VEKR8FQ1Qa5iAiqVGqF/40fe0194-c226-4583-aa62-e79f6aa537e5.mp4"> </a> </div> <video src="https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/1VEKR8FQ1Qa5iAiqVGqF/40fe0194-c226-4583-aa62-e79f6aa537e5.mp4">Simulator Screen Recording - iPhone 15 Pro - 2024-09-21 at 18.53.35.mp4</video> Resolves #324
- Loading branch information
Showing
14 changed files
with
472 additions
and
315 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
apps/mobile/components/common/burndown-chart/active-value-indicator.tsx
This file contains 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,108 @@ | ||
import { useColorPalette } from '@/hooks/use-color-palette' | ||
import { useDefaultCurrency } from '@/stores/user-settings/hooks' | ||
import { nFormatter } from '@6pm/currency' | ||
import { dayjsExtended } from '@6pm/utilities' | ||
import { useState } from 'react' | ||
import { runOnJS, useDerivedValue } from 'react-native-reanimated' | ||
import type { ChartPressState } from 'victory-native' | ||
|
||
import { | ||
Circle, | ||
Line as SkiaLine, | ||
Text as SkiaText, | ||
useFont, | ||
vec, | ||
} from '@shopify/react-native-skia' | ||
import { DiffBadge } from './diff-badge' | ||
|
||
type ActiveValueIndicatorProps = { | ||
bottom: number | ||
top: number | ||
pressState: ChartPressState<{ | ||
x: number | ||
y: { | ||
average: number | ||
amount: number | ||
accumulated: number | ||
} | ||
}> | ||
} | ||
|
||
export function ActiveValueIndicator({ | ||
bottom, | ||
top, | ||
pressState, | ||
}: ActiveValueIndicatorProps) { | ||
const { getColor } = useColorPalette() | ||
const tooltipFont = useFont( | ||
require('../../../assets/fonts/Haskoy-Medium.ttf'), | ||
12, | ||
) | ||
const x = pressState.x.position | ||
const y = pressState.y.accumulated.position | ||
const activeValue = pressState.y.amount.value | ||
const date = pressState.x.value | ||
const start = useDerivedValue(() => vec(x.value, bottom - 12)) | ||
const end = useDerivedValue(() => vec(x.value, top + 1.5 * 12)) | ||
const defaultCurrency = useDefaultCurrency() | ||
const [value, setValue] = useState<string>('') | ||
|
||
function formatDate(value: number, date: number) { | ||
const result = ` | ||
${nFormatter(value, 0)} ${defaultCurrency} on ${dayjsExtended( | ||
dayjsExtended().set('date', date), | ||
).format('MMM D')} | ||
` | ||
setValue(result) | ||
} | ||
const activeValueDisplay = useDerivedValue(() => { | ||
runOnJS(formatDate)(activeValue.value, date.value) | ||
return value! | ||
}) | ||
const activeValueWidth = useDerivedValue( | ||
() => | ||
tooltipFont | ||
?.getGlyphWidths?.(tooltipFont.getGlyphIDs(activeValueDisplay.value)) | ||
.reduce((sum, value) => sum + value, 0) || 0, | ||
) | ||
const activeValueX = useDerivedValue(() => { | ||
if (date.value < 5) { | ||
return date.value | ||
} | ||
if (date.value > 26) { | ||
return x.value - activeValueWidth.value | ||
} | ||
return x.value - activeValueWidth.value / 2 | ||
}) | ||
|
||
const diffAmount = Math.round( | ||
(pressState.y.average.value.value || 0) - | ||
(pressState.y.accumulated.value.value || 0), | ||
) | ||
|
||
return ( | ||
<> | ||
<SkiaLine | ||
p1={start} | ||
p2={end} | ||
opacity={0.3} | ||
color={getColor('--muted-foreground')} | ||
strokeWidth={1} | ||
/> | ||
<Circle cx={x} cy={y} r={7} color={getColor('--foreground')} /> | ||
<Circle cx={x} cy={y} r={4.5} color={getColor('--muted')} /> | ||
<SkiaText | ||
color={getColor('--muted-foreground')} | ||
font={tooltipFont} | ||
text={activeValueDisplay} | ||
x={activeValueX} | ||
y={top + 12} | ||
/> | ||
<DiffBadge | ||
anchorDay={date.value} | ||
diffAmount={diffAmount} | ||
point={{ x: x.value, y: y.value }} | ||
/> | ||
</> | ||
) | ||
} |
Oops, something went wrong.