Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to hide null values in header #544

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ The card stricly validates all the options available (but not for the `apex_conf
| `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` |
| `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) |
| `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 |
| `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 |
| `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 |
| `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). |
| `in_chart` | boolean | `true` | v1.4.0 | If `false`, hides the serie from the chart |
| `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. |
Expand Down
14 changes: 13 additions & 1 deletion src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import {
DEFAULT_SHOW_IN_LEGEND,
DEFAULT_SHOW_LEGEND_VALUE,
DEFAULT_SHOW_NAME_IN_HEADER,
DEFAULT_HIDE_NULL_IN_HEADER,
DEFAULT_HIDE_ZERO_IN_HEADER,
DEFAULT_SHOW_OFFSET_IN_NAME,
DEFAULT_UPDATE_DELAY,
moment,
Expand Down Expand Up @@ -405,6 +407,8 @@ class ChartsCard extends LitElement {
in_header: DEFAULT_SHOW_IN_HEADER,
in_chart: DEFAULT_SHOW_IN_CHART,
name_in_header: DEFAULT_SHOW_NAME_IN_HEADER,
hide_null_in_header: DEFAULT_HIDE_NULL_IN_HEADER,
hide_zero_in_header: DEFAULT_HIDE_ZERO_IN_HEADER,
offset_in_name: DEFAULT_SHOW_OFFSET_IN_NAME,
};
} else {
Expand All @@ -420,6 +424,10 @@ class ChartsCard extends LitElement {
: serie.show.in_header;
serie.show.name_in_header =
serie.show.name_in_header === undefined ? DEFAULT_SHOW_NAME_IN_HEADER : serie.show.name_in_header;
serie.show.hide_null_in_header =
serie.show.hide_null_in_header === undefined ? DEFAULT_HIDE_NULL_IN_HEADER : serie.show.hide_null_in_header;
serie.show.hide_zero_in_header =
serie.show.hide_zero_in_header === undefined ? DEFAULT_HIDE_ZERO_IN_HEADER : serie.show.hide_zero_in_header;
serie.show.offset_in_name =
serie.show.offset_in_name === undefined ? DEFAULT_SHOW_OFFSET_IN_NAME : serie.show.offset_in_name;
}
Expand Down Expand Up @@ -682,7 +690,11 @@ class ChartsCard extends LitElement {
return html`
<div id="header__states">
${this._config?.series.map((serie, index) => {
if (serie.show.in_header) {
if (
serie.show.in_header &&
(!serie.show.hide_null_in_header || this._headerState?.[index] !== null) &&
(!serie.show.hide_zero_in_header || this._headerState?.[index] !== 0)
) {
return html`
<div
id="states__state"
Expand Down
2 changes: 2 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const DEFAULT_SHOW_IN_HEADER = true;
export const DEFAULT_SHOW_IN_CHART = true;
export const DEFAULT_SHOW_NAME_IN_HEADER = true;
export const DEFAULT_SHOW_OFFSET_IN_NAME = true;
export const DEFAULT_HIDE_NULL_IN_HEADER = false;
export const DEFAULT_HIDE_ZERO_IN_HEADER = false;
export const DEFAULT_STATISTICS_TYPE = 'mean';
export const DEFAULT_STATISTICS_PERIOD = 'hour';

Expand Down
2 changes: 2 additions & 0 deletions src/types-config-ti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export const ChartCardSeriesShowConfigExt = t.iface([], {
"legend_value": t.opt("boolean"),
"in_header": t.opt(t.union("boolean", t.lit('raw'), t.lit('before_now'), t.lit('after_now'))),
"name_in_header": t.opt("boolean"),
"hide_null_in_header": t.opt("boolean"),
"hide_zero_in_header": t.opt("boolean"),
"header_color_threshold": t.opt("boolean"),
"in_chart": t.opt("boolean"),
"datalabels": t.opt(t.union("boolean", t.lit('total'), t.lit('percent'))),
Expand Down
2 changes: 2 additions & 0 deletions src/types-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export interface ChartCardSeriesShowConfigExt {
legend_value?: boolean;
in_header?: boolean | 'raw' | 'before_now' | 'after_now';
name_in_header?: boolean;
hide_null_in_header?: boolean;
hide_zero_in_header?: boolean;
header_color_threshold?: boolean;
in_chart?: boolean;
datalabels?: boolean | 'total' | 'percent';
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface ChartCardSeriesShowConfig extends ChartCardSeriesShowConfigExt
legend_value: boolean;
in_header: boolean | 'raw' | 'before_now' | 'after_now';
name_in_header: boolean;
hide_null_in_header: boolean;
hide_zero_in_header: boolean;
in_chart: boolean;
offset_in_name: boolean;
}
Expand Down