@@ -583,33 +583,82 @@ class PredbatTableCard extends HTMLElement {
583583 }
584584
585585 if ( column === "pv-column" || column === "load-column" || column === 'import-column' || column === 'export-column' ) {
586+
587+ const hasBoldTags = / < b > .* ?< \/ b > / . test ( theItem . value ) ;
588+ const hasItalicTags = / < i > .* ?< \/ i > / . test ( theItem . value ) ;
589+ let contentWithoutTags = theItem . value . replace ( / < b > ( .* ?) < \/ b > / g, '$1' ) ;
590+ contentWithoutTags = contentWithoutTags . replace ( / < i > ( .* ?) < \/ i > / g, '$1' ) ;
591+ let debugPrices = false ;
592+ if ( theItem . value . includes ( "(" ) && theItem . value . includes ( ")" ) )
593+ debugPrices = true ;
594+
595+ if ( this . config . debug_columns !== undefined ) { // there are debug columns in the YAML
596+ if ( this . config . debug_columns !== undefined && this . config . debug_columns . indexOf ( column ) > - 1 ) { // the column is a debug column
597+
598+ // SHOW THE DEBUG VALUE TOO!
599+ newContent = theItem . value ;
600+ } else {
601+ // we need to remove the debug value from the string
602+ if ( column === "pv-column" || column === "load-column" )
603+ newContent = parseFloat ( theItem . value ) . toFixed ( 2 ) ;
604+ else {
605+ if ( debugPrices ) {
606+ let priceStrings = this . getPricesFromPriceString ( contentWithoutTags , hasBoldTags , hasItalicTags , debugPrices ) ;
607+ newContent = priceStrings [ 0 ] ;
608+ }
609+ }
610+ }
611+ } else { // there are NO debug columns in the YAML, so dont show debug values even if HTML Debug is ON
612+ if ( column === "pv-column" || column === "load-column" )
613+ newContent = parseFloat ( theItem . value ) . toFixed ( 2 ) ;
614+ else {
615+ if ( debugPrices ) {
616+ let priceStrings = this . getPricesFromPriceString ( contentWithoutTags , hasBoldTags , hasItalicTags , debugPrices ) ;
617+ newContent = priceStrings [ 0 ] ;
618+ }
619+ }
620+
621+ }
586622
623+ /*
587624 const hasBoldTags = /<b>.*?<\/b>/.test(theItem.value);
588625
589626 //check for HTML Debug values
590- if ( newContent . includes ( "(" ) && newContent . includes ( ")" ) ) {
627+
628+ if(theItem.value.includes("(") && theItem.value.includes(")") && !theItem.value.includes("?")){
591629 const match = theItem.value.match(/(\d+(?:\.\d+)?)\s*\((\d+(?:\.\d+)?)\)/);
592- if ( hasBoldTags )
593- newContent = "<b>" + parseFloat ( match [ 1 ] ) . toFixed ( 2 ) + " (" + parseFloat ( match [ 2 ] ) . toFixed ( 2 ) + ")</b>" ;
594- else
595- newContent = parseFloat ( match [ 1 ] ) . toFixed ( 2 ) + " (" + parseFloat ( match [ 2 ] ) . toFixed ( 2 ) + ")" ;
630+
631+ if(match !== null){
632+ if(hasBoldTags)
633+ newContent = "<b>" + parseFloat(match[1]).toFixed(2) + " (" + parseFloat(match[2]).toFixed(2) + ")</b>";
634+ else
635+ newContent = parseFloat(match[1]).toFixed(2) + " (" + parseFloat(match[2]).toFixed(2) + ")";
636+ }
596637 }
597638
598639 if(this.config.debug_columns !== undefined) {// there are debug columns in the YAML
599- if ( this . config . debug_columns . indexOf ( column ) < 0 )
640+ if(this.config.debug_columns.indexOf(column) < 0){
600641 if(hasBoldTags){
601642 let contentWithoutTags = theItem.value.replace(/<b>(.*?)<\/b>/g, '$1');
602643 newContent = `<b>` + parseFloat(contentWithoutTags).toFixed(2) + `</b>`;
603644 } else
604645 newContent = parseFloat(newContent).toFixed(2);
646+ }
605647
606648 } else {
607- if ( hasBoldTags ) {
608- let contentWithoutTags = theItem . value . replace ( / < b > ( .* ?) < \/ b > / g, '$1' ) ;
609- newContent = `<b>` + parseFloat ( contentWithoutTags ) . toFixed ( 2 ) + `</b>` ;
610- } else
611- newContent = parseFloat ( newContent ) . toFixed ( 2 ) ;
649+ if(!theItem.value.includes("?")){
650+ if(hasBoldTags){
651+ let contentWithoutTags = theItem.value.replace(/<b>(.*?)<\/b>/g, '$1');
652+ newContent = `<b>` + parseFloat(contentWithoutTags).toFixed(2) + `</b>`;
653+ } else
654+ newContent = parseFloat(newContent).toFixed(2);
655+ } else {
656+ const testRegex = /(\d+\.\d+)\D+(\d+\.\d+)/;
657+ const testMatches = thePriceString.match(testRegex);
658+ newContent = testMatches[1];
659+ }
612660 }
661+ */
613662 }
614663
615664
@@ -1928,6 +1977,8 @@ class PredbatTableCard extends HTMLElement {
19281977 }
19291978
19301979 getDarkenHexColor ( hexColor , percent ) {
1980+
1981+
19311982 // Ensure the percent is within the valid range
19321983 percent = Math . max ( 0 , Math . min ( 100 , percent ) ) ;
19331984
@@ -1948,6 +1999,8 @@ class PredbatTableCard extends HTMLElement {
19481999 r = Math . min ( 255 , Math . max ( 0 , r ) ) ;
19492000 g = Math . min ( 255 , Math . max ( 0 , g ) ) ;
19502001 b = Math . min ( 255 , Math . max ( 0 , b ) ) ;
2002+
2003+ //console.log(r + " " + g + " " + b);
19512004
19522005 // Convert RGB back to HEX
19532006 const darkenedHexColor = `#${ ( 1 << 24 | r << 16 | g << 8 | b ) . toString ( 16 ) . slice ( 1 ) } ` ;
0 commit comments