Tabbed Page Widget/Card

Hello,

is it somehow possible to create a tabbed page card. On the tabbed pages are charts with different periods (year, month, week, day).

I mean something like this. Thanks!

uid: EnergyChartCard
props:
  parameterGroups: []
  parameters:
    - name: prop1
      label: Prop 1
      type: TEXT
      description: A text prop
    - name: item
      label: Item
      type: TEXT
      context: item
      description: An item to control
tags: []
component: f7-card
config: {}
slots:
  default:
    - component: oh-tabs
      config:
        label: Stromverbrauch_Haus
        sidebar: true
      tabs:
        - component: oh-tab
          config:
            icon: f7:squares_below_rectangle
            page: page:StromHaus_Verbrauch_Jahr
            title: Stromverbrauch_Jahr
          slots:
            default: []
        - component: oh-tab
          config:
            icon: f7:squares_below_rectangle
            page: page:StromHaus_Verbrauch_Monat
            title: Stromverbrauch_Monat
          slots:
            default: []
        - component: oh-tab
          config:
            icon: f7:squares_below_rectangle
            page: page:StromHaus_Verbrauch_Woche
            title: Stromverbrauch_Woche
          slots:
            default: []
        - component: oh-tab
          config:
            title: Stromverbrauch_Tag
            icon: f7:squares_below_rectangle
            page: page:StromHaus_Verbrauch_Tag
          slots:
            default: []

Technically, yes, you could force a tabbar onto a card. There are several caveats here: 1) an oh-tabs component does not exist and you can’t use oh-tab components so you would have to build this from scratch using all the f7 components. 2) The tabbar and tab pages are not designed to be shoe-horned into a card container so you are going to run into numerous style issues that are going to take a lot of work to fix.

All, in all, I would strongly advise against going forward with this: for me it would not be worth the substantial effort.

There are several other mechanisms that you could use to create a similar system just using widget variables and basic oh button or link components.

My main problem is, that at the moment it is not possible to dynamically change the period of charts (year, month, week, day), as it is fixed to the chart. So I have created 4 charts and put them into a tapped page. This looks like this:

I was also thinking to put it into a Web Frame Card, but here I’m not able to permenently remove the left Openhab navigation panel.

Some time ago you have posted an example with f7-tabs using the Label component. But I guess there is not something like a Page component to reference the chart pages.

Do you have any further ideas?

Of course, if you do not specify the chartType property, then the chart does allow for changing the period dynamically using the middle button of the selector (and the period can even be made response with a widget expression). If, for some reason, that doesn’t work for you, however,
it’s very simple to convert chart to a widget or component that can then be built into other widgets. Once you have created the chart page, copy the entire configuration from the code tab of that page. Then you just past that configuration under a oh-cart component:

- component: oh-chart
  ...copied chart config goes here

Once, you have done that, then the chart will easily format onto a card, and to make it dynamic (again, because the period can be set with an expression), a simple series of oh-link or oh-button components that set a period variable would be sufficient to switch the chart period on just that single chart component without recourse to multiple versions and tabs.

I’m using aggregated series and this seems not to work with dynamic period.

I could make it working like this, but I had to use f7-page instead f7-card. The size does not change dynamic and I had to set fixed height/width. Can I change it to f7-card and make it somehow dynamic?

uid: EnergyChartCard
tags: []
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Oct 2, 2024, 9:44:13 PM
component: f7-page
config:
  style:
    padding: 0
    height: 400px
    width: 800px
  tabs: true
slots:
  fixed:
    - component: f7-tabs
      slots:
        default:
          - component: f7-page-content
            config:
              id: tab1
              tab: true
              tabActive: true
            slots:
              default:
                - component: oh-chart
                  config:
                    label: StromHaus_Verbrauch_Jahr
                    future: false
                    chartType: year
                  slots:
                    grid:
                      - component: oh-chart-grid
                        config: {}
                    legend:
                      - component: oh-chart-legend
                        config:
                          bottom: 3
                          type: scroll
                    series:
                      - component: oh-aggregate-series
                        config:
                          aggregationFunction: diff_last
                          dimension1: month
                          gridIndex: 0
                          item: StromHaus_Zaehlerstand
                          name: Strom Haus Verbrauch
                          service: jdbc
                          type: bar
                          xAxisIndex: 0
                          yAxisIndex: 0
                    tooltip:
                      - component: oh-chart-tooltip
                        config:
                          confine: true
                    xAxis:
                      - component: oh-category-axis
                        config:
                          categoryType: year
                          gridIndex: 0
                          monthFormat: short
                          weekdayFormat: short
                    yAxis:
                      - component: oh-value-axis
                        config:
                          gridIndex: 0
          - component: f7-page-content
            config:
              id: tab2
              tab: true
            slots:
              default:
                - component: oh-chart
                  config:
                    chartType: month
                    label: StromHaus_Verbrauch_Monat
                  slots:
                    grid:
                      - component: oh-chart-grid
                        config: {}
                    legend:
                      - component: oh-chart-legend
                        config:
                          bottom: 3
                          type: scroll
                    series:
                      - component: oh-aggregate-series
                        config:
                          aggregationFunction: diff_last
                          dimension1: date
                          gridIndex: 0
                          item: StromHaus_Zaehlerstand
                          name: Strom Haus Verbrauch
                          service: jdbc
                          type: bar
                          xAxisIndex: 0
                          yAxisIndex: 0
                    tooltip:
                      - component: oh-chart-tooltip
                        config:
                          confine: true
                    xAxis:
                      - component: oh-category-axis
                        config:
                          categoryType: month
                          gridIndex: 0
                          monthFormat: short
                          weekdayFormat: short
                    yAxis:
                      - component: oh-value-axis
                        config:
                          gridIndex: 0
          - component: f7-page-content
            config:
              id: tab3
              tab: true
            slots:
              default:
                - component: oh-chart
                  config:
                    chartType: isoWeek
                    label: StromHaus_Verbrauch_Woche
                  slots:
                    grid:
                      - component: oh-chart-grid
                        config: {}
                    legend:
                      - component: oh-chart-legend
                        config:
                          bottom: 3
                          type: scroll
                    series:
                      - component: oh-aggregate-series
                        config:
                          aggregationFunction: diff_last
                          dimension1: isoWeekday
                          gridIndex: 0
                          item: StromHaus_Zaehlerstand
                          name: Strom Haus Verbrauch
                          service: jdbc
                          type: bar
                          xAxisIndex: 0
                          yAxisIndex: 0
                    tooltip:
                      - component: oh-chart-tooltip
                        config:
                          confine: true
                    xAxis:
                      - component: oh-category-axis
                        config:
                          categoryType: week
                          gridIndex: 0
                          monthFormat: short
                          weekdayFormat: short
                    yAxis:
                      - component: oh-value-axis
                        config:
                          gridIndex: 0
          - component: f7-page-content
            config:
              id: tab4
              tab: true
            slots:
              default:
                - component: oh-chart
                  config:
                    chartType: day
                    label: StromHaus_Verbrauch_Tag
                  slots:
                    grid:
                      - component: oh-chart-grid
                        config: {}
                    xAxis:
                      - component: oh-category-axis
                        config:
                          gridIndex: 0
                          categoryType: day
                          monthFormat: short
                          weekdayFormat: short
                    yAxis:
                      - component: oh-value-axis
                        config:
                          gridIndex: 0
                          name: kWh
                    series:
                      - component: oh-aggregate-series
                        config:
                          name: Strom Haus Zählerstand
                          item: StromHaus_Zaehlerstand
                          gridIndex: 0
                          xAxisIndex: 0
                          yAxisIndex: 0
                          type: bar
                          dimension1: hour
                          aggregationFunction: diff_last
                    tooltip:
                      - component: oh-chart-tooltip
                        config:
                          confine: true
                    legend:
                      - component: oh-chart-legend
                        config:
                          bottom: 3
                          type: scroll
    - component: f7-toolbar
      config:
        bottom: true
        tabbar: true
      slots:
        default:
          - component: f7-link
            config:
              tabLink: "#tab1"
              tabLinkActive: true
              text: Jahr
          - component: f7-link
            config:
              tabLink: "#tab2"
              text: Monat
          - component: f7-link
            config:
              tabLink: "#tab3"
              text: Woche
          - component: f7-link
            config:
              tabLink: "#tab4"
              text: Tag

This would be the best approach! Do you have an example for this? I have not really an idea how to do it.

Change:
f7-pagef7-card
fixed slot → default slot

I would also change:
f7-page-contentf7-tab

but, that’s not required.

Because you need the fixed period charts, it would look similar in structure to the tab version. The difference would be that for each oh-cart component you would add a visible property that looks like this:

visible: =vars.chartSelect == 'some distinct value here, e.g. month'

For the first chart that you want to be visible before any selections have been made you could modify that to be:

visible: =vars.chartSelect == 'some distinct value here, e.g. month' || !!vars.chartSelect

Then you would just need a way to set that variable. The advantage over the tabbar at this point is that the selection widgets do not have to be buttons at the bottom of the card if you don’t want them to be. You could make a popover, or a drop down, or just two arrow buttons to scroll, or one big button that covers the whole card just selects the next chart in a loop, etc. The important part is that you choose an oh- component that has actions which allow you to set a variable. For a button that would just be something like this:

- component: oh-button
  config:
    text: month
    action: variable
    actionVariable: chartSelect
    actionVariableValue: month

Thanks! It is working with this changes.

It seems to be not that easy, as you need to set several values in the YAML code.

For “year” you have:

chartType: year
dimension1: month
categoryType: year

For “day” you have:

chartType: day
dimension1: hour
categoryType: day

Is it actually possible to have these drop down, button… selection in another widget, so that it is valid for the complete page; the intention is to use this selection for several charts on the page?

Right, but the only one of those that is the real issue (I believe) is the chartType. The other properties accept expressions, but chartType does not which is why I said:

The f7 tabs and tabbar work by creating all the different tabs and then just showing the one that is indicated by the tab button selected and hiding the others. The system I outlined with the variables does the same thing. It uses the visible property to show the one chart you want, while hiding the others. It doesn’t buy you any improvement in the brevity of the widget or resources, but it does buy you flexibility. You have more options for setting variables with oh components than you do with what f7 components can set an active tab. You don’t have to change any of the actual chart properties with the variable system I proposed; you only have to add the visible property.

Yes, widget variables are, by default, scoped to the page they are on (with one exception). This was, in fact, the original idea behind them: to be able to share information between widgets on a page.

You could also cast your net wider and not limit your self to just simulating a tabbar. There are a dizzying array of options at this point with the widget system. For example, you could put you charts in different slides on a swiper and then just swipe through them.