MindFreeze / ha-sankey-chart

A Home Assistant lovelace card to display a sankey chart. For example for power consumption
MIT License
378 stars 20 forks source link

Manually specified priorites for sorting #190

Closed NickStallman closed 4 months ago

NickStallman commented 5 months ago

Is your feature request related to a problem? Please describe. I've just found this card and it's creating some amazingly clear charts, however I did struggle a little with sorting to ensure the chart always looks aesthetically pleasing, functional and avoiding unnecessary crossovers.

Describe the solution you'd like The current sort parameters work well enough, but don't give exact control of ordering.

For example, if I have a Power point circuit, and a bunch of devices on that power point circuit, the sort works nicely by organising them highest power to lowest which works well. However I'd then have a catchall entity representing any un-monitored usage, and I might want that always on the right as a convention so I always know where the "other" usage is.

Or if I have a particular order in mind for a section, it may be easiest to simply number the entities in the appropriate order to explicitly control the order.

This could be handled relatively easily with a "sort_priority" parameter for each entity. If two entities have the same priority then regular sort rules apply, and the sort_priority would default to 0.

So for the example of "sort all devices normally, but with the catch-all last", something like this would work well:

  - entities:
    - entity_id: device_1
      type: entity
      sort_priority: 0 // the default value
    - entity_id: device_2
      type: entity
    - type: remaining_parent_state
      entity_id: other_usage
      sort_priority: 1

Or to explicitly order a section you'd just set sort_priority as 1, 2, 3, etc... as desired.

I haven't checked the relevant sort code yet, but rather than just sorting as per the existing sort rules, it could be broken in to two steps, first sort by sort_priority, then inside each group of entities with the same sort_priority then follow the existing rules.

Describe alternatives you've considered Looking over the examples and documentation, I don't see any currently existing alternative way to get better control over sorting, however I may have missed it.

NickStallman commented 4 months ago

Just for further context, what I'd hope to avoid is this:

image

Due to how I've got it set up, if the grid (red, top) is always sorted first (lower priority), and the house (blue) is sorted last (higher priority) then it would be impossible for unnecessary waviness when there's many values that are close together jumping around.

MindFreeze commented 4 months ago

I see your point but TBH I don't want to complicate this even more. This is why I don't use sorting myself. I added sorting based on requests, then I had to add sort_by_parent. Your chart has overlapping parents so even that option is not enough. I hate adding more complexity and the card is already too complicated for most people and maintenance is hard. At this point I would advise to just not use sorting or only use it in the last section with sort by parent.

NickStallman commented 4 months ago

No worries, that's understandable. :)

It'll be a bit more tedious to achieve the desired result without it but I'll fiddle and see what I can do with my config.