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!

billboard feature

kruzhambus4aadd02d0094
diff --git a/src/hooks/useSize.jsx b/src/hooks/useSize.jsx
new file mode 100644
index 000000000..312a9a41c
--- /dev/null
+++ b/src/hooks/useSize.jsx
@@ -0,0 +1,27 @@
+/* eslint-disable consistent-return */
+import { useEffect, useRef, useState } from 'react'
+import _get from 'lodash/get'
+
+export default () => {
+ const [size, setSize] = useState({
+ width: 0, height: 0,
+ })
+ const ref = useRef(null)
+ useEffect(() => {
+ const DOMnode = ref.current
+ if (!DOMnode) {
+ return
+ }
+ const resizeObserver = new ResizeObserver((entries) => {
+ setSize({
+ width: _get(entries, '0.contentRect.width', 0),
+ height: _get(entries, '0.contentRect.height', 0),
+ })
+ })
+ resizeObserver.observe(DOMnode)
+ return () => {
+ resizeObserver.unobserve(DOMnode)
+ }
+ }, [])
+ return [ref, size]
+}
diff --git a/src/pages/Project/View/ViewProject.helpers.jsx b/src/pages/Project/View/ViewProject.helpers.jsx
index 1801f0472..a7718a378 100644
--- a/src/pages/Project/View/ViewProject.helpers.jsx
+++ b/src/pages/Project/View/ViewProject.helpers.jsx
@@ -236,7 +236,7 @@ const getColumnsPerf = (chart, activeChartMetrics) => {
const noRegionPeriods = ['custom', 'yesterday']
// function to get the settings and data for the chart(main diagram)
-const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFormat) => {
+const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFormat, rotateXAxias) => {
const xAxisSize = _size(chart.x)
let regions
@@ -317,6 +317,7 @@ const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFo
x: {
tick: {
fit: true,
+ rotate: rotateXAxias ? 45 : 0,
format: timeFormat === TimeFormat['24-hour'] ? (x) => d3.timeFormat(tbsFormatMapper24h[timeBucket])(x) : null,
},
localtime: timeFormat === TimeFormat['24-hour'],
@@ -377,7 +378,7 @@ const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFo
}
}
-const getSettingsPerf = (chart, timeBucket, activeChartMetrics) => {
+const getSettingsPerf = (chart, timeBucket, activeChartMetrics, rotateXAxias) => {
const xAxisSize = _size(chart.x)
return {
@@ -418,6 +419,7 @@ const getSettingsPerf = (chart, timeBucket, activeChartMetrics) => {
type: 'timeseries',
tick: {
format: tbsFormatMapper[timeBucket],
+ rotate: rotateXAxias ? 45 : 0,
},
},
y: {
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 82697c501..ddb9c3053 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -2,6 +2,7 @@
import React, {
useState, useEffect, useMemo, memo, useRef, Fragment, useCallback,
} from 'react'
+import useSize from 'hooks/useSize'
import { useHistory, useParams, Link } from 'react-router-dom'
import domToImage from 'dom-to-image'
import { saveAs } from 'file-saver'
@@ -22,7 +23,6 @@ import _values from 'lodash/values'
import _find from 'lodash/find'
import _filter from 'lodash/filter'
import _startsWith from 'lodash/startsWith'
-import _isEqual from 'lodash/isEqual'
import _debounce from 'lodash/debounce'
import _some from 'lodash/some'
import PropTypes from 'prop-types'
@@ -132,6 +132,8 @@ const ViewProject = ({
const [isPanelsDataEmptyPerf, setIsPanelsDataEmptyPerf] = useState(false)
const [panelsDataPerf, setPanelsDataPerf] = useState({})
const timeFormat = useMemo(() => user.timeFormat || TimeFormat['12-hour'], [user])
+ const [ref, size] = useSize()
+ console.log('size', size)
const tabs = useMemo(() => {
return [
@@ -615,6 +617,65 @@ const ViewProject = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeTab])
+ useEffect(() => {
+ if ((size.width < 400 && size.width > 50) && !isLoading) {
+ if (activeTab === PROJECT_TABS.performance) {
+ const bbSettings = getSettingsPerf(chartDataPerf, timeBucket, activeChartMetricsPerf, true)
+
+ if (!_isEmpty(mainChart)) {
+ mainChart.destroy()
+ }
+
+ setMainChart(() => {
+ const generete = bb.generate(bbSettings)
+ generete.data.names(dataNamesPerf)
+ return generete
+ })
+ } else {
+ const applyRegions = !_includes(noRegionPeriods, activePeriod.period)
+ const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat, true)
+
+ if (!_isEmpty(mainChart)) {
+ mainChart.destroy()
+ }
+
+ setMainChart(() => {
+ const generete = bb.generate(bbSettings)
+ generete.data.names(dataNames)
+ return generete
+ })
+ }
+ } else if (size.width > 400 && !isLoading) {
+ if (activeTab === PROJECT_TABS.performance) {
+ const bbSettings = getSettingsPerf(chartDataPerf, timeBucket, activeChartMetricsPerf)
+
+ if (!_isEmpty(mainChart)) {
+ mainChart.destroy()
+ }
+
+ setMainChart(() => {
+ const generete = bb.generate(bbSettings)
+ generete.data.names(dataNamesPerf)
+ return generete
+ })
+ } else {
+ const applyRegions = !_includes(noRegionPeriods, activePeriod.period)
+ const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat)
+
+ if (!_isEmpty(mainChart)) {
+ mainChart.destroy()
+ }
+
+ setMainChart(() => {
+ const generete = bb.generate(bbSettings)
+ generete.data.names(dataNames)
+ return generete
+ })
+ }
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [size.width, activeTab, chartData, chartDataPerf, isLoading])
+
useEffect(() => {
if (activeTab === PROJECT_TABS.traffic) {
if (!isLoading && !_isEmpty(chartData) && !_isEmpty(mainChart)) {
@@ -1416,6 +1477,7 @@ const ViewProject = ({
className={cx('h-80', {
hidden: checkIfAllMetricsAreDisabled,
})}
+ ref={ref}
>
<div className='h-80' id='dataChart' />
</div>
@@ -1532,6 +1594,7 @@ const ViewProject = ({
className={cx('h-80', {
hidden: checkIfAllMetricsAreDisabled,
})}
+ ref={ref}
>
<div className='h-80' id='dataChart' />
</div>
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index 6f20b310f..45448e453 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -75,17 +75,17 @@ export const timeBucketToDays = [
]
export const tbsFormatMapper = {
- hour: '%d %B %H:%M',
- day: '%d %B',
- week: '%d %B',
- month: '%d %B %Y',
+ hour: '%d %b %H:%M',
+ day: '%d %b',
+ week: '%d %b',
+ month: '%d %b %Y',
}
export const tbsFormatMapper24h = {
hour: '%H:%M',
- day: '%d %B',
- week: '%d %B',
- month: '%d %B %Y',
+ day: '%d %b',
+ week: '%d %b',
+ month: '%d %b %Y',
}
export const TimeFormat = {