From b92e87071bf95509b759badf18ed987509fd3541 Mon Sep 17 00:00:00 2001 From: Renato Pozzi Date: Mon, 10 May 2021 00:03:33 +0200 Subject: [PATCH] initial chart improvements --- components/charts/Area.js | 112 +++++++++++++++++++++++++++++++ components/charts/Jumbo.js | 39 ++++++++++- components/charts/Performance.js | 10 +++ pages/websites/[seed]/index.js | 11 ++- 4 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 components/charts/Area.js diff --git a/components/charts/Area.js b/components/charts/Area.js new file mode 100644 index 00000000..de4e82ba --- /dev/null +++ b/components/charts/Area.js @@ -0,0 +1,112 @@ +import Chart from "react-apexcharts"; + +const Area = () => { + const data = { + series: [ + { + name: "series1", + data: [31, 40, 28, 100, 51, 300, 420, 109, 100, 1230], + }, + ], + options: { + chart: { + height: 350, + type: "area", + toolbar: { + show: false, + }, + zoom: { + enabled: false, + }, + // sparkline: { + // enabled: true, + // }, + }, + grid: { + row: { + // colors: ["#e5e5e5", "transparent"], + opacity: 0.5, + }, + column: { + //colors: ["#f8f8f8", "transparent"], + }, + yaxis: { + lines: { + show: false, + }, + }, + xaxis: { + lines: { + show: false, + }, + }, + show: false, + padding: { + left: 0, + right: 0, + }, + }, + dataLabels: { + enabled: false, + }, + stroke: { + curve: "smooth", + }, + yaxis: { + labels: { + show: true, + style: { + colors: "#FFFFFF", + fontSize: "14px", + fontWeight: 800, + cssClass: "apexcharts-xaxis-label", + }, + padding: { + left: 0, + right: 0, + }, + }, + }, + xaxis: { + type: "datetime", + categories: [ + "2018-09-19T00:00:00.000Z", + "2018-09-19T01:30:00.000Z", + "2018-09-19T02:30:00.000Z", + "2018-09-19T03:30:00.000Z", + "2018-09-19T04:30:00.000Z", + "2018-09-19T05:30:00.000Z", + "2018-09-19T06:30:00.000Z", + "2018-09-19T07:30:00.000Z", + "2018-09-19T08:30:00.000Z", + "2018-09-19T09:30:00.000Z", + "2018-09-19T010:30:00.000Z", + ], + axisBorder: { + show: false, + }, + lines: { + show: false, + }, + labels: { + show: true, + style: { + colors: "#FFFFFF", + fontSize: "14px", + fontWeight: 800, + cssClass: "apexcharts-xaxis-label", + }, + }, + }, + tooltip: { + x: { + format: "dd/MM/yy HH:mm", + }, + }, + }, + }; + + return ; +}; + +export default Area; diff --git a/components/charts/Jumbo.js b/components/charts/Jumbo.js index 4f092767..73e13730 100644 --- a/components/charts/Jumbo.js +++ b/components/charts/Jumbo.js @@ -1,6 +1,43 @@ +import { ArrowSmDownIcon, ArrowSmUpIcon } from "@heroicons/react/solid"; + +function classNames(...classes) { + return classes.filter(Boolean).join(" "); +} + +const item = { + changeType: "increase", +}; + export const Jumbo = ({ title, value }) => (
-
{title}
+
+
{title}
+ +
+ {item?.changeType === "increase" ? ( +
+
{value}
); diff --git a/components/charts/Performance.js b/components/charts/Performance.js index 3f959f63..fff0d657 100644 --- a/components/charts/Performance.js +++ b/components/charts/Performance.js @@ -1,5 +1,6 @@ import { Stats } from "../Stats"; import { useGraph } from "../../hooks/useGraph"; +import { Jumbo } from "./Jumbo"; export const Performance = ({ url, timeRange }) => { const { graph, isLoading, isError } = useGraph(url, timeRange); @@ -8,6 +9,14 @@ export const Performance = ({ url, timeRange }) => { if (isError) return
failed to load
; return ( +
+ + + + +
+ + /* { }, ]} /> + */ ); }; diff --git a/pages/websites/[seed]/index.js b/pages/websites/[seed]/index.js index 0c1375e8..b99ea489 100644 --- a/pages/websites/[seed]/index.js +++ b/pages/websites/[seed]/index.js @@ -1,3 +1,4 @@ +import dynamic from "next/dynamic"; import { useState } from "react"; import { withAuth } from "../../../hoc/withAuth"; import { useWebsite } from "../../../hooks/useWebsite"; @@ -11,6 +12,8 @@ import { CountryViews } from "../../../components/charts/CountryViews"; import { RealtimeVisitors } from "../../../components/RealtimeVisitors"; import { RangeSelector } from "../../../components/RangeSelector"; import { PageHeading } from "../../../components/PageHeading"; +import { Jumbo } from "../../../components/charts/Jumbo"; +//import { Area } from "../../../components/charts/Area"; export async function getServerSideProps(context) { const { seed } = context.query; @@ -20,6 +23,8 @@ export async function getServerSideProps(context) { }; } +const Area = dynamic(() => import("../../../components/charts/Area"), { ssr: false }); + const Website = ({ seed }) => { const { website, isLoading, isError } = useWebsite({ seed }); const [timeRange, setTimeRange] = useState(TimeRanges.DAY); @@ -28,7 +33,7 @@ const Website = ({ seed }) => { if (isError) return
failed to load
; return ( -
+
{ /> - + + + {/* */}