Skip to content

grid

GridLayout #

Bases: VuetifyTemplate

A draggable & resizable grid layout which can be dragged via a toolbar.

Arguably, this should use solara's components directly, but it doesn't function correctly with "component_vue" decorator.

Source code in src/sdss_explorer/dashboard/components/views/grid.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class GridLayout(v.VuetifyTemplate):
    """
    A draggable & resizable grid layout which can be dragged via a toolbar.

    Arguably, this should use solara's components directly, but it
    doesn't function correctly with "component_vue" decorator.
    """

    template_file = os.path.join(os.path.dirname(__file__),
                                 "../../../vue/gridlayout_toolbar.vue")
    gridlayout_loaded = t.Bool(False).tag(sync=True)
    items = t.Union([t.List(), t.Dict()],
                    default_value=[]).tag(sync=True,
                                          **widgets.widget_serialization)
    grid_layout = t.List(default_value=[]).tag(sync=True)
    draggable = t.CBool(True).tag(sync=True)
    resizable = t.CBool(True).tag(sync=True)

add_view(plottype, layout=None, **kwargs) #

Add a view to the grid. Layout can be parsed as a pre-made dict

Source code in src/sdss_explorer/dashboard/components/views/grid.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def add_view(plottype, layout: Optional[dict] = None, **kwargs):
    """Add a view to the grid. Layout can be parsed as a pre-made dict"""
    if layout is None:
        if len(GridState.grid_layout.value) == 0:
            prev = {"x": 0, "y": -12, "h": 12, "w": 12, "moved": False}
        else:
            prev = GridState.grid_layout.value[-1]
        maxH = 40
        minH = 7
        if plottype == "stats":
            height = 7
        elif plottype == "targets":
            height = 9
            maxH = 9
            minH = 9
        else:
            height = 10
        # horizontal or vertical offset depending on width
        if 12 - prev["w"] - prev["x"] >= 6:
            # beside
            x = prev["x"] + 6
            y = prev["y"]
        else:
            # the row below
            x = 0
            y = prev["y"] + prev["h"] + 4
        layout = {
            "x": x,
            "y": y,
            "w": 6,
            "h": height,
            "maxH": maxH,
            "minH": minH,
            "moved": False,
        }

    # always update with current index
    i = GridState.index.value
    layout.update({"i": i})

    # add and update state vars
    GridState.index.value += 1
    GridState.grid_layout.value = GridState.grid_layout.value + [layout]

    logger.debug("entering cardmake")
    card = ViewCard(plottype, i, **kwargs)
    logger.debug("got card")
    newlist = GridState.objects.value.copy() + [card]
    logger.debug("appended")
    GridState.objects.value = newlist
    logger.debug("set")
    logger.debug("append done, exiting")