Skip to content

Commit 51ad567

Browse files
committed
re-fetch and autoscale on relevant config changes
1 parent 0582af3 commit 51ad567

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/plotly-graph-card.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ export class PlotlyGraph extends HTMLElement {
9898
position: absolute;
9999
color: #ffffff;
100100
top: 0;
101-
padding: 5px;
101+
padding: 10px;
102+
width: calc(100% - 20px);
102103
background: rgba(203,0,0,0.8);
103104
overflow-wrap: break-word;
104-
width: 100%;
105105
display: none;
106106
}
107+
#error-msg a{
108+
color: mediumturquoise;
109+
}
107110
</style>
108111
<div id="title"> </div>
109112
<div id="plotly"> </div>
@@ -273,23 +276,16 @@ export class PlotlyGraph extends HTMLElement {
273276
// The user supplied configuration. Throw an exception and Lovelace will
274277
// render an error card.
275278
async setConfig(config: InputConfig) {
279+
const was = this.config;
276280
this.config = config;
277-
await this.plot({ should_fetch: false });
281+
const is = this.config;
282+
this.touchController.isEnabled = !is.disable_pinch_to_zoom;
283+
if (is.hours_to_show !== was?.hours_to_show || is.offset !== was?.offset) {
284+
this.exitBrowsingMode();
285+
} else {
286+
await this.plot({ should_fetch: false });
287+
}
278288
}
279-
// async _setConfig(config: InputConfig) {
280-
// config = JSON.parse(JSON.stringify(config));
281-
// this.config = config;
282-
// const newConfig = parseConfig(config);
283-
// const was = this.parsed_config;
284-
// this.parsed_config = newConfig;
285-
// const is = this.parsed_config;
286-
// this.touchController.isEnabled = !is.disable_pinch_to_zoom;
287-
// if (is.hours_to_show !== was?.hours_to_show || is.offset !== was?.offset) {
288-
// this.exitBrowsingMode();
289-
// } else {
290-
// await this.fetch();
291-
// }
292-
// }
293289
getCSSVars() {
294290
const styles = window.getComputedStyle(this.contentEl);
295291
let haTheme = {
@@ -336,7 +332,7 @@ export class PlotlyGraph extends HTMLElement {
336332
this.errorMsgEl.style.display = errors.length ? "block" : "none";
337333
this.errorMsgEl.innerHTML = errors
338334
.map((e) => "<span>" + (e || "See devtools console") + "</span>")
339-
.join("\n");
335+
.join("\n<br />\n");
340336
this.parsed_config = parsed;
341337
console.log("fetched", this.parsed_config);
342338

0 commit comments

Comments
 (0)