steer-core 0.1.16__py3-none-any.whl → 0.1.17__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 +176 -125
- steer_core/Apps/Components/SliderComponents.py +205 -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.17.dist-info}/METADATA +1 -1
- steer_core-0.1.17.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.17.dist-info}/WHEEL +0 -0
- {steer_core-0.1.16.dist-info → steer_core-0.1.17.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,21 @@ class SliderWithTextInput:
|
|
|
175
180
|
step=self.step,
|
|
176
181
|
disabled=self.slider_disable,
|
|
177
182
|
marks=slider_marks,
|
|
178
|
-
updatemode=
|
|
183
|
+
updatemode="mouseup",
|
|
179
184
|
)
|
|
180
185
|
|
|
181
186
|
def _make_input(self):
|
|
182
187
|
"""
|
|
183
188
|
Create and configure the Dash numeric input component.
|
|
184
|
-
|
|
189
|
+
|
|
185
190
|
Generates a dcc.Input with number type for precise value entry.
|
|
186
191
|
The input is synchronized with the slider and provides an alternative
|
|
187
192
|
method for users to specify exact values.
|
|
188
|
-
|
|
193
|
+
|
|
189
194
|
Returns:
|
|
190
195
|
dash.dcc.Input: Configured numeric input component with ID, type,
|
|
191
196
|
value constraints, styling, and step specification.
|
|
192
|
-
|
|
197
|
+
|
|
193
198
|
Note:
|
|
194
199
|
- Input type is set to 'number' for numeric validation
|
|
195
200
|
- Left margin styling provides visual alignment with slider
|
|
@@ -197,22 +202,22 @@ class SliderWithTextInput:
|
|
|
197
202
|
"""
|
|
198
203
|
return ds.dcc.Input(
|
|
199
204
|
id=self.input_id,
|
|
200
|
-
type=
|
|
205
|
+
type="number",
|
|
201
206
|
value=self.default_val,
|
|
202
|
-
style={
|
|
207
|
+
style={"margin-left": "20px"},
|
|
203
208
|
step=self.step,
|
|
204
|
-
disabled=self.slider_disable
|
|
209
|
+
disabled=self.slider_disable,
|
|
205
210
|
)
|
|
206
211
|
|
|
207
212
|
def __call__(self):
|
|
208
213
|
"""
|
|
209
214
|
Generate the complete component layout as a callable object.
|
|
210
|
-
|
|
215
|
+
|
|
211
216
|
Creates and returns a Dash HTML Div containing the title, optional message,
|
|
212
217
|
slider, and input components arranged in a cohesive layout. This method allows
|
|
213
218
|
the class instance to be used as a callable that returns the complete
|
|
214
219
|
component structure.
|
|
215
|
-
|
|
220
|
+
|
|
216
221
|
Returns:
|
|
217
222
|
dash.html.Div: Complete component layout containing:
|
|
218
223
|
- Title paragraph (conditional based on with_slider_titles)
|
|
@@ -220,7 +225,7 @@ class SliderWithTextInput:
|
|
|
220
225
|
- Slider component in a styled container
|
|
221
226
|
- Numeric input component
|
|
222
227
|
- Spacing elements (line breaks)
|
|
223
|
-
|
|
228
|
+
|
|
224
229
|
Note:
|
|
225
230
|
- Title display is controlled by with_slider_titles attribute
|
|
226
231
|
- When title is hidden, a non-breaking space maintains layout
|
|
@@ -229,71 +234,83 @@ class SliderWithTextInput:
|
|
|
229
234
|
- Container width is controlled by div_width attribute
|
|
230
235
|
"""
|
|
231
236
|
slider_title = self.title if self.with_slider_titles else "\u00A0"
|
|
232
|
-
|
|
237
|
+
|
|
233
238
|
# Build the component list
|
|
234
239
|
components = [
|
|
235
|
-
ds.html.P(
|
|
240
|
+
ds.html.P(
|
|
241
|
+
slider_title,
|
|
242
|
+
style={
|
|
243
|
+
"margin-left": "20px",
|
|
244
|
+
"margin-bottom": "0px",
|
|
245
|
+
"font-weight": "bold",
|
|
246
|
+
},
|
|
247
|
+
)
|
|
236
248
|
]
|
|
237
|
-
|
|
249
|
+
|
|
238
250
|
# Add optional message if provided
|
|
239
251
|
if self.message:
|
|
240
252
|
components.append(
|
|
241
|
-
ds.html.P(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
ds.html.P(
|
|
254
|
+
self.message,
|
|
255
|
+
style={
|
|
256
|
+
"margin-left": "20px",
|
|
257
|
+
"margin-bottom": "5px",
|
|
258
|
+
"margin-top": "2px",
|
|
259
|
+
"font-size": "0.9em",
|
|
260
|
+
"color": "#666666",
|
|
261
|
+
"font-style": "italic",
|
|
262
|
+
},
|
|
263
|
+
)
|
|
249
264
|
)
|
|
250
|
-
|
|
265
|
+
|
|
251
266
|
# Add slider, input, and breaks
|
|
252
|
-
components.extend(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
components.extend(
|
|
268
|
+
[
|
|
269
|
+
ds.html.Div([self._make_slider()], style={"margin-bottom": "-18px"}),
|
|
270
|
+
self._make_input(),
|
|
271
|
+
ds.html.Br(),
|
|
272
|
+
ds.html.Br(),
|
|
273
|
+
]
|
|
274
|
+
)
|
|
257
275
|
|
|
258
|
-
return ds.html.Div(
|
|
276
|
+
return ds.html.Div(
|
|
277
|
+
components, style={"width": self.div_width, "margin-left": "-20px"}
|
|
278
|
+
)
|
|
259
279
|
|
|
260
280
|
@property
|
|
261
281
|
def components(self):
|
|
262
282
|
"""
|
|
263
283
|
Get a dictionary mapping component types to their IDs.
|
|
264
|
-
|
|
284
|
+
|
|
265
285
|
Provides easy access to the IDs of the slider and input components
|
|
266
286
|
for use in Dash callbacks and component interactions.
|
|
267
|
-
|
|
287
|
+
|
|
268
288
|
Returns:
|
|
269
289
|
dict: Dictionary with component type keys mapping to their ID dictionaries.
|
|
270
|
-
|
|
290
|
+
|
|
271
291
|
Example:
|
|
272
292
|
>>> component.components
|
|
273
293
|
{
|
|
274
294
|
'slider': {'type': 'parameter', 'subtype': 'slider', 'property': 'temperature'},
|
|
275
295
|
'input': {'type': 'parameter', 'subtype': 'input', 'property': 'temperature'}
|
|
276
296
|
}
|
|
277
|
-
|
|
297
|
+
|
|
278
298
|
Note:
|
|
279
299
|
This property is particularly useful for setting up Dash callbacks
|
|
280
300
|
that need to reference the specific component IDs.
|
|
281
301
|
"""
|
|
282
|
-
return {
|
|
283
|
-
|
|
284
|
-
'input': self.input_id
|
|
285
|
-
}
|
|
286
|
-
|
|
302
|
+
return {"slider": self.slider_id, "input": self.input_id}
|
|
303
|
+
|
|
287
304
|
def get_value_inputs(self):
|
|
288
305
|
"""
|
|
289
306
|
Get Input objects for listening to component value changes.
|
|
290
|
-
|
|
307
|
+
|
|
291
308
|
Returns a list of Dash Input objects that can be used in callbacks to
|
|
292
309
|
listen for value changes from either the slider or input components.
|
|
293
|
-
|
|
310
|
+
|
|
294
311
|
Returns:
|
|
295
312
|
list: List containing [Input(slider_id, 'value'), Input(input_id, 'value')]
|
|
296
|
-
|
|
313
|
+
|
|
297
314
|
Example:
|
|
298
315
|
>>> @app.callback(
|
|
299
316
|
... Output('some-output', 'children'),
|
|
@@ -302,21 +319,18 @@ class SliderWithTextInput:
|
|
|
302
319
|
... def update_display(slider_val, input_val):
|
|
303
320
|
... return f"Value: {slider_val or input_val}"
|
|
304
321
|
"""
|
|
305
|
-
return [
|
|
306
|
-
|
|
307
|
-
Input(self.input_id, 'value')
|
|
308
|
-
]
|
|
309
|
-
|
|
322
|
+
return [Input(self.slider_id, "value"), Input(self.input_id, "value")]
|
|
323
|
+
|
|
310
324
|
def get_value_outputs(self):
|
|
311
325
|
"""
|
|
312
326
|
Get Output objects for updating component values.
|
|
313
|
-
|
|
327
|
+
|
|
314
328
|
Returns a list of Dash Output objects that can be used in callbacks to
|
|
315
329
|
update the values of both the slider and input components.
|
|
316
|
-
|
|
330
|
+
|
|
317
331
|
Returns:
|
|
318
332
|
list: List containing [Output(slider_id, 'value'), Output(input_id, 'value')]
|
|
319
|
-
|
|
333
|
+
|
|
320
334
|
Example:
|
|
321
335
|
>>> @app.callback(
|
|
322
336
|
... component.get_value_outputs(),
|
|
@@ -325,25 +339,22 @@ class SliderWithTextInput:
|
|
|
325
339
|
... def update_components(new_value):
|
|
326
340
|
... return [new_value, new_value]
|
|
327
341
|
"""
|
|
328
|
-
return [
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
]
|
|
332
|
-
|
|
333
|
-
def get_pattern_matching_value_inputs(self, property_name='ALL'):
|
|
342
|
+
return [Output(self.slider_id, "value"), Output(self.input_id, "value")]
|
|
343
|
+
|
|
344
|
+
def get_pattern_matching_value_inputs(self, property_name="ALL"):
|
|
334
345
|
"""
|
|
335
346
|
Get pattern-matching Input objects for listening to multiple component instances.
|
|
336
|
-
|
|
347
|
+
|
|
337
348
|
Returns Input objects using pattern-matching to listen to all components
|
|
338
349
|
with the specified property name, useful for multi-component callbacks.
|
|
339
|
-
|
|
350
|
+
|
|
340
351
|
Args:
|
|
341
352
|
property_name: The property to match. Use 'ALL' for all properties,
|
|
342
353
|
or specify a specific property name.
|
|
343
|
-
|
|
354
|
+
|
|
344
355
|
Returns:
|
|
345
356
|
list: List containing pattern-matching Input objects
|
|
346
|
-
|
|
357
|
+
|
|
347
358
|
Example:
|
|
348
359
|
>>> @app.callback(
|
|
349
360
|
... Output('summary', 'children'),
|
|
@@ -352,28 +363,29 @@ class SliderWithTextInput:
|
|
|
352
363
|
... def update_summary(slider_values, input_values):
|
|
353
364
|
... return f"Total sliders: {len(slider_values)}"
|
|
354
365
|
"""
|
|
355
|
-
pattern = {
|
|
356
|
-
input_pattern = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
366
|
+
pattern = {"type": "parameter", "subtype": "slider", "property": property_name}
|
|
367
|
+
input_pattern = {
|
|
368
|
+
"type": "parameter",
|
|
369
|
+
"subtype": "input",
|
|
370
|
+
"property": property_name,
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return [Input(pattern, "value"), Input(input_pattern, "value")]
|
|
374
|
+
|
|
375
|
+
def get_pattern_matching_value_outputs(self, property_name="ALL"):
|
|
364
376
|
"""
|
|
365
377
|
Get pattern-matching Output objects for updating multiple component instances.
|
|
366
|
-
|
|
378
|
+
|
|
367
379
|
Returns Output objects using pattern-matching to update all components
|
|
368
380
|
with the specified property name.
|
|
369
|
-
|
|
381
|
+
|
|
370
382
|
Args:
|
|
371
383
|
property_name: The property to match. Use 'ALL' for all properties,
|
|
372
384
|
or specify a specific property name.
|
|
373
|
-
|
|
385
|
+
|
|
374
386
|
Returns:
|
|
375
387
|
list: List containing pattern-matching Output objects
|
|
376
|
-
|
|
388
|
+
|
|
377
389
|
Example:
|
|
378
390
|
>>> @app.callback(
|
|
379
391
|
... component.get_pattern_matching_value_outputs('ALL'),
|
|
@@ -384,31 +396,32 @@ class SliderWithTextInput:
|
|
|
384
396
|
... return [[0] * len(slider_values), [0] * len(input_values)]
|
|
385
397
|
... return [dash.no_update, dash.no_update]
|
|
386
398
|
"""
|
|
387
|
-
pattern = {
|
|
388
|
-
input_pattern = {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
399
|
+
pattern = {"type": "parameter", "subtype": "slider", "property": property_name}
|
|
400
|
+
input_pattern = {
|
|
401
|
+
"type": "parameter",
|
|
402
|
+
"subtype": "input",
|
|
403
|
+
"property": property_name,
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return [Output(pattern, "value"), Output(input_pattern, "value")]
|
|
407
|
+
|
|
395
408
|
def _validate_and_clamp_value(self, value):
|
|
396
409
|
"""
|
|
397
410
|
Validate and clamp a value to the component's valid range.
|
|
398
|
-
|
|
411
|
+
|
|
399
412
|
Ensures that any input value is within the min_val to max_val range
|
|
400
413
|
and handles None values appropriately.
|
|
401
|
-
|
|
414
|
+
|
|
402
415
|
Args:
|
|
403
416
|
value: The value to validate and clamp.
|
|
404
|
-
|
|
417
|
+
|
|
405
418
|
Returns:
|
|
406
419
|
float: The clamped value within the valid range, or the current
|
|
407
420
|
default_val if the input value is invalid.
|
|
408
421
|
"""
|
|
409
422
|
if value is None:
|
|
410
423
|
return self.default_val if self.default_val is not None else self.min_val
|
|
411
|
-
|
|
424
|
+
|
|
412
425
|
try:
|
|
413
426
|
numeric_value = float(value)
|
|
414
427
|
return max(self.min_val, min(self.max_val, numeric_value))
|
|
@@ -419,23 +432,23 @@ class SliderWithTextInput:
|
|
|
419
432
|
class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
420
433
|
"""
|
|
421
434
|
A custom Dash component that extends SliderWithTextInput by adding a checkbox with a message.
|
|
422
|
-
|
|
435
|
+
|
|
423
436
|
This component inherits all functionality from SliderWithTextInput and adds a checkbox
|
|
424
437
|
positioned beneath the input field. The checkbox can be used to enable/disable features,
|
|
425
438
|
toggle options, or provide additional control over the parameter being adjusted.
|
|
426
|
-
|
|
439
|
+
|
|
427
440
|
The checkbox includes an associated message that describes its purpose or provides
|
|
428
441
|
additional context for the user. The checkbox is larger than standard size and has
|
|
429
442
|
proper spacing between the checkbox and its label text.
|
|
430
|
-
|
|
443
|
+
|
|
431
444
|
Attributes:
|
|
432
445
|
checkbox_message (str): The message displayed next to the checkbox
|
|
433
446
|
checkbox_default (bool): Default checked state of the checkbox
|
|
434
447
|
checkbox_id (dict): Computed ID for the checkbox component
|
|
435
|
-
|
|
448
|
+
|
|
436
449
|
Note:
|
|
437
450
|
The checkbox value is [True] when checked, [] when unchecked.
|
|
438
|
-
|
|
451
|
+
|
|
439
452
|
Example:
|
|
440
453
|
>>> slider_component = SliderWithTextInputAndCheckbox(
|
|
441
454
|
... id_base={'type': 'parameter', 'index': 0},
|
|
@@ -466,12 +479,12 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
466
479
|
checkbox_default: bool = False,
|
|
467
480
|
with_slider_titles: bool = True,
|
|
468
481
|
slider_disable: bool = False,
|
|
469
|
-
div_width: str =
|
|
482
|
+
div_width: str = "calc(90%)",
|
|
470
483
|
message: str = None,
|
|
471
484
|
):
|
|
472
485
|
"""
|
|
473
486
|
Initialize the SliderWithTextInputAndCheckbox component.
|
|
474
|
-
|
|
487
|
+
|
|
475
488
|
Args:
|
|
476
489
|
id_base (dict): Base dictionary for generating component IDs.
|
|
477
490
|
property_name (str): String identifier for this property.
|
|
@@ -503,113 +516,122 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
503
516
|
div_width=div_width,
|
|
504
517
|
message=message,
|
|
505
518
|
)
|
|
506
|
-
|
|
519
|
+
|
|
507
520
|
# Add checkbox-specific attributes
|
|
508
521
|
self.checkbox_message = checkbox_message
|
|
509
522
|
self.checkbox_default = checkbox_default
|
|
510
|
-
self.checkbox_id = self._make_id(
|
|
523
|
+
self.checkbox_id = self._make_id("checkbox")
|
|
511
524
|
|
|
512
525
|
def _make_checkbox(self):
|
|
513
526
|
"""
|
|
514
527
|
Create and configure the Dash checkbox component.
|
|
515
|
-
|
|
528
|
+
|
|
516
529
|
Returns:
|
|
517
530
|
dash.html.Div: Container with a larger checkbox and separated label text.
|
|
518
531
|
"""
|
|
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
|
-
|
|
532
|
+
return ds.html.Div(
|
|
533
|
+
[
|
|
534
|
+
ds.dcc.Checklist(
|
|
535
|
+
id=self.checkbox_id,
|
|
536
|
+
options=[{"label": "", "value": True}],
|
|
537
|
+
value=[True] if self.checkbox_default else [],
|
|
538
|
+
style={
|
|
539
|
+
"display": "inline-block",
|
|
540
|
+
"margin-right": "10px",
|
|
541
|
+
"transform": "scale(1.3)", # Make checkbox larger
|
|
542
|
+
"transform-origin": "left top", # Changed to 'top' for better alignment
|
|
543
|
+
"vertical-align": "baseline", # Use baseline alignment
|
|
544
|
+
},
|
|
545
|
+
labelStyle={"margin": "0px"},
|
|
546
|
+
),
|
|
547
|
+
ds.html.Span(
|
|
548
|
+
self.checkbox_message,
|
|
549
|
+
style={
|
|
550
|
+
"display": "inline-block",
|
|
551
|
+
"vertical-align": "baseline", # Match checkbox baseline
|
|
552
|
+
"margin-left": "5px",
|
|
553
|
+
"line-height": "1.3", # Slightly higher line height
|
|
554
|
+
"margin-top": "-4px", # Pull text up more aggressively
|
|
555
|
+
},
|
|
556
|
+
),
|
|
557
|
+
],
|
|
558
|
+
style={"margin-left": "20px", "margin-top": "10px", "line-height": "1"},
|
|
559
|
+
)
|
|
544
560
|
|
|
545
561
|
def __call__(self):
|
|
546
562
|
"""
|
|
547
563
|
Generate the complete component layout including the checkbox.
|
|
548
|
-
|
|
564
|
+
|
|
549
565
|
Creates and returns a Dash HTML Div containing the title, optional message,
|
|
550
566
|
slider, input, and checkbox components arranged in a cohesive layout.
|
|
551
|
-
|
|
567
|
+
|
|
552
568
|
Returns:
|
|
553
569
|
dash.html.Div: Complete component layout containing all elements plus checkbox.
|
|
554
570
|
"""
|
|
555
571
|
slider_title = self.title if self.with_slider_titles else "\u00A0"
|
|
556
|
-
|
|
572
|
+
|
|
557
573
|
# Build the component list
|
|
558
574
|
components = [
|
|
559
|
-
ds.html.P(
|
|
575
|
+
ds.html.P(
|
|
576
|
+
slider_title, style={"margin-left": "20px", "margin-bottom": "0px"}
|
|
577
|
+
)
|
|
560
578
|
]
|
|
561
|
-
|
|
579
|
+
|
|
562
580
|
# Add optional message if provided
|
|
563
581
|
if self.message:
|
|
564
582
|
components.append(
|
|
565
|
-
ds.html.P(
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
583
|
+
ds.html.P(
|
|
584
|
+
self.message,
|
|
585
|
+
style={
|
|
586
|
+
"margin-left": "20px",
|
|
587
|
+
"margin-bottom": "5px",
|
|
588
|
+
"margin-top": "2px",
|
|
589
|
+
"font-size": "0.9em",
|
|
590
|
+
"color": "#666666",
|
|
591
|
+
"font-style": "italic",
|
|
592
|
+
},
|
|
593
|
+
)
|
|
573
594
|
)
|
|
574
|
-
|
|
595
|
+
|
|
575
596
|
# Add slider and input
|
|
576
|
-
components.extend(
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
597
|
+
components.extend(
|
|
598
|
+
[
|
|
599
|
+
ds.html.Div([self._make_slider()], style={"margin-bottom": "-18px"}),
|
|
600
|
+
self._make_input(),
|
|
601
|
+
]
|
|
602
|
+
)
|
|
603
|
+
|
|
581
604
|
# Add checkbox beneath the input
|
|
582
|
-
components.extend([
|
|
583
|
-
self._make_checkbox(),
|
|
584
|
-
ds.html.Br(), ds.html.Br()
|
|
585
|
-
])
|
|
605
|
+
components.extend([self._make_checkbox(), ds.html.Br(), ds.html.Br()])
|
|
586
606
|
|
|
587
|
-
return ds.html.Div(
|
|
607
|
+
return ds.html.Div(
|
|
608
|
+
components, style={"width": self.div_width, "margin-left": "-20px"}
|
|
609
|
+
)
|
|
588
610
|
|
|
589
611
|
@property
|
|
590
612
|
def components(self):
|
|
591
613
|
"""
|
|
592
614
|
Get a dictionary mapping component types to their IDs, including the checkbox.
|
|
593
|
-
|
|
615
|
+
|
|
594
616
|
Returns:
|
|
595
617
|
dict: Dictionary with component type keys mapping to their ID dictionaries.
|
|
596
618
|
"""
|
|
597
619
|
return {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
620
|
+
"slider": self.slider_id,
|
|
621
|
+
"input": self.input_id,
|
|
622
|
+
"checkbox": self.checkbox_id,
|
|
601
623
|
}
|
|
602
|
-
|
|
624
|
+
|
|
603
625
|
def get_checkbox_input(self):
|
|
604
626
|
"""
|
|
605
627
|
Get Input object for listening to checkbox value changes.
|
|
606
|
-
|
|
628
|
+
|
|
607
629
|
Returns:
|
|
608
630
|
Input: Dash Input object for the checkbox component.
|
|
609
|
-
|
|
631
|
+
|
|
610
632
|
Note:
|
|
611
633
|
The checkbox value will be [True] when checked, [] when unchecked.
|
|
612
|
-
|
|
634
|
+
|
|
613
635
|
Example:
|
|
614
636
|
>>> @app.callback(
|
|
615
637
|
... Output('some-output', 'children'),
|
|
@@ -619,18 +641,18 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
619
641
|
... is_checked = True in (checkbox_value or [])
|
|
620
642
|
... return f"Checkbox is {'checked' if is_checked else 'unchecked'}"
|
|
621
643
|
"""
|
|
622
|
-
return Input(self.checkbox_id,
|
|
623
|
-
|
|
644
|
+
return Input(self.checkbox_id, "value")
|
|
645
|
+
|
|
624
646
|
def get_checkbox_output(self):
|
|
625
647
|
"""
|
|
626
648
|
Get Output object for updating checkbox value.
|
|
627
|
-
|
|
649
|
+
|
|
628
650
|
Returns:
|
|
629
651
|
Output: Dash Output object for the checkbox component.
|
|
630
|
-
|
|
652
|
+
|
|
631
653
|
Note:
|
|
632
654
|
To check the checkbox, return [True]. To uncheck, return [].
|
|
633
|
-
|
|
655
|
+
|
|
634
656
|
Example:
|
|
635
657
|
>>> @app.callback(
|
|
636
658
|
... component.get_checkbox_output(),
|
|
@@ -641,18 +663,18 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
641
663
|
... return [True]
|
|
642
664
|
... return []
|
|
643
665
|
"""
|
|
644
|
-
return Output(self.checkbox_id,
|
|
645
|
-
|
|
666
|
+
return Output(self.checkbox_id, "value")
|
|
667
|
+
|
|
646
668
|
def get_all_inputs(self):
|
|
647
669
|
"""
|
|
648
670
|
Get Input objects for all component values (slider, input, and checkbox).
|
|
649
|
-
|
|
671
|
+
|
|
650
672
|
Returns:
|
|
651
673
|
list: List containing Input objects for slider, input, and checkbox.
|
|
652
|
-
|
|
674
|
+
|
|
653
675
|
Note:
|
|
654
676
|
The checkbox value will be [True] when checked, [] when unchecked.
|
|
655
|
-
|
|
677
|
+
|
|
656
678
|
Example:
|
|
657
679
|
>>> @app.callback(
|
|
658
680
|
... Output('summary', 'children'),
|
|
@@ -664,8 +686,7 @@ class SliderWithTextInputAndCheckbox(SliderWithTextInput):
|
|
|
664
686
|
... return f"Value: {value}, Option enabled: {is_checked}"
|
|
665
687
|
"""
|
|
666
688
|
return [
|
|
667
|
-
Input(self.slider_id,
|
|
668
|
-
Input(self.input_id,
|
|
669
|
-
Input(self.checkbox_id,
|
|
689
|
+
Input(self.slider_id, "value"),
|
|
690
|
+
Input(self.input_id, "value"),
|
|
691
|
+
Input(self.checkbox_id, "value"),
|
|
670
692
|
]
|
|
671
|
-
|