TDRChart
This commit is contained in:
@@ -4,6 +4,7 @@ import { RootState } from "../../../../../../redux/store";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { Chart, registerables } from "chart.js";
|
import { Chart, registerables } from "chart.js";
|
||||||
import "chartjs-adapter-date-fns";
|
import "chartjs-adapter-date-fns";
|
||||||
|
import { getColor } from "../../../../../../utils/colors";
|
||||||
|
|
||||||
// 🟢 **Prop-Typ für isFullScreen hinzufügen**
|
// 🟢 **Prop-Typ für isFullScreen hinzufügen**
|
||||||
interface TDRChartProps {
|
interface TDRChartProps {
|
||||||
@@ -42,8 +43,9 @@ const TDRChart: React.FC = () => {
|
|||||||
{
|
{
|
||||||
label: "TDR Entfernung (km)",
|
label: "TDR Entfernung (km)",
|
||||||
data: tdrChartData,
|
data: tdrChartData,
|
||||||
borderColor: "rgba(255, 99, 132, 1)",
|
borderColor: getColor("littwin-blue"), // Nutzt automatisch die Tailwind-Farbe
|
||||||
backgroundColor: "rgba(255, 99, 132, 0.2)",
|
borderWidth: 0.5,
|
||||||
|
//backgroundColor: getColor("littwin-blue"),
|
||||||
tension: 0.1,
|
tension: 0.1,
|
||||||
parsing: {
|
parsing: {
|
||||||
xAxisKey: "t", // Schlüssel für den Zeitstempel
|
xAxisKey: "t", // Schlüssel für den Zeitstempel
|
||||||
@@ -95,7 +97,7 @@ const TDRChart: React.FC = () => {
|
|||||||
}, [tdrChartData]);
|
}, [tdrChartData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ width: "100%", height: isFullScreen ? "100%" : "20rem" }}>
|
<div style={{ width: "100%", height: isFullScreen ? "90%" : "28rem" }}>
|
||||||
<canvas ref={chartRef} style={{ width: "100%", height: "100%" }} />
|
<canvas ref={chartRef} style={{ width: "100%", height: "100%" }} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ const TDRChartActionBar: React.FC = () => {
|
|||||||
|
|
||||||
const handleSortToggle = () => {
|
const handleSortToggle = () => {
|
||||||
setSortAscending(!sortAscending);
|
setSortAscending(!sortAscending);
|
||||||
setDateiListe((prevListe) =>
|
setDateiListe((prevListe) => [...prevListe].reverse()); // 🔄 Umkehren der Reihenfolge
|
||||||
[...prevListe].sort((a, b) =>
|
|
||||||
sortAscending ? a.localeCompare(b) : b.localeCompare(a)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAktualisieren = () => {
|
const handleAktualisieren = () => {
|
||||||
@@ -130,7 +126,8 @@ const TDRChartActionBar: React.FC = () => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const BASE_URL = "http://localhost:3002";
|
const BASE_URL = window.location.origin;
|
||||||
|
console.log("BASE_URL in TDRChartACtionBar:", BASE_URL);
|
||||||
|
|
||||||
const [showChart, setShowChart] = useState(false);
|
const [showChart, setShowChart] = useState(false);
|
||||||
|
|
||||||
@@ -214,12 +211,15 @@ const TDRChartActionBar: React.FC = () => {
|
|||||||
<span className="ml-1">Sortieren</span>
|
<span className="ml-1">Sortieren</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
{/* Aktualisieren-Button */}
|
||||||
|
{/*
|
||||||
|
<button
|
||||||
onClick={handleAktualisieren}
|
onClick={handleAktualisieren}
|
||||||
className="px-3 py-1 bg-green-500 text-white rounded text-sm"
|
className="px-3 py-1 bg-green-500 text-white rounded text-sm"
|
||||||
>
|
>
|
||||||
Aktualisieren
|
Aktualisieren
|
||||||
</button>
|
</button>
|
||||||
|
*/}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
40
redux/slices/tdrChartSlice.ts
Normal file
40
redux/slices/tdrChartSlice.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
|
// 🔹 State-Interface
|
||||||
|
interface TDRChartState {
|
||||||
|
dateiListe: string[];
|
||||||
|
sortAscending: boolean;
|
||||||
|
tdrChartData: { t: number; m: number }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Anfangsstate
|
||||||
|
const initialState: TDRChartState = {
|
||||||
|
dateiListe: [],
|
||||||
|
sortAscending: true,
|
||||||
|
tdrChartData: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 🔹 Redux Slice
|
||||||
|
const tdrChartSlice = createSlice({
|
||||||
|
name: "tdrChart",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
setDateiListe: (state, action: PayloadAction<string[]>) => {
|
||||||
|
state.dateiListe = action.payload;
|
||||||
|
},
|
||||||
|
toggleSortOrder: (state) => {
|
||||||
|
state.sortAscending = !state.sortAscending;
|
||||||
|
state.dateiListe.reverse(); // 🔄 Reihenfolge umkehren
|
||||||
|
},
|
||||||
|
setTDRChartData: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<{ t: number; m: number }[]>
|
||||||
|
) => {
|
||||||
|
state.tdrChartData = action.payload;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { setDateiListe, toggleSortOrder, setTDRChartData } =
|
||||||
|
tdrChartSlice.actions;
|
||||||
|
export default tdrChartSlice.reducer;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// /redux/store.ts
|
||||||
import { configureStore } from "@reduxjs/toolkit";
|
import { configureStore } from "@reduxjs/toolkit";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import authReducer from "./slices/authSlice";
|
import authReducer from "./slices/authSlice";
|
||||||
@@ -12,6 +13,7 @@ import opcuaSettingsReducer from "./slices/opcuaSettingsSlice";
|
|||||||
import digitalOutputsReducer from "./slices/digitalOutputsSlice";
|
import digitalOutputsReducer from "./slices/digitalOutputsSlice";
|
||||||
import analogeEingaengeReducer from "./slices/analogeEingaengeSlice";
|
import analogeEingaengeReducer from "./slices/analogeEingaengeSlice";
|
||||||
import brushReducer from "./slices/brushSlice";
|
import brushReducer from "./slices/brushSlice";
|
||||||
|
import tdrChartReducer from "./slices/tdrChartSlice";
|
||||||
|
|
||||||
const store = configureStore({
|
const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
@@ -27,6 +29,7 @@ const store = configureStore({
|
|||||||
digitalOutputs: digitalOutputsReducer,
|
digitalOutputs: digitalOutputsReducer,
|
||||||
analogeEingaenge: analogeEingaengeReducer,
|
analogeEingaenge: analogeEingaengeReducer,
|
||||||
brush: brushReducer,
|
brush: brushReducer,
|
||||||
|
tdrChart: tdrChartReducer,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
7
utils/colors.ts
Normal file
7
utils/colors.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const tailwindColors = {
|
||||||
|
"littwin-blue": "#00AEEF", // Hier alle Tailwind-Farben manuell eintragen
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getColor = (colorName: string) => {
|
||||||
|
return tailwindColors[colorName] || colorName; // Falls die Farbe nicht existiert, wird der Name direkt zurückgegeben
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user