Skip to content

Commit

Permalink
feat(#153): static_scale option to disable dynamic scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze committed Dec 6, 2023
1 parent d14f83a commit b932f1f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This card is intended to display connections between entities with numeric state
| min_box_distance | number | **Optional** | 5 | Minimum space between entity boxes
| min_state | number | **Optional** | >0 | Any entity below this value will not be displayed. Only positive numbers above 0 are allowed. The default is to show everything above 0.
| throttle | number | **Optional** | | Minimum time in ms between updates/rerenders
| static_scale | number | **Optional** | | State value corresponding to the maximum height size of the card. For example, if this is set to 1000, then a box with state 500 will take up half of its section. If some section exceeds the value of `static_scale`, the card will dynamically rescale overriding this option. See (#153)

### Sections object

Expand Down
8 changes: 8 additions & 0 deletions src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ export class Chart extends LitElement {

private _calcBoxes() {
this.statePerPixelY = 0;
if (this.config.static_scale) {
// use static scale to set a minimum statePerPixelY
this._calcBoxHeights(
[{ state: this.config.static_scale, size: 0 } as Box],
this.config.height,
this.config.static_scale,
);
}
const filteredConfig = filterConfigByZoomEntity(this.config, this.zoomEntity);
const sectionsStates: SectionState[] = [];
filteredConfig.sections.forEach(section => {
Expand Down
1 change: 1 addition & 0 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class SankeyChartEditor extends LitElement implements LovelaceCardEditor
name: '',
schema: [
{ name: 'min_state', selector: { number: { mode: 'box' } } },
{ name: 'static_scale', selector: { number: { mode: 'box' } } },
{ name: 'round', selector: { number: { mode: 'box', unit_of_measurement: localize('editor.decimals') } } },
{ name: 'throttle', selector: { number: { mode: 'box', unit_of_measurement: 'ms' } } },
{
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"min_box_height": "Min box height",
"min_box_distance": "Min box distance",
"min_state": "Min state",
"static_scale": "Static scale",
"round": "Round",
"throttle": "Throttle",
"unit_prefix": "Unit prefix",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface SankeyChartConfig extends LovelaceCardConfig {
min_box_distance?: number;
throttle?: number;
min_state?: number;
static_scale?: number;
}

export interface Section {
Expand Down

0 comments on commit b932f1f

Please sign in to comment.