Fix some min/mean/max issues with statistics line charts (#25107)

* Fix some min/mean/max issues with statistics line charts

* minor simplification
This commit is contained in:
karwosts 2025-04-21 04:09:07 -07:00 committed by GitHub
parent 6bf8faa96a
commit 53dd0cbaa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -450,12 +450,14 @@ export class StatisticsChart extends LitElement {
const hasMean = const hasMean =
this.statTypes.includes("mean") && statisticsHaveType(stats, "mean"); this.statTypes.includes("mean") && statisticsHaveType(stats, "mean");
const drawBands = const hasMax =
hasMean || this.statTypes.includes("max") && statisticsHaveType(stats, "max");
(this.statTypes.includes("min") && const hasMin =
statisticsHaveType(stats, "min") && this.statTypes.includes("min") && statisticsHaveType(stats, "min");
this.statTypes.includes("max") && const drawBands = [hasMean, hasMax, hasMin].filter(Boolean).length > 1;
statisticsHaveType(stats, "max"));
const bandTop = hasMax ? "max" : "mean";
const bandBottom = hasMin ? "min" : "mean";
const sortedTypes = drawBands const sortedTypes = drawBands
? [...this.statTypes].sort((a, b) => { ? [...this.statTypes].sort((a, b) => {
@ -472,10 +474,12 @@ export class StatisticsChart extends LitElement {
let displayedLegend = false; let displayedLegend = false;
sortedTypes.forEach((type) => { sortedTypes.forEach((type) => {
if (statisticsHaveType(stats, type)) { if (statisticsHaveType(stats, type)) {
const band = drawBands && (type === "min" || type === "max"); const band = drawBands && (type === bandTop || type === bandBottom);
statTypes.push(type); statTypes.push(type);
const borderColor = const borderColor =
band && hasMean ? color + (this.hideLegend ? "00" : "7F") : color; band && hasMin && hasMax && hasMean
? color + (this.hideLegend ? "00" : "7F")
: color;
const backgroundColor = band ? color + "3F" : color + "7F"; const backgroundColor = band ? color + "3F" : color + "7F";
const series: LineSeriesOption | BarSeriesOption = { const series: LineSeriesOption | BarSeriesOption = {
id: `${statistic_id}-${type}`, id: `${statistic_id}-${type}`,
@ -510,7 +514,7 @@ export class StatisticsChart extends LitElement {
if (band && this.chartType === "line") { if (band && this.chartType === "line") {
series.stack = `band-${statistic_id}`; series.stack = `band-${statistic_id}`;
series.stackStrategy = "all"; series.stackStrategy = "all";
if (drawBands && type === "max") { if (drawBands && type === bandTop) {
(series as LineSeriesOption).areaStyle = { (series as LineSeriesOption).areaStyle = {
color: color + "3F", color: color + "3F",
}; };
@ -553,10 +557,14 @@ export class StatisticsChart extends LitElement {
} else { } else {
val.push((stat.sum || 0) - firstSum); val.push((stat.sum || 0) - firstSum);
} }
} else if (type === "max" && this.chartType === "line") { } else if (
const max = stat.max || 0; type === bandTop &&
val.push(Math.abs(max - (stat.min || 0))); this.chartType === "line" &&
val.push(max); drawBands
) {
const top = stat[bandTop] || 0;
val.push(Math.abs(top - (stat[bandBottom] || 0)));
val.push(top);
} else { } else {
val.push(stat[type] ?? null); val.push(stat[type] ?? null);
} }