|
31 | 31 |
|
32 | 32 | import dash_bootstrap_components as dbc |
33 | 33 |
|
34 | | -hist_card = dbc.Card( |
35 | | - [ |
36 | | - dbc.CardBody( |
37 | | - [ |
38 | | - dbc.Row( |
39 | | - [ |
40 | | - dbc.Col(dbc.Label("Histogram")), |
41 | | - dbc.Col( |
42 | | - dbc.Checklist( |
43 | | - options=[{"label": "Enable", "value": True}], |
44 | | - value=[], |
45 | | - id="histogram-switch", |
46 | | - switch=True, |
47 | | - style={"float": "right"}, |
48 | | - ) |
49 | | - ), |
50 | | - ] |
51 | | - ), |
52 | | - html.Hr(), |
53 | | - dbc.Row( |
54 | | - [ |
55 | | - dbc.Col( |
56 | | - dbc.InputGroup( |
57 | | - [ |
58 | | - dbc.InputGroupText("x"), |
59 | | - dbc.Select( |
60 | | - id="x-picker-histogram", |
61 | | - disabled=False, |
62 | | - ), |
63 | | - ] |
64 | | - ) |
65 | | - ), |
66 | | - dbc.Tooltip( |
67 | | - "Select x axis", |
68 | | - target="x-picker-histogram", |
69 | | - placement="top", |
70 | | - ), |
71 | | - dbc.Col( |
72 | | - dbc.InputGroup( |
73 | | - [ |
74 | | - dbc.InputGroupText("y"), |
75 | | - dbc.Select( |
76 | | - id="y-histogram", |
77 | | - options=[ |
78 | | - { |
79 | | - "label": "Probability", |
80 | | - "value": "probability", |
| 34 | + |
| 35 | +def get_hist_card_layout(): |
| 36 | + """ |
| 37 | + Creates and returns a Dash Bootstrap Card layout for a histogram visualization panel. |
| 38 | +
|
| 39 | + The layout includes: |
| 40 | + - A header with a label and an enable switch. |
| 41 | + - Selectors for x, y, and color axes, each with tooltips. |
| 42 | + - A loading spinner that wraps a collapsible area containing: |
| 43 | + - A histogram graph. |
| 44 | + - An export button with tooltip. |
| 45 | +
|
| 46 | + Args: |
| 47 | + None |
| 48 | +
|
| 49 | + Returns: |
| 50 | + dbc.Card: A Dash Bootstrap Card component containing the histogram controls and visualization. |
| 51 | + """ |
| 52 | + return dbc.Card( |
| 53 | + [ |
| 54 | + dbc.CardBody( |
| 55 | + [ |
| 56 | + dbc.Row( |
| 57 | + [ |
| 58 | + dbc.Col(dbc.Label("Histogram")), |
| 59 | + dbc.Col( |
| 60 | + dbc.Checklist( |
| 61 | + options=[{"label": "Enable", "value": True}], |
| 62 | + value=[], |
| 63 | + id="histogram-switch", |
| 64 | + switch=True, |
| 65 | + style={"float": "right"}, |
| 66 | + ) |
| 67 | + ), |
| 68 | + ] |
| 69 | + ), |
| 70 | + html.Hr(), |
| 71 | + dbc.Row( |
| 72 | + [ |
| 73 | + dbc.Col( |
| 74 | + dbc.InputGroup( |
| 75 | + [ |
| 76 | + dbc.InputGroupText("x"), |
| 77 | + dbc.Select( |
| 78 | + id="x-picker-histogram", |
| 79 | + disabled=False, |
| 80 | + ), |
| 81 | + ] |
| 82 | + ) |
| 83 | + ), |
| 84 | + dbc.Tooltip( |
| 85 | + "Select x axis", |
| 86 | + target="x-picker-histogram", |
| 87 | + placement="top", |
| 88 | + ), |
| 89 | + dbc.Col( |
| 90 | + dbc.InputGroup( |
| 91 | + [ |
| 92 | + dbc.InputGroupText("y"), |
| 93 | + dbc.Select( |
| 94 | + id="y-histogram", |
| 95 | + options=[ |
| 96 | + { |
| 97 | + "label": "Probability", |
| 98 | + "value": "probability", |
| 99 | + }, |
| 100 | + { |
| 101 | + "label": "Density", |
| 102 | + "value": "density", |
| 103 | + }, |
| 104 | + ], |
| 105 | + value="density", |
| 106 | + disabled=False, |
| 107 | + ), |
| 108 | + ] |
| 109 | + ) |
| 110 | + ), |
| 111 | + dbc.Tooltip( |
| 112 | + "Select y axis", |
| 113 | + target="y-histogram", |
| 114 | + placement="top", |
| 115 | + ), |
| 116 | + dbc.Col( |
| 117 | + dbc.InputGroup( |
| 118 | + [ |
| 119 | + dbc.InputGroupText("c"), |
| 120 | + dbc.Select( |
| 121 | + id="c-picker-histogram", |
| 122 | + disabled=False, |
| 123 | + ), |
| 124 | + ] |
| 125 | + ) |
| 126 | + ), |
| 127 | + dbc.Tooltip( |
| 128 | + "Select color axis", |
| 129 | + target="c-picker-histogram", |
| 130 | + placement="top", |
| 131 | + ), |
| 132 | + ] |
| 133 | + ), |
| 134 | + dcc.Loading( |
| 135 | + id="loading_histogram", |
| 136 | + children=[ |
| 137 | + dbc.Collapse( |
| 138 | + html.Div( |
| 139 | + [ |
| 140 | + dcc.Graph( |
| 141 | + id="histogram", |
| 142 | + config={"displaylogo": False}, |
| 143 | + figure={ |
| 144 | + "data": [{"type": "histogram", "x": []}] |
81 | 145 | }, |
82 | | - {"label": "Density", "value": "density"}, |
83 | | - ], |
84 | | - value="density", |
85 | | - disabled=False, |
86 | | - ), |
87 | | - ] |
88 | | - ) |
89 | | - ), |
90 | | - dbc.Tooltip( |
91 | | - "Select y axis", |
92 | | - target="y-histogram", |
93 | | - placement="top", |
94 | | - ), |
95 | | - dbc.Col( |
96 | | - dbc.InputGroup( |
97 | | - [ |
98 | | - dbc.InputGroupText("c"), |
99 | | - dbc.Select( |
100 | | - id="c-picker-histogram", |
101 | | - disabled=False, |
102 | | - ), |
103 | | - ] |
| 146 | + ), |
| 147 | + dbc.Row( |
| 148 | + [ |
| 149 | + dbc.Col( |
| 150 | + dbc.Button( |
| 151 | + html.I( |
| 152 | + className="bi bi-camera-fill" |
| 153 | + ), |
| 154 | + id="export-histogram", |
| 155 | + n_clicks=0, |
| 156 | + style={"float": "right"}, |
| 157 | + ) |
| 158 | + ), |
| 159 | + ] |
| 160 | + ), |
| 161 | + dbc.Tooltip( |
| 162 | + "Export the current figure", |
| 163 | + target="export-histogram", |
| 164 | + placement="top", |
| 165 | + ), |
| 166 | + ] |
| 167 | + ), |
| 168 | + is_open=False, |
| 169 | + id="collapse-hist", |
104 | 170 | ) |
105 | | - ), |
106 | | - dbc.Tooltip( |
107 | | - "Select color axis", |
108 | | - target="c-picker-histogram", |
109 | | - placement="top", |
110 | | - ), |
111 | | - ] |
112 | | - ), |
113 | | - dcc.Loading( |
114 | | - id="loading_histogram", |
115 | | - children=[ |
116 | | - dbc.Collapse( |
117 | | - html.Div( |
118 | | - [ |
119 | | - dcc.Graph( |
120 | | - id="histogram", |
121 | | - config={"displaylogo": False}, |
122 | | - figure={ |
123 | | - "data": [{"type": "histogram", "x": []}] |
124 | | - }, |
125 | | - ), |
126 | | - dbc.Row( |
127 | | - [ |
128 | | - dbc.Col( |
129 | | - dbc.Button( |
130 | | - html.I( |
131 | | - className="bi bi-camera-fill" |
132 | | - ), |
133 | | - id="export-histogram", |
134 | | - n_clicks=0, |
135 | | - style={"float": "right"}, |
136 | | - ) |
137 | | - ), |
138 | | - ] |
139 | | - ), |
140 | | - dbc.Tooltip( |
141 | | - "Export the current figure", |
142 | | - target="export-histogram", |
143 | | - placement="top", |
144 | | - ), |
145 | | - ] |
146 | | - ), |
147 | | - is_open=False, |
148 | | - id="collapse-hist", |
149 | | - ) |
150 | | - ], |
151 | | - type="default", |
152 | | - ), |
153 | | - ] |
154 | | - ) |
155 | | - ], |
156 | | - className="shadow-sm", |
157 | | -) |
| 171 | + ], |
| 172 | + type="default", |
| 173 | + ), |
| 174 | + ] |
| 175 | + ) |
| 176 | + ], |
| 177 | + className="shadow-sm", |
| 178 | + ) |
0 commit comments