fix(dees-chart-area): optimize series update handling and y-axis scaling logic
This commit is contained in:
@@ -468,16 +468,16 @@ export class DeesChartArea extends DeesElement {
|
|||||||
if (!this.chart) {
|
if (!this.chart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Store the new data first
|
// Store the new data first
|
||||||
this.internalChartData = newSeries;
|
this.internalChartData = newSeries;
|
||||||
|
|
||||||
// Handle rolling window if enabled
|
// Handle rolling window if enabled
|
||||||
if (this.rollingWindow > 0 && this.realtimeMode) {
|
if (this.rollingWindow > 0 && this.realtimeMode) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const cutoffTime = now - this.rollingWindow;
|
const cutoffTime = now - this.rollingWindow;
|
||||||
|
|
||||||
// Filter data to only include points within the rolling window
|
// Filter data to only include points within the rolling window
|
||||||
const filteredSeries = newSeries.map(series => ({
|
const filteredSeries = newSeries.map(series => ({
|
||||||
name: series.name,
|
name: series.name,
|
||||||
@@ -488,25 +488,41 @@ export class DeesChartArea extends DeesElement {
|
|||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Only update if we have data
|
// Only update if we have data
|
||||||
if (filteredSeries.some(s => s.data.length > 0)) {
|
if (filteredSeries.some(s => s.data.length > 0)) {
|
||||||
// Handle y-axis scaling first
|
// Build a single options update with series, x-axis window, and y-axis
|
||||||
|
const isDark = !this.goBright;
|
||||||
|
const options: ApexCharts.ApexOptions = {
|
||||||
|
series: filteredSeries,
|
||||||
|
xaxis: {
|
||||||
|
min: cutoffTime,
|
||||||
|
max: now,
|
||||||
|
labels: {
|
||||||
|
format: 'HH:mm:ss',
|
||||||
|
datetimeUTC: false,
|
||||||
|
style: {
|
||||||
|
colors: [isDark ? 'hsl(0 0% 63.9%)' : 'hsl(0 0% 20%)'],
|
||||||
|
fontSize: '12px',
|
||||||
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
||||||
|
fontWeight: '400',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tickAmount: 6,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle y-axis scaling
|
||||||
if (this.yAxisScaling === 'dynamic') {
|
if (this.yAxisScaling === 'dynamic') {
|
||||||
const allValues = filteredSeries.flatMap(s => (s.data as any[]).map(d => d.y));
|
const allValues = filteredSeries.flatMap(s => (s.data as any[]).map(d => d.y));
|
||||||
if (allValues.length > 0) {
|
if (allValues.length > 0) {
|
||||||
const maxValue = Math.max(...allValues);
|
const maxValue = Math.max(...allValues);
|
||||||
const dynamicMax = Math.ceil(maxValue * 1.1);
|
const dynamicMax = Math.ceil(maxValue * 1.1);
|
||||||
await this.chart.updateOptions({
|
options.yaxis = { min: 0, max: dynamicMax };
|
||||||
yaxis: {
|
|
||||||
min: 0,
|
|
||||||
max: dynamicMax
|
|
||||||
}
|
|
||||||
}, false, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.chart.updateSeries(filteredSeries, false);
|
await this.chart.updateOptions(options, false, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.chart.updateSeries(newSeries, animate);
|
await this.chart.updateSeries(newSeries, animate);
|
||||||
|
|||||||
Reference in New Issue
Block a user