[OH3] Main UI - Custom List-Item Widget with colorbars for percentage visualisation

Hello Community, I have some issues with CSS / Responsive development.

following custom widget in desktop view looking as expected:

desktop_view

3 color bars with:

  • 3 colors in the first line for 3 price ranges (up to 24cent green, up to 30 orange and red for prices over)
  • 2 split bars for 0 to 100% solar power (orange for external energy, green for solar power)
  • 2 split bars for 0 to 100% autarky level

Its a mixure of aWATTar Binding for stock exchange energy prices calculated with the costs of my self produces Photovoltaic Solar Power price and the relation between external power and self produced. I used a 1x1px transparent space gif with different colored backgrunds.

with the following code:

uid: Strompreis_Uebersicht
timestamp: Mar 5, 2021, 6:18:42 PM
component: oh-list-card
config: {}
slots:
  default:
    - component: oh-image
      config:
        url: http://192.168.178.11:8081/img/s.gif
        style:
          position: absolute
          background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #99FF33)'"
          top: 6px
          right: =10   + 'px'
          width: =200  + 'px'
          height: 20px
          z-index: 20
    - component: oh-label-item
      config:
        item: PowerDogAPI_PDEffektiverStrompreis
        title: Effektiver Strompreis
        style:
          font-weight: 800
          z-index: 99
        action: analyzer
        actionAnalyzerItems:
          - aWATTarHourlyPrice_Current_Totalgross
          - PowerDogAPI_PDEffektiverStrompreis
    - component: oh-label-item
      config:
        item: PowerDogAPI_PDAnteilPV
        title: Anteil Sonnenstrom
        style:
          font-weight: 800
          z-index: 99
    - component: oh-image
      config:
        url: http://192.168.178.11:8081/img/s.gif
        style:
          position: absolute
          background: "linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)"
          top: 38px
          right: =10 + 200 * (items.PowerDogAPI_PDAnteilPV.state / 100) + 'px'
          width: =200 * ((100 - items.PowerDogAPI_PDAnteilPV.state) / 100) + 'px'
          height: 20px
          z-index: 2
    - component: oh-image
      config:
        url: http://192.168.178.11:8081/img/s.gif
        style:
          position: absolute
          background: "linear-gradient(to left, hsla(0, 100%, 100%, 0), #009900)"
          top: 38px
          right: =10 + 'px'
          width: =200 * (items.PowerDogAPI_PDAnteilPV.state / 100) + 'px'
          height: 20px
          z-index: 1
    - component: oh-label-item
      config:
        title: ='Autarkie heute'
        item: Autarkie_Wert
        iconUseState: false
        style:
          font-weight: 800
          z-index: 99
    - component: oh-image
      config:
        url: http://192.168.178.11:8081/img/s.gif
        style:
          position: absolute
          background: "linear-gradient(to left, hsla(0, 100%, 100%, 0), #e67300)"
          top: 70px
          right: =10 + 200 * (items.Autarkie_Wert.state / 100) + 'px'
          width: =200 * ((100 - items.Autarkie_Wert.state) / 100) + 'px'
          height: 20px
          z-index: 1
    - component: oh-image
      config:
        url: http://192.168.178.11:8081/img/s.gif
        style:
          position: absolute
          background: "linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)"
          top: 70px
          right: =10 + 'px'
          width: =200 * (items.Autarkie_Wert.state / 100) + 'px'
          height: 20px
          z-index: 2
    - component: oh-label-item
      config:
        item: aWATTarHourlyPrice_Current_Totalgross
        title: Preis Strombörse
        style:
          font-weight: 800
          z-index: 99

but in mobile view it shows up like this and I have no idea how to fix it… any recomendations?

If this is fixed I will set up Probs and finetune the view.

Hi Ronald,

without actually having tested it, I assume the issue is that you are using absolute width values for the “gradient image” and this simply makes it too large on narrow screens.

The “displacement” could also be a result of this and make the columns wrap somehow. Perhaps that disappears by itself once you changed it to relative widths.

I complete rebuild the Widget with some help of the Weather Widget:

Desktop and Mobile View are looking good now:

desktop_view_new

with the following code:

uid: Strompreis_Uebersicht
timestamp: Mar 7, 2021, 12:00:07 PM
component: f7-card
config:
  style:
    #background-color: rgb(255, 255, 255)
    background: "='linear-gradient(to top, #404040, #262626)'"
    border-radius: 20px
    height: 192px
    overflow: hidden
    -ms-user-select: none
    -moz-user-select: none
    -webkit-user-select: none
    user-select: none
