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!

improved chart

Blue Mouse52356176d52f
diff --git a/src/pages/Project/View/ViewProject.helpers.jsx b/src/pages/Project/View/ViewProject.helpers.jsx
index 7d18a5ba1..817094c88 100644
--- a/src/pages/Project/View/ViewProject.helpers.jsx
+++ b/src/pages/Project/View/ViewProject.helpers.jsx
@@ -19,7 +19,7 @@ import _reduce from 'lodash/reduce'
import JSZip from 'jszip'
import { tbsFormatMapper } from 'redux/constants'
-import { getTimeFromSeconds, getStringFromTime } from 'utils/generic'
+import { getTimeFromSeconds, getStringFromTime, sumArrays } from 'utils/generic'
import countries from 'utils/isoCountries'
const getAvg = (arr) => {
@@ -136,17 +136,10 @@ const CHART_METRICS_MAPPING = {
const CHART_METRICS_MAPPING_PERF = {
full: 'full',
+ timing: 'timing',
network: 'network',
frontend: 'frontend',
backend: 'backend',
- dns: 'dns',
- tls: 'tls',
- conn: 'conn',
- response: 'response',
- render: 'render',
- dom_load: 'dom_load',
- page_load: 'page_load',
- ttfb: 'ttfb',
}
// function to filter the data for the chart
@@ -203,7 +196,7 @@ const getColumnsPerf = (chart, activeChartMetrics) => {
const columns = [
['x', ..._map(chart.x, el => dayjs(el).toDate())],
]
- console.log(activeChartMetrics)
+
if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.full) {
columns.push(['dns', ...chart.dns])
columns.push(['tls', ...chart.tls])
@@ -211,10 +204,15 @@ const getColumnsPerf = (chart, activeChartMetrics) => {
columns.push(['response', ...chart.response])
columns.push(['render', ...chart.render])
columns.push(['dom_load', ...chart.domLoad])
- columns.push(['page_load', ...chart.pageLoad])
columns.push(['ttfb', ...chart.ttfb])
}
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.timing) {
+ columns.push(['frontend', ...sumArrays(chart.render, chart.domLoad)])
+ columns.push(['network', ...sumArrays(chart.dns, chart.tls, chart.conn, chart.response)])
+ columns.push(['backend', ...chart.ttfb])
+ }
+
if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.network) {
columns.push(['dns', ...chart.dns])
columns.push(['tls', ...chart.tls])
@@ -225,47 +223,12 @@ const getColumnsPerf = (chart, activeChartMetrics) => {
if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.frontend) {
columns.push(['render', ...chart.render])
columns.push(['dom_load', ...chart.domLoad])
- columns.push(['page_load', ...chart.pageLoad])
}
if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.backend) {
columns.push(['ttfb', ...chart.ttfb])
}
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.dns) {
- columns.push(['dns', ...chart.dns])
- }
-
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.tls) {
- columns.push(['tls', ...chart.tls])
- }
-
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.conn) {
- columns.push(['conn', ...chart.conn])
- }
-
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.response) {
- columns.push(['response', ...chart.response])
- }
-
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.render) {
- columns.push(['render', ...chart.render])
- }
-
- // eslint-disable-next-line camelcase
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.dom_load) {
- columns.push(['dom_load', ...chart.domLoad])
- }
-
- // eslint-disable-next-line camelcase
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.page_load) {
- columns.push(['page_load', ...chart.pageLoad])
- }
-
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.ttfb) {
- columns.push(['ttfb', ...chart.ttfb])
- }
-
return columns
}
@@ -540,7 +503,7 @@ const getSettingsPerf = (chart, timeBucket, activeChartMetrics, applyRegions) =>
},
y: {
tick: {
- format: (d) => `${d} ms`,
+ format: (d) => getStringFromTime(getTimeFromSeconds(d), true),
},
},
},
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 94fa7a593..f2e956951 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -99,7 +99,7 @@ const ViewProject = ({
[CHART_METRICS_MAPPING.viewsPerUnique]: false,
[CHART_METRICS_MAPPING.trendlines]: false,
})
- const [activeChartMetricsPerf, setActiveChartMetricsPerf] = useState(CHART_METRICS_MAPPING_PERF.full)
+ const [activeChartMetricsPerf, setActiveChartMetricsPerf] = useState(CHART_METRICS_MAPPING_PERF.timing)
const [sessionDurationAVG, setSessionDurationAVG] = useState(null)
const checkIfAllMetricsAreDisabled = useMemo(() => !_some(activeChartMetrics, (value) => value), [activeChartMetrics])
const [filters, setFilters] = useState([])
@@ -179,9 +179,14 @@ const ViewProject = ({
return [
{
id: CHART_METRICS_MAPPING_PERF.full,
- label: t('dashboard.timing'),
+ label: t('dashboard.timingFull'),
active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.full),
},
+ {
+ id: CHART_METRICS_MAPPING_PERF.timing,
+ label: t('dashboard.timing'),
+ active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.timing),
+ },
{
id: CHART_METRICS_MAPPING_PERF.network,
label: t('dashboard.network'),
@@ -197,46 +202,6 @@ const ViewProject = ({
label: t('dashboard.backend'),
active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.backend),
},
- {
- id: CHART_METRICS_MAPPING_PERF.dns,
- label: t('dashboard.dns'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.dns),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.tls,
- label: t('dashboard.tls'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.tls),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.conn,
- label: t('dashboard.conn'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.conn),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.response,
- label: t('dashboard.response'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.response),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.render,
- label: t('dashboard.render'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.render),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.dom_load,
- label: t('dashboard.domLoad'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.dom_load),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.page_load,
- label: t('dashboard.pageLoad'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.page_load),
- },
- {
- id: CHART_METRICS_MAPPING_PERF.ttfb,
- label: t('dashboard.ttfb'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.ttfb),
- },
]
}, [t, activeChartMetricsPerf])
@@ -264,7 +229,6 @@ const ViewProject = ({
response: t('dashboard.response'),
render: t('dashboard.render'),
dom_load: t('dashboard.domLoad'),
- page_load: t('dashboard.pageLoad'),
ttfb: t('dashboard.ttfb'),
}
}, [t])
diff --git a/src/utils/generic.js b/src/utils/generic.js
index edb44b624..f665cc644 100644
--- a/src/utils/generic.js
+++ b/src/utils/generic.js
@@ -1,5 +1,8 @@
import _find from 'lodash/find'
import _replace from 'lodash/replace'
+import _round from 'lodash/round'
+import _map from 'lodash/map'
+import _reduce from 'lodash/reduce'
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/
@@ -47,16 +50,27 @@ export const getTimeFromSeconds = (seconds) => {
const h = 0 | seconds / 3600
const m = 0 | (seconds % 3600) / 60
const s = 0 | seconds % 60
+ const ms = 0 | (seconds % 1) * 1000
- return { h, m, s }
+ return {
+ h, m, s, ms,
+ }
}
-export const getStringFromTime = (time) => {
- const { h, m, s } = time
+export const getStringFromTime = (time, showMS) => {
+ const {
+ h, m, s, ms,
+ } = time
- if (h === 0 && m === 0 && s === 0) {
+ if (h === 0 && m === 0 && s === 0 && (!showMS || ms === 0)) {
return '0s'
}
- return `${h ? `${h}h ` : ''}${m ? `${m}m ` : ''}${s ? `${s}s` : ''}`
+ return `${h ? `${h}h ` : ''}${m ? `${m}m ` : ''}${s || (showMS && ms > 0) ? `${showMS ? _round(s + ms / 1000, 2) : s}s` : ''}`
+}
+
+export const sumArrays = (...arrays) => {
+ return _map(arrays[0], (_, index) => {
+ return _reduce(arrays, (sum, array) => sum + array[index], 0)
+ })
}