@@ -118,6 +118,8 @@ export class PlotlyGraph extends HTMLElement {
118118 color: red;
119119 top: 0;
120120 background: rgba(0, 0, 0, 0.4);
121+ overflow-wrap: break-word;
122+ width: 100%;
121123 }
122124 </style>
123125 <div id="title"> </div>
@@ -227,10 +229,14 @@ export class PlotlyGraph extends HTMLElement {
227229 return await this . _setConfig ( config ) ;
228230 } catch ( e : any ) {
229231 console . error ( e ) ;
230- this . msgEl . innerText = JSON . stringify ( e . message || "" ) . replace (
231- / \\ " / g,
232- '"'
233- ) ;
232+ if ( typeof e . message === "string" ) {
233+ this . msgEl . innerText = e . message ;
234+ } else {
235+ this . msgEl . innerText = JSON . stringify ( e . message || "" ) . replace (
236+ / \\ " / g,
237+ '"'
238+ ) ;
239+ }
234240 }
235241 }
236242 async _setConfig ( config : InputConfig ) {
@@ -241,7 +247,16 @@ export class PlotlyGraph extends HTMLElement {
241247 ? schemeName
242248 : colorSchemes [ schemeName ] ||
243249 colorSchemes [ Object . keys ( colorSchemes ) [ schemeName ] ] ||
244- colorSchemes . category10 ;
250+ null ;
251+ if ( colorScheme === null ) {
252+ throw new Error (
253+ `color_scheme: "${
254+ config . color_scheme
255+ } " is not valid. Valid are an array of colors (see readme) or ${ Object . keys (
256+ colorSchemes
257+ ) } `
258+ ) ;
259+ }
245260 const newConfig : Config = {
246261 title : config . title ,
247262 hours_to_show : config . hours_to_show ?? 1 ,
@@ -269,8 +284,11 @@ export class PlotlyGraph extends HTMLElement {
269284 }
270285 if ( "statistic" in entity || "period" in entity ) {
271286 const validStatistic = STATISTIC_TYPES . includes ( entity . statistic ! ) ;
272- if ( ! validStatistic ) entity . statistic = "mean" ;
273- console . log ( entity . period ) ;
287+ if ( entity . statistic === undefined ) entity . statistic = "mean" ;
288+ else if ( ! validStatistic )
289+ throw new Error (
290+ `statistic: "${ entity . statistic } " is not valid. Use ${ STATISTIC_TYPES } `
291+ ) ;
274292 // @TODO : cleanup how this is done
275293 if ( entity . period === "auto" ) {
276294 entity . autoPeriod = {
@@ -285,9 +303,14 @@ export class PlotlyGraph extends HTMLElement {
285303
286304 if ( isAutoPeriodConfig ) {
287305 entity . autoPeriod = entity . period ;
306+ entity . period = undefined ;
288307 }
289308 const validPeriod = STATISTIC_PERIODS . includes ( entity . period ) ;
290- if ( ! validPeriod ) entity . period = "hour" ;
309+ if ( entity . period === undefined ) entity . period = "hour" ;
310+ else if ( ! validPeriod )
311+ throw new Error (
312+ `period: "${ entity . period } " is not valid. Use ${ STATISTIC_PERIODS } `
313+ ) ;
291314 }
292315 const [ oldAPI_entity , oldAPI_attribute ] = entity . entity . split ( "::" ) ;
293316 if ( oldAPI_attribute ) {
0 commit comments