Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

simplify session chart zoom feature

Blue Mouse2af144a26c2f
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index 3ab987bc2..6dad855e2 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -765,7 +765,6 @@ const getSettingsSession = (
rotateXAxis: boolean,
chartType: string,
onZoom?: (domain: [Date, Date]) => void,
- onresized?: () => void,
): ChartOptions => {
const chartData = chartInput || { x: [] } // Default to an empty chart structure if undefined
const xAxisSize = _size(chartData.x)
@@ -813,7 +812,6 @@ const getSettingsSession = (
auto: true,
timer: false,
},
- onresized,
axis: {
x: {
clipPath: false,
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 0d2593aac..6902d592d 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -3379,7 +3379,6 @@ const ViewProject = () => {
dataNames={dataNames}
onZoom={setZoomedTimeRange}
onChartReady={setSessionChartInstance}
- zoomedTimeRange={zoomedTimeRange}
/>
{zoomedTimeRange ? (
<button
diff --git a/web/app/pages/Project/View/components/SessionChart.tsx b/web/app/pages/Project/View/components/SessionChart.tsx
index fd4d437d7..91c024dd5 100644
--- a/web/app/pages/Project/View/components/SessionChart.tsx
+++ b/web/app/pages/Project/View/components/SessionChart.tsx
@@ -1,5 +1,5 @@
import billboard, { type ChartOptions, type Chart } from 'billboard.js'
-import { useEffect, useRef, useCallback, useMemo } from 'react'
+import { useEffect, useRef } from 'react'
import { getSettingsSession } from '../ViewProject.helpers'
@@ -17,7 +17,6 @@ interface SessionChartProps {
dataNames: any
onZoom?: (domain: [Date, Date] | null) => void
onChartReady?: (chart: Chart | null) => void
- zoomedTimeRange?: [Date, Date] | null
}
export const SessionChart = ({
@@ -29,32 +28,9 @@ export const SessionChart = ({
dataNames,
onZoom,
onChartReady,
- zoomedTimeRange,
}: SessionChartProps) => {
const chartRef = useRef<Chart | null>(null)
- const [from, to] = useMemo(() => {
- if (!zoomedTimeRange?.[0] || !zoomedTimeRange?.[1]) {
- return [null, null]
- }
-
- return [zoomedTimeRange[0], zoomedTimeRange[1]]
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [
- // eslint-disable-next-line react-hooks/exhaustive-deps
- zoomedTimeRange?.[0]?.getTime(),
- // eslint-disable-next-line react-hooks/exhaustive-deps
- zoomedTimeRange?.[1]?.getTime(),
- ])
-
- const handleChartResized = useCallback(() => {
- if (!chartRef.current || !from || !to) {
- return
- }
-
- chartRef.current.zoom([from, to])
- }, [from, to])
-
useEffect(() => {
const bbSettings: ChartOptions = getSettingsSession(
chart,
@@ -63,12 +39,10 @@ export const SessionChart = ({
rotateXAxis,
chartType,
onZoom,
- handleChartResized,
)
if (chartRef.current) {
chartRef.current.destroy()
- chartRef.current = null
}
const generate = billboard.generate(bbSettings)
@@ -79,32 +53,18 @@ export const SessionChart = ({
onChartReady(generate)
}
- if (from && to && generate) {
- generate.zoom([from, to])
- }
-
return () => {
- if (chartRef.current) {
- chartRef.current.destroy()
- chartRef.current = null
- if (onChartReady) {
- onChartReady(null)
- }
+ if (!generate) {
+ return
+ }
+
+ generate.destroy()
+ chartRef.current = null
+ if (onChartReady) {
+ onChartReady(null)
}
}
- }, [
- chart,
- timeBucket,
- timeFormat,
- rotateXAxis,
- chartType,
- dataNames,
- onZoom,
- onChartReady,
- handleChartResized,
- from,
- to,
- ])
+ }, [chart, timeBucket, timeFormat, rotateXAxis, chartType, dataNames, onZoom, onChartReady])
return <div className='mt-5 h-80 md:mt-0 [&_svg]:!overflow-visible' id='sessionChart' />
}