4242MAX_PH = 16
4343MIN_V = - 4
4444MAX_V = 4
45+ PANEL_LINE_HEIGHT = "2em"
4546
4647
4748class PourbaixDiagramComponent (MPComponent ):
@@ -127,6 +128,16 @@ class PourbaixDiagramComponent(MPComponent):
127128 }
128129 )
129130
131+ @staticmethod
132+ def create_centered_object (content ):
133+ return html .Div (
134+ content ,
135+ style = {
136+ "display" : "flex" ,
137+ "justifyContent" : "center" ,
138+ },
139+ )
140+
130141 @staticmethod
131142 def get_figure (
132143 pourbaix_diagram : PourbaixDiagram , heatmap_entry = None , show_water_lines = True
@@ -460,28 +471,44 @@ def _sub_layouts(self) -> dict[str, Component]:
460471 style = {
461472 "fontWeight" : "bold" ,
462473 "textAlign" : "center" ,
474+ "flex" : "0 0 100%" ,
463475 },
464476 ),
465477 html .H5 (
466478 "Composition of" ,
467479 id = self .id ("composition-title" ),
468480 # style={"fontWeight": "bold"},
469481 ),
470- ]
471- ),
472- dcc .Input (
473- id = self .id ("comp-text" ),
474- type = "text" ,
482+ ],
475483 style = {
476- "textAlign" : "center" ,
477- "width" : "10rem" ,
478- "marginRight" : "0.2rem" ,
479- "marginBottom" : "0.2rem" ,
480- "height" : "36px" ,
481- "fontSize" : "14px" ,
484+ "line-height" : PANEL_LINE_HEIGHT ,
485+ "display" : "flex" ,
486+ "flexWrap" : "wrap" ,
487+ "justifyContent" : "center" ,
482488 },
483489 ),
484- ctl .Block (html .Div (id = self .id ("display-composition" ))),
490+ PourbaixDiagramComponent .create_centered_object (
491+ dcc .Input (
492+ id = self .id ("comp-text" ),
493+ className = "input" ,
494+ type = "text" ,
495+ style = {
496+ "textAlign" : "center" ,
497+ "width" : "10rem" ,
498+ "marginRight" : "0.2rem" ,
499+ "marginBottom" : "0.2rem" ,
500+ "height" : "36px" ,
501+ "fontSize" : "14px" ,
502+ },
503+ ),
504+ ),
505+ ctl .Block (
506+ PourbaixDiagramComponent .create_centered_object (
507+ html .Div (
508+ id = self .id ("display-composition" ),
509+ )
510+ )
511+ ),
485512 html .Hr (
486513 style = {
487514 "backgroundColor" : "#C5C5C6" ,
@@ -505,16 +532,19 @@ def _sub_layouts(self) -> dict[str, Component]:
505532 html .Div (
506533 id = self .id ("element_specific_controls" ),
507534 ),
508- html .Button (
509- "Update" ,
510- id = self .id ("comp-conc-btn" ),
511- style = {"display" : "none" },
535+ PourbaixDiagramComponent .create_centered_object (
536+ html .Button (
537+ "Update" ,
538+ id = self .id ("comp-conc-btn" ),
539+ style = {"display" : "none" },
540+ ),
512541 ),
513542 ],
514543 style = {
515544 "backgroundColor" : "#F1F1F5" ,
516545 },
517546 ),
547+ html .Br (),
518548 self .get_bool_input (
519549 "show_heatmap" , # kwarg_label
520550 # state=self.default_state,
@@ -679,27 +709,26 @@ def update_element_specific_sliders(
679709 # exclude O and H
680710 elements = elements - ELEMENTS_HO
681711
682- comp_inputs = []
683712 conc_inputs = []
684713
685714 for element in sorted (elements ):
686- conc_input = html .Div (
687- [
688- self .get_numerical_input (
689- f"conc-{ element } " ,
690- default = 1e-6 ,
691- min = MIN_CONCENTRATION ,
692- max = MAX_CONCENTRATION ,
693- label = f"concentration of { element } ion" ,
694- style = {"width" : "10rem" , "fontSize" : "14px" },
695- )
696- ]
715+ conc_input = PourbaixDiagramComponent .create_centered_object (
716+ self .get_numerical_input (
717+ f"conc-{ element } " ,
718+ default = 1e-6 ,
719+ min = MIN_CONCENTRATION ,
720+ max = MAX_CONCENTRATION ,
721+ label = f"concentration of { element } ion" ,
722+ style = {
723+ "width" : "10rem" ,
724+ "fontSize" : "14px" ,
725+ },
726+ )
697727 )
698728
699729 conc_inputs .append (conc_input )
700730
701731 comp_conc_controls = []
702- comp_conc_controls += comp_inputs
703732
704733 ion_label = (
705734 "Ion Concentrations Control"
@@ -714,8 +743,10 @@ def update_element_specific_sliders(
714743 ),
715744 )
716745 comp_conc_controls .append (
717- html .H6 (
718- f"💡 Set the range between { MIN_CONCENTRATION } and { MAX_CONCENTRATION } (M)"
746+ PourbaixDiagramComponent .create_centered_object (
747+ html .H6 (
748+ f"💡 Set the range between { MIN_CONCENTRATION } and { MAX_CONCENTRATION } (M)"
749+ )
719750 )
720751 )
721752
@@ -724,7 +755,9 @@ def update_element_specific_sliders(
724755 # comp_panel_style
725756 comp_panel_style = {"display" : "none" }
726757 if len (elements ) > 1 :
727- comp_panel_style = {"display" : "block" }
758+ comp_panel_style = {
759+ "display" : "block" ,
760+ }
728761
729762 # elements store
730763 elements = [element .symbol for element in elements ]
@@ -741,7 +774,12 @@ def update_element_specific_sliders(
741774 update_string = "Composition & concentration update"
742775
743776 return (
744- html .Div (comp_conc_controls ),
777+ html .Div (
778+ comp_conc_controls ,
779+ style = {
780+ "line-height" : PANEL_LINE_HEIGHT ,
781+ },
782+ ),
745783 comp_panel_style ,
746784 elements ,
747785 default_comp ,
0 commit comments