diff --git a/components/common/HoverTooltip.js b/components/common/HoverTooltip.js
index 2a98ab84..59fd6277 100644
--- a/components/common/HoverTooltip.js
+++ b/components/common/HoverTooltip.js
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import { Tooltip } from 'react-basics';
import styles from './HoverTooltip.module.css';
-export function HoverTooltip({ tooltip }) {
+export function HoverTooltip({ children }) {
const [position, setPosition] = useState({ x: -1000, y: -1000 });
useEffect(() => {
@@ -18,8 +18,8 @@ export function HoverTooltip({ tooltip }) {
}, []);
return (
-
-
+
+
);
}
diff --git a/components/common/WorldMap.js b/components/common/WorldMap.js
index 55a13f0b..a371e2d3 100644
--- a/components/common/WorldMap.js
+++ b/components/common/WorldMap.js
@@ -15,7 +15,7 @@ import styles from './WorldMap.module.css';
export function WorldMap({ data, className }) {
const { basePath } = useRouter();
const [tooltip, setTooltip] = useState();
- const [theme] = useTheme();
+ const { theme } = useTheme();
const colors = useMemo(
() => ({
baseColor: THEME_COLORS[theme].primary,
diff --git a/components/input/LanguageButton.js b/components/input/LanguageButton.js
index e2a51223..049b49f3 100644
--- a/components/input/LanguageButton.js
+++ b/components/input/LanguageButton.js
@@ -9,9 +9,9 @@ export function LanguageButton() {
const { locale, saveLocale, dir } = useLocale();
const items = Object.keys(languages).map(key => ({ ...languages[key], value: key }));
- function handleSelect(value) {
- //saveLocale(value);
- console.log('WTFFFF');
+ function handleSelect(value, close) {
+ saveLocale(value);
+ close();
}
return (
@@ -22,24 +22,28 @@ export function LanguageButton() {
-
- {items.map(({ value, label }) => {
- return (
-
- {label}
- {value === locale && (
-
-
-
- )}
-
- );
- })}
-
+ {close => {
+ return (
+
+ {items.map(({ value, label }) => {
+ return (
+
+ {label}
+ {value === locale && (
+
+
+
+ )}
+
+ );
+ })}
+
+ );
+ }}
);
diff --git a/components/input/ThemeButton.js b/components/input/ThemeButton.js
index b945ab7d..8ab0cdcd 100644
--- a/components/input/ThemeButton.js
+++ b/components/input/ThemeButton.js
@@ -5,7 +5,7 @@ import Icons from 'components/icons';
import styles from './ThemeButton.module.css';
export function ThemeButton() {
- const [theme, setTheme] = useTheme();
+ const { theme, saveTheme } = useTheme();
const transitions = useTransition(theme, {
initial: { opacity: 1 },
@@ -21,7 +21,7 @@ export function ThemeButton() {
});
function handleClick() {
- setTheme(theme === 'light' ? 'dark' : 'light');
+ saveTheme(theme === 'light' ? 'dark' : 'light');
}
return (
diff --git a/components/messages.js b/components/messages.js
index fb0dee3c..0de3a44c 100644
--- a/components/messages.js
+++ b/components/messages.js
@@ -123,7 +123,11 @@ export const labels = defineMessages({
reports: { id: 'label.reports', defaultMessage: 'Reports' },
eventData: { id: 'label.event-data', defaultMessage: 'Event data' },
funnel: { id: 'label.funnel', defaultMessage: 'Funnel' },
+ url: { id: 'label.url', defaultMessage: 'URL' },
urls: { id: 'label.urls', defaultMessage: 'URLs' },
+ add: { id: 'label.add', defaultMessage: 'Add' },
+ window: { id: 'label.window', defaultMessage: 'Window' },
+ addUrl: { id: 'label.add-url', defaultMessage: 'Add URL' },
});
export const messages = defineMessages({
diff --git a/components/metrics/BarChart.js b/components/metrics/BarChart.js
index 8e1784df..9206b800 100644
--- a/components/metrics/BarChart.js
+++ b/components/metrics/BarChart.js
@@ -1,102 +1,39 @@
-import { useState, useRef, useEffect, useMemo, useCallback } from 'react';
-import { StatusLight, Loading } from 'react-basics';
+import { useState, useRef, useEffect, useCallback } from 'react';
+import { Loading } from 'react-basics';
import classNames from 'classnames';
import Chart from 'chart.js/auto';
import HoverTooltip from 'components/common/HoverTooltip';
import Legend from 'components/metrics/Legend';
import { formatLongNumber } from 'lib/format';
-import { dateFormat } from 'lib/date';
import useLocale from 'hooks/useLocale';
import useTheme from 'hooks/useTheme';
-import { DEFAULT_ANIMATION_DURATION, THEME_COLORS } from 'lib/constants';
+import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
import styles from './BarChart.module.css';
+function defaultRenderYLabel(label) {
+ return +label > 1000 ? formatLongNumber(label) : label;
+}
+
export function BarChart({
datasets,
unit,
animationDuration = DEFAULT_ANIMATION_DURATION,
stacked = false,
loading = false,
- onCreate = () => {},
- onUpdate = () => {},
+ renderXLabel,
+ renderYLabel,
+ XAxisType = 'time',
+ YAxisType = 'linear',
+ renderTooltip,
+ onCreate,
+ onUpdate,
className,
}) {
const canvas = useRef();
const chart = useRef(null);
const [tooltip, setTooltip] = useState(null);
const { locale } = useLocale();
- const [theme] = useTheme();
-
- const colors = useMemo(
- () => ({
- text: THEME_COLORS[theme].gray700,
- line: THEME_COLORS[theme].gray200,
- }),
- [theme],
- );
-
- const renderYLabel = label => {
- return +label > 1000 ? formatLongNumber(label) : label;
- };
-
- const renderXLabel = useCallback(
- (label, index, values) => {
- const d = new Date(values[index].value);
-
- switch (unit) {
- case 'minute':
- return dateFormat(d, 'h:mm', locale);
- case 'hour':
- return dateFormat(d, 'p', locale);
- case 'day':
- return dateFormat(d, 'MMM d', locale);
- case 'month':
- return dateFormat(d, 'MMM', locale);
- case 'year':
- return dateFormat(d, 'YYY', locale);
- default:
- return label;
- }
- },
- [locale, unit],
- );
-
- const renderTooltip = useCallback(
- model => {
- const { opacity, labelColors, dataPoints } = model.tooltip;
-
- if (!dataPoints?.length || !opacity) {
- setTooltip(null);
- return;
- }
-
- const formats = {
- millisecond: 'T',
- second: 'pp',
- minute: 'p',
- hour: 'h:mm aaa - PP',
- day: 'PPPP',
- week: 'PPPP',
- month: 'LLLL yyyy',
- quarter: 'qqq',
- year: 'yyyy',
- };
-
- setTooltip(
-
-
{dateFormat(new Date(dataPoints[0].raw.x), formats[unit], locale)}
-
-
-
- {formatLongNumber(dataPoints[0].raw.y)} {dataPoints[0].dataset.label}
-
-
-
-
,
- );
- },
- [unit],
- );
+ const { theme, colors } = useTheme();
const getOptions = useCallback(() => {
return {
@@ -117,12 +54,12 @@ export function BarChart({
},
tooltip: {
enabled: false,
- external: renderTooltip,
+ external: renderTooltip ? renderTooltip.bind(null, setTooltip) : undefined,
},
},
scales: {
x: {
- type: 'time',
+ type: XAxisType,
stacked: true,
time: {
unit,
@@ -131,34 +68,44 @@ export function BarChart({
display: false,
},
border: {
- color: colors.line,
+ color: colors.chart.line,
},
ticks: {
- color: colors.text,
+ color: colors.chart.text,
autoSkip: false,
maxRotation: 0,
callback: renderXLabel,
},
},
y: {
- type: 'linear',
+ type: YAxisType,
min: 0,
beginAtZero: true,
stacked,
grid: {
- color: colors.line,
+ color: colors.chart.line,
},
border: {
- color: colors.line,
+ color: colors.chart.line,
},
ticks: {
color: colors.text,
- callback: renderYLabel,
+ callback: renderYLabel || defaultRenderYLabel,
},
},
},
};
- }, [animationDuration, renderTooltip, renderXLabel, stacked, colors, unit, locale]);
+ }, [
+ animationDuration,
+ renderTooltip,
+ renderXLabel,
+ XAxisType,
+ YAxisType,
+ stacked,
+ colors,
+ unit,
+ locale,
+ ]);
const createChart = () => {
Chart.defaults.font.family = 'Inter';
@@ -173,7 +120,7 @@ export function BarChart({
options,
});
- onCreate(chart.current);
+ onCreate?.(chart.current);
};
const updateChart = () => {
@@ -186,7 +133,7 @@ export function BarChart({
chart.current.options = getOptions();
- onUpdate(chart.current);
+ onUpdate?.(chart.current);
chart.current.update();
};
@@ -208,7 +155,11 @@ export function BarChart({