File tree Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,9 @@ export function addPreParsingDefaults(yaml: InputConfig): InputConfig {
119119
120120export function addPostParsingDefaults ( {
121121 yaml,
122- isBrowsing,
123- old_uirevision,
124122 css_vars,
125123} : {
126124 yaml : Config ;
127- isBrowsing : boolean ;
128- old_uirevision : number ;
129125 css_vars : HATheme ;
130126} ) : Config {
131127 // 3rd pass: decorate
@@ -150,8 +146,6 @@ export function addPostParsingDefaults({
150146 xaxis : {
151147 range : yaml . visible_range ,
152148 } ,
153- //changing the uirevision triggers a reset to the axes
154- uirevision : isBrowsing ? old_uirevision : Math . random ( ) ,
155149 } ,
156150 yaml . raw_plotly_config ? { } : yAxisTitles ,
157151 yaml . layout
Original file line number Diff line number Diff line change @@ -46,9 +46,6 @@ class ConfigParser {
4646 this . errors = [ ] ;
4747 this . hass = hass ;
4848 this . yaml_with_defaults = addPreParsingDefaults ( input_yaml ) ;
49- const isBrowsing = ! ! input_yaml . visible_range ;
50- console . log ( "isBrowsing" , isBrowsing ) ;
51-
5249 // 2nd pass: evaluate functions
5350
5451 this . fnParam = {
@@ -74,8 +71,6 @@ class ConfigParser {
7471 //TODO: mutates
7572 this . yaml = addPostParsingDefaults ( {
7673 yaml : this . yaml ,
77- isBrowsing,
78- old_uirevision,
7974 css_vars,
8075 } ) ;
8176
Original file line number Diff line number Diff line change @@ -226,7 +226,8 @@ export class PlotlyGraph extends HTMLElement {
226226 }
227227
228228 getVisibleRange ( ) {
229- return this . contentEl . layout . xaxis ! . range ! . map ( ( date ) => {
229+ // TODO: if the x axis is not there, or is not time, don't fetch & replot
230+ return this . contentEl . layout . xaxis ?. range ?. map ( ( date ) => {
230231 // if autoscale is used after scrolling, plotly returns the dates as timestamps (numbers) instead of iso strings
231232 if ( Number . isFinite ( date ) ) return date ;
232233 if ( date . startsWith ( "-" ) ) {
@@ -309,19 +310,30 @@ export class PlotlyGraph extends HTMLElement {
309310 if ( this . pausedRendering ) return ;
310311 const should_fetch = this . fetchScheduled ;
311312 this . fetchScheduled = false ;
313+ let i = 0 ;
312314 while ( ! ( this . config && this . hass && this . isConnected ) ) {
315+ if ( i ++ > 10 ) throw new Error ( "Card didn't load" ) ;
313316 console . log ( "waiting for loading" ) ;
314317 await sleep ( 100 ) ;
315318 }
316319 const fetch_mask = this . contentEl . data . map (
317320 ( { visible } ) => should_fetch && visible !== "legendonly"
318321 ) ;
322+ const uirevision = this . isBrowsing
323+ ? this . contentEl . layout ?. uirevision || 0
324+ : Math . random ( ) ;
319325 const yaml = merge (
320326 { } ,
321327 this . config ,
322- { layout : this . size } ,
323- { fetch_mask } ,
328+ {
329+ layout : {
330+ ...this . size ,
331+ ...{ uirevision } ,
332+ } ,
333+ fetch_mask,
334+ } ,
324335 this . isBrowsing ? { visible_range : this . getVisibleRange ( ) } : { } ,
336+
325337 this . config
326338 ) ;
327339 const { errors, parsed } = await this . configParser . update ( {
You can’t perform that action at this time.
0 commit comments