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!

fix: disable chart zoom on mobile devices

Blue Mouse0f8adeccd4e5
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index a2ad3f1f6..f95d1d313 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -1234,6 +1234,7 @@ const getSettingsSession = (
rotateXAxis: boolean,
chartType: string,
onZoom?: (domain: [Date, Date]) => void,
+ enableZoom: boolean = true,
): ChartOptions => {
const chartData = chartInput || { x: [] } // Default to an empty chart structure if undefined
const xAxisSize = _size(chartData.x)
@@ -1291,12 +1292,14 @@ const getSettingsSession = (
colors: dataColors,
type: chartType === chartTypes.line ? area() : bar(),
},
- zoom: {
- enabled: zoom(),
- type: 'drag',
- onzoom: onZoom,
- resetButton: false, // We render a custom button that also resets pageflow
- },
+ zoom: enableZoom
+ ? {
+ enabled: zoom(),
+ type: 'drag',
+ onzoom: onZoom,
+ resetButton: false, // We render a custom button that also resets pageflow
+ }
+ : undefined,
grid: {
y: {
show: true,
diff --git a/web/app/pages/Project/tabs/Sessions/SessionChart.tsx b/web/app/pages/Project/tabs/Sessions/SessionChart.tsx
index 2d2eae136..e2c463837 100644
--- a/web/app/pages/Project/tabs/Sessions/SessionChart.tsx
+++ b/web/app/pages/Project/tabs/Sessions/SessionChart.tsx
@@ -30,6 +30,17 @@ export const SessionChart = ({
onZoom,
className,
}: SessionChartProps) => {
+ const isTouchDevice = useMemo(() => {
+ if (typeof window === 'undefined') return false
+ const hasTouchEvent = 'ontouchstart' in window
+ const hasMaxTouchPoints =
+ typeof navigator !== 'undefined' && navigator.maxTouchPoints > 0
+ const coarsePointer = window.matchMedia
+ ? window.matchMedia('(pointer: coarse)').matches
+ : false
+ return hasTouchEvent || hasMaxTouchPoints || coarsePointer
+ }, [])
+
const options: ChartOptions = useMemo(() => {
// Session inspector chart is always rendered as a line/area chart,
// regardless of the user's global chart type preference.
@@ -40,12 +51,21 @@ export const SessionChart = ({
rotateXAxis,
chartTypes.line,
onZoom,
+ !isTouchDevice,
)
- }, [chart, timeBucket, timeFormat, rotateXAxis, onZoom])
+ }, [chart, timeBucket, timeFormat, rotateXAxis, onZoom, isTouchDevice])
const deps = useMemo(
- () => [chart, timeBucket, timeFormat, rotateXAxis, dataNames, onZoom],
- [chart, timeBucket, timeFormat, rotateXAxis, dataNames, onZoom],
+ () => [
+ chart,
+ timeBucket,
+ timeFormat,
+ rotateXAxis,
+ dataNames,
+ onZoom,
+ isTouchDevice,
+ ],
+ [chart, timeBucket, timeFormat, rotateXAxis, dataNames, onZoom, isTouchDevice],
)
return (
diff --git a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
index 179127757..6ff40aafc 100644
--- a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
+++ b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
@@ -137,6 +137,17 @@ export const SessionDetailView = ({
null,
)
+ const isTouchDevice = useMemo(() => {
+ if (typeof window === 'undefined') return false
+ const hasTouchEvent = 'ontouchstart' in window
+ const hasMaxTouchPoints =
+ typeof navigator !== 'undefined' && navigator.maxTouchPoints > 0
+ const coarsePointer = window.matchMedia
+ ? window.matchMedia('(pointer: coarse)').matches
+ : false
+ return hasTouchEvent || hasMaxTouchPoints || coarsePointer
+ }, [])
+
const sessionDuration = useMemo(() => {
if (!activeSession?.details) return 0
@@ -400,7 +411,7 @@ export const SessionDetailView = ({
>
{t('project.sessionActivity')}
</Text>
- {zoomedTimeRange ? (
+ {zoomedTimeRange && !isTouchDevice ? (
<button
onClick={resetZoom}
className='rounded border bg-white px-2 py-1 text-xs text-gray-800 hover:bg-gray-100 dark:border-slate-700 dark:bg-slate-800 dark:text-gray-200 hover:dark:bg-slate-700'
@@ -415,7 +426,7 @@ export const SessionDetailView = ({
timeFormat={timeFormat}
rotateXAxis={rotateXAxis}
dataNames={dataNames}
- onZoom={setZoomedTimeRange}
+ onZoom={isTouchDevice ? undefined : setZoomedTimeRange}
className='h-[300px] [&_svg]:overflow-visible!'
/>
</div>