dbuezas / lovelace-plotly-graph-card

Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more!
414 stars 20 forks source link

The legend of the datapoint corresponding to show_value is polluted when data is generated by a filters-fn combination #257

Open r-jean-pierre opened 1 year ago

r-jean-pierre commented 1 year ago

Describe the bug Only if data is generated by filters-fn, the legend of the first point (show_value) gets extra information from I suppose the underlying-fake-scatterplot

Screenshots image

while other data points are perfect: image

yaml

filters:
  - fn: |-
      ({ meta }) => ({
        xs: meta.dailyweek.map((date) => new Date(date)-3600*1000),
        ys: meta.dailyweek_HP.map((value) => value)
      })
dbuezas commented 1 year ago

Interesting, I do add hoverinfo: 'skip' on the "fake" traces used for show_value https://github.com/dbuezas/lovelace-plotly-graph-card/blob/master/src/parse-config/parse-config.ts#LL208C22-L208C22

Is there anything special in the rest of the yaml?

r-jean-pierre commented 1 year ago

Interesting, I do add hoverinfo: 'skip' on the "fake" traces used for show_value https://github.com/dbuezas/lovelace-plotly-graph-card/blob/master/src/parse-config/parse-config.ts#LL208C22-L208C22

Is there anything special in the rest of the yaml?

except: hovermode: "x unified" and a personal hovertemplate, i really have nothing special

dbuezas commented 1 year ago

Uhm. The hovertemplate may be overriding it. I could add an extra property to remove the hovertemplate from the "fake" trace I use for show_value. Can you check if removing "hovertemplate" from the entity makes it disappear?

r-jean-pierre commented 1 year ago

So, almost sure that it's not related to the templating, here is a minimalistic, but complete, example:

  - type: custom:plotly-graph  # test nrj
    entities:
    - entity: sensor.myenedis_05606946388355
      filters:
        - fn: |-
            ({ meta }) => ({
              xs: meta.dailyweek.map((date) => new Date(date)-3600*1000).reverse(),
              ys: meta.daily.map(value => value).reverse()
            })
      show_value: true
    - entity: sensor.myenedis_05606946388355
      filters:
        - fn: |-
            ({ meta }) => ({
              xs: meta.dailyweek.map((date) => new Date(date)-3600*1000).reverse(),
              ys: meta.daily.map(value => value).reverse()
            })
      show_value: true

    layout:
      hovermode: "x unified"    # -> this option is guilty

    hours_to_show: 180h
    time_offset: -30h

image

if i use the default hovermode, than it is what could be expected: image image

dbuezas commented 1 year ago

Then it looks like it is a plotly bug :/ Just found this: https://github.com/plotly/plotly.js/issues/5516

maybe try with hoverinfo: none instead of skip

dbuezas commented 1 year ago

Ok, it needs both hoverinfo and hovertemplate

hovertemplate: false
hoverinfo: none

adding these two to an entity makes the tooltip go away, even in x-unified hover mode.

I'll keep this open and fix in the next release by adding those two to the template of the fake trace used for show_value.

In the meanwhile if it bothers you, you could add a second trace with no hoverinfo and template, remove all but the last datapoints and set show_value on it.