Skip to content

Commit 375de4f

Browse files
committed
fix(annotations): Do not erase apex_config manually defined xaxis and points annotations
Fixes #932
1 parent 6abdc16 commit 375de4f

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

src/apexcharts-card.ts

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,63 +1042,62 @@ class ChartsCard extends LitElement {
10421042
start.getFullYear() === end.getFullYear() &&
10431043
start.getMonth() === end.getMonth() &&
10441044
start.getDate() === end.getDate();
1045-
return {
1046-
points: this._config?.series_in_graph.flatMap((serie, index) => {
1047-
if (serie.show.extremas) {
1048-
const { min, max } = this._graphs?.[serie.index]?.minMaxWithTimestamp(
1049-
this._seriesOffset[serie.index]
1050-
? new Date(start.getTime() + this._seriesOffset[serie.index]).getTime()
1051-
: start.getTime(),
1052-
this._seriesOffset[serie.index]
1053-
? new Date(end.getTime() + this._seriesOffset[serie.index]).getTime()
1054-
: end.getTime(),
1055-
this._serverTimeOffset - (this._seriesTimeDelta[serie.index] || 0),
1056-
) || {
1057-
min: [0, null],
1058-
max: [0, null],
1059-
};
1060-
const bgColor = computeColor(this._colors[index]);
1061-
const txtColor = computeTextColor(bgColor);
1062-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1063-
const extremas: any = [];
1064-
if (min[0] && ['min', 'min+time', true, 'time'].includes(serie.show.extremas)) {
1065-
const withTime = serie.show.extremas === 'time' || serie.show.extremas === 'min+time';
1066-
extremas.push(
1067-
...this._getPointAnnotationStyle(
1068-
min,
1069-
this._seriesOffset[serie.index],
1070-
bgColor,
1071-
txtColor,
1072-
serie,
1073-
index,
1074-
serie.invert,
1075-
sameDay,
1076-
withTime,
1077-
),
1078-
);
1079-
}
1080-
if (max[0] && ['max', 'max+time', true, 'time'].includes(serie.show.extremas)) {
1081-
const withTime = serie.show.extremas === 'time' || serie.show.extremas === 'max+time';
1082-
extremas.push(
1083-
...this._getPointAnnotationStyle(
1084-
max,
1085-
this._seriesOffset[serie.index],
1086-
bgColor,
1087-
txtColor,
1088-
serie,
1089-
index,
1090-
serie.invert,
1091-
sameDay,
1092-
withTime,
1093-
),
1094-
);
1095-
}
1096-
return extremas;
1097-
} else {
1098-
return [];
1045+
const minMaxPoints = this._config?.series_in_graph.flatMap((serie, index) => {
1046+
if (serie.show.extremas) {
1047+
const { min, max } = this._graphs?.[serie.index]?.minMaxWithTimestamp(
1048+
this._seriesOffset[serie.index]
1049+
? new Date(start.getTime() + this._seriesOffset[serie.index]).getTime()
1050+
: start.getTime(),
1051+
this._seriesOffset[serie.index]
1052+
? new Date(end.getTime() + this._seriesOffset[serie.index]).getTime()
1053+
: end.getTime(),
1054+
this._serverTimeOffset - (this._seriesTimeDelta[serie.index] || 0),
1055+
) || {
1056+
min: [0, null],
1057+
max: [0, null],
1058+
};
1059+
const bgColor = computeColor(this._colors[index]);
1060+
const txtColor = computeTextColor(bgColor);
1061+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1062+
const extremas: any = [];
1063+
if (min[0] && ['min', 'min+time', true, 'time'].includes(serie.show.extremas)) {
1064+
const withTime = serie.show.extremas === 'time' || serie.show.extremas === 'min+time';
1065+
extremas.push(
1066+
...this._getPointAnnotationStyle(
1067+
min,
1068+
this._seriesOffset[serie.index],
1069+
bgColor,
1070+
txtColor,
1071+
serie,
1072+
index,
1073+
serie.invert,
1074+
sameDay,
1075+
withTime,
1076+
),
1077+
);
10991078
}
1100-
}),
1101-
};
1079+
if (max[0] && ['max', 'max+time', true, 'time'].includes(serie.show.extremas)) {
1080+
const withTime = serie.show.extremas === 'time' || serie.show.extremas === 'max+time';
1081+
extremas.push(
1082+
...this._getPointAnnotationStyle(
1083+
max,
1084+
this._seriesOffset[serie.index],
1085+
bgColor,
1086+
txtColor,
1087+
serie,
1088+
index,
1089+
serie.invert,
1090+
sameDay,
1091+
withTime,
1092+
),
1093+
);
1094+
}
1095+
return extremas;
1096+
} else {
1097+
return [];
1098+
}
1099+
});
1100+
return { points: [...(minMaxPoints || []), ...(this._config?.apex_config?.annotations?.points || [])] };
11021101
}
11031102

11041103
private _getPointAnnotationStyle(
@@ -1193,6 +1192,7 @@ class ChartsCard extends LitElement {
11931192
},
11941193
borderColor: color,
11951194
},
1195+
...(this._config?.apex_config?.annotations?.xaxis || []),
11961196
],
11971197
};
11981198
}

0 commit comments

Comments
 (0)