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

Sort with group by? #135

Closed
KidA001 opened this issue Oct 15, 2023 · 6 comments · Fixed by #138
Closed

Sort with group by? #135

KidA001 opened this issue Oct 15, 2023 · 6 comments · Fixed by #138
Assignees
Labels
enhancement New feature or request

Comments

@KidA001
Copy link

KidA001 commented Oct 15, 2023

Is your feature request related to a problem? Please describe.
I'm using the sort feature and though I do want to sort, it makes it difficult to understand when the lines from a previous parent cross with another. See my screenshot below.
image

Describe the solution you'd like
It would be great if there was a way to sort and group by the previous parent. For instance in my screenshot above I'd like to sort the Main House and Studio/Garage respectively, so that the lines from the children don't cross.

Describe alternatives you've considered
Maybe there is already a way to do this that I'm not familiar with. Thanks for your work, this is an awesome tool

@MindFreeze MindFreeze self-assigned this Oct 17, 2023
@MindFreeze MindFreeze added the enhancement New feature or request label Oct 17, 2023
@KidA001
Copy link
Author

KidA001 commented Oct 17, 2023

@MindFreeze I'm thinking of trying to take on this feature and curious if you have input. It would be helpful if the Box type knew what it's parent was. Seeing where you set boxes, would it make sense to set the parent's name here here?

chart.ts:

// Line 228

const boxes: Box[] = section.entities
  .filter(entityConf => {
    const { min_state } = this.config;
    // remove empty entity boxes
    if (entityConf.type === 'remaining_parent_state') {
      return this.connectionsByChild.get(entityConf)?.some(c => c.state && c.state >= min_state);
    }
    if (entityConf.type === 'remaining_child_state') {
      return this.connectionsByParent.get(entityConf)?.some(c => c.state && c.state >= min_state);
    }
    const { state } = this._getMemoizedState(entityConf);
    return state && state >= min_state;
  })

...

Still understanding your code a bit, but if you have input on where the parent info could be pulled and assigned to a new field on Box above. If _sortBoxes(..) can know which box belongs to which parent it makes grouping by possible. Then SectionConfig could take an additional field group_by_parent?: Boolean

@MindFreeze
Copy link
Owner

Skip the group_by_parent option and let's make this the default behavior. The issue is that parents may also be sorted and that sorting isn't saved yet.
So first this.sections = filteredConfig.sections.map(...) has to be refactored to a forEach loop of filteredConfig.sections that assigns to this.sections[i] at each loop.
This way when we call this._sortBoxes we can pass this.sections[i-1] which is the sorted parent boxes and they contain children info, so we can sort by parent first and then by state

MindFreeze added a commit that referenced this issue Oct 18, 2023
* refactor(#135): refactor to allow sorting by parent

* feat(#135): sort boxes by parent first
@MindFreeze
Copy link
Owner

@KidA001 I found it easier to just implement it. It will be part of 1.16.0

@KidA001
Copy link
Author

KidA001 commented Oct 18, 2023

Hah, I was going to say it sounds like you know exactly what to do. These HA plugins often get hoarded with feature requests so I try to offer my support when I'm making one myself. Thanks for working on this!

@nathan-curtis
Copy link

nathan-curtis commented Oct 20, 2023

@MindFreeze how do I turn this off? It's completely jacked all my charts - I sort by entity value asc - and its not working correctly.
Yep - reverted to 1.15.1 and both this sorting and a bar scaling issue that appeared both went away.

@nathan-curtis
Copy link

Skip the group_by_parent option and let's make this the default behavior. The issue is that parents may also be sorted and that sorting isn't saved yet. So first this.sections = filteredConfig.sections.map(...) has to be refactored to a forEach loop of filteredConfig.sections that assigns to this.sections[i] at each loop. This way when we call this._sortBoxes we can pass this.sections[i-1] which is the sorted parent boxes and they contain children info, so we can sort by parent first and then by state

This is my breaking change, sir, and a regression as not listed as breaking. Please revert. or provide override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants