Skip to content

Commit

Permalink
fix(#143): add sort_group_by_parent option so default sorting behav…
Browse files Browse the repository at this point in the history
…ior is reverted
  • Loading branch information
MindFreeze committed Oct 20, 2023
1 parent 2c943c0 commit fce9bdd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This card is intended to display connections between entities with numeric state
| entities | list | **Required** | | Entities to show in this section. Could be just the entity_id as a string or an object, see [entities object](#entities-object) for additional options. Note that the order of this list matters
| sort_by | string | **Optional** | | Sort the entities in this section. Valid options are: 'state'. If your values change often, you may want to use the `throttle` option to limit update frequency
| sort_dir | string | **Optional** | desc | Sorting direction. Valid options are: 'asc' for smallest first & 'desc' for biggest first
| sort_group_by_parent | boolean | **Optional** | false | Group entities by parent before sorting. See #135
| min_width | string | **Optional** | | Minimum section width. Any CSS value is OK. Examples: 75px, 50%, 1em

### Entities object
Expand Down
2 changes: 1 addition & 1 deletion src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class Chart extends LitElement {
const availableHeight = this.config.height - (boxes.length - 1) * this.config.min_box_distance;
// calc sizes to determine statePerPixelY ratio and find the best one
const calcResults = this._calcBoxHeights(boxes, availableHeight, total);
const parentBoxes = this.sections[this.sections.length - 1]?.boxes || [];
const parentBoxes = section.sort_group_by_parent ? this.sections[this.sections.length - 1]?.boxes || [] : [];
const sectionState = {
boxes: this._sortBoxes(parentBoxes, calcResults.boxes, section.sort_by, section.sort_dir),
total,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface SectionConfig {
entities: EntityConfigOrStr[];
sort_by?: 'state';
sort_dir?: 'asc' | 'desc';
sort_group_by_parent?: boolean;
min_width?: string;
}

Expand Down Expand Up @@ -114,6 +115,7 @@ export interface Section {
entities: EntityConfigInternal[];
sort_by?: 'state';
sort_dir?: 'asc' | 'desc';
sort_group_by_parent?: boolean;
min_width?: string;
}

Expand Down

0 comments on commit fce9bdd

Please sign in to comment.