Skip to content
47 changes: 16 additions & 31 deletions studio/src/components/analytics/barlist.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cn } from "@/lib/utils";
import React from "react";
import Link from "next/link";
import { Url } from "next/dist/shared/lib/router/router";
import { cn } from '@/lib/utils';
import React from 'react';
import Link from 'next/link';
import { Url } from 'next/dist/shared/lib/router/router';

type Bar = {
key: string;
Expand Down Expand Up @@ -65,38 +65,29 @@ const BarList = React.forwardRef<HTMLDivElement, BarListProps>((props, ref) => {
}

return (
<div
ref={ref}
className={cn("flex justify-between space-x-6", className)}
{...other}
>
<div className={cn("relative w-full")}>
<div ref={ref} className={cn('flex justify-between space-x-6', className)} {...other}>
<div className={cn('relative w-full')}>
{data.map((item, idx) => {
const Icon = item.icon;

return (
<div
key={item.key}
className={cn(
"flex items-center rounded-sm bg-primary/30 text-secondary-foreground",
'flex items-center rounded-sm bg-primary/30 text-secondary-foreground',
`h-${rowHeight}`,
rowClassName,
idx === data.length - 1 ? "mb-0" : "mb-2",
idx === data.length - 1 ? 'mb-0' : 'mb-2',
)}
style={{
width: `${widths[idx]}%`,
transition: showAnimation ? "all 1s" : "",
transition: showAnimation ? 'all 1s' : '',
}}
>
<div className={cn("absolute left-2 flex w-full text-sm")}>
{Icon ? <Icon className={cn("mr-2 h-5 w-5")} /> : null}
<div className={cn('absolute left-2 flex w-full text-sm')}>
{Icon ? <Icon className={cn('mr-2 h-5 w-5')} /> : null}
{item.href ? (
<Link
href={item.href}
target={item.target}
rel="noreferrer"
className={cn("flex-1 truncate")}
>
<Link href={item.href} target={item.target} rel="noreferrer" className={cn('flex-1 truncate')}>
{item.name}
</Link>
) : (
Expand All @@ -107,26 +98,20 @@ const BarList = React.forwardRef<HTMLDivElement, BarListProps>((props, ref) => {
);
})}
</div>
<div className={"min-w-min text-right"}>
<div className={'min-w-min text-right'}>
{data.map((item, idx) => (
<div
key={item.key}
className={cn(
"flex items-center justify-end",
`h-${rowHeight}`,
idx === data.length - 1 ? "mb-0" : "mb-2",
)}
className={cn('flex items-center justify-end', `h-${rowHeight}`, idx === data.length - 1 ? 'mb-0' : 'mb-2')}
>
<p className={cn("whitespace-nowrap text-sm text-foreground")}>
{valueFormatter(item.value)}
</p>
<p className={cn('whitespace-nowrap text-sm text-foreground')}>{valueFormatter(item.value)}</p>
</div>
))}
</div>
</div>
);
});

BarList.displayName = "BarList";
BarList.displayName = 'BarList';

export default BarList;
83 changes: 21 additions & 62 deletions studio/src/components/analytics/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,33 @@ import {
TooltipProps,
XAxis,
YAxis,
} from "recharts";
import React from "react";
import useWindowSize from "@/hooks/use-window-size";
import { formatDateTime } from "@/lib/format-date";
} from 'recharts';
import React from 'react';
import useWindowSize from '@/hooks/use-window-size';
import { formatDateTime } from '@/lib/format-date';

const labelFormatter = (label: number, utc?: boolean) => {
return utc
? new Date(label).toUTCString()
: label
? formatDateTime(label)
: label;
return utc ? new Date(label).toUTCString() : label ? formatDateTime(label) : label;
};

export const valueFormatter = (tick: number) =>
tick === 0 || tick % 1 != 0 ? "" : `${tick}`;
export const valueFormatter = (tick: number) => (tick === 0 || tick % 1 != 0 ? '' : `${tick}`);

type TimeSetting = "relative" | "local" | "utc";
type TimeSetting = 'relative' | 'local' | 'utc';

export const nanoTimestampToTime = (nano: number) => {
let ms = (nano / 1000000).toFixed(1);

if (parseFloat(ms) > 1000) {
let seconds = (nano / 1000000000).toFixed(1); // Converting nano to seconds
return seconds + " s";
return seconds + ' s';
}
return ms + " ms";
return ms + ' ms';
};

export const tooltipWrapperClassName =
"rounded-md border !border-popover !bg-popover/60 p-2 text-sm shadow-md outline-0 backdrop-blur-lg";
'rounded-md border !border-popover !bg-popover/60 p-2 text-sm shadow-md outline-0 backdrop-blur-lg';

export const ChartTooltip = (
props: TooltipProps<any, any> & { utc?: boolean },
) => {
export const ChartTooltip = (props: TooltipProps<any, any> & { utc?: boolean }) => {
const { utc, ...rest } = props;
return (
<Tooltip
Expand All @@ -53,23 +46,15 @@ export const ChartTooltip = (
);
};

ChartTooltip.displayName = "Tooltip";
ChartTooltip.displayName = 'Tooltip';

export const CustomTooltip = ({
active,
payload,
label,
p95,
utc,
valueLabel = "Value",
}: any) => {
export const CustomTooltip = ({ active, payload, label, p95, utc, valueLabel = 'Value' }: any) => {
if (active && payload && payload.length) {
return (
<div className={tooltipWrapperClassName}>
<p className="label">{labelFormatter(label, utc)}</p>
<p className="intro">
{valueLabel}:{" "}
{p95 ? nanoTimestampToTime(payload[0].value) : payload[0].value}
{valueLabel}: {p95 ? nanoTimestampToTime(payload[0].value) : payload[0].value}
</p>
</div>
);
Expand Down Expand Up @@ -101,12 +86,7 @@ export const BarChartComponent = ({
return (
<ResponsiveContainer width="100%" height={chartHeight} className="-ml-6">
<BarChart data={data}>
<CartesianGrid
color="currenColor"
strokeWidth="0.2"
vertical={false}
strokeDasharray="3 1"
/>
<CartesianGrid color="currentColor" strokeWidth="0.2" vertical={false} strokeDasharray="3 1" />
Comment thread
comatory marked this conversation as resolved.
<Bar dataKey="value" fill="indianred" barSize={12} />
<XAxis
dataKey="timestamp"
Expand All @@ -120,14 +100,8 @@ export const BarChartComponent = ({
right: isMobile ? 16 : 32,
}}
/>
<YAxis
tickFormatter={valueFormatter}
dataKey="value"
axisLine={false}
tickLine={false}
interval={1}
/>
<ChartTooltip utc={viewOption.value === "utc"} />
<YAxis tickFormatter={valueFormatter} dataKey="value" axisLine={false} tickLine={false} interval={1} />
<ChartTooltip utc={viewOption.value === 'utc'} />
</BarChart>
</ResponsiveContainer>
);
Expand Down Expand Up @@ -165,19 +139,10 @@ export const LineChartComponent = ({
className?: string;
}) => {
return (
<ResponsiveContainer
width="100%"
height={chartHeight}
className={className}
>
<ResponsiveContainer width="100%" height={chartHeight} className={className}>
<LineChart data={data}>
{cartesianGrid && (
<CartesianGrid
color="currenColor"
strokeWidth="0.2"
vertical={false}
strokeDasharray="3 1"
/>
<CartesianGrid color="currentColor" strokeWidth="0.2" vertical={false} strokeDasharray="3 1" />
)}
<Line dot={false} type="monotone" dataKey="value" strokeWidth="2" />
<XAxis
Expand All @@ -191,15 +156,9 @@ export const LineChartComponent = ({
padding={xAxisPadding}
hide={hideXAxis}
/>
<YAxis
tickFormatter={yAxisTickFormatter}
dataKey="value"
axisLine={false}
tickLine={false}
hide={hideYAxis}
/>
<YAxis tickFormatter={yAxisTickFormatter} dataKey="value" axisLine={false} tickLine={false} hide={hideYAxis} />

<ChartTooltip utc={viewOption.value === "utc"} />
<ChartTooltip utc={viewOption.value === 'utc'} />
</LineChart>
</ResponsiveContainer>
);
Expand Down
Loading
Loading