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 inconsistent annotation length cutoff

Blue Mouse1164fa924b81
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index 0029174a2..e7d4722be 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -58,6 +58,9 @@ import countries from '~/utils/isoCountries'
import { TrafficLogResponse } from './interfaces/traffic'
+// Max length of annotation text displayed on chart (truncated with "...")
+export const ANNOTATION_CHART_TEXT_MAX_LENGTH = 25
+
const { saveAs } = filesaver
const getAvg = (arr: any) => {
@@ -508,7 +511,10 @@ const getSettings = (
// Convert annotations to grid lines
const lines: GridLineOptions[] = _map(annotations || [], (annotation) => ({
value: dayjs(annotation.date).toDate(),
- text: annotation.text.length > 25 ? `${annotation.text.substring(0, 25)}...` : annotation.text,
+ text:
+ annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
+ ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
+ : annotation.text,
class: 'annotation-line',
position: 'start',
}))
@@ -1019,7 +1025,10 @@ const getSettingsError = (
// Convert annotations to grid lines
const annotationLines: GridLineOptions[] = _map(annotations || [], (annotation) => ({
value: dayjs(annotation.date).toDate(),
- text: annotation.text.length > 25 ? `${annotation.text.substring(0, 25)}...` : annotation.text,
+ text:
+ annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
+ ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
+ : annotation.text,
class: 'annotation-line',
position: 'start',
}))
@@ -1352,7 +1361,10 @@ const getSettingsPerf = (
// Convert annotations to grid lines
const annotationLines: GridLineOptions[] = _map(annotations || [], (annotation) => ({
value: dayjs(annotation.date).toDate(),
- text: annotation.text.length > 25 ? `${annotation.text.substring(0, 25)}...` : annotation.text,
+ text:
+ annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
+ ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
+ : annotation.text,
class: 'annotation-line',
position: 'start',
}))
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index ab60f5351..df61de32f 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -218,6 +218,7 @@ import {
SHORTCUTS_TIMEBUCKETS_LISTENERS,
CHART_MEASURES_MAPPING_PERF,
getDeviceRowMapper,
+ ANNOTATION_CHART_TEXT_MAX_LENGTH,
} from './ViewProject.helpers'
const SESSIONS_TAKE = 30
@@ -835,7 +836,10 @@ const ViewProjectContent = () => {
// Find annotation that matches this text (could be truncated)
existingAnnotation =
annotations.find(
- (a) => a.text === lineText || (a.text.length > 20 && `${a.text.substring(0, 20)}...` === lineText),
+ (a) =>
+ a.text === lineText ||
+ (a.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH &&
+ `${a.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...` === lineText),
) || null
if (existingAnnotation) {
date = dayjs(existingAnnotation.date).format('YYYY-MM-DD')