-
Notifications
You must be signed in to change notification settings - Fork 584
fix: WIP Chart and tooltips are not informative #3915
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 5 commits
012b154
f1d51fc
d3fbe99
bc45baf
fe8061f
4244b92
a1add6d
f9e4616
1343ec4
d039e99
ff8fbb0
27299c8
4860cb0
c0dbd09
038238c
f09ae5b
105c8a4
a611f0c
ec30287
bd59fff
519e83d
cb0425d
379a093
0f2d2d0
138d1ed
d703d6b
38d4239
d02bab9
4bb804e
d2db157
e035f3b
eca153c
3e1bb17
a48344d
e654219
a8fcd5b
84088f5
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||
ChartTooltipContent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} from "@/components/ui/chart"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { formatNumber } from "@/lib/fmt"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import type { CompoundTimeseriesGranularity } from "@/lib/trpc/routers/utils/granularity"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Grid } from "@unkey/icons"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEffect, useRef, useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Bar, BarChart, ReferenceArea, ResponsiveContainer, YAxis } from "recharts"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -18,8 +19,8 @@ import { calculateTimePoints } from "./utils/calculate-timepoints"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
import { formatTimestampLabel } from "./utils/format-timestamp"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
type Selection = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
start: string | number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
end: string | number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
start: string | number | undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
end: string | number | undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
startTimestamp?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
endTimestamp?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
21
to
26
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. 🧹 Nitpick (assertive) Narrow Selection types to numbers to avoid coercions. Store numeric x values and drop string union; fewer Number() casts downstream. type Selection = {
- start: string | number | undefined;
- end: string | number | undefined;
+ start: number | undefined;
+ end: number | undefined;
startTimestamp?: number;
endTimestamp?: number;
}; And coerce on mouse down: - setSelection({
- start: e.activeLabel,
- end: e.activeLabel,
+ const labelNum = Number(e.activeLabel);
+ setSelection({
+ start: labelNum,
+ end: labelNum, 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -30,6 +31,13 @@ type TimeseriesData = { | |||||||||||||||||||||||||||||||||||||||||||||||||||
[key: string]: unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
type ChartMouseEvent = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
activeLabel?: string | number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
activePayload?: Array<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
payload: TimeseriesData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
type LogsTimeseriesBarChartProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data?: TimeseriesData[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
config: ChartConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -39,6 +47,7 @@ type LogsTimeseriesBarChartProps = { | |||||||||||||||||||||||||||||||||||||||||||||||||||
isLoading?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
isError?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
enableSelection?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
granularity?: CompoundTimeseriesGranularity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
export function LogsTimeseriesBarChart({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -50,9 +59,13 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
isLoading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
isError, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
enableSelection = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
granularity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}: LogsTimeseriesBarChartProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const chartRef = useRef<HTMLDivElement>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const [selection, setSelection] = useState<Selection>({ start: "", end: "" }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const [selection, setSelection] = useState<Selection>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
start: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
end: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// biome-ignore lint/correctness/useExhaustiveDependencies: We need this to re-trigger distanceToTop calculation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -62,8 +75,7 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}, [onMount, isLoading, isError]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// biome-ignore lint/suspicious/noExplicitAny: those are safe to leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleMouseDown = (e: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleMouseDown = (e: ChartMouseEvent) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!enableSelection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -76,8 +88,7 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// biome-ignore lint/suspicious/noExplicitAny: those are safe to leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleMouseMove = (e: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleMouseMove = (e: ChartMouseEvent) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!enableSelection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -104,8 +115,8 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
onSelectionChange({ start, end }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
setSelection({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
start: "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
end: "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
start: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
end: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
startTimestamp: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
endTimestamp: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -126,9 +137,8 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
? calculateTimePoints( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data[0]?.originalTimestamp ?? Date.now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data.at(-1)?.originalTimestamp ?? Date.now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
).map((time, i) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
<div key={i} className="z-10"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
).map((time) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
<div key={time.getTime()} className="z-10"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{formatTimestampLabel(time)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -187,8 +197,11 @@ export function LogsTimeseriesBarChart({ | |||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
className="rounded-lg shadow-lg border border-gray-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
labelFormatter={(_, payload) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||
//@ts-expect-error This is okay to ignore | ||||||||||||||||||||||||||||||||||||||||||||||||||||
createTimeIntervalFormatter(data, "HH:mm")(payload) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
createTimeIntervalFormatter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
"HH:mm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
granularity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
)(payload as TimeseriesData[]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.