📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Don't reset zoom on resize
Blue Mousee600967fbcbc
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsxindex f2a9f0459..b84b27afc 100644--- a/web/app/pages/Project/View/ViewProject.helpers.tsx+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx@@ -757,6 +757,7 @@ const getSettingsSession = (rotateXAxis: boolean,chartType: string,onZoom?: (domain: [Date, Date]) => void,+ onresized?: () => void,): ChartOptions => {const xAxisSize = _size(chart.x)@@ -791,6 +792,7 @@ 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.tsxindex f34a6f208..8797a3e42 100644--- a/web/app/pages/Project/View/ViewProject.tsx+++ b/web/app/pages/Project/View/ViewProject.tsx@@ -2217,6 +2217,13 @@ const ViewProject = () => {navigate(_replace(routes.project_settings, ':id', id))}+ const resetSessionChartZoom = () => {+ if (sessionChartInstance) {+ sessionChartInstance.unzoom()+ }+ setZoomedTimeRange(null)+ }+const getFilterLink = (column: string, value: string): LinkProps['to'] => {const isFilterActive = filters.findIndex((filter) => filter.column === column && filter.filter === value) >= 0@@ -2463,21 +2470,6 @@ const ViewProject = () => {</div>)- const handleChartZoom = useCallback((domain: [Date, Date] | null) => {- setZoomedTimeRange(domain)- }, [])-- const handleSessionChartReady = useCallback((chartInst: Chart | null) => {- setSessionChartInstance(chartInst)- }, [])-- const resetSessionChartZoom = () => {- if (sessionChartInstance) {- sessionChartInstance.unzoom()- }- setZoomedTimeRange(null)- }-if (authLoading || !project) {return (<>@@ -3313,8 +3305,9 @@ const ViewProject = () => {rotateXAxis={rotateXAxis}chartType={chartType}dataNames={dataNames}- onZoom={handleChartZoom}- onChartReady={handleSessionChartReady}+ onZoom={setZoomedTimeRange}+ onChartReady={setSessionChartInstance}+ zoomedTimeRange={zoomedTimeRange}/>{zoomedTimeRange ? (<button@@ -3326,7 +3319,7 @@ const ViewProject = () => {) : null}</div>) : null}- <Pageflow pages={activeSession?.pages} timeFormat={timeFormat} zoomDomain={zoomedTimeRange} />+ <Pageflow pages={activeSession?.pages} timeFormat={timeFormat} zoomedTimeRange={zoomedTimeRange} />{_isEmpty(activeSession) && sessionLoading ? <Loader /> : null}{activeSession !== null &&_isEmpty(activeSession?.chart) &&diff --git a/web/app/pages/Project/View/components/Pageflow.tsx b/web/app/pages/Project/View/components/Pageflow.tsxindex 84b08503f..1b0ca48e3 100644--- a/web/app/pages/Project/View/components/Pageflow.tsx+++ b/web/app/pages/Project/View/components/Pageflow.tsx@@ -19,7 +19,7 @@ interface PageflowProps {metadata?: Metadata[]}[]timeFormat: '12-hour' | '24-hour'- zoomDomain?: [Date, Date] | null+ zoomedTimeRange?: [Date, Date] | null}const KeyValue = ({ evKey, evValue }: { evKey: string; evValue: string }) => (@@ -41,20 +41,20 @@ const TransValue = ({ metadata, children }: { metadata?: Metadata[]; children: R</div>)-export const Pageflow = ({ pages, timeFormat, zoomDomain }: PageflowProps) => {+export const Pageflow = ({ pages, timeFormat, zoomedTimeRange }: PageflowProps) => {const {t,i18n: { language },} = useTranslation('common')- const filteredPages = zoomDomain+ const filteredPages = zoomedTimeRange? pages.filter((page) => {const pageTime = new Date(page.created).getTime()- return pageTime >= zoomDomain[0].getTime() && pageTime <= zoomDomain[1].getTime()+ return pageTime >= zoomedTimeRange[0].getTime() && pageTime <= zoomedTimeRange[1].getTime()}): pages- if (zoomDomain && _isEmpty(filteredPages)) {+ if (zoomedTimeRange && _isEmpty(filteredPages)) {return (<div className='my-4 py-8 text-center font-mono text-gray-800 dark:text-gray-300'>{t('project.noEventsForSelectedPeriod')}diff --git a/web/app/pages/Project/View/components/SessionChart.tsx b/web/app/pages/Project/View/components/SessionChart.tsxindex c4b58cf2d..6fd291060 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 } from 'react'+import { useEffect, useRef, useCallback, useMemo } from 'react'import { getSettingsSession } from '../ViewProject.helpers'@@ -14,7 +14,8 @@ interface SessionChartProps {chartType: stringdataNames: anyonZoom?: (domain: [Date, Date] | null) => void- onChartReady?: (chart: Chart) => void+ onChartReady?: (chart: Chart | null) => void+ zoomedTimeRange?: [Date, Date] | null}export const SessionChart = ({@@ -26,9 +27,32 @@ 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,@@ -37,10 +61,12 @@ export const SessionChart = ({rotateXAxis,chartType,onZoom,+ handleChartResized,)if (chartRef.current) {chartRef.current.destroy()+ chartRef.current = null}const generate = billboard.generate(bbSettings)@@ -51,16 +77,32 @@ export const SessionChart = ({onChartReady(generate)}+ if (from && to && generate) {+ generate.zoom([from, to])+ }+return () => {- if (generate) {- generate.destroy()+ if (chartRef.current) {+ chartRef.current.destroy()chartRef.current = nullif (onChartReady) {- onChartReady(null as any)+ onChartReady(null)}}}- }, [chart, timeBucket, timeFormat, rotateXAxis, chartType, dataNames, onChartReady, onZoom])+ }, [+ chart,+ timeBucket,+ timeFormat,+ rotateXAxis,+ chartType,+ dataNames,+ onZoom,+ onChartReady,+ handleChartResized,+ from,+ to,+ ])return <div className='mt-5 h-80 md:mt-0 [&_svg]:!overflow-visible' id='sessionChart' />}