steer-core 0.1.16__py3-none-any.whl → 0.1.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- steer_core/Apps/Components/MaterialSelectors.py +444 -302
- steer_core/Apps/Components/RangeSliderComponents.py +177 -125
- steer_core/Apps/Components/SliderComponents.py +206 -184
- steer_core/Apps/ContextManagers.py +26 -20
- steer_core/Apps/Performance/CallbackTimer.py +3 -2
- steer_core/Apps/Utils/SliderControls.py +239 -209
- steer_core/Constants/Units.py +6 -1
- steer_core/Data/database.db +0 -0
- steer_core/DataManager.py +123 -122
- steer_core/Decorators/Coordinates.py +9 -4
- steer_core/Decorators/Electrochemical.py +7 -2
- steer_core/Decorators/General.py +7 -4
- steer_core/Decorators/Objects.py +4 -1
- steer_core/Mixins/Colors.py +185 -1
- steer_core/Mixins/Coordinates.py +112 -89
- steer_core/Mixins/Data.py +1 -1
- steer_core/Mixins/Plotter.py +149 -0
- steer_core/Mixins/Serializer.py +5 -7
- steer_core/Mixins/TypeChecker.py +42 -29
- steer_core/__init__.py +1 -1
- {steer_core-0.1.16.dist-info → steer_core-0.1.18.dist-info}/METADATA +1 -1
- steer_core-0.1.18.dist-info/RECORD +34 -0
- steer_core-0.1.16.dist-info/RECORD +0 -33
- {steer_core-0.1.16.dist-info → steer_core-0.1.18.dist-info}/WHEEL +0 -0
- {steer_core-0.1.16.dist-info → steer_core-0.1.18.dist-info}/top_level.txt +0 -0
|
@@ -7,16 +7,16 @@ from dash import Input, Output
|
|
|
7
7
|
class SliderWithTextInput:
|
|
8
8
|
"""
|
|
9
9
|
A custom Dash component that combines a slider and text input for synchronized value control.
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
This component creates a user interface element consisting of a slider and a numeric input field
|
|
12
12
|
that can be used together to set numeric values. The slider provides visual feedback and easy
|
|
13
13
|
adjustment, while the text input allows for precise value entry. Both components are synchronized
|
|
14
14
|
and share the same value constraints.
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
The component is designed for use in Dash applications where users need to input numeric values
|
|
17
17
|
within a specified range, with the flexibility of both visual (slider) and precise (text input)
|
|
18
18
|
control methods.
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
Attributes:
|
|
21
21
|
id_base (dict): Base identifier dictionary used to construct unique IDs for child components
|
|
22
22
|
min_val (float): Minimum allowed value for both slider and input
|
|
@@ -32,7 +32,7 @@ class SliderWithTextInput:
|
|
|
32
32
|
message (str): Optional message displayed between title and slider
|
|
33
33
|
slider_id (dict): Computed ID for the slider component
|
|
34
34
|
input_id (dict): Computed ID for the input component
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
Example:
|
|
37
37
|
>>> slider_component = SliderWithTextInput(
|
|
38
38
|
... id_base={'type': 'parameter', 'index': 0},
|
|
@@ -60,13 +60,13 @@ class SliderWithTextInput:
|
|
|
60
60
|
default_val: Union[float, list[float]] = None,
|
|
61
61
|
with_slider_titles: bool = True,
|
|
62
62
|
slider_disable: bool = False,
|
|
63
|
-
div_width: str =
|
|
63
|
+
div_width: str = "calc(90%)",
|
|
64
64
|
message: str = None,
|
|
65
65
|
marks: dict = None,
|
|
66
66
|
):
|
|
67
67
|
"""
|
|
68
68
|
Initialize the SliderWithTextInput component.
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
Args:
|
|
71
71
|
id_base (dict): Base dictionary for generating component IDs. Should contain
|
|
72
72
|
identifying information that will be extended with component-specific
|
|
@@ -100,12 +100,12 @@ class SliderWithTextInput:
|
|
|
100
100
|
auto-generating marks from mark_interval.
|
|
101
101
|
Keys should be numeric positions, values should be labels.
|
|
102
102
|
Defaults to None.
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
Raises:
|
|
105
105
|
ValueError: If min_val >= max_val, or if step <= 0, or if mark_interval <= 0.
|
|
106
106
|
TypeError: If default_val is provided but not numeric.
|
|
107
107
|
"""
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
self.id_base = id_base
|
|
110
110
|
self.min_val = min_val
|
|
111
111
|
self.max_val = max_val
|
|
@@ -120,41 +120,41 @@ class SliderWithTextInput:
|
|
|
120
120
|
self.message = message
|
|
121
121
|
self.marks = marks
|
|
122
122
|
|
|
123
|
-
self.slider_id = self._make_id(
|
|
124
|
-
self.input_id = self._make_id(
|
|
123
|
+
self.slider_id = self._make_id("slider")
|
|
124
|
+
self.input_id = self._make_id("input")
|
|
125
125
|
|
|
126
126
|
def _make_id(self, subtype: str):
|
|
127
127
|
"""
|
|
128
128
|
Generate a unique ID dictionary for component sub-elements.
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
Combines the base ID with component-specific subtype and property information
|
|
131
131
|
to create unique identifiers for Dash callbacks and component references.
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
Args:
|
|
134
134
|
subtype (str): The specific component subtype (e.g., 'slider', 'input').
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
Returns:
|
|
137
137
|
dict: Complete ID dictionary containing base ID information plus subtype
|
|
138
138
|
and property specifications.
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
Example:
|
|
141
141
|
>>> component._make_id('slider')
|
|
142
142
|
{'type': 'parameter', 'index': 0, 'subtype': 'slider', 'property': 'temperature'}
|
|
143
143
|
"""
|
|
144
|
-
return {**self.id_base,
|
|
144
|
+
return {**self.id_base, "subtype": subtype, "property": self.property_name}
|
|
145
145
|
|
|
146
146
|
def _make_slider(self):
|
|
147
147
|
"""
|
|
148
148
|
Create and configure the Dash slider component.
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
Generates a dcc.Slider with the specified range, step size, default value,
|
|
151
151
|
and tick marks. The slider provides visual feedback for value selection
|
|
152
152
|
and is synchronized with the text input component.
|
|
153
|
-
|
|
153
|
+
|
|
154
154
|
Returns:
|
|
155
155
|
dash.dcc.Slider: Configured slider component with ID, value constraints,
|
|
156
156
|
tick marks, and styling options.
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
Note:
|
|
159
159
|
- Uses pre-computed marks if provided, otherwise generates tick marks
|
|
160
160
|
at intervals specified by mark_interval
|
|
@@ -165,8 +165,13 @@ class SliderWithTextInput:
|
|
|
165
165
|
if self.marks is not None:
|
|
166
166
|
slider_marks = self.marks
|
|
167
167
|
else:
|
|
168
|
-
slider_marks = {
|
|
169
|
-
|
|
168
|
+
slider_marks = {
|
|
169
|
+
int(i): ""
|
|
170
|
+
for i in np.arange(
|
|
171
|
+
self.min_val, self.max_val + self.mark_interval, self.mark_interval
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
170
175
|
return ds.dcc.Slider(
|
|
171
176
|
id=self.slider_id,
|
|
172
177
|
min=self.min_val,
|
|
@@ -175,21 +180,22 @@ class SliderWithTextInput:
|
|
|
175
180
|
step=self.step,
|
|
176
181
|
disabled=self.slider_disable,
|
|
177
182
|
marks=slider_marks,
|
|
178
|
-
updatemode=
|
|
183
|
+
updatemode="mouseup",
|
|
184
|
+
tooltip={"placement": "right", "always_visible": False}
|
|
179
185
|
)
|
|
180
186
|
|
|
181
187
|
def _make_input(self):
|
|
182
188
|
"""
|
|
183
189
|
Create and configure the Dash numeric input component.
|
|
184
|
-
|
|
190
|
+
|
|
185
191
|
Generates a dcc.Input with number type for precise value entry.
|
|
186
192
|
The input is synchronized with the slider and provides an alternative
|
|
187
193
|
method for users to specify exact values.
|
|
188
|
-
|
|
194
|
+
|
|
189
195
|
Returns:
|
|
190
196
|
dash.dcc.Input: Configured numeric input component with ID, type,
|
|
191
197
|
value constraints, styling, and step specification.
|
|
192
|
-
|
|
198
|
+
|
|
193
199
|
Note:
|
|
194
200
|
- Input type is set to 'number' for numeric validation
|
|
195
201
|
- Left margin styling provides visual alignment with slider
|
|
@@ -197,22 +203,22 @@ class SliderWithTextInput:
|
|
|
197
203
|
"""
|
|
198
204
|
return ds.dcc.Input(
|
|
199
205
|
id=self.input_id,
|
|
200
|
-
type=
|
|
206
|
+
type="number",
|
|
201
207
|
value=self.default_val,
|
|
202
|
-
style={
|
|
208
|
+
style={"margin-left": "20px"},
|
|
203
209
|
step=self.step,
|
|
204
|
-
disabled=self.slider_disable
|
|
210
|
+
disabled=self.slider_disable,
|
|
205
211
|
)
|
|
206
212
|
|
|
207
213
|
def __call__(self):
|
|
208
214
|
"""
|
|
209
215
|
Generate the complete component layout as a callable object.
|
|
210
|
-
|
|
216
|
+
|
|
211
217
|
Creates and returns a Dash HTML Div containing the title, optional message,
|
|
212
218
|
slider, and input components arranged in a cohesive layout. This method allows
|
|
213
219
|
the class instance to be used as a callable that returns the complete
|
|
214
220
|
component structure.
|
|
215
|
-
|
|
221
|
+
|
|
216
222
|
Returns:
|
|
217
223
|
dash.html.Div: Complete component layout containing:
|
|
218
224
|
- Title paragraph (conditional based on with_slider_titles)
|
|
@@ -220,7 +226,7 @@ class SliderWithTextInput:
|
|
|
220
226
|
- Slider component in a styled container
|
|
221
227
|
- Numeric input component
|
|
222
228
|
- Spacing elements (line breaks)
|
|
223
|
-
|
|
229
|
+
|
|
224
230
|
Note:
|
|
225
231
|
- Title display is controlled by with_slider_titles attribute
|
|
226
232
|
- When title is hidden, a non-breaking space maintains layout
|
|
@@ -229,71 +235,83 @@ class SliderWithTextInput:
|
|
|
229
235
|
- Container width is controlled by div_width attribute
|
|
230
236
|
"""
|
|
231
237
|
slider_title = self.title if self.with_slider_titles else "\u00A0"
|
|
232
|
-
|
|
238
|
+
|
|
233
239
|
# Build the component list
|
|
234
240
|
components = [
|
|
235
|
-
ds.html.P(
|
|
241
|
+
ds.html.P(
|
|
242
|
+
slider_title,
|
|
243
|
+
style={
|
|
244
|
+
"margin-left": "20px",
|
|
245
|
+
"margin-bottom": "0px",
|
|
246
|
+
"font-weight": "bold",
|
|
247
|
+
},
|
|
248
|
+
)
|
|
236
249
|
]
|
|
237
|
-
|
|
250
|
+
|
|
238
251
|
# Add optional message if provided
|
|
239
252
|
if self.message:
|
|
240
253
|
components.append(
|
|
241
|
-
ds.html.P(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
254
|
+
ds.html.P(
|
|
255
|
+
self.message,
|
|
256
|
+
style={
|
|
257
|
+
"margin-left": "20px",
|
|
258
|
+
"margin-bottom": "5px",
|
|
259
|
+
"margin-top": "2px",
|
|
260
|
+
"font-size": "0.9em",
|
|
261
|
+
"color": "#666666",
|
|
262
|
+
"font-style": "italic",
|
|
263
|
+
},
|
|
264
|
+
)
|
|
249
265
|
)
|
|
250
|
-
|
|
266
|
+
|
|
251
267
|
# Add slider, input, and breaks
|
|
252
|
-
components.extend(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
268
|
+
components.extend(
|
|
269
|
+
[
|
|
270
|
+
ds.html.Div([self._make_slider()], style={"margin-bottom": "-18px"}),
|
|
271
|
+
self._make_input(),
|
|
272
|
+
ds.html.Br(),
|
|
273
|
+
ds.html.Br(),
|
|
274
|
+
]
|
|
275
|
+
)
|
|
257
276
|
|
|
258
|
-
return ds.html.Div(
|
|
277
|
+
return ds.html.Div(
|
|
278
|
+
components, style={"width": self.div_width, "margin-left": "-20px"}
|
|
279
|
+
)
|
|
259
280
|
|
|
260
281
|
@property
|
|
261
282
|
def components(self):
|
|
262
283
|
"""
|
|
263
284
|
Get a dictionary mapping component types to their IDs.
|
|
264
|
-
|
|
285
|
+
|
|
265
286
|
Provides easy access to the IDs of the slider and input components
|
|
266
287
|
for use in Dash callbacks and component interactions.
|
|
267
|
-
|
|
288
|
+
|
|
268
289
|
Returns:
|
|
269
290
|
dict: Dictionary with component type keys mapping to their ID dictionaries.
|
|
270
|
-
|
|
291
|
+
|
|
271
292
|
Example:
|
|
272
293
|
>>> component.components
|
|
273
294
|
{
|
|
274
295
|
'slider': {'type': 'parameter', 'subtype': 'slider', 'property': 'temperature'},
|
|
275
296
|
'input': {'type': 'parameter', 'subtype': 'input', 'property': 'temperature'}
|
|
276
297
|
}
|
|
277
|
-
|
|
298
|
+
|
|
278
299
|
Note:
|
|
279
300
|
This property is particularly useful for setting up Dash callbacks
|
|
280
301
|
that need to reference the specific component IDs.
|
|
281
302
|
"""
|
|
282
|
-
return {
|
|
283
|
-
|
|
284
|
-
'input': self.input_id
|
|
285
|
-
}
|
|
286
|
-
|
|
303
|
+
return {"slider": self.slider_id, "input": self.input_id}
|
|
304
|
+
|
|
287
305
|
def get_value_inputs(self):
|
|
288
306
|
"""
|
|
289
307
|
Get Input objects for listening to component value changes.
|
|
290
|
-
|
|
308
|
+
|
|
291
309
|
Returns a list of Dash Input objects that can be used in callbacks to
|
|
292
310
|
listen for value changes from either the slider or input components.
|
|
293
|
-
|
|
311
|
+
|
|
294
312
|
Returns:
|
|
295
313
|
list: List containing [Input(slider_id, 'value'), Input(input_id, 'value')]
|
|
296
|
-
|
|
314
|
+
|
|
297
315
|
Example:
|
|
298
316
|
>>> @app.callback(
|
|
299
317
|
... Output('some-output', 'children'),
|
|
@@ -302,21 +320,18 @@ class SliderWithTextInput:
|
|
|
302
320
|
... def update_display(slider_val, input_val):
|
|
303
321
|
... return f"Value: {slider_val or input_val}"
|
|
304
322
|
"""
|
|
305
|
-
return [
|
|
306
|
-
|
|
307
|
-
Input(self.input_id, 'value')
|
|
308
|
-
]
|
|
309
|
-
|
|
323
|
+
return [Input(self.slider_id, "value"), Input(self.input_id, "value")]
|
|
324
|
+
|
|
310
325
|
def get_value_outputs(self):
|
|
311
326
|
"""
|
|
312
327
|
Get Output objects for updating component values.
|
|
313
|
-
|
|
328
|
+
|
|
314
329
|
Returns a list of Dash Output objects that can be used in callbacks to
|
|
315
330
|
update the values of both the slider and input components.
|
|
316
|
-
|
|
331
|
+
|
|
317
332
|
Returns:
|
|
318
333
|
list: List containing [Output(slider_id, 'value'), Output(input_id, 'value')]
|
|
319
|
-
|
|
334
|
+
|
|
320
335
|
Example:
|
|
321
336
|
>>> @app.callback(
|
|
322
337
|
... component.get_value_outputs(),
|
|
@@ -325,25 +340,22 @@ class SliderWithTextInput:
|
|
|
325
340
|
... def update_components(new_value):
|
|
326
341
|
... return [new_value, new_value]
|
|
327
342
|
"""
|
|
328
|
-
return [
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
]
|
|
332
|
-
|
|
333
|
-
def get_pattern_matching_value_inputs(self, property_name='ALL'):
|
|
343
|
+
return [Output(self.slider_id, "value"), Output(self.input_id, "value")]
|
|
344
|
+
|
|
345
|
+
def get_pattern_matching_value_inputs(self, property_name="ALL"):
|
|
334
346
|
"""
|
|
335
347
|
Get pattern-matching Input objects for listening to multiple component instances.
|
|
336
|
-
|
|
348
|
+
|
|
337
349
|
Returns Input objects using pattern-matching to listen to all components
|
|
338
350
|
with the specified property name, useful for multi-component callbacks.
|
|
339
|
-
|
|
351
|
+
|
|
340
352
|
Args:
|
|
341
353
|
property_name: The property to match. Use 'ALL' for all properties,
|
|
342
354
|
or specify a specific property name.
|
|
343
|
-
|
|
355
|
+
|
|
344
356
|
Returns:
|
|
345
357
|
list: List containing pattern-matching Input objects
|
|
346
|
-
|
|
358
|
+
|
|
347
359
|
Example:
|
|
348
360
|
>>> @app.callback(
|
|
349
361
|
... Output('summary', 'children'),
|
|
@@ -352,28 +364,29 @@ class SliderWithTextInput:
|
|
|
352
364
|
... def update_summary(slider_values, input_values):
|
|
353
365
|
... return f"Total sliders: {len(slider_values)}"
|
|
354
366
|
"""
|
|
355
|
-
pattern = {
|
|
356
|
-
input_pattern = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
367
|
+
pattern = {"type": "parameter", "subtype": "slider", "property": property_name}
|
|
368
|
+
input_pattern = {
|
|
369
|
+
"type": "parameter",
|
|
370
|
+
"subtype": "input",
|
|
371
|
+
"property": property_name,
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return [Input(pattern, "value"), Input(input_pattern, "value")]
|
|
375
|
+
|
|
376
|
+
def get_pattern_matching_value_outputs(self, property_name="ALL"):
|
|
364
377
|
"""
|
|
365
378
|
Get pattern-matching Output objects for updating multiple component instances.
|
|
366
|
-
|
|
379
|
+
|
|
367
380
|
Returns Output objects using pattern-matching to update all components
|
|
368
381
|
with the specified property name.
|
|
369
|
-
|
|
382
|
+
|
|
370
383
|
Args:
|
|
371
384
|
property_name: The property to match. Use 'ALL' for all properties,
|
|
372
385
|
or specify a specific property name.
|
|
373
|
-
|
|
386
|
+
|
|
374
387
|
Returns:
|
|
375
388
|
list: List containing pattern-matching Output objects
|
|
376
|
-
|
|
389
|
+
|
|
377
390
|
Example:
|
|
378
391
|
>>> @app.callback(
|
|
379
392
|
... component.get_pattern_matching_value_outputs('ALL'),
|
|
@@ -384,31 +397,32 @@ class SliderWithTextInput:
|
|
|
384
397
|
... return [[0] * len(slider_values), [0] * len(input_values)]
|
|
385
398
|
... return [dash.no_update, dash.no_update]
|
|
386
399
|
"""
|
|
387
|
-
pattern = {
|
|
388
|
-
input_pattern = {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
400
|
+
pattern = {"type": "parameter", "subtype": "slider", "property": property_name}
|
|
401
|
+
input_pattern = {
|
|
402
|
+
"type": "parameter",
|
|
403
|
+
"subtype": "input",
|
|
404
|
+
"property": property_name,
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return [Output(pattern, "value"), Output(input_pattern, "value")]
|
|
408
|
+
|
|
395
409
|
def _validate_and_clamp_value(self, value):
|
|
396
410
|
"""
|
|
397
411
|
Validate and clamp a value to the component's valid range.
|
|
398
|
-
|
|
412
|
+
|
|
399
413
|
Ensures that any input value is within the min_val to max_val range
|
|
400
414
|
and handles None values appropriately.
|
|
401
|
-
|
|
415
|
+
|
|
402
416
|
Args:
|
|
403
417
|
value: The value to validate and clamp.
|
|
404
|
-
|
|
418
|
+
|
|
405
419
|
Returns:
|
|
406
420
|
float: The clamped value within the valid range, or the current
|
|
407
421
|
default_val if the input value is invalid.
|
|
408
422
|
"""
|
|
409
423
|
if value is None:
|
|
410
424
|
return self.default_val if self.default_val is not None else self.min_val
|
|
411
|
-
|
|
425
|
+
|
|
412
426
|
try:
|
|
413
427
|
numeric_value = float(value)
|
|
414
428
|
return max(self.min_val, min(self.max_val, numeric_value))
|
|
@@ -419,23 +433,23 @@ class SliderWithTextInput:
|
|
|
419
433
|
class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
420
434
|
"""
|
|
421
435
|
A custom Dash component that extends SliderWithTextInput by adding a checkbox with a message.
|
|
422
|
-
|
|
436
|
+
|
|
423
437
|
This component inherits all functionality from SliderWithTextInput and adds a checkbox
|
|
424
438
|
positioned beneath the input field. The checkbox can be used to enable/disable features,
|
|
425
439
|
toggle options, or provide additional control over the parameter being adjusted.
|
|
426
|
-
|
|
440
|
+
|
|
427
441
|
The checkbox includes an associated message that describes its purpose or provides
|
|
428
442
|
additional context for the user. The checkbox is larger than standard size and has
|
|
429
443
|
proper spacing between the checkbox and its label text.
|
|
430
|
-
|
|
444
|
+
|
|
431
445
|
Attributes:
|
|
432
446
|
checkbox_message (str): The message displayed next to the checkbox
|
|
433
447
|
checkbox_default (bool): Default checked state of the checkbox
|
|
434
448
|
checkbox_id (dict): Computed ID for the checkbox component
|
|
435
|
-
|
|
449
|
+
|
|
436
450
|
Note:
|
|
437
451
|
The checkbox value is [True] when checked, [] when unchecked.
|
|
438
|
-
|
|
452
|
+
|
|
439
453
|
Example:
|
|
440
454
|
>>> slider_component = SliderWithTextInputAndCheckbox(
|
|
441
455
|
... id_base={'type': 'parameter', 'index': 0},
|
|
@@ -466,12 +480,12 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
466
480
|
checkbox_default: bool = False,
|
|
467
481
|
with_slider_titles: bool = True,
|
|
468
482
|
slider_disable: bool = False,
|
|
469
|
-
div_width: str =
|
|
483
|
+
div_width: str = "calc(90%)",
|
|
470
484
|
message: str = None,
|
|
471
485
|
):
|
|
472
486
|
"""
|
|
473
487
|
Initialize the SliderWithTextInputAndCheckbox component.
|
|
474
|
-
|
|
488
|
+
|
|
475
489
|
Args:
|
|
476
490
|
id_base (dict): Base dictionary for generating component IDs.
|
|
477
491
|
property_name (str): String identifier for this property.
|
|
@@ -503,113 +517,122 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
503
517
|
div_width=div_width,
|
|
504
518
|
message=message,
|
|
505
519
|
)
|
|
506
|
-
|
|
520
|
+
|
|
507
521
|
# Add checkbox-specific attributes
|
|
508
522
|
self.checkbox_message = checkbox_message
|
|
509
523
|
self.checkbox_default = checkbox_default
|
|
510
|
-
self.checkbox_id = self._make_id(
|
|
524
|
+
self.checkbox_id = self._make_id("checkbox")
|
|
511
525
|
|
|
512
526
|
def _make_checkbox(self):
|
|
513
527
|
"""
|
|
514
528
|
Create and configure the Dash checkbox component.
|
|
515
|
-
|
|
529
|
+
|
|
516
530
|
Returns:
|
|
517
531
|
dash.html.Div: Container with a larger checkbox and separated label text.
|
|
518
532
|
"""
|
|
519
|
-
return ds.html.Div(
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
533
|
+
return ds.html.Div(
|
|
534
|
+
[
|
|
535
|
+
ds.dcc.Checklist(
|
|
536
|
+
id=self.checkbox_id,
|
|
537
|
+
options=[{"label": "", "value": True}],
|
|
538
|
+
value=[True] if self.checkbox_default else [],
|
|
539
|
+
style={
|
|
540
|
+
"display": "inline-block",
|
|
541
|
+
"margin-right": "10px",
|
|
542
|
+
"transform": "scale(1.3)", # Make checkbox larger
|
|
543
|
+
"transform-origin": "left top", # Changed to 'top' for better alignment
|
|
544
|
+
"vertical-align": "baseline", # Use baseline alignment
|
|
545
|
+
},
|
|
546
|
+
labelStyle={"margin": "0px"},
|
|
547
|
+
),
|
|
548
|
+
ds.html.Span(
|
|
549
|
+
self.checkbox_message,
|
|
550
|
+
style={
|
|
551
|
+
"display": "inline-block",
|
|
552
|
+
"vertical-align": "baseline", # Match checkbox baseline
|
|
553
|
+
"margin-left": "5px",
|
|
554
|
+
"line-height": "1.3", # Slightly higher line height
|
|
555
|
+
"margin-top": "-4px", # Pull text up more aggressively
|
|
556
|
+
},
|
|
557
|
+
),
|
|
558
|
+
],
|
|
559
|
+
style={"margin-left": "20px", "margin-top": "10px", "line-height": "1"},
|
|
560
|
+
)
|
|
544
561
|
|
|
545
562
|
def __call__(self):
|
|
546
563
|
"""
|
|
547
564
|
Generate the complete component layout including the checkbox.
|
|
548
|
-
|
|
565
|
+
|
|
549
566
|
Creates and returns a Dash HTML Div containing the title, optional message,
|
|
550
567
|
slider, input, and checkbox components arranged in a cohesive layout.
|
|
551
|
-
|
|
568
|
+
|
|
552
569
|
Returns:
|
|
553
570
|
dash.html.Div: Complete component layout containing all elements plus checkbox.
|
|
554
571
|
"""
|
|
555
572
|
slider_title = self.title if self.with_slider_titles else "\u00A0"
|
|
556
|
-
|
|
573
|
+
|
|
557
574
|
# Build the component list
|
|
558
575
|
components = [
|
|
559
|
-
ds.html.P(
|
|
576
|
+
ds.html.P(
|
|
577
|
+
slider_title, style={"margin-left": "20px", "margin-bottom": "0px"}
|
|
578
|
+
)
|
|
560
579
|
]
|
|
561
|
-
|
|
580
|
+
|
|
562
581
|
# Add optional message if provided
|
|
563
582
|
if self.message:
|
|
564
583
|
components.append(
|
|
565
|
-
ds.html.P(
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
584
|
+
ds.html.P(
|
|
585
|
+
self.message,
|
|
586
|
+
style={
|
|
587
|
+
"margin-left": "20px",
|
|
588
|
+
"margin-bottom": "5px",
|
|
589
|
+
"margin-top": "2px",
|
|
590
|
+
"font-size": "0.9em",
|
|
591
|
+
"color": "#666666",
|
|
592
|
+
"font-style": "italic",
|
|
593
|
+
},
|
|
594
|
+
)
|
|
573
595
|
)
|
|
574
|
-
|
|
596
|
+
|
|
575
597
|
# Add slider and input
|
|
576
|
-
components.extend(
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
598
|
+
components.extend(
|
|
599
|
+
[
|
|
600
|
+
ds.html.Div([self._make_slider()], style={"margin-bottom": "-18px"}),
|
|
601
|
+
self._make_input(),
|
|
602
|
+
]
|
|
603
|
+
)
|
|
604
|
+
|
|
581
605
|
# Add checkbox beneath the input
|
|
582
|
-
components.extend([
|
|
583
|
-
self._make_checkbox(),
|
|
584
|
-
ds.html.Br(), ds.html.Br()
|
|
585
|
-
])
|
|
606
|
+
components.extend([self._make_checkbox(), ds.html.Br(), ds.html.Br()])
|
|
586
607
|
|
|
587
|
-
return ds.html.Div(
|
|
608
|
+
return ds.html.Div(
|
|
609
|
+
components, style={"width": self.div_width, "margin-left": "-20px"}
|
|
610
|
+
)
|
|
588
611
|
|
|
589
612
|
@property
|
|
590
613
|
def components(self):
|
|
591
614
|
"""
|
|
592
615
|
Get a dictionary mapping component types to their IDs, including the checkbox.
|
|
593
|
-
|
|
616
|
+
|
|
594
617
|
Returns:
|
|
595
618
|
dict: Dictionary with component type keys mapping to their ID dictionaries.
|
|
596
619
|
"""
|
|
597
620
|
return {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
621
|
+
"slider": self.slider_id,
|
|
622
|
+
"input": self.input_id,
|
|
623
|
+
"checkbox": self.checkbox_id,
|
|
601
624
|
}
|
|
602
|
-
|
|
625
|
+
|
|
603
626
|
def get_checkbox_input(self):
|
|
604
627
|
"""
|
|
605
628
|
Get Input object for listening to checkbox value changes.
|
|
606
|
-
|
|
629
|
+
|
|
607
630
|
Returns:
|
|
608
631
|
Input: Dash Input object for the checkbox component.
|
|
609
|
-
|
|
632
|
+
|
|
610
633
|
Note:
|
|
611
634
|
The checkbox value will be [True] when checked, [] when unchecked.
|
|
612
|
-
|
|
635
|
+
|
|
613
636
|
Example:
|
|
614
637
|
>>> @app.callback(
|
|
615
638
|
... Output('some-output', 'children'),
|
|
@@ -619,18 +642,18 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
619
642
|
... is_checked = True in (checkbox_value or [])
|
|
620
643
|
... return f"Checkbox is {'checked' if is_checked else 'unchecked'}"
|
|
621
644
|
"""
|
|
622
|
-
return Input(self.checkbox_id,
|
|
623
|
-
|
|
645
|
+
return Input(self.checkbox_id, "value")
|
|
646
|
+
|
|
624
647
|
def get_checkbox_output(self):
|
|
625
648
|
"""
|
|
626
649
|
Get Output object for updating checkbox value.
|
|
627
|
-
|
|
650
|
+
|
|
628
651
|
Returns:
|
|
629
652
|
Output: Dash Output object for the checkbox component.
|
|
630
|
-
|
|
653
|
+
|
|
631
654
|
Note:
|
|
632
655
|
To check the checkbox, return [True]. To uncheck, return [].
|
|
633
|
-
|
|
656
|
+
|
|
634
657
|
Example:
|
|
635
658
|
>>> @app.callback(
|
|
636
659
|
... component.get_checkbox_output(),
|
|
@@ -641,18 +664,18 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
641
664
|
... return [True]
|
|
642
665
|
... return []
|
|
643
666
|
"""
|
|
644
|
-
return Output(self.checkbox_id,
|
|
645
|
-
|
|
667
|
+
return Output(self.checkbox_id, "value")
|
|
668
|
+
|
|
646
669
|
def get_all_inputs(self):
|
|
647
670
|
"""
|
|
648
671
|
Get Input objects for all component values (slider, input, and checkbox).
|
|
649
|
-
|
|
672
|
+
|
|
650
673
|
Returns:
|
|
651
674
|
list: List containing Input objects for slider, input, and checkbox.
|
|
652
|
-
|
|
675
|
+
|
|
653
676
|
Note:
|
|
654
677
|
The checkbox value will be [True] when checked, [] when unchecked.
|
|
655
|
-
|
|
678
|
+
|
|
656
679
|
Example:
|
|
657
680
|
>>> @app.callback(
|
|
658
681
|
... Output('summary', 'children'),
|
|
@@ -664,8 +687,7 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
664
687
|
... return f"Value: {value}, Option enabled: {is_checked}"
|
|
665
688
|
"""
|
|
666
689
|
return [
|
|
667
|
-
Input(self.slider_id,
|
|
668
|
-
Input(self.input_id,
|
|
669
|
-
Input(self.checkbox_id,
|
|
690
|
+
Input(self.slider_id, "value"),
|
|
691
|
+
Input(self.input_id, "value"),
|
|
692
|
+
Input(self.checkbox_id, "value"),
|
|
670
693
|
]
|
|
671
|
-
|