Implement camera stats graphs (#10831)

* Implement camera graphs

* Cleanup naming

* Cleanup rendering

* Cleanup spacing

* Fix audio name

* theme updates to match design corretly

* Mobile color fixes

* Mobile color fixes
This commit is contained in:
Nicolas Mowen
2024-04-04 14:55:04 -06:00
committed by GitHub
parent 466a9104e5
commit fb7cfe5471
22 changed files with 430 additions and 292 deletions

View File

@@ -87,7 +87,7 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {
className={
group == "default"
? "text-selected bg-blue-900 focus:bg-blue-900 bg-opacity-60 focus:bg-opacity-60"
: "text-muted-foreground bg-secondary focus:text-muted-foreground focus:bg-secondary"
: "text-secondary-foreground bg-secondary focus:text-secondary-foreground focus:bg-secondary"
}
size="xs"
onClick={() => (group ? setGroup("default", true) : null)}
@@ -109,7 +109,7 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {
className={
group == name
? "text-selected bg-blue-900 focus:bg-blue-900 bg-opacity-60 focus:bg-opacity-60"
: "text-muted-foreground bg-secondary"
: "text-secondary-foreground bg-secondary"
}
size="xs"
onClick={() => setGroup(name, group != "default")}

View File

@@ -35,7 +35,7 @@ export default function ReviewActionGroup({
}, [selectedReviews, setSelectedReviews, pullLatestData]);
return (
<div className="absolute inset-x-2 inset-y-0 md:left-auto md:right-2 p-2 flex gap-2 justify-between items-center bg-background">
<div className="absolute inset-x-2 inset-y-0 md:left-auto py-2 flex gap-2 justify-between items-center bg-background">
<div className="mx-1 flex justify-center items-center text-sm text-muted-foreground">
<div className="p-1">{`${selectedReviews.length} selected`}</div>
<div className="p-1">{"|"}</div>
@@ -58,7 +58,7 @@ export default function ReviewActionGroup({
}}
>
<FaCompactDisc />
{isDesktop && "Export"}
{isDesktop && <div className="text-primary-foreground">Export</div>}
</Button>
)}
<Button
@@ -68,7 +68,9 @@ export default function ReviewActionGroup({
onClick={onMarkAsReviewed}
>
<FaCircleCheck />
{isDesktop && "Mark as reviewed"}
{isDesktop && (
<div className="text-primary-foreground">Mark as reviewed</div>
)}
</Button>
<Button
className="p-2 flex items-center gap-1"
@@ -77,7 +79,7 @@ export default function ReviewActionGroup({
onClick={onDelete}
>
<HiTrash />
{isDesktop && "Delete"}
{isDesktop && <div className="text-primary-foreground">Delete</div>}
</Button>
</div>
</div>

View File

@@ -223,8 +223,8 @@ function CamerasFilterButton({
variant="secondary"
size="sm"
>
<FaVideo className="text-muted-foreground" />
<div className="hidden md:block">
<FaVideo className="text-secondary-foreground" />
<div className="hidden md:block text-primary-foreground">
{selectedCameras == undefined
? "All Cameras"
: `${selectedCameras.length} Cameras`}
@@ -368,7 +368,7 @@ function ShowReviewFilter({
);
return (
<>
<div className="hidden h-9 md:flex p-2 justify-start items-center text-sm bg-secondary hover:bg-secondary/80 text-secondary-foreground rounded-md cursor-pointer">
<div className="hidden h-9 md:flex p-2 justify-start items-center text-sm bg-secondary hover:bg-secondary/80 text-primary-foreground rounded-md cursor-pointer">
<Switch
id="reviewed"
checked={showReviewedSwitch == 1}
@@ -412,8 +412,8 @@ function CalendarFilterButton({
const trigger = (
<Button size="sm" className="flex items-center gap-2" variant="secondary">
<FaCalendarAlt className="text-muted-foreground" />
<div className="hidden md:block">
<FaCalendarAlt className="text-secondary-foreground" />
<div className="hidden md:block text-primary-foreground">
{day == undefined ? "Last 24 Hours" : selectedDate}
</div>
</Button>
@@ -473,8 +473,8 @@ function GeneralFilterButton({
const trigger = (
<Button size="sm" className="flex items-center gap-2" variant="secondary">
<FaFilter className="text-muted-foreground" />
<div className="hidden md:block">Filter</div>
<FaFilter className="text-secondary-foreground" />
<div className="hidden md:block text-primary-foreground">Filter</div>
</Button>
);
const content = (
@@ -546,7 +546,7 @@ export function GeneralFilterContent({
<div className="h-auto overflow-y-auto overflow-x-hidden">
<div className="flex justify-between items-center my-2.5">
<Label
className="mx-2 text-secondary-foreground cursor-pointer"
className="mx-2 text-primary-foreground cursor-pointer"
htmlFor="allLabels"
>
All Labels
@@ -653,7 +653,7 @@ function ShowMotionOnlyButton({
onCheckedChange={setMotionOnlyButton}
/>
<Label
className="mx-2 text-secondary-foreground cursor-pointer"
className="mx-2 text-primary-foreground cursor-pointer"
htmlFor="collapse-motion"
>
Motion only

View File

@@ -3,6 +3,7 @@ import { FrigateConfig } from "@/types/frigateConfig";
import { Threshold } from "@/types/graph";
import { useCallback, useEffect, useMemo } from "react";
import Chart from "react-apexcharts";
import { MdCircle } from "react-icons/md";
import useSWR from "swr";
type ThresholdBarGraphProps = {
@@ -35,6 +36,10 @@ export function ThresholdBarGraph({
const formatTime = useCallback(
(val: unknown) => {
if (val == 0) {
return;
}
const date = new Date(updateTimes[Math.round(val as number)] * 1000);
return date.toLocaleTimeString([], {
hour12: config?.ui.time_format != "24hour",
@@ -94,6 +99,7 @@ export function ThresholdBarGraph({
tickAmount: 4,
tickPlacement: "on",
labels: {
offsetX: -30,
formatter: formatTime,
},
axisBorder: {
@@ -181,7 +187,7 @@ export function StorageGraph({ graphId, used, total }: StorageGraphProps) {
},
},
tooltip: {
theme: systemTheme || theme,
show: false,
},
xaxis: {
axisBorder: {
@@ -199,7 +205,7 @@ export function StorageGraph({ graphId, used, total }: StorageGraphProps) {
min: 0,
max: 100,
},
};
} as ApexCharts.ApexOptions;
}, [graphId, systemTheme, theme]);
useEffect(() => {
@@ -235,3 +241,135 @@ export function StorageGraph({ graphId, used, total }: StorageGraphProps) {
</div>
);
}
const GRAPH_COLORS = ["#5C7CFA", "#ED5CFA", "#FAD75C"];
type CameraLineGraphProps = {
graphId: string;
unit: string;
dataLabels: string[];
updateTimes: number[];
data: ApexAxisChartSeries;
};
export function CameraLineGraph({
graphId,
unit,
dataLabels,
updateTimes,
data,
}: CameraLineGraphProps) {
const { data: config } = useSWR<FrigateConfig>("config", {
revalidateOnFocus: false,
});
const lastValues = useMemo<number[] | undefined>(() => {
if (!dataLabels || !data || data.length == 0) {
return undefined;
}
return dataLabels.map(
(_, labelIdx) =>
// @ts-expect-error y is valid
data[labelIdx].data[data[labelIdx].data.length - 1]?.y ?? 0,
) as number[];
}, [data, dataLabels]);
const { theme, systemTheme } = useTheme();
const formatTime = useCallback(
(val: unknown) => {
if (val == 0) {
return;
}
const date = new Date(updateTimes[Math.round(val as number)] * 1000);
return date.toLocaleTimeString([], {
hour12: config?.ui.time_format != "24hour",
hour: "2-digit",
minute: "2-digit",
});
},
[config, updateTimes],
);
const options = useMemo(() => {
return {
chart: {
id: graphId,
selection: {
enabled: false,
},
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
colors: GRAPH_COLORS,
grid: {
show: false,
},
legend: {
show: false,
},
dataLabels: {
enabled: false,
},
stroke: {
width: 1,
},
tooltip: {
theme: systemTheme || theme,
},
markers: {
size: 0,
},
xaxis: {
tickAmount: 4,
tickPlacement: "between",
labels: {
offsetX: -30,
formatter: formatTime,
},
axisBorder: {
show: false,
},
axisTicks: {
show: false,
},
},
yaxis: {
show: false,
min: 0,
},
} as ApexCharts.ApexOptions;
}, [graphId, systemTheme, theme, formatTime]);
useEffect(() => {
ApexCharts.exec(graphId, "updateOptions", options, true, true);
}, [graphId, options]);
return (
<div className="w-full flex flex-col">
{lastValues && (
<div className="flex items-center gap-2.5">
{dataLabels.map((label, labelIdx) => (
<div key={label} className="flex items-center gap-1">
<MdCircle
className="size-2"
style={{ color: GRAPH_COLORS[labelIdx] }}
/>
<div className="text-xs text-muted-foreground">{label}</div>
<div className="text-xs text-primary-foreground">
{lastValues[labelIdx]}
{unit}
</div>
</div>
))}
</div>
)}
<Chart type="line" options={options} series={data} height="120" />
</div>
);
}

View File

@@ -1,101 +0,0 @@
import { GraphData } from "@/types/graph";
import Chart from "react-apexcharts";
type TimelineGraphProps = {
id: string;
data: GraphData[];
start: number;
end: number;
objects: number[];
};
/**
* A graph meant to be overlaid on top of a timeline
*/
export default function TimelineGraph({
id,
data,
start,
end,
objects,
}: TimelineGraphProps) {
return (
<Chart
type="bar"
options={{
colors: [
({ dataPointIndex }: { dataPointIndex: number }) => {
if (objects.includes(dataPointIndex)) {
return "#06b6d4";
} else {
return "#991b1b";
}
},
],
chart: {
id: id,
selection: {
enabled: false,
},
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
dataLabels: { enabled: false },
grid: {
show: false,
padding: {
bottom: 2,
top: -12,
left: -20,
right: 0,
},
},
legend: {
show: false,
position: "top",
},
plotOptions: {
bar: {
columnWidth: "100%",
barHeight: "100%",
hideZeroBarsWhenGrouped: true,
},
},
stroke: {
width: 0,
},
tooltip: {
enabled: false,
},
xaxis: {
type: "datetime",
axisBorder: {
show: false,
},
axisTicks: {
show: false,
},
labels: {
show: false,
},
min: start,
max: end,
},
yaxis: {
axisBorder: {
show: false,
},
labels: {
show: false,
},
},
}}
series={data}
height="100%"
/>
);
}

View File

@@ -32,10 +32,10 @@ export function LiveListIcon({ layout }: LiveIconProps) {
return (
<div className="size-full flex flex-col gap-0.5 rounded-md overflow-hidden">
<div
className={`size-full ${layout == "list" ? "bg-selected" : "bg-muted-foreground"}`}
className={`size-full ${layout == "list" ? "bg-selected" : "bg-secondary-foreground"}`}
/>
<div
className={`size-full ${layout == "list" ? "bg-selected" : "bg-muted-foreground"}`}
className={`size-full ${layout == "list" ? "bg-selected" : "bg-secondary-foreground"}`}
/>
</div>
);

View File

@@ -12,11 +12,11 @@ import { TooltipPortal } from "@radix-ui/react-tooltip";
const variants = {
primary: {
active: "font-bold text-white bg-selected",
inactive: "text-muted-foreground bg-secondary",
inactive: "text-secondary-foreground bg-secondary",
},
secondary: {
active: "font-bold text-selected",
inactive: "text-muted-foreground",
inactive: "text-secondary-foreground",
},
};

View File

@@ -122,8 +122,8 @@ export default function ExportDialog({
setMode("select");
}}
>
<FaArrowDown className="p-1 fill-secondary bg-muted-foreground rounded-md" />
{isDesktop && "Export"}
<FaArrowDown className="p-1 fill-secondary bg-secondary-foreground rounded-md" />
{isDesktop && <div className="text-primary-foreground">Export</div>}
</Button>
</Trigger>
<Content

View File

@@ -24,7 +24,7 @@ export default function MobileCameraDrawer({
<Drawer open={cameraDrawer} onOpenChange={setCameraDrawer}>
<DrawerTrigger asChild>
<Button className="rounded-lg capitalize" size="sm" variant="secondary">
<FaVideo className="text-muted-foreground" />
<FaVideo className="text-secondary-foreground" />
</Button>
</DrawerTrigger>
<DrawerContent className="max-h-[75dvh] px-4 mx-1 rounded-t-2xl overflow-hidden">

View File

@@ -137,7 +137,7 @@ export default function MobileReviewSettingsDrawer({
className="w-full flex justify-center items-center gap-2"
onClick={() => setDrawerMode("export")}
>
<FaArrowDown className="p-1 fill-secondary bg-muted-foreground rounded-md" />
<FaArrowDown className="p-1 fill-secondary bg-secondary-foreground rounded-md" />
Export
</Button>
)}
@@ -146,7 +146,7 @@ export default function MobileReviewSettingsDrawer({
className="w-full flex justify-center items-center gap-2"
onClick={() => setDrawerMode("calendar")}
>
<FaCalendarAlt className="fill-muted-foreground" />
<FaCalendarAlt className="fill-secondary-foreground" />
Calendar
</Button>
)}
@@ -155,7 +155,7 @@ export default function MobileReviewSettingsDrawer({
className="w-full flex justify-center items-center gap-2"
onClick={() => setDrawerMode("filter")}
>
<FaFilter className="fill-muted-foreground" />
<FaFilter className="fill-secondary-foreground" />
Filter
</Button>
)}
@@ -282,7 +282,7 @@ export default function MobileReviewSettingsDrawer({
variant="secondary"
onClick={() => setDrawerMode("select")}
>
<FaCog className="text-muted-foreground" />
<FaCog className="text-secondary-foreground" />
</Button>
</DrawerTrigger>
<DrawerContent className="max-h-[80dvh] overflow-hidden flex flex-col items-center gap-2 px-4 pb-4 mx-1 rounded-t-2xl">

View File

@@ -23,7 +23,7 @@ export default function MobileTimelineDrawer({
<Drawer open={drawer} onOpenChange={setDrawer}>
<DrawerTrigger asChild>
<Button className="rounded-lg capitalize" size="sm" variant="secondary">
<FaFlag className="text-muted-foreground" />
<FaFlag className="text-secondary-foreground" />
</Button>
</DrawerTrigger>
<DrawerContent className="max-h-[75dvh] overflow-hidden flex flex-col items-center gap-2 px-4 pb-4 mx-1 rounded-t-2xl">