Skip to content

Commit d270125

Browse files
authored
Implemented better approach to show_value. (#178)
1 parent f109101 commit d270125

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

readme.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,44 @@ entities:
258258
259259
Note that `5minute` period statistics are limited in time as normal recorder history is, contrary to other periods which keep data for years.
260260

261+
## show_value:
262+
263+
Shows the value of the last datapoint as text in the plot.
264+
265+
Examples:
266+
267+
```yaml
268+
type: custom:plotly-graph
269+
entities:
270+
- entity: sensor.temperature
271+
show_value: true
272+
```
273+
274+
Often one wants this to be the case for all entities
275+
276+
```yaml
277+
defaults:
278+
entity:
279+
show_value: true
280+
```
281+
282+
If you want to make extra room for the value, you can either increase the right margin of the whole plot like this:
283+
284+
```yaml
285+
layout:
286+
margin:
287+
r: 100
288+
```
289+
290+
Or make space inside the the plot like this:
291+
292+
```yaml
293+
defaults:
294+
entity:
295+
show_value:
296+
right_margin: 20 # this is 20% of the space in the x axis
297+
```
298+
261299
## Offsets
262300

263301
Offsets are useful to shift data in the temporal axis. For example, if you have a sensor that reports the forecasted temperature 3 hours from now, it means that the current value should be plotted in the future. With the `offset` attribute you can shift the data so it is placed in the correct position.
@@ -365,8 +403,7 @@ entities:
365403
lambda: |- # Transforms the data
366404
(ys) => ys.map(y => (y × 9/5) + 32)
367405
unit_of_measurement: °F # Overrides the unit
368-
show_value: # shows the last value with 40% right margin
369-
right_margin: 40
406+
show_value: true # shows the last value as text
370407
texttemplate: >- # custom format for show_value
371408
<b>%{y}</b>%{customdata.unit_of_measurement}<br>
372409
%{customdata.name}

src/plotly-graph-card.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class PlotlyGraph extends HTMLElement {
285285
const padPercent = Math.max(
286286
...this.parsed_config.entities.map(({ show_value }) => {
287287
if (show_value === false) return 0 / 100;
288-
if (show_value === true) return 10 / 100;
288+
if (show_value === true) return 0 / 100;
289289
return show_value.right_margin / 100;
290290
})
291291
);
@@ -545,6 +545,7 @@ export class PlotlyGraph extends HTMLElement {
545545
show_value_traces.push({
546546
texttemplate: `%{y:.2~f}%{customdata.unit_of_measurement}`, // here so it can be overwritten
547547
...mergedTrace,
548+
cliponaxis: false, // allows the marker + text to be rendered above the right y axis. See https://github.com/dbuezas/lovelace-plotly-graph-card/issues/171
548549
mode: "text+markers",
549550
showlegend: false,
550551
hoverinfo: "skip",

src/themed-layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const defaultExtraYAxes: Partial<Plotly.LayoutAxis> = {
77
overlaying: "y",
88
showgrid: false,
99
visible: false,
10+
// This makes sure that the traces are rendered above the right y axis,
11+
// including the marker and its text. Useful for show_value. See cliponaxis in entity
12+
layer: "below traces",
1013
};
1114

1215
const defaultLayout: Partial<Plotly.Layout> = {

0 commit comments

Comments
 (0)