2025-03-19 12:36:33 +00:00
|
|
|
import { useMemo, useState } from "react";
|
|
|
|
import ChartComponent from "../../layout/sidebarLeft/visualization/widgets/ChartComponent";
|
|
|
|
import { useWidgetStore } from "../../../store/useWidgetStore";
|
2025-03-20 11:00:43 +00:00
|
|
|
import PieGraphComponent from "../charts/PieGraphComponent";
|
|
|
|
import BarGraphComponent from "../charts/BarGraphComponent";
|
|
|
|
import LineGraphComponent from "../charts/LineGraphComponent";
|
2025-03-19 12:36:33 +00:00
|
|
|
|
|
|
|
export const DraggableWidget = ({ widget }: { widget: any }) => {
|
|
|
|
const { selectedChartId, setSelectedChartId } = useWidgetStore();
|
|
|
|
|
|
|
|
const handlePointerDown = () => {
|
|
|
|
if (selectedChartId?.id !== widget.id) {
|
|
|
|
setSelectedChartId(widget);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
key={widget.id}
|
2025-03-20 11:00:43 +00:00
|
|
|
className={`chart-container ${
|
|
|
|
selectedChartId?.id === widget.id && "activeChart"
|
|
|
|
}`}
|
2025-03-19 12:36:33 +00:00
|
|
|
onPointerDown={handlePointerDown}
|
|
|
|
>
|
|
|
|
{widget.type === "progress" ? (
|
2025-03-20 11:00:43 +00:00
|
|
|
// <ProgressCard title={widget.title} data={widget.data} />
|
|
|
|
<></>
|
2025-03-19 12:36:33 +00:00
|
|
|
) : (
|
2025-03-20 11:00:43 +00:00
|
|
|
<>
|
|
|
|
{widget.type === "line" && (
|
|
|
|
<LineGraphComponent
|
|
|
|
type={widget.type}
|
|
|
|
title={widget.title}
|
|
|
|
fontSize={widget.fontSize}
|
|
|
|
fontWeight={widget.fontWeight}
|
|
|
|
data={{
|
|
|
|
measurements: [
|
|
|
|
{ name: "testDevice", fields: "powerConsumption" },
|
|
|
|
{ name: "furnace", fields: "powerConsumption" },
|
|
|
|
],
|
|
|
|
interval: 1000,
|
|
|
|
duration: "1h",
|
|
|
|
}}
|
2025-03-19 12:36:33 +00:00
|
|
|
/>
|
2025-03-20 11:00:43 +00:00
|
|
|
)}
|
|
|
|
{widget.type === "bar" && (
|
|
|
|
<BarGraphComponent
|
|
|
|
type={widget.type}
|
|
|
|
title={widget.title}
|
|
|
|
fontSize={widget.fontSize}
|
|
|
|
fontWeight={widget.fontWeight}
|
|
|
|
data={{
|
|
|
|
measurements: [
|
|
|
|
{ name: "testDevice", fields: "powerConsumption" },
|
|
|
|
{ name: "furnace", fields: "powerConsumption" },
|
|
|
|
],
|
|
|
|
interval: 1000,
|
|
|
|
duration: "1h",
|
|
|
|
}}
|
2025-03-19 12:36:33 +00:00
|
|
|
/>
|
2025-03-20 11:00:43 +00:00
|
|
|
)}
|
|
|
|
{widget.type === "pie" && (
|
|
|
|
<PieGraphComponent
|
|
|
|
type={widget.type}
|
|
|
|
title={widget.title}
|
|
|
|
fontSize={widget.fontSize}
|
|
|
|
fontWeight={widget.fontWeight}
|
|
|
|
data={{
|
|
|
|
measurements: [
|
|
|
|
{ name: "testDevice", fields: "powerConsumption" },
|
|
|
|
{ name: "furnace", fields: "powerConsumption" },
|
|
|
|
],
|
|
|
|
interval: 1000,
|
|
|
|
duration: "1h",
|
|
|
|
}}
|
2025-03-19 12:36:33 +00:00
|
|
|
/>
|
2025-03-20 11:00:43 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2025-03-19 12:36:33 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|