slots:
  default:
    - component: f7-block
      config:
        class:
          - no-padding
          - no-margin
        style:
          #background: yellow
          width: 100%
          height: 100%
          position: absolute
          top: 0
          left: 0
          z-index: 1
     
    - component: f7-row
      config:
        visible: true
      slots:
        default:
          - component: f7-col
            config:
              visible: true
            slots:
              default:
                
                - component: Label
                  config:
                    text: Strom 
                    class:
                      - padding-left
                    style:
                      #position: absolute
                      #background: black
                      white-space: nowrap
                      overflow: hidden
                      text-overflow: ellipsis
                      #text-shadow: var(--weather-text-shadow-strong)
                      font-size: 28px
                      line-height: 50px
                      font-weight: 600
                      z-index: 90
                      letter-spacing: .75px
                      #font-size: var(--weather-font-size-large)
                      text-shadow: var(--weather-text-shadow-strong)
                
                    
                
                - component: f7-row
                  config:
                    visible: true
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      #background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                      width: 100%
                      height: 30px
                      top: 51px
                    
                  slots:
                    default:
                      
                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            - component: Label
                              config:
                                text: Effektiver Strompreis
                                class:
                                  - padding-left
                                style:
                                  position: relative
                                  
                                  #background: red
                                  #background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  line-height: 31px
                                  font-weight: 400
                                  z-index: 20
                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            - component: Label
                              config:
                                text: =items.PowerDogAPI_PDEffektiverStrompreis.displayState 
                                class:
                                  - padding-right
                                style:
                                  position: relative
                                  
                                  #background: blue
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  text-align: right
                                  line-height: 31px
                                  font-weight: 400
                                  
                                  z-index: 90
                - component: f7-block
                  config:
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      
                      background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                      width: 100%
                      height: 30px
                      
                      top: 51px
                      z-index: 2            


                - component: f7-row
                  config:
                    visible: true
                    class:
                      - no-padding
                      - no-margin
                    style:
                      position: absolute
                      width: 100%
                      height: 30px
                      top: 82px
                  slots:
                    default:
                      
                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            
                            - component: Label
                              config:
                                text: Anteil Sonnenstrom
                                class:
                                  - padding-left
                                style:
                                  position: relative
                                  
                                  #background: red
                                  #background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  line-height: 31px
                                  font-weight: 400
                                  z-index: 20


                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            - component: Label
                              config:
                                text: =items.PowerDogAPI_PDAnteilPV.displayState 
                                class:
                                  - padding-right
                                style:
                                  position: relative
                                  
                                  #background: blue
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  text-align: right
                                  line-height: 31px
                                  font-weight: 400
                                  
                                  z-index: 90
                - component: f7-block
                  config:
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      background: "linear-gradient(to left, hsla(0, 100%, 100%, 0), #e67300)"
                      width: =(100 - items.PowerDogAPI_PDAnteilPV.state * 0.80 ) + '%'
                      height: 30px
                      
                      top: 82px
                      z-index: 1
                - component: f7-block
                  config:
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      background: "linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)"
                      width: =items.PowerDogAPI_PDAnteilPV.state + '%'
                      height: 30px
                      right: 0
                      top: 82px
                      z-index: 1


                - component: f7-row
                  config:
                    visible: true
                    class:
                      - no-padding
                      - no-margin
                    style:
                      position: absolute
                      width: 100%
                      height: 30px
                      top: 113px
                  slots:
                    default:
                      
                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            
                            - component: Label
                              config:
                                text: Autarkie
                                class:
                                  - padding-left
                                style:
                                  position: relative
                                  
                                  #background: red
                                  #background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  line-height: 31px
                                  font-weight: 400
                                  z-index: 20


                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            - component: Label
                              config:
                                text: =items.Autarkie_Wert.displayState
                                class:
                                  - padding-right
                                style:
                                  position: relative
                                  
                                  #background: blue
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  text-align: right
                                  line-height: 31px
                                  font-weight: 400
                                  
                                  z-index: 90
                - component: f7-block
                  config:
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      background: "linear-gradient(to left, hsla(0, 100%, 100%, 0), #e67300)"
                      width: =(100 - items.Autarkie_Wert.state * 0.80 ) + '%'
                      height: 30px
                      
                      top: 113px
                      z-index: 1
                - component: f7-block
                  config:
                    class:
                      - no-padding
                      - no-margin
                    style:
                      
                      position: absolute
                      background: "linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)"
                      width: =items.Autarkie_Wert.state * 1  + '%'
                      height: 30px
                      right: 0
                      top: 113px
                      z-index: 1


                - component: f7-row
                  config:
                    visible: true
                    class:
                      - no-padding
                      - no-margin
                    style:
                      position: absolute
                      width: 100%
                      height: 30px
                      top: 144px
                  slots:
                    default:
                      
                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            
                            - component: Label
                              config:
                                text: Preis Strombörse
                                class:
                                  - padding-left
                                style:
                                  position: relative
                                  
                                  #background: red
                                  #background: "=(items.PowerDogAPI_PDEffektiverStrompreis.state > 24) ? ((items.PowerDogAPI_PDEffektiverStrompreis.state > 30) ? 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #cc0000)' : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #e67300)') : 'linear-gradient(to right, hsla(0, 100%, 100%, 0), #009900)'"
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  line-height: 31px
                                  font-weight: 400
                                  z-index: 20


                      - component: f7-col
                        config:
                          visible: true
                        slots:
                          default:
                            - component: Label
                              config:
                                text: =items.aWATTarHourlyPrice_Current_Totalgross.displayState
                                class:
                                  - padding-right
                                style:
                                  position: relative
                                  
                                  #background: blue
                                  white-space: nowrap
                                  overflow: hidden
                                  text-overflow: ellipsis
                                  #text-shadow: var(--weather-text-shadow-strong)
                                  font-size: 16px
                                  text-align: right
                                  line-height: 31px
                                  font-weight: 400
                                  
                                  z-index: 90


1 Like

Nice one :+1: