Skip to content

Commit 3dd6485

Browse files
committed
Add options to hide null and zero values in header
1 parent 6601972 commit 3dd6485

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ The card stricly validates all the options available (but not for the `apex_conf
196196
| `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` |
197197
| `in_header` | boolean or string | `true` | v1.4.0 | If `show_states` is enabled, this would show/hide this specific serie 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) |
198198
| `name_in_header` | boolean | `true` | v1.8.0 | Only valid if `in_header: true`. If `false`, it will hide the name of the serie under the its state in the header |
199+
| `hide_null_in_header` | boolean | `false` | v2.1.3 | Only valid if `in_header: true`. If `true`, it will hide the name of the series in the header if the value is null |
200+
| `hide_zero_in_header` | boolean | `false` | v2.1.3 | Only valid if `in_header: true`. If `true`, it will hide the name of the series in the header if the value is zero |
199201
| `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). |
200202
| `in_chart` | boolean | `true` | v1.4.0 | If `false`, hides the serie from the chart |
201203
| `datalabels` | boolean or string | `false` | v1.5.0 | If `true` will show the value of each point for this serie 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 serie instead of the value in the case of a `pie` or `donut` chart. |

src/apexcharts-card.ts

+13-1
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_HIDE_NULL_IN_HEADER,
68+
DEFAULT_HIDE_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+
hide_null_in_header: DEFAULT_HIDE_NULL_IN_HEADER,
411+
hide_zero_in_header: DEFAULT_HIDE_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.hide_null_in_header =
428+
serie.show.hide_null_in_header === undefined ? DEFAULT_HIDE_NULL_IN_HEADER : serie.show.hide_null_in_header;
429+
serie.show.hide_zero_in_header =
430+
serie.show.hide_zero_in_header === undefined ? DEFAULT_HIDE_ZERO_IN_HEADER : serie.show.hide_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
}
@@ -682,7 +690,11 @@ class ChartsCard extends LitElement {
682690
return html`
683691
<div id="header__states">
684692
${this._config?.series.map((serie, index) => {
685-
if (serie.show.in_header) {
693+
if (
694+
serie.show.in_header &&
695+
(!serie.show.hide_null_in_header || this._headerState?.[index] !== null) &&
696+
(!serie.show.hide_zero_in_header || this._headerState?.[index] !== 0)
697+
) {
686698
return html`
687699
<div
688700
id="states__state"

src/const.ts

+2
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_HIDE_NULL_IN_HEADER = false;
23+
export const DEFAULT_HIDE_ZERO_IN_HEADER = false;
2224
export const DEFAULT_STATISTICS_TYPE = 'mean';
2325
export const DEFAULT_STATISTICS_PERIOD = 'hour';
2426

src/types-config-ti.ts

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export const ChartCardSeriesShowConfigExt = t.iface([], {
115115
"legend_value": t.opt("boolean"),
116116
"in_header": t.opt(t.union("boolean", t.lit('raw'), t.lit('before_now'), t.lit('after_now'))),
117117
"name_in_header": t.opt("boolean"),
118+
"hide_null_in_header": t.opt("boolean"),
119+
"hide_zero_in_header": t.opt("boolean"),
118120
"header_color_threshold": t.opt("boolean"),
119121
"in_chart": t.opt("boolean"),
120122
"datalabels": t.opt(t.union("boolean", t.lit('total'), t.lit('percent'))),

src/types-config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export interface ChartCardSeriesShowConfigExt {
115115
legend_value?: boolean;
116116
in_header?: boolean | 'raw' | 'before_now' | 'after_now';
117117
name_in_header?: boolean;
118+
hide_null_in_header?: boolean;
119+
hide_zero_in_header?: boolean;
118120
header_color_threshold?: boolean;
119121
in_chart?: boolean;
120122
datalabels?: boolean | 'total' | 'percent';

src/types.ts

+2
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+
hide_null_in_header: boolean;
39+
hide_zero_in_header: boolean;
3840
in_chart: boolean;
3941
offset_in_name: boolean;
4042
}

0 commit comments

Comments
 (0)