Skip to content

Commit

Permalink
internal draft
Browse files Browse the repository at this point in the history
  • Loading branch information
clarasb committed Dec 18, 2024
1 parent 4aeaf43 commit 118e1f3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/serve/panels-demo/my_viewer_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from chartlets import Extension
from .my_panel_1 import panel as my_panel_1
from .my_panel_2 import panel as my_panel_2
from .my_panel_3 import panel as my_panel_3

ext = Extension(__name__)
ext.add(my_panel_1)
ext.add(my_panel_2)
ext.add(my_panel_3)
52 changes: 52 additions & 0 deletions examples/serve/panels-demo/my_viewer_ext/my_panel_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from chartlets import Component, Input, State, Output
from chartlets.components import Box, Button, CircularProgress, Plot, Select, Typography

from xcube.webapi.viewer.contrib import Panel
from xcube.webapi.viewer.contrib import get_dataset
from xcube.server.api import Context


panel = Panel(__name__, title="Spectral")


@panel.layout(
State("@app", "selectedDatasetId",),
State("@app", "selectedTimeLabel"),
State("@app", "selectedPlace"),
)
def render_panel(
ctx: Context,
dataset_id: str,
time_label: float,
place_geometry: str,
) -> Component:
dataset = get_dataset(ctx, dataset_id)
# plot = Plot(id="plot", chart=None, style={"paddingTop": 6})

place_text = Typography(id="text", children=[f"selected place_{type(place_geometry)}"], color='pink')
button = Button(id="button", text="ADD", style={"maxWidth": 100})

controls = Box(
children=[button],
style={
"display": "flex",
"flexDirection": "row",
"alignItems": "center",
"gap": 6,
"padding": 6,
},
)

return Box(
children=[place_text, controls],
style={
"display": "flex",
"flexDirection": "column",
"alignItems": "center",
"width": "100%",
"height": "100%",
"gap": 6,
"padding": 6,
},
)

8 changes: 8 additions & 0 deletions xcube/webapi/viewer/contrib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ def get_datasets_ctx(ctx: Context) -> DatasetsContext:

def get_dataset(ctx: Context, dataset_id: str | None = None) -> xr.Dataset | None:
return get_datasets_ctx(ctx).get_dataset(dataset_id) if dataset_id else None


def get_places_ctx(ctx: Context) -> DatasetsContext:
return ctx.get_api_ctx("places")


def get_places(ctx: Context, dataset_id: str | None = None) -> xr.Dataset | None:
return get_datasets_ctx(ctx).get_dataset(dataset_id) if dataset_id else None

0 comments on commit 118e1f3

Please sign in to comment.