Add datatime switcher.

pull/425/head
Andrey Dolgolev 2021-11-16 00:50:08 +02:00
rodzic 44537e67f7
commit e221f1d2d9
3 zmienionych plików z 57 dodań i 19 usunięć

Wyświetl plik

@ -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 = () => {
</Heading>
<Spacer />
<RangeSelector
initialRange={timeRange}
initialRange={MINUTE_KEY}
ranges={Object.keys(timeMap)}
size={["sm", "md", null]}
onChange={(e) => setTimeRange(e)}
onChange={(e) => {
setTimeRange(timeMap[e]);
}}
/>
<IconButton
icon={<BiTrash />}
@ -210,7 +214,8 @@ const Analytics = () => {
{name}
</Text>
<SubscriptionReport
url={s3PresignedURLs.week}
timeRange={timeRange}
url={s3PresignedURLs[timeRange]}
id={v4()}
type={v4()}
/>

Wyświetl plik

@ -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}

Wyświetl plik

@ -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 <Spinner />;
return (
@ -86,7 +85,11 @@ const SubscriptionReport = ({ url, id, type }) => {
>
{key}
</Text>
<Report data={data.events[key]} metric={key} />
<Report
data={data.events[key]}
metric={key}
timeRange={timeRange}
/>
</Flex>
);
})}
@ -123,7 +126,11 @@ const SubscriptionReport = ({ url, id, type }) => {
>
{key}
</Text>
<Report data={data.functions[key]} metric={key} />
<Report
data={data.functions[key]}
metric={key}
timeRange={timeRange}
/>
</Flex>
);
})}
@ -160,7 +167,11 @@ const SubscriptionReport = ({ url, id, type }) => {
>
{key}
</Text>
<Report data={data.generic[key]} metric={key} />
<Report
data={data.generic[key]}
metric={key}
timeRange={timeRange}
/>
</Flex>
);
})}