Skip to content

Commit f6657a1

Browse files
authored
Merge pull request #508 from materialsproject/phonon_ui
Phonon UI
2 parents 24cff6f + 4433c55 commit f6657a1

5 files changed

Lines changed: 57 additions & 15 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ dist/*
1515
.vscode
1616

1717
**/_version.py
18+
19+
.venv/

crystal_toolkit/components/phonon.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,21 @@ def _sub_layouts(self) -> dict[str, Component]:
199199

200200
crystal_animation_controls = html.Details(
201201
[
202-
html.Summary("Control Panel"),
202+
html.Summary(
203+
html.Strong("Control Panel"),
204+
style={
205+
"textAlign": "center",
206+
},
207+
),
203208
html.Div(
204209
[
210+
hr,
205211
html.H6(
206-
"Supercell modification", style={"textAlign": "center"}
212+
"Supercell modification",
213+
style={
214+
"textAlign": "center",
215+
"marginBottom": "0",
216+
},
207217
),
208218
html.Div(
209219
[
@@ -214,7 +224,8 @@ def _sub_layouts(self) -> dict[str, Component]:
214224
is_int=True,
215225
label="x",
216226
min=1,
217-
style={"height": "16px"},
227+
style={"height": "15px"},
228+
label_style={"textAlign": "center"},
218229
),
219230
self.get_numerical_input(
220231
kwarg_label="scale-y",
@@ -223,7 +234,8 @@ def _sub_layouts(self) -> dict[str, Component]:
223234
is_int=True,
224235
label="y",
225236
min=1,
226-
style={"height": "16px"},
237+
style={"height": "15px"},
238+
label_style={"textAlign": "center"},
227239
),
228240
self.get_numerical_input(
229241
kwarg_label="scale-z",
@@ -232,7 +244,8 @@ def _sub_layouts(self) -> dict[str, Component]:
232244
is_int=True,
233245
label="z",
234246
min=1,
235-
style={"height": "16px"},
247+
style={"height": "15px"},
248+
label_style={"textAlign": "center"},
236249
),
237250
],
238251
style={
@@ -249,7 +262,13 @@ def _sub_layouts(self) -> dict[str, Component]:
249262
step=0.01,
250263
domain=[0, 1],
251264
label="Vibration magnitude",
252-
# styleInput={"height": "40px"},
265+
styleInput={
266+
"height": "32px",
267+
"box-sizing": "border-box",
268+
"borderRadius": "4px",
269+
"width": "5rem",
270+
},
271+
label_style={"textAlign": "center"},
253272
),
254273
),
255274
hr,
@@ -260,7 +279,14 @@ def _sub_layouts(self) -> dict[str, Component]:
260279
step=0.01,
261280
domain=[0, 1],
262281
label="Velocity",
263-
)
282+
styleInput={
283+
"height": "32px",
284+
"box-sizing": "border-box",
285+
"borderRadius": "4px",
286+
"width": "5rem",
287+
},
288+
label_style={"textAlign": "center"},
289+
),
264290
),
265291
hr,
266292
html.Div(

crystal_toolkit/core/mpcomponent.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def get_numerical_input(
355355
help_str: str | None = None,
356356
is_int: bool = False,
357357
shape: tuple[int, ...] = (),
358+
label_style: dict | None = None,
358359
**kwargs,
359360
) -> html.Div:
360361
"""For Python classes which take matrices as inputs, this will generate a corresponding Dash
@@ -370,6 +371,7 @@ def get_numerical_input(
370371
:param help_str: Text for a tooltip when hovering over label.
371372
:param is_int: if True, will use a numeric input
372373
:param shape: (3, 3) for matrix, (1, 3) for vector, (1, 1) for scalar
374+
:param label_style: the customized styling for labeling `add_label_help`
373375
:return: a Dash layout
374376
"""
375377
state = state or {}
@@ -440,7 +442,7 @@ def matrix_element(idx, value=0):
440442

441443
matrix = html.Div(matrix_div_contents)
442444

443-
return add_label_help(matrix, label, help_str)
445+
return add_label_help(matrix, label, help_str, label_style)
444446

445447
def get_slider_input(
446448
self,
@@ -450,6 +452,7 @@ def get_slider_input(
450452
label: str | None = None,
451453
help_str: str | None = None,
452454
multiple: bool = False,
455+
label_style: dict | None = None,
453456
**kwargs,
454457
):
455458
state = state or {}
@@ -473,7 +476,7 @@ def get_slider_input(
473476
**slider_kwargs,
474477
)
475478

476-
return add_label_help(slider_input, label, help_str)
479+
return add_label_help(slider_input, label, help_str, label_style)
477480

478481
def get_bool_input(
479482
self,
@@ -482,6 +485,7 @@ def get_bool_input(
482485
state: dict | None = None,
483486
label: str | None = None,
484487
help_str: str | None = None,
488+
label_style: dict | None = None,
485489
**kwargs,
486490
):
487491
"""For Python classes which take boolean values as inputs, this will generate a
@@ -496,6 +500,7 @@ def get_bool_input(
496500
and the default value as a value. Ignored if `default` is set. It can be useful
497501
to use `state` if you want to set defaults for multiple inputs from a single dictionary.
498502
:param help_str: Text for a tooltip when hovering over label.
503+
:param label_style: the customized styling for labeling `add_label_help`
499504
:return: a Dash layout
500505
"""
501506
state = state or {}
@@ -508,7 +513,7 @@ def get_bool_input(
508513
**kwargs,
509514
)
510515

511-
return add_label_help(bool_input, label, help_str)
516+
return add_label_help(bool_input, label, help_str, label_style)
512517

513518
def get_choice_input(
514519
self,
@@ -519,6 +524,7 @@ def get_choice_input(
519524
help_str: str | None = None,
520525
options: list[dict] | None = None,
521526
clearable: bool = False,
527+
label_style: dict | None = None,
522528
**kwargs,
523529
):
524530
"""For Python classes which take pre-defined values as inputs, this will generate a
@@ -534,6 +540,7 @@ def get_choice_input(
534540
:param help_str: Text for a tooltip when hovering over label.
535541
:param options: Options to choose from, as per dcc.Dropdown
536542
:param clearable: If True, will allow Dropdown to be cleared after a selection is made.
543+
:param label_style: the customized styling for labeling `add_label_help`
537544
:return: a Dash layout
538545
"""
539546
state = state or {}
@@ -547,7 +554,7 @@ def get_choice_input(
547554
arbitraryProps={**kwargs},
548555
)
549556

550-
return add_label_help(option_input, label, help_str)
557+
return add_label_help(option_input, label, help_str, label_style)
551558

552559
def get_dict_input(
553560
self,
@@ -559,6 +566,7 @@ def get_dict_input(
559566
dict_size: int | None = None,
560567
key_name: str = "key",
561568
value_name: str = "value",
569+
label_style: dict | None = None,
562570
**kwargs,
563571
) -> mpc.FilterField:
564572
"""For Python classes which take dictionaries as inputs. The keys are fixed and only the
@@ -575,6 +583,7 @@ def get_dict_input(
575583
:param dict_size: size of the dict. Can be specified in case there is no initial default or state.
576584
:param key_name: name describing the keys of the dictionary.
577585
:param value_name: name describing the values of the dictionary.
586+
:param label_style: the customized styling for labeling `add_label_help`
578587
:return: a Dash layout
579588
"""
580589
state = state or {}
@@ -625,7 +634,7 @@ def pair_element(idx, key=None, value=None):
625634

626635
dict_input = html.Div(dict_div_contents)
627636

628-
return add_label_help(dict_input, label, help_str)
637+
return add_label_help(dict_input, label, help_str, label_style)
629638

630639
def get_alarm_window(
631640
self,

crystal_toolkit/helpers/layouts.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,14 @@ def __init__(
11601160

11611161

11621162
# TODO: review
1163-
def add_label_help(input, label, help) -> mpc.FilterField:
1163+
def add_label_help(input, label, help, label_style=None) -> mpc.FilterField:
11641164
"""Combine an input, label, and tooltip text into a single consistent component."""
1165-
return mpc.FilterField(input, id=uuid4().hex, label=label, tooltip=help)
1165+
if label_style is None:
1166+
label_style = {}
1167+
1168+
return mpc.FilterField(
1169+
input, id=uuid4().hex, label=label, tooltip=help, styleLabel=label_style
1170+
)
11661171

11671172

11681173
# TODO: review

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ requires-python = ">=3.10"
1111
authors = [{ name = "Matt Horton", email = "mkhorton@lbl.gov" }]
1212

1313
dependencies = [
14-
"dash-mp-components==0.5.0rc1",
14+
"dash-mp-components==0.5.1rc2",
1515
"dash>=2.11.0",
1616
"flask-caching",
1717
"frozendict",

0 commit comments

Comments
 (0)