Skip to content

Commit

Permalink
#19 show_units option
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze committed Jul 19, 2022
1 parent 4cddda6 commit 7ea287a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This card is intended to display connections between entities with numeric state
| show_icons | boolean | **Optional** | false | Display entity icons
| show_names | boolean | **Optional** | false | Display entity names
| show_states | boolean | **Optional** | true | Display entity states
| show_units | boolean | **Optional** | true | Display unit of measurement
| min_box_height | number | **Optional** | 3 | Minimum size of an entity box
| min_box_distance | number | **Optional** | 5 | Minimum space between entity boxes

Expand Down
5 changes: 3 additions & 2 deletions src/ha-sankey-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class SankeyChart extends LitElement {
min_box_height: 3,
min_box_distance: 5,
show_states: true,
show_units: true,
...config,
};

Expand Down Expand Up @@ -157,7 +158,7 @@ export class SankeyChart extends LitElement {
}

protected renderSection(index: number): TemplateResult {
const {show_names, show_icons, show_states} = this.config;
const {show_names, show_icons, show_states, show_units} = this.config;
const section = this.sections[index];
const {boxes, spacerH} = section;
const hasChildren = index < this.sections.length - 1 && boxes.some(b => b.children.length > 0);
Expand Down Expand Up @@ -189,7 +190,7 @@ export class SankeyChart extends LitElement {
${show_icons ? html`<ha-icon .icon=${stateIcon(box.entity)}></ha-icon>` : null}
</div>
<div class="label" style=${styleMap(labelStyle)}>
${show_states ? html`<span class="state">${formattedState}</span><span class="unit">${box.unit_of_measurement}</span>` : null}
${show_states ? html`<span class="state">${formattedState}</span>${show_units ? html`<span class="unit">${box.unit_of_measurement}</span>` : null}` : null}
${show_names ? html`<span class="name">&nbsp;${name}</span>` : null}
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export interface SankeyChartConfig extends LovelaceCardConfig {
wide?: boolean;
show_icons?: boolean;
show_names?: boolean;
show_states?: boolean;
show_units?: boolean;
min_box_height?: number,
min_box_distance?: number,
show_states?: boolean;
}

export interface Config extends SankeyChartConfig {
Expand Down

0 comments on commit 7ea287a

Please sign in to comment.