From e221f1d2d960483e9b2ec013c3a1268a34d90a9f Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Tue, 16 Nov 2021 00:50:08 +0200 Subject: [PATCH] Add datatime switcher. --- frontend/pages/dashboard/[dashboardId].js | 17 ++++++--- frontend/src/components/Report.js | 38 +++++++++++++++---- frontend/src/components/SubscriptionReport.js | 21 +++++++--- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/frontend/pages/dashboard/[dashboardId].js b/frontend/pages/dashboard/[dashboardId].js index a8581698..fa006bd3 100644 --- a/frontend/pages/dashboard/[dashboardId].js +++ b/frontend/pages/dashboard/[dashboardId].js @@ -20,9 +20,11 @@ import { v4 } from "uuid"; const HOUR_KEY = "Hourly"; const DAY_KEY = "Daily"; +const MINUTE_KEY = "Minutes"; let timeMap = {}; -timeMap[HOUR_KEY] = "hour"; -timeMap[DAY_KEY] = "day"; +timeMap[DAY_KEY] = "month"; +timeMap[HOUR_KEY] = "week"; +timeMap[MINUTE_KEY] = "day"; const Analytics = () => { const { toggleAlert } = useContext(OverlayContext); @@ -89,7 +91,7 @@ const Analytics = () => { // [nodesReady] // ); - const [timeRange, setTimeRange] = useState(HOUR_KEY); + const [timeRange, setTimeRange] = useState(timeMap[MINUTE_KEY]); const router = useRouter(); const { dashboardId } = router.params; const { dashboardCache, dashboardLinksCache, deleteDashboard } = @@ -169,10 +171,12 @@ const Analytics = () => { setTimeRange(e)} + onChange={(e) => { + setTimeRange(timeMap[e]); + }} /> } @@ -210,7 +214,8 @@ const Analytics = () => { {name} diff --git a/frontend/src/components/Report.js b/frontend/src/components/Report.js index ec7d9df8..e8b9fe00 100644 --- a/frontend/src/components/Report.js +++ b/frontend/src/components/Report.js @@ -1,7 +1,7 @@ import React from "react"; import { ResponsiveLineCanvas } from "@nivo/line"; -const Report = ({ data, metric }) => { +const Report = ({ data, metric, timeRange }) => { const commonProperties = { animate: false, enableSlices: "x", @@ -24,7 +24,29 @@ const Report = ({ data, metric }) => { const xyCumulativeData = xyData.map(generateCumulativeSum(0)); - console.log(`metric ${metric} \n xyCumulativeData: `, xyCumulativeData); + const timeformat_scale = { + month: "%Y-%m-%d %H", + week: "%Y-%m-%d %H", + day: "%Y-%m-%d %H %M", + }; + + const timeformat_xformat = { + month: "time:%Y-%m-%d %H", + week: "time:%Y-%m-%d %H", + day: "time:%Y-%m-%d %H %M", + }; + + const axis_format = { + month: "%m-%d", + week: "%d", + day: "%H:%M", + }; + + const tickValues_format = { + month: "every 1 days", + week: "every 1 days", + day: "every 1 hours", + }; const plotData = [{ id: "1", data: xyCumulativeData }]; @@ -36,11 +58,11 @@ const Report = ({ data, metric }) => { isInteractive={true} xScale={{ type: "time", - format: "%Y-%m-%d %H", + format: timeformat_scale[timeRange], useUTC: false, - precision: "hour", + precision: "minute", }} - xFormat="time:%Y-%m-%d %H" + xFormat={timeformat_xformat[timeRange]} yScale={{ type: "linear", max: "auto", @@ -56,14 +78,14 @@ const Report = ({ data, metric }) => { legend: "count", }} axisBottom={{ - format: "%Y-%m-%d", - tickValues: "every 1 day", + format: axis_format[timeRange], + tickValues: tickValues_format[timeRange], legend: "time", tickRotation: 0, legendOffset: 35, legendPosition: "middle", }} - curve={"basis"} + curve={"monotoneY"} enableArea={true} enablePointLabel={false} pointSize={0} diff --git a/frontend/src/components/SubscriptionReport.js b/frontend/src/components/SubscriptionReport.js index d66a563a..d90ecaa0 100644 --- a/frontend/src/components/SubscriptionReport.js +++ b/frontend/src/components/SubscriptionReport.js @@ -12,14 +12,13 @@ timeMap[HOUR_KEY] = "hour"; timeMap[DAY_KEY] = "day"; timeMap[WEEK_KEY] = "week"; -const SubscriptionReport = ({ url, id, type }) => { +const SubscriptionReport = ({ timeRange, url, id, type }) => { const { data, isLoading } = usePresignedURL({ url: url, isEnabled: true, id: id, type: type, }); - const plotMinW = "500px"; if (!data || isLoading) return ; return ( @@ -86,7 +85,11 @@ const SubscriptionReport = ({ url, id, type }) => { > {key} - + ); })} @@ -123,7 +126,11 @@ const SubscriptionReport = ({ url, id, type }) => { > {key} - + ); })} @@ -160,7 +167,11 @@ const SubscriptionReport = ({ url, id, type }) => { > {key} - + ); })}