fix(dees-chart-area): optimize series update handling and y-axis scaling logic
This commit is contained in:
@@ -491,22 +491,38 @@ export class DeesChartArea extends DeesElement {
|
||||
|
||||
// Only update if we have data
|
||||
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') {
|
||||
const allValues = filteredSeries.flatMap(s => (s.data as any[]).map(d => d.y));
|
||||
if (allValues.length > 0) {
|
||||
const maxValue = Math.max(...allValues);
|
||||
const dynamicMax = Math.ceil(maxValue * 1.1);
|
||||
await this.chart.updateOptions({
|
||||
yaxis: {
|
||||
min: 0,
|
||||
max: dynamicMax
|
||||
}
|
||||
}, false, false);
|
||||
options.yaxis = { min: 0, max: dynamicMax };
|
||||
}
|
||||
}
|
||||
|
||||
await this.chart.updateSeries(filteredSeries, false);
|
||||
await this.chart.updateOptions(options, false, false);
|
||||
}
|
||||
} else {
|
||||
await this.chart.updateSeries(newSeries, animate);
|
||||
|
||||
Reference in New Issue
Block a user