This commit is contained in:
sebseb7
2025-12-26 01:23:33 +01:00
parent 3d43a42b12
commit 1dfa59ae13
4 changed files with 421 additions and 319 deletions

View File

@@ -318,12 +318,19 @@ export default class Chart extends Component {
const newLastValues = {};
const newFlashStates = { ...this.state.flashStates };
// Get latest value for each channel (last row)
// Get latest value for each channel (search from end of data)
if (processedData.length > 0) {
const lastRow = processedData[processedData.length - 1];
effectiveChannels.forEach(channelId => {
const newVal = lastRow[channelId];
if (newVal !== null && newVal !== undefined) {
// Find most recent non-null value for this channel
let newVal = null;
for (let i = processedData.length - 1; i >= 0 && newVal === null; i--) {
const val = processedData[i][channelId];
if (val !== null && val !== undefined) {
newVal = val;
}
}
if (newVal !== null) {
newLastValues[channelId] = newVal;
const oldVal = this.state.lastValues[channelId];
@@ -331,6 +338,7 @@ export default class Chart extends Component {
if (oldVal !== undefined && oldVal !== newVal) {
const direction = newVal > oldVal ? 'up' : 'down';
newFlashStates[channelId] = direction;
console.log(`[Flash] ${channelId}: ${oldVal}${newVal} (${direction})`);
// Clear flash after 1 second
if (this.flashTimeouts[channelId]) {
@@ -364,7 +372,7 @@ export default class Chart extends Component {
let axisMin = Infinity;
let axisMax = -Infinity;
const axisSeries = series.filter(s => s.yAxisKey === axisKey).map(s => s.dataKey);
const axisSeries = series.filter(s => s.yAxisId === axisKey).map(s => s.dataKey);
if (axisSeries.length === 0) return {}; // No data for this axis
@@ -459,7 +467,7 @@ export default class Chart extends Component {
label: label,
connectNulls: true,
showMark: false,
yAxisKey: yAxisKey,
yAxisId: yAxisKey,
};
if (color) sObj.color = color;
// Enable area fill if fillColor is set (with configurable opacity)
@@ -470,16 +478,16 @@ export default class Chart extends Component {
return sObj;
});
const hasRightAxis = series.some(s => s.yAxisKey === 'right');
const hasRightAxis = series.some(s => s.yAxisId === 'right');
const leftLimits = this.computeAxisLimits('left', effectiveChannels, series);
const rightLimits = this.computeAxisLimits('right', effectiveChannels, series);
const yAxes = [
{ id: 'left', scaleType: 'linear', ...leftLimits }
{ id: 'left', ...leftLimits }
];
if (hasRightAxis) {
yAxes.push({ id: 'right', scaleType: 'linear', ...rightLimits });
yAxes.push({ id: 'right', position: 'right', ...rightLimits });
}
// Calculate X-Axis Limits
@@ -569,10 +577,9 @@ export default class Chart extends Component {
valueFormatter: (date) => date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
}]}
yAxis={yAxes}
rightAxis={hasRightAxis ? 'right' : null}
slotProps={{
legend: { hidden: true },
lineHighlight: { strokeWidth: 3 },
}}
sx={{
'& .MuiLineElement-root': {