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: filter out annotations that are always visible for the 'Today' period

Blue Mousec3c81de9bb79
diff --git a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
index 153aa220b..a80e3d8fc 100644
--- a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
+++ b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
@@ -1,4 +1,5 @@
import cx from 'clsx'
+import dayjs from 'dayjs'
import _isEmpty from 'lodash/isEmpty'
import _keys from 'lodash/keys'
import _map from 'lodash/map'
@@ -235,6 +236,23 @@ const PerformanceViewInner = ({
const overallCompare: Partial<OverallPerformanceObject> = {}
const chartDataCompare: any = {}
+ // Filter annotations to only those within the chart's visible x-axis range
+ const filteredAnnotations = useMemo(() => {
+ const xAxis = (chartData as { x?: string[] })?.x
+ if (!annotations?.length || !xAxis?.length) return annotations || []
+
+ const rangeStart = dayjs(xAxis[0]).startOf('day')
+ const rangeEnd = dayjs(xAxis[xAxis.length - 1]).endOf('day')
+
+ return annotations.filter((a) => {
+ const d = dayjs(a.date)
+ return (
+ (d.isAfter(rangeStart) || d.isSame(rangeStart, 'day')) &&
+ (d.isBefore(rangeEnd) || d.isSame(rangeEnd, 'day'))
+ )
+ })
+ }, [annotations, chartData])
+
// Panel active tabs
const [activeTabs, setActiveTabs] = useState<{
location: 'cc' | 'rg' | 'ct' | 'map'
@@ -488,7 +506,7 @@ const PerformanceViewInner = ({
enableZoom={shouldEnableZoom}
dataNames={dataNames}
className='mt-5 h-80 md:mt-0 [&_svg]:overflow-visible!'
- annotations={annotations}
+ annotations={filteredAnnotations}
/>
</div>
) : null}
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index 3712f8c7d..b3ff9a965 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -1,4 +1,5 @@
import cx from 'clsx'
+import dayjs from 'dayjs'
import _filter from 'lodash/filter'
import _includes from 'lodash/includes'
import _isEmpty from 'lodash/isEmpty'
@@ -610,6 +611,23 @@ const TrafficViewInner = ({
[activeChartMetrics, activeChartMetricsCustomEvents],
)
+ // Filter annotations to only those within the chart's visible x-axis range
+ const filteredAnnotations = useMemo(() => {
+ const xAxis = (chartData as { x?: string[] })?.x
+ if (!annotations?.length || !xAxis?.length) return annotations || []
+
+ const rangeStart = dayjs(xAxis[0]).startOf('day')
+ const rangeEnd = dayjs(xAxis[xAxis.length - 1]).endOf('day')
+
+ return annotations.filter((a) => {
+ const d = dayjs(a.date)
+ return (
+ (d.isAfter(rangeStart) || d.isSame(rangeStart, 'day')) &&
+ (d.isBefore(rangeEnd) || d.isSame(rangeEnd, 'day'))
+ )
+ })
+ }, [annotations, chartData])
+
const isConflicted = useCallback(
(conflicts: string[] | undefined) => {
if (!conflicts) return false
@@ -1089,7 +1107,7 @@ const TrafficViewInner = ({
enableZoom={shouldEnableZoom}
dataNames={dataNames}
className='mt-5 h-80 md:mt-0 [&_svg]:overflow-visible!'
- annotations={annotations}
+ annotations={filteredAnnotations}
/>
</div>
) : null}