Login
Back to bricks list
Introduction Version

Resource views


The Resource Views are ways to visualize Resources. Resource views are decorated methods of the view class that return a View object.


How to create a Resource View?


To create a valid resource view, you will need to create a method in the Resource class that:


  • Is decorated with the @view_decorator
    • In the decorator, it is a good practice to declare the correct view type that is returned so that the user will know what to expect when using your view.
    • Returns a View object

      Once these conditions are met, the view will be available in the interface when the user opens the resource.


      Here is an example of a view of the Robot. This view return the latitude or longitude position of the Robot as json (JSONView). It takes a configuration to choose whether to return the latitude or longitude.


          @view(view_type=JSONView, human_name="View position",
                            specs={"position": StrParam(default_value="latitude", allowed_values=['latitude', 'longitude'])})
          def view_only_position(self, params: ConfigParams) -> JSONView:
              position: str = params.get_value('position')
              position_value = self.position[1] if position == 'latitude' else self.position[0]
              return JSONView({"position": position, "value": position_value})
      


      View object


      View object are classes that are used to format data so that the interface can show the correct view with correct data. The interface only supports a specific list of views:


      • JsonView
        • TableView
          • TextVIew
            • TableView
              • NetworkView
                • ImageView
                  • ScatterPlot2dView
                    • Line2dView
                      • BarPLotView
                        • StackedBarPLotView
                          • HistogramView
                            • BoxPlotView
                              • VennDiagramView
                                • HeatMapView
                                  • ResourceListView
                                    • MultiView

                                      You will need to check the code of these classes to see how to provide the data in the correct format for the view


                                      Configuration


                                      The same you define config specs for your task, you can define specs for your view. The specs must be defined in the specs parameter of the @view decorator.


                                      In the example we defined 1 spec called position for the view.


                                      @view(view_type=JSONView, human_name="View position",
                                                         specs={"position": StrParam(default_value="latitude", allowed_values=['latitude', 'longitude'])})
                                      


                                      The default view


                                      A resource can have only one default view and all parameters of the default view must be optional. The default view is the recommended view for the resource. The default view of children classes overrides the default view of parent classes.



                                      Technical information


                                      You can add specific technical information on a view by calling add_technical_info. Please check the Technical Information section in the Resource documentation.


                                      Create a new view type (for expert)



                                      ViewSpecs


                                      You can also provide spec at the view type level. It means that all the view methods that use this view type (in the @view decorator) will inherit thoses specs. This is only to be used when you want to create a re-usable view type that always need config.