Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

improve charts

Bill Yang26c8b0433de0
diff --git a/client/package-lock.json b/client/package-lock.json
index 3c8a72f5a..a65f592cd 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -9,6 +9,8 @@
"version": "0.1.0",
"dependencies": {
"@clickhouse/client": "^1.10.1",
+ "@nivo/core": "^0.88.0",
+ "@nivo/line": "^0.88.0",
"@phosphor-icons/react": "^2.1.7",
"@radix-ui/react-dialog": "^1.1.5",
"@radix-ui/react-dropdown-menu": "^2.1.5",
@@ -18,6 +20,7 @@
"@tanstack/react-query": "^5.64.2",
"@tanstack/react-query-devtools": "^5.64.2",
"@types/country-flag-icons": "^1.2.2",
+ "@types/lodash": "^4.17.15",
"@types/luxon": "^3.4.2",
"@types/pg": "^8.11.11",
"class-variance-authority": "^0.7.1",
@@ -26,6 +29,7 @@
"country-flag-icons": "^1.5.14",
"date-fns": "^4.1.0",
"drizzle-orm": "^0.38.4",
+ "lodash": "^4.17.21",
"lucide-react": "^0.474.0",
"luxon": "^3.5.0",
"next": "15.1.6",
@@ -1450,6 +1454,164 @@
"node": ">= 10"
}
},
+ "node_modules/@nivo/annotations": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/annotations/-/annotations-0.88.0.tgz",
+ "integrity": "sha512-NXE+1oIUn+EGWMQpnpeRMLgi2wyuzhGDoJQY4OUHissCUiNotid2oNQ/PXJwN0toiu+/j9SyhzI32xr70OPi7Q==",
+ "dependencies": {
+ "@nivo/colors": "0.88.0",
+ "@nivo/core": "0.88.0",
+ "@react-spring/web": "9.4.5 || ^9.7.2",
+ "lodash": "^4.17.21"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/axes": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/axes/-/axes-0.88.0.tgz",
+ "integrity": "sha512-jF7aIxzTNayV5cI1J/b9Q1FfpMBxTXGk3OwSigXMSfYWlliskDn2u0qGRLiYhuXFdQAWIp4oXsO1GcAQ0eRVdg==",
+ "dependencies": {
+ "@nivo/core": "0.88.0",
+ "@nivo/scales": "0.88.0",
+ "@react-spring/web": "9.4.5 || ^9.7.2",
+ "@types/d3-format": "^1.4.1",
+ "@types/d3-time-format": "^2.3.1",
+ "d3-format": "^1.4.4",
+ "d3-time-format": "^3.0.0"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/colors": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/colors/-/colors-0.88.0.tgz",
+ "integrity": "sha512-IZ+leYIqAlo7dyLHmsQwujanfRgXyoQ5H7PU3RWLEn1PP0zxDKLgEjFEDADpDauuslh2Tx0L81GNkWR6QSP0Mw==",
+ "dependencies": {
+ "@nivo/core": "0.88.0",
+ "@types/d3-color": "^3.0.0",
+ "@types/d3-scale": "^4.0.8",
+ "@types/d3-scale-chromatic": "^3.0.0",
+ "@types/prop-types": "^15.7.2",
+ "d3-color": "^3.1.0",
+ "d3-scale": "^4.0.2",
+ "d3-scale-chromatic": "^3.0.0",
+ "lodash": "^4.17.21",
+ "prop-types": "^15.7.2"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/core": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/core/-/core-0.88.0.tgz",
+ "integrity": "sha512-XjUkA5MmwjLP38bdrJwn36Gj7T5SYMKD55LYQp/1nIJPdxqJ38dUfE4XyBDfIEgfP6yrHOihw3C63cUdnUBoiw==",
+ "dependencies": {
+ "@nivo/tooltip": "0.88.0",
+ "@react-spring/web": "9.4.5 || ^9.7.2",
+ "@types/d3-shape": "^3.1.6",
+ "d3-color": "^3.1.0",
+ "d3-format": "^1.4.4",
+ "d3-interpolate": "^3.0.1",
+ "d3-scale": "^4.0.2",
+ "d3-scale-chromatic": "^3.0.0",
+ "d3-shape": "^3.2.0",
+ "d3-time-format": "^3.0.0",
+ "lodash": "^4.17.21",
+ "prop-types": "^15.7.2"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/nivo/donate"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/legends": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/legends/-/legends-0.88.0.tgz",
+ "integrity": "sha512-d4DF9pHbD8LmGJlp/Gp1cF4e8y2wfQTcw3jVhbZj9zkb7ZWB7JfeF60VHRfbXNux9bjQ9U78/SssQqueVDPEmg==",
+ "dependencies": {
+ "@nivo/colors": "0.88.0",
+ "@nivo/core": "0.88.0",
+ "@types/d3-scale": "^4.0.8",
+ "d3-scale": "^4.0.2"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/line": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/line/-/line-0.88.0.tgz",
+ "integrity": "sha512-hFTyZ3BdAZvq2HwdwMj2SJGUeodjEW+7DLtFMIIoVIxmjZlAs3z533HcJ9cJd3it928fDm8SF/rgHs0TztYf9Q==",
+ "dependencies": {
+ "@nivo/annotations": "0.88.0",
+ "@nivo/axes": "0.88.0",
+ "@nivo/colors": "0.88.0",
+ "@nivo/core": "0.88.0",
+ "@nivo/legends": "0.88.0",
+ "@nivo/scales": "0.88.0",
+ "@nivo/tooltip": "0.88.0",
+ "@nivo/voronoi": "0.88.0",
+ "@react-spring/web": "9.4.5 || ^9.7.2",
+ "d3-shape": "^3.2.0"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/scales": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/scales/-/scales-0.88.0.tgz",
+ "integrity": "sha512-HbpxkQp6tHCltZ1yDGeqdLcaJl5ze54NPjurfGtx/Uq+H5IQoBd4Tln49bUar5CsFAMsXw8yF1HQvASr7I1SIA==",
+ "dependencies": {
+ "@types/d3-scale": "^4.0.8",
+ "@types/d3-time": "^1.1.1",
+ "@types/d3-time-format": "^3.0.0",
+ "d3-scale": "^4.0.2",
+ "d3-time": "^1.0.11",
+ "d3-time-format": "^3.0.0",
+ "lodash": "^4.17.21"
+ }
+ },
+ "node_modules/@nivo/scales/node_modules/@types/d3-time-format": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/@types/d3-time-format/-/d3-time-format-3.0.4.tgz",
+ "integrity": "sha512-or9DiDnYI1h38J9hxKEsw513+KVuFbEVhl7qdxcaudoiqWWepapUen+2vAriFGexr6W5+P4l9+HJrB39GG+oRg=="
+ },
+ "node_modules/@nivo/tooltip": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/tooltip/-/tooltip-0.88.0.tgz",
+ "integrity": "sha512-iEjVfQA8gumAzg/yUinjTwswygCkE5Iwuo8opwnrbpNIqMrleBV+EAKIgB0PrzepIoW8CFG/SJhoiRfbU8jhOw==",
+ "dependencies": {
+ "@nivo/core": "0.88.0",
+ "@react-spring/web": "9.4.5 || ^9.7.2"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
+ "node_modules/@nivo/voronoi": {
+ "version": "0.88.0",
+ "resolved": "https://registry.npmjs.org/@nivo/voronoi/-/voronoi-0.88.0.tgz",
+ "integrity": "sha512-MyiNLvODthFoMjQ7Wjp693nogbTmVEx8Yn/7QkJhyPQbFyyA37TF/D1a/ox4h2OslXtP6K9QFN+42gB/zu7ixw==",
+ "dependencies": {
+ "@nivo/core": "0.88.0",
+ "@nivo/tooltip": "0.88.0",
+ "@types/d3-delaunay": "^6.0.4",
+ "@types/d3-scale": "^4.0.8",
+ "d3-delaunay": "^6.0.4",
+ "d3-scale": "^4.0.2"
+ },
+ "peerDependencies": {
+ "react": ">= 16.14.0 < 19.0.0"
+ }
+ },
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -2150,6 +2312,72 @@
"resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.1.0.tgz",
"integrity": "sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg=="
},
+ "node_modules/@react-spring/animated": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/animated/-/animated-9.7.5.tgz",
+ "integrity": "sha512-Tqrwz7pIlsSDITzxoLS3n/v/YCUHQdOIKtOJf4yL6kYVSDTSmVK1LI1Q3M/uu2Sx4X3pIWF3xLUhlsA6SPNTNg==",
+ "dependencies": {
+ "@react-spring/shared": "~9.7.5",
+ "@react-spring/types": "~9.7.5"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
+ "node_modules/@react-spring/core": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/core/-/core-9.7.5.tgz",
+ "integrity": "sha512-rmEqcxRcu7dWh7MnCcMXLvrf6/SDlSokLaLTxiPlAYi11nN3B5oiCUAblO72o+9z/87j2uzxa2Inm8UbLjXA+w==",
+ "dependencies": {
+ "@react-spring/animated": "~9.7.5",
+ "@react-spring/shared": "~9.7.5",
+ "@react-spring/types": "~9.7.5"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/react-spring/donate"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
+ "node_modules/@react-spring/rafz": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/rafz/-/rafz-9.7.5.tgz",
+ "integrity": "sha512-5ZenDQMC48wjUzPAm1EtwQ5Ot3bLIAwwqP2w2owG5KoNdNHpEJV263nGhCeKKmuA3vG2zLLOdu3or6kuDjA6Aw=="
+ },
+ "node_modules/@react-spring/shared": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/shared/-/shared-9.7.5.tgz",
+ "integrity": "sha512-wdtoJrhUeeyD/PP/zo+np2s1Z820Ohr/BbuVYv+3dVLW7WctoiN7std8rISoYoHpUXtbkpesSKuPIw/6U1w1Pw==",
+ "dependencies": {
+ "@react-spring/rafz": "~9.7.5",
+ "@react-spring/types": "~9.7.5"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
+ "node_modules/@react-spring/types": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/types/-/types-9.7.5.tgz",
+ "integrity": "sha512-HVj7LrZ4ReHWBimBvu2SKND3cDVUPWKLqRTmWe/fNY6o1owGOX0cAHbdPDTMelgBlVbrTKrre6lFkhqGZErK/g=="
+ },
+ "node_modules/@react-spring/web": {
+ "version": "9.7.5",
+ "resolved": "https://registry.npmjs.org/@react-spring/web/-/web-9.7.5.tgz",
+ "integrity": "sha512-lmvqGwpe+CSttsWNZVr+Dg62adtKhauGwLyGE/RRyZ8AAMLgb9x3NDMA5RMElXo+IMyTkPp7nxTB8ZQlmhb6JQ==",
+ "dependencies": {
+ "@react-spring/animated": "~9.7.5",
+ "@react-spring/core": "~9.7.5",
+ "@react-spring/shared": "~9.7.5",
+ "@react-spring/types": "~9.7.5"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
"node_modules/@swc/counter": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz",
@@ -2227,11 +2455,21 @@
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A=="
},
+ "node_modules/@types/d3-delaunay": {
+ "version": "6.0.4",
+ "resolved": "https://registry.npmjs.org/@types/d3-delaunay/-/d3-delaunay-6.0.4.tgz",
+ "integrity": "sha512-ZMaSKu4THYCU6sV64Lhg6qjf1orxBthaC161plr5KuPHo3CNm8DTHiLw/5Eq2b6TsNP0W0iJrUOFscY6Q450Hw=="
+ },
"node_modules/@types/d3-ease": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@types/d3-ease/-/d3-ease-3.0.2.tgz",
"integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA=="
},
+ "node_modules/@types/d3-format": {
+ "version": "1.4.5",
+ "resolved": "https://registry.npmjs.org/@types/d3-format/-/d3-format-1.4.5.tgz",
+ "integrity": "sha512-mLxrC1MSWupOSncXN/HOlWUAAIffAEBaI4+PKy2uMPsKe4FNZlk7qrbTjmzJXITQQqBHivaks4Td18azgqnotA=="
+ },
"node_modules/@types/d3-interpolate": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
@@ -2253,6 +2491,11 @@
"@types/d3-time": "*"
}
},
+ "node_modules/@types/d3-scale-chromatic": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/@types/d3-scale-chromatic/-/d3-scale-chromatic-3.1.0.tgz",
+ "integrity": "sha512-iWMJgwkK7yTRmWqRB5plb1kadXyQ5Sj8V/zYlFGMUBbIPKQScw+Dku9cAAMgJG+z5GYDoMjWGLVOvjghDEFnKQ=="
+ },
"node_modules/@types/d3-shape": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-3.1.7.tgz",
@@ -2266,11 +2509,21 @@
"resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-1.1.4.tgz",
"integrity": "sha512-JIvy2HjRInE+TXOmIGN5LCmeO0hkFZx5f9FZ7kiN+D+YTcc8pptsiLiuHsvwxwC7VVKmJ2ExHUgNlAiV7vQM9g=="
},
+ "node_modules/@types/d3-time-format": {
+ "version": "2.3.4",
+ "resolved": "https://registry.npmjs.org/@types/d3-time-format/-/d3-time-format-2.3.4.tgz",
+ "integrity": "sha512-xdDXbpVO74EvadI3UDxjxTdR6QIxm1FKzEA/+F8tL4GWWUg/hgvBqf6chql64U5A9ZUGWo7pEu4eNlyLwbKdhg=="
+ },
"node_modules/@types/d3-timer": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@types/d3-timer/-/d3-timer-3.0.2.tgz",
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw=="
},
+ "node_modules/@types/lodash": {
+ "version": "4.17.15",
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.15.tgz",
+ "integrity": "sha512-w/P33JFeySuhN6JLkysYUK2gEmy9kHHFN7E8ro0tkfmlDOgxBDzWEZ/J8cWA+fHqFevpswDTFZnDx+R9lbL6xw=="
+ },
"node_modules/@types/luxon": {
"version": "3.4.2",
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.4.2.tgz",
@@ -2346,6 +2599,11 @@
"node": ">=12"
}
},
+ "node_modules/@types/prop-types": {
+ "version": "15.7.14",
+ "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz",
+ "integrity": "sha512-gNMvNH49DJ7OJYv+KAKn0Xp45p8PLl6zo2YnvDIbTd4J6MER2BmWN49TG7n9LvkyihINxeKW8+3bfS2yDC9dzQ=="
+ },
"node_modules/@types/react": {
"version": "19.0.8",
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.0.8.tgz",
@@ -2678,6 +2936,17 @@
"node": ">=12"
}
},
+ "node_modules/d3-delaunay": {
+ "version": "6.0.4",
+ "resolved": "https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-6.0.4.tgz",
+ "integrity": "sha512-mdjtIZ1XLAM8bm/hx3WwjfHt6Sggek7qH043O8KEjDXN40xi3vx/6pYSVTwLjEgiXQTbvaouWKynLBiUZ6SK6A==",
+ "dependencies": {
+ "delaunator": "5"
+ },
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/d3-ease": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
@@ -2725,6 +2994,18 @@
"node": ">=12"
}
},
+ "node_modules/d3-scale-chromatic": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/d3-scale-chromatic/-/d3-scale-chromatic-3.1.0.tgz",
+ "integrity": "sha512-A3s5PWiZ9YCXFye1o246KoscMWqf8BsD9eRiJ3He7C9OBaxKhAd5TFCdEx/7VbKtxxTsu//1mMJFrEt572cEyQ==",
+ "dependencies": {
+ "d3-color": "1 - 3",
+ "d3-interpolate": "1 - 3"
+ },
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/d3-scale/node_modules/d3-time": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.0.tgz",
@@ -2799,6 +3080,14 @@
"resolved": "https://registry.npmjs.org/decimal.js-light/-/decimal.js-light-2.5.1.tgz",
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg=="
},
+ "node_modules/delaunator": {
+ "version": "5.0.1",
+ "resolved": "https://registry.npmjs.org/delaunator/-/delaunator-5.0.1.tgz",
+ "integrity": "sha512-8nvh+XBe96aCESrGOqMp/84b13H9cdKbG5P2ejQCh4d4sK9RL4371qou9drQjMhvnPmhWl5hnmqbEE0fXr9Xnw==",
+ "dependencies": {
+ "robust-predicates": "^3.0.2"
+ }
+ },
"node_modules/detect-libc": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz",
@@ -4189,6 +4478,11 @@
"node": ">=0.10.0"
}
},
+ "node_modules/robust-predicates": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/robust-predicates/-/robust-predicates-3.0.2.tgz",
+ "integrity": "sha512-IXgzBWvWQwE6PrDI05OvmXUIruQTcoMDzRsOd5CDvHCVLcLHMTSYvOK5Cm46kWqlV3yAbuSpBZdJ5oP5OUoStg=="
+ },
"node_modules/run-parallel": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
diff --git a/client/package.json b/client/package.json
index 2b4556d31..5ece5ef1e 100644
--- a/client/package.json
+++ b/client/package.json
@@ -10,6 +10,8 @@
},
"dependencies": {
"@clickhouse/client": "^1.10.1",
+ "@nivo/core": "^0.88.0",
+ "@nivo/line": "^0.88.0",
"@phosphor-icons/react": "^2.1.7",
"@radix-ui/react-dialog": "^1.1.5",
"@radix-ui/react-dropdown-menu": "^2.1.5",
@@ -19,6 +21,7 @@
"@tanstack/react-query": "^5.64.2",
"@tanstack/react-query-devtools": "^5.64.2",
"@types/country-flag-icons": "^1.2.2",
+ "@types/lodash": "^4.17.15",
"@types/luxon": "^3.4.2",
"@types/pg": "^8.11.11",
"class-variance-authority": "^0.7.1",
@@ -27,6 +30,7 @@
"country-flag-icons": "^1.5.14",
"date-fns": "^4.1.0",
"drizzle-orm": "^0.38.4",
+ "lodash": "^4.17.21",
"lucide-react": "^0.474.0",
"luxon": "^3.5.0",
"next": "15.1.6",
diff --git a/client/src/app/actions/getPageviews.ts b/client/src/app/actions/getPageviews.ts
index 9f63ea8c0..5cf1845cf 100644
--- a/client/src/app/actions/getPageviews.ts
+++ b/client/src/app/actions/getPageviews.ts
@@ -3,7 +3,7 @@
import { clickhouse } from "@/lib/clickhouse";
import { getTimeStatement } from "./utils";
-type GetPageViewsResponse = { time: string; pageviews: number }[];
+export type GetPageViewsResponse = { time: string; pageviews: number }[];
export async function getPageViews({
startDate,
diff --git a/client/src/app/components/MainSection/Chart.tsx b/client/src/app/components/MainSection/Chart.tsx
new file mode 100644
index 000000000..b454882d0
--- /dev/null
+++ b/client/src/app/components/MainSection/Chart.tsx
@@ -0,0 +1,149 @@
+"use client";
+import { Theme } from "@nivo/core";
+import { ResponsiveLine } from "@nivo/line";
+import { GetPageViewsResponse } from "../../actions/getPageviews";
+import { DateTime } from "luxon";
+import { round } from "lodash";
+
+export const nivoTheme: Theme = {
+ axis: {
+ legend: {
+ text: {
+ fill: "hsl(var(--neutral-400))",
+ },
+ },
+ ticks: {
+ line: {},
+ text: {
+ fill: "hsl(var(--neutral-400))",
+ },
+ },
+ },
+ grid: {
+ line: {
+ stroke: "hsl(var(--neutral-800))",
+ strokeWidth: 1,
+ },
+ },
+ tooltip: {
+ basic: {
+ fontFamily: "Roboto Mono",
+ },
+ container: {
+ backdropFilter: "blur( 7px )",
+ background: "rgb(40, 40, 40, 0.8)",
+ color: "rgb(255, 255, 255)",
+ },
+ },
+ crosshair: { line: { stroke: "hsl(var(--neutral-50))" } },
+ annotations: {
+ text: {
+ fill: "hsl(var(--neutral-400))",
+ },
+ },
+ text: {
+ fill: "hsl(var(--neutral-400))",
+ },
+ labels: {
+ text: {
+ fill: "hsl(var(--neutral-400))",
+ },
+ },
+};
+
+export const formatter = Intl.NumberFormat("en", { notation: "compact" });
+
+export function Chart({
+ data,
+}: {
+ data:
+ | {
+ data?: GetPageViewsResponse;
+ error?: string;
+ }
+ | undefined;
+}) {
+ return (
+ <ResponsiveLine
+ data={[
+ {
+ id: "1",
+ data:
+ data?.data?.map((e) => ({
+ x: e.time,
+ y: e.pageviews,
+ })) ?? [],
+ },
+ ]}
+ theme={nivoTheme}
+ margin={{ top: 20, right: 30, bottom: 20, left: 40 }}
+ xScale={{
+ type: "time",
+ format: "%Y-%m-%d %H:%M:%S",
+ precision: "second",
+ }}
+ yScale={{
+ type: "linear",
+ min: 0,
+ max: "auto",
+ stacked: true,
+ reverse: false,
+ }}
+ enableGridX={false}
+ yFormat=" >-.2f"
+ axisTop={null}
+ axisRight={null}
+ axisBottom={{
+ tickSize: 0,
+ tickPadding: 10,
+ tickRotation: 0,
+ truncateTickAt: 0,
+ tickValues: 24,
+ format: (value) => {
+ return DateTime.fromJSDate(value).toFormat("ha");
+ },
+ }}
+ axisLeft={{
+ tickSize: 0,
+ tickPadding: 10,
+ tickRotation: 0,
+ truncateTickAt: 0,
+ tickValues: 5,
+ format: formatter.format,
+ }}
+ enableTouchCrosshair={true}
+ enablePoints={false}
+ useMesh={true}
+ enableSlices={"x"}
+ colors={["hsl(var(--fuchsia-400))"]}
+ enableArea={true}
+ areaBaselineValue={0}
+ areaOpacity={0.3}
+ defs={[
+ {
+ id: "gradient",
+ type: "linearGradient",
+ colors: [
+ { offset: 0, color: "hsl(var(--fuchsia-400))", opacity: 1 },
+ { offset: 100, color: "hsl(var(--fuchsia-400))", opacity: 0 },
+ ],
+ },
+ ]}
+ fill={[{ match: "*", id: "gradient" }]}
+ sliceTooltip={({ slice }) => {
+ return (
+ <div className="text-sm bg-neutral-900 p-2 rounded-md">
+ <div>
+ {DateTime.fromJSDate(
+ slice.points[0].data.x as any
+ ).toLocaleString(DateTime.DATETIME_SHORT)}
+ </div>
+ <div>
+ {round(Number(slice.points[0].data.yFormatted)).toLocaleString()}
+ </div>
+ </div>
+ );
+ }}
+ />
+ );
+}
diff --git a/client/src/app/components/MainSection/MainSection.tsx b/client/src/app/components/MainSection/MainSection.tsx
index c376d4cf7..76c6c0ca7 100644
--- a/client/src/app/components/MainSection/MainSection.tsx
+++ b/client/src/app/components/MainSection/MainSection.tsx
@@ -1,143 +1,18 @@
"use client";
import { Card, CardContent } from "@/components/ui/card";
-import {
- ChartConfig,
- ChartContainer,
- ChartTooltip,
- ChartTooltipContent,
-} from "@/components/ui/chart";
-import { Spinner } from "@/components/ui/spinner";
-import { DateTime } from "luxon";
-import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts";
import { useTimeSelection } from "../../../lib/timeSelectionStore";
-import { formatter } from "../../../lib/utils";
import { useGetPageviews } from "../../hooks/useGetPageviews";
-
-const chartConfig = {
- visitors: {
- label: "Visitors",
- },
- desktop: {
- label: "Desktop",
- color: "hsl(var(--chart-5))",
- // color: "hsl(var(--chart-1))",
- },
- // mobile: {
- // label: "Mobile",
- // color: "hsl(var(--chart-2))",
- // },
-} satisfies ChartConfig;
+import { Chart } from "./Chart";
export function MainSection() {
const { time } = useTimeSelection();
- console.log(time);
-
const { data, isLoading, error } = useGetPageviews();
- let body = <Spinner />;
-
- if (data?.data) {
- const processed = data.data.map((e) => ({
- date: e.time,
- desktop: e.pageviews,
- // mobile: e.pageviews,
- }));
-
- const maxPageviews = Math.max(...processed.map((e) => e.desktop));
-
- body = (
- <AreaChart data={processed}>
- <defs>
- <linearGradient id="fillDesktop" x1="0" y1="0" x2="0" y2="1">
- <stop
- offset="5%"
- stopColor="var(--color-desktop)"
- stopOpacity={0.8}
- />
- <stop
- offset="95%"
- stopColor="var(--color-desktop)"
- stopOpacity={0.1}
- />
- </linearGradient>
- <linearGradient id="fillMobile" x1="0" y1="0" x2="0" y2="1">
- <stop
- offset="5%"
- stopColor="var(--color-mobile)"
- stopOpacity={0.8}
- />
- <stop
- offset="95%"
- stopColor="var(--color-mobile)"
- stopOpacity={0.1}
- />
- </linearGradient>
- </defs>
- <CartesianGrid vertical={false} />
- <XAxis
- dataKey="date"
- tickLine={false}
- axisLine={false}
- tickMargin={8}
- minTickGap={-100}
- // tickCount={10}
- tickFormatter={(value) => {
- const date2 = DateTime.fromFormat(value, "yyyy-MM-dd HH:mm:ss");
- return date2.toFormat("ha");
- }}
- />
- <YAxis
- dataKey="desktop"
- tickLine={false}
- axisLine={false}
- tickMargin={8}
- minTickGap={10}
- tickCount={5}
- domain={[0, maxPageviews]}
- tickFormatter={(value) => {
- return formatter(value);
- }}
- />
- <ChartTooltip
- cursor={false}
- content={
- <ChartTooltipContent
- labelFormatter={(value) => {
- const date2 = DateTime.fromFormat(value, "yyyy-MM-dd HH:mm:ss");
- return date2.toFormat("ha");
- }}
- indicator="dot"
- />
- }
- />
- <Area
- dataKey="mobile"
- type="linear"
- fill="url(#fillMobile)"
- stroke="var(--color-mobile)"
- stackId="a"
- />
- <Area
- dataKey="desktop"
- type="linear"
- fill="url(#fillDesktop)"
- stroke="var(--color-desktop)"
- stackId="a"
- />
- {/* <ChartLegend content={<ChartLegendContent />} /> */}
- </AreaChart>
- );
- }
return (
<Card>
- <CardContent className="pt-4 sm:px-6 sm:pt-6">
- <ChartContainer
- config={chartConfig}
- className="aspect-auto h-[300px] w-full"
- >
- {body}
- </ChartContainer>
+ <CardContent className="pt-4 sm:px-6 sm:pt-6 aspect-auto h-[350px] w-full">
+ <Chart data={data} />
</CardContent>
</Card>
);
diff --git a/client/src/app/components/shared/StandardCard.tsx b/client/src/app/components/shared/StandardCard.tsx
index 199ed15bf..4959676c4 100644
--- a/client/src/app/components/shared/StandardCard.tsx
+++ b/client/src/app/components/shared/StandardCard.tsx
@@ -59,9 +59,7 @@ export function StandardCard<T extends { percentage: number; count: number }>({
))}
{data?.data?.length && data?.data?.length > 10 && (
<Dialog>
- <DialogTrigger>
- <Button variant="outline">View All</Button>
- </DialogTrigger>
+ <Button variant="outline">View All</Button>
<DialogContent className="max-w-[90vw] w-[1000px]">
<DialogHeader>
<DialogTitle>{title}</DialogTitle>