Skip to content

Commit

Permalink
Merge pull request #1 from HousewareHQ/product-analytics/adding-info-…
Browse files Browse the repository at this point in the history
…for-graph

changes for adding some ui elements for metadata of pa charts
  • Loading branch information
babboe1 authored Sep 2, 2024
2 parents 2ddcf55 + f416ecb commit 064012f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 37 additions & 2 deletions src/components/charts/Funnels.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import { Card, Flex, Typography } from "antd";
import { Card, Flex, Typography, Tag } from "antd";
import ReactECharts from "echarts-for-react";

import Markdown from "react-markdown";
import { useThemeManager } from "../useThemeManager";
import getFunnelsChartOptions from "./getFunnelsChartOptions";
import { CalendarOutlined, FieldTimeOutlined } from "@ant-design/icons";

function formatConversionWindow(intervalInSeconds: number): string {
const units = [
{ value: 60 * 60 * 24 * 30, name: 'month' },
{ value: 60 * 60 * 24 * 7, name: 'week' },
{ value: 60 * 60 * 24, name: 'day' },
{ value: 60 * 60, name: 'hour' },
{ value: 60, name: 'minute' },
{ value: 1, name: 'second' }
];

for (const unit of units) {
if (intervalInSeconds >= unit.value) {
const value = Math.round(intervalInSeconds / unit.value * 100) / 100;
const unitName = value === 1 ? unit.name : `${unit.name}s`;
return `${value} ${unitName}`;
}
}

return `${intervalInSeconds} seconds`;
}

export function Funnels({
chartResponse,
Expand All @@ -20,6 +41,12 @@ export function Funnels({
themeMode: currentTheme,
});

const startDate = queryConfiguration?.start_date;
const endDate = queryConfiguration?.end_date;

const windowInterval = queryConfiguration?.conversion?.window_interval;
const formattedWindow = formatConversionWindow(windowInterval);

return (
<Flex
vertical
Expand All @@ -35,6 +62,14 @@ export function Funnels({
width: "100%",
}}
>
<Flex justify="flex-end" align="center" style={{ marginBottom: 16 }}>
<Tag icon={<CalendarOutlined />} color="blue">
{startDate} - {endDate}
</Tag>
<Tag icon={<FieldTimeOutlined />} color="green" style={{ marginLeft: 8 }}>
{formattedWindow} window
</Tag>
</Flex>
<ReactECharts
style={{ height: "40vh", width: "100%" }}
option={chartOptions}
Expand Down
11 changes: 10 additions & 1 deletion src/components/charts/Trends.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Card, Flex, Typography } from "antd";
import { Card, Flex, Typography, Tag } from "antd";
import ReactECharts from "echarts-for-react";
import Markdown from "react-markdown";
import { useThemeManager } from "../useThemeManager";
import { getTrendsChartOptions } from "./getTrendsChartOptions";
import { CalendarOutlined } from "@ant-design/icons";

export function Trends({
chartResponse,
Expand All @@ -19,6 +20,9 @@ export function Trends({
themeMode: currentTheme,
});

const startDate = queryConfiguration?.time?.start_date;
const endDate = queryConfiguration?.time?.end_date;

return (
<Flex
vertical
Expand All @@ -34,6 +38,11 @@ export function Trends({
width: "100%",
}}
>
<Flex justify="flex-end" align="center" style={{ marginBottom: 16 }}>
<Tag icon={<CalendarOutlined />} color="blue">
{startDate} - {endDate}
</Tag>
</Flex>
<ReactECharts
style={{ height: "40vh", width: "100%" }}
option={chartOptions}
Expand Down

0 comments on commit 064012f

Please sign in to comment.