Skip to content

Commit

Permalink
Added plot export settings to embedding-explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
x-tabdeveloping committed Jun 20, 2024
1 parent dda66f7 commit 6eef079
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
17 changes: 17 additions & 0 deletions embedding_explorer/blueprints/clustering.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Blueprint for the clustering application."""

import warnings
from typing import Iterable, Optional

Expand Down Expand Up @@ -91,6 +92,21 @@ def create_clustering_app(
""",
id="clustering_container",
)
app_blueprint.clientside_callback(
"""
function(width, height, scale) {
const newConfig = {
toImageButtonOptions: {height: height, width: width, scale: scale},
};
return newConfig;
}
""",
Output(f"{name}_cluster_map", "config"),
Input(f"{name}_export_width", "value"),
Input(f"{name}_export_height", "value"),
Input(f"{name}_export_scale", "value"),
prevent_initial_callback=False,
)
app_blueprint.clientside_callback(
"""
function(checked) {
Expand Down Expand Up @@ -220,4 +236,5 @@ def update_data(
# --------[ Registering callbacks ]--------
for blueprint in blueprints:
blueprint.register_callbacks(app_blueprint)

return app_blueprint
92 changes: 90 additions & 2 deletions embedding_explorer/blueprints/explorer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Blueprint for the main application."""

from typing import Iterable, Optional

import dash_mantine_components as dmc
import numpy as np
from dash_extensions.enrich import DashBlueprint, dcc, html
from dash_extensions.enrich import (DashBlueprint, Input, Output, State, dcc,
html)
from sklearn.base import BaseEstimator

from embedding_explorer.components.network import create_network
Expand Down Expand Up @@ -111,7 +113,76 @@ def create_explorer(
),
],
value="search",
)
),
],
),
dmc.Accordion(
chevronPosition="right",
variant="contained",
children=[
dmc.AccordionItem(
[
dmc.AccordionControl(
html.Div(
[
dmc.Text("Export Settings"),
dmc.Text(
"Set settings for image export.",
size="sm",
weight=400,
color="dimmed",
),
]
)
),
dmc.AccordionPanel(
[
dmc.NumberInput(
label="Export Width",
description="Width of the exported image.",
value=1000,
min=100,
step=1,
stepHoldDelay=500,
stepHoldInterval=100,
id="{}_export_width".format(
name
),
size="md",
className="mb-3",
),
dmc.NumberInput(
label="Export Height",
description="Height of the exported image.",
value=800,
min=100,
step=1,
stepHoldDelay=500,
stepHoldInterval=100,
id="{}_export_height".format(
name
),
size="md",
className="mb-3",
),
dmc.NumberInput(
label="Scale",
description="Factor to scale the image resolution with.",
value=1,
min=0.05,
step=0.05,
precision=2,
id="{}_export_scale".format(
name
),
size="md",
className="mb-3",
),
]
),
],
value="search",
),
],
),
html.Button(
Expand Down Expand Up @@ -145,4 +216,21 @@ def create_explorer(
# --------[ Registering callbacks ]--------
for blueprint in blueprints:
blueprint.register_callbacks(app_blueprint)

app_blueprint.clientside_callback(
"""
function(width, height, scale) {
const newConfig = {
toImageButtonOptions: {height: height, width: width, scale: scale},
scrollZoom: true,
};
return newConfig;
}
""",
Output(f"{name}_network", "config"),
Input(f"{name}_export_width", "value"),
Input(f"{name}_export_height", "value"),
Input(f"{name}_export_scale", "value"),
prevent_initial_callback=False,
)
return app_blueprint
46 changes: 46 additions & 0 deletions embedding_explorer/components/clustering_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,52 @@ def create_clustering_settings(name):
minRows=2,
id="{}_projection_params".format(name),
),
html.Div(
[
dmc.Text("Export Settings"),
dmc.Text(
"Choose export settings for the image.",
size="sm",
weight=400,
color="dimmed",
),
]
),
dmc.NumberInput(
label="Export Width",
description="Width of the exported image.",
value=1000,
min=100,
step=1,
stepHoldDelay=500,
stepHoldInterval=100,
id="{}_export_width".format(name),
size="md",
className="mb-3",
),
dmc.NumberInput(
label="Export Height",
description="Height of the exported image.",
value=800,
min=100,
step=1,
stepHoldDelay=500,
stepHoldInterval=100,
id="{}_export_height".format(name),
size="md",
className="mb-3",
),
dmc.NumberInput(
label="Scale",
description="Factor to scale the image resolution with.",
value=1,
min=0.05,
step=0.05,
precision=2,
id="{}_export_scale".format(name),
size="md",
className="mb-3",
),
html.Button(
"Submit",
className="""
Expand Down

0 comments on commit 6eef079

Please sign in to comment.