Skip to content

Commit 63bcb9a

Browse files
committed
feat(#87): configurable min state threshold
1 parent 9841547 commit 63bcb9a

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This card is intended to display connections between entities with numeric state
3232
| show_units | boolean | **Optional** | true | Display unit of measurement
3333
| min_box_height | number | **Optional** | 3 | Minimum size of an entity box
3434
| min_box_distance | number | **Optional** | 5 | Minimum space between entity boxes
35+
| min_state | number | **Optional** | 0+ | Any entity below this value will not be displayed. The default is to show everything above 0
3536
| throttle | number | **Optional** | | Minimum time in ms between updates/rerenders
3637

3738
### Sections object

src/chart.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,16 @@ export class Chart extends LitElement {
227227
let total = 0;
228228
const boxes: Box[] = section.entities
229229
.filter(entityConf => {
230+
const {min_state} = this.config;
230231
// remove empty entity boxes
231232
if (entityConf.type === 'remaining_parent_state') {
232-
return this.connectionsByChild.get(entityConf)?.some(c => c.state);
233+
return this.connectionsByChild.get(entityConf)?.some(c => c.state && c.state >= min_state);
233234
}
234235
if (entityConf.type === 'remaining_child_state') {
235-
return this.connectionsByParent.get(entityConf)?.some(c => c.state);
236+
return this.connectionsByParent.get(entityConf)?.some(c => c.state && c.state >= min_state);
236237
}
237-
return this._getMemoizedState(entityConf).state;
238+
const { state } = this._getMemoizedState(entityConf);
239+
return state && state >= min_state;
238240
})
239241
.map(entityConf => {
240242
const { state, unit_of_measurement } = this._getMemoizedState(entityConf);

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface SankeyChartConfig extends LovelaceCardConfig {
6666
min_box_height?: number,
6767
min_box_distance?: number,
6868
throttle?: number,
69+
min_state?: number,
6970
}
7071

7172
export interface Section {
@@ -80,6 +81,7 @@ export interface Config extends SankeyChartConfig {
8081
height: number;
8182
min_box_height: number;
8283
min_box_distance: number;
84+
min_state: number;
8385
sections: Section[];
8486
}
8587

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export function normalizeConfig(conf: SankeyChartConfig): Config {
173173
show_states: true,
174174
show_units: true,
175175
...config,
176+
min_state: config.min_state ? Math.abs(config.min_state) : 0,
176177
sections,
177178
};
178179
}

0 commit comments

Comments
 (0)