Skip to content

Commit baf2066

Browse files
feat(series): Add option to hide null or zero values in the header (#544)
Fixes #543 * Add options to hide null and zero values in header * Update options naming --------- Co-authored-by: Jérôme Wiedemann <jerome@wnetworks.org>
1 parent 8d204fc commit baf2066

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ The card strictly validates all the options available (but not for the `apex_con
197197
| `as_duration` | string | | v1.3.0 | Will pretty print the states as durations. Doesn't affect the graph, only the tooltip/legend/header display. You provide the source unit of your sensor. Valid values are `millisecond`, `second`, `minute`, `hour`, `day`, `week`, `month`, `year`.<br/>Eg: if the state is `345` and `as_duration` is set to `minute` then it would display `5h 45m` |
198198
| `in_header` | boolean or string | `true` | v1.4.0 | If `show_states` is enabled, this would show/hide this specific series in the header. If set to `raw` (introduced in v1.7.0), it would display the latest raw state of the entity in the header bypassing any grouping/transformation done by the card. If the graph spans into the future (using `data_generator`): `before_now` would display the value just before the current time and `after_now` would display the value just after the current time (Introduced in v1.8.0) |
199199
| `name_in_header` | boolean | `true` | v1.8.0 | Only valid if `in_header: true`. If `false`, it will hide the name of the series under its state in the header |
200+
| `null_in_header` | boolean | `true` | NEXT_VERSION | Only valid if `in_header: true`. If `false`, it will hide the name of the series in the header if the value is null |
201+
| `zero_in_header` | boolean | `true` | NEXT_VERSION | Only valid if `in_header: true`. If `false`, it will hide the name of the series in the header if the value is zero |
200202
| `header_color_threshold` | boolean | `false` | v1.7.0 | If `true` and `color_threshold` experimental mode is enabled, it will colorize the header's state based on the threshold (ignoring opacity). |
201203
| `in_chart` | boolean | `true` | v1.4.0 | If `false`, hides the series from the chart |
202204
| `datalabels` | boolean or string | `false` | v1.5.0 | If `true` will show the value of each point for this series directly in the chart. Don't use it if you have a lot of points displayed, it will be a mess. If you set it to `total` (introduced in v1.7.0), it will display the stacked total value (only works when `stacked: true`). If you set it to `percent`, it will display the percentage of the series instead of the value in the case of a `pie` or `donut` chart. |

src/apexcharts-card.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import {
6464
DEFAULT_SHOW_IN_LEGEND,
6565
DEFAULT_SHOW_LEGEND_VALUE,
6666
DEFAULT_SHOW_NAME_IN_HEADER,
67+
DEFAULT_SHOW_NULL_IN_HEADER,
68+
DEFAULT_SHOW_ZERO_IN_HEADER,
6769
DEFAULT_SHOW_OFFSET_IN_NAME,
6870
DEFAULT_UPDATE_DELAY,
6971
moment,
@@ -405,6 +407,8 @@ class ChartsCard extends LitElement {
405407
in_header: DEFAULT_SHOW_IN_HEADER,
406408
in_chart: DEFAULT_SHOW_IN_CHART,
407409
name_in_header: DEFAULT_SHOW_NAME_IN_HEADER,
410+
null_in_header: DEFAULT_SHOW_NULL_IN_HEADER,
411+
zero_in_header: DEFAULT_SHOW_ZERO_IN_HEADER,
408412
offset_in_name: DEFAULT_SHOW_OFFSET_IN_NAME,
409413
};
410414
} else {
@@ -420,6 +424,10 @@ class ChartsCard extends LitElement {
420424
: serie.show.in_header;
421425
serie.show.name_in_header =
422426
serie.show.name_in_header === undefined ? DEFAULT_SHOW_NAME_IN_HEADER : serie.show.name_in_header;
427+
serie.show.null_in_header =
428+
serie.show.null_in_header === undefined ? DEFAULT_SHOW_NULL_IN_HEADER : serie.show.null_in_header;
429+
serie.show.zero_in_header =
430+
serie.show.zero_in_header === undefined ? DEFAULT_SHOW_ZERO_IN_HEADER : serie.show.zero_in_header;
423431
serie.show.offset_in_name =
424432
serie.show.offset_in_name === undefined ? DEFAULT_SHOW_OFFSET_IN_NAME : serie.show.offset_in_name;
425433
}
@@ -685,7 +693,11 @@ class ChartsCard extends LitElement {
685693
return html`
686694
<div id="header__states">
687695
${this._config?.series.map((serie, index) => {
688-
if (serie.show.in_header) {
696+
if (
697+
serie.show.in_header &&
698+
(serie.show.null_in_header || this._headerState?.[index] !== null) &&
699+
(serie.show.zero_in_header || this._headerState?.[index] !== 0)
700+
) {
689701
return html`
690702
<div
691703
id="states__state"

src/const.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const DEFAULT_SHOW_IN_HEADER = true;
1919
export const DEFAULT_SHOW_IN_CHART = true;
2020
export const DEFAULT_SHOW_NAME_IN_HEADER = true;
2121
export const DEFAULT_SHOW_OFFSET_IN_NAME = true;
22+
export const DEFAULT_SHOW_NULL_IN_HEADER = true;
23+
export const DEFAULT_SHOW_ZERO_IN_HEADER = true;
2224
export const DEFAULT_STATISTICS_TYPE = 'mean';
2325
export const DEFAULT_STATISTICS_PERIOD = 'hour';
2426

src/types-config-ti.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export const ChartCardSeriesShowConfigExt = t.iface([], {
119119
"legend_value": t.opt("boolean"),
120120
"in_header": t.opt(t.union("boolean", t.lit('raw'), t.lit('before_now'), t.lit('after_now'))),
121121
"name_in_header": t.opt("boolean"),
122+
"null_in_header": t.opt("boolean"),
123+
"zero_in_header": t.opt("boolean"),
122124
"header_color_threshold": t.opt("boolean"),
123125
"in_chart": t.opt("boolean"),
124126
"datalabels": t.opt(t.union("boolean", t.lit('total'), t.lit('percent'))),

src/types-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export interface ChartCardSeriesShowConfigExt {
121121
legend_value?: boolean;
122122
in_header?: boolean | 'raw' | 'before_now' | 'after_now';
123123
name_in_header?: boolean;
124+
null_in_header?: boolean;
125+
zero_in_header?: boolean;
124126
header_color_threshold?: boolean;
125127
in_chart?: boolean;
126128
datalabels?: boolean | 'total' | 'percent';

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export interface ChartCardSeriesShowConfig extends ChartCardSeriesShowConfigExt
3535
legend_value: boolean;
3636
in_header: boolean | 'raw' | 'before_now' | 'after_now';
3737
name_in_header: boolean;
38+
null_in_header: boolean;
39+
zero_in_header: boolean;
3840
in_chart: boolean;
3941
offset_in_name: boolean;
4042
}

0 commit comments

Comments
 (0)