@@ -137,18 +137,19 @@ export class PlotlyGraph extends HTMLElement {
137137 const units = Array . from (
138138 new Set ( Object . values ( attributes ) . map ( ( a ) => a . unit_of_measurement ) )
139139 ) ;
140+
140141 this . data = entities . map ( ( trace ) => {
141142 const entity_id = trace . entity ;
142143 const history = histories [ entity_id ] || { } ;
143144 const attribute = attributes [ entity_id ] || { } ;
144- const yaxis_idx = units . indexOf ( attribute . unit_of_measurement ) + 1 ;
145+ const yaxis_idx = units . indexOf ( attribute . unit_of_measurement ) ;
145146 return {
146147 name : trace . name || attribute . friendly_name || entity_id ,
147148 hovertemplate : `%{y} ${ attribute . unit_of_measurement || "" } ` ,
148149 ...trace ,
149150 x : history . map ( ( { last_changed } ) => new Date ( last_changed ) ) ,
150151 y : history . map ( ( { state } ) => state ) ,
151- yaxis : "y" + yaxis_idx ,
152+ yaxis : "y" + ( yaxis_idx == 0 ? "" : yaxis_idx + 1 ) ,
152153 } ;
153154 } ) ;
154155
@@ -182,6 +183,7 @@ export class PlotlyGraph extends HTMLElement {
182183 const units = Array . from (
183184 new Set ( Object . values ( attributes ) . map ( ( a ) => a . unit_of_measurement ) )
184185 ) ;
186+
185187 const yAxisTitles = Object . fromEntries (
186188 units . map ( ( unit , i ) => [ "yaxis" + ( i == 0 ? "" : i + 1 ) , { title : unit } ] )
187189 ) ;
@@ -195,6 +197,7 @@ export class PlotlyGraph extends HTMLElement {
195197 modeBarButtonsToRemove : [ "resetScale2d" , "toImage" ] ,
196198 ...config . config ,
197199 } ;
200+ console . log ( this . data , layout ) ;
198201 this . isInternalRelayout = true ;
199202 await Plotly . react ( contentEl , data , layout , plotlyConfig ) ;
200203 this . isInternalRelayout = false ;
0 commit comments