Skip to content

Commit 81c70f2

Browse files
committed
add sliders functionality
- update update_menu.rs ButtonBuilder and Button to be consistent with Slider Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 33c6e64 commit 81c70f2

File tree

16 files changed

+2987
-27
lines changed

16 files changed

+2987
-27
lines changed

docs/book/src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
- [Subplots](./recipes/subplots.md)
3232
- [Subplots](./recipes/subplots/subplots.md)
3333
- [Multiple Axes](./recipes/subplots/multiple_axes.md)
34+
- [Custom Controls](./recipes/custom_controls.md)
35+
- [Dropdowns](./recipes/custom_controls/dropdowns.md)
36+
- [Sliders](./recipes/custom_controls/sliders.md)

docs/book/src/gallery.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/book/src/gallery/financial_charts.md

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Custom Controls
2+
3+
This section covers interactive controls that can be added to plots to modify data or layout attributes dynamically.
4+
5+
| Control Type | Preview |
6+
|--------------|---------|
7+
| [Dropdown Menus and Buttons](./custom_controls/dropdowns.md) | ![Dropdown Example](./img/dropdown.png) |
8+
| [Sliders](./custom_controls/sliders.md) | ![Slider Example](./img/sliders.png) |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dropdown Menus
2+
3+
Dropdown menus, implemented as an `UpdateMenu` in Plotly.rs, allow users to modify a plot's data or layout attributes by selecting an option from a list.
4+
5+
## Dropdown for Selecting Data
6+
7+
You can use a dropdown menu to switch between different sets of data. In this example, we show two different bar charts and use a dropdown to select which one is visible.
8+
9+
```rust,no_run
10+
{{#include ../../../../../examples/custom_controls/src/main.rs:bar_plot_with_dropdown_for_different_data}}
11+
```
12+
{{#include ../../../../../examples/custom_controls/output/inline_bar_plot.html}}
13+
14+
## Dropdown for Modifying Layout
15+
16+
Update menus can also modify layout attributes. Here, we use buttons (a variation of a dropdown) to change the `bar_mode` of a bar chart, toggling between grouped and stacked bars.
17+
18+
```rust,no_run
19+
{{#include ../../../../../examples/custom_controls/src/main.rs:bar_chart_with_modifiable_bar_mode}}
20+
```
21+
{{#include ../../../../../examples/custom_controls/output/inline_bar_chart.html}}
22+
23+
## Dropdown for Modifying Colorscales
24+
25+
You can dynamically change the colorscale of a heatmap or contour plot.
26+
27+
```rust,no_run
28+
{{#include ../../../../../examples/custom_controls/src/main.rs:heat_map_with_modifiable_colorscale}}
29+
```
30+
{{#include ../../../../../examples/custom_controls/output/inline_heat_map.html}}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Sliders
2+
3+
4+
Sliders provide interactive controls to animate through different data states or parameters. They are different from range sliders and are typically used for animating through time series data or changing plot parameters dynamically.
5+
6+
Data sliders support various customization options including:
7+
- **Positioning**: Control x, y coordinates and anchors
8+
- **Styling**: Background color, border color, width, and font
9+
- **Behavior**: Active step highlighting, step execution control
10+
- **Dimensions**: Length, width, and orientation (horizontal/vertical)
11+
- **Steps**: Multiple steps with different data states or parameters
12+
13+
## Customizing a Simple Data Slider
14+
15+
Sliders are perfect for stepping through sequential data, like time series. This example creates a slider to show the population of different animals for four consecutive years.
16+
It shows how to use the slider API to customize slider features.
17+
18+
```rust,no_run
19+
{{#include ../../../../../examples/custom_controls/src/main.rs:bar_chart_with_slider_customization}}
20+
```
21+
{{#include ../../../../../examples/custom_controls/output/inline_bar_chart_with_slider_customization.html}}
22+
23+
## Slider for Parameter Control
24+
25+
Sliders aren't just for data; they can also be used to control parameters in a function. Here, a slider modifies the frequency of a sinusoidal wave, updating the plot in real-time.
26+
27+
```rust,no_run
28+
{{#include ../../../../../examples/custom_controls/src/main.rs:sinusoidal_slider_example}}
29+
```
30+
{{#include ../../../../../examples/custom_controls/output/inline_sinusoidal_slider_example.html}}
31+
32+
## Advanced Slider: GDP vs. Life Expectancy
33+
34+
This example, based on the Python Plotly Gapminder dataset, demonstrates a more complex use case. A slider is used to animate a bubble chart showing the relationship between GDP per capita and life expectancy across different continents over several decades. See [https://plotly.com/python/sliders/](https://plotly.com/python/sliders/)
35+
36+
```rust,no_run
37+
{{#include ../../../../../examples/custom_controls/src/main.rs:gdp_life_expectancy_slider_example}}
38+
```
39+
{{#include ../../../../../examples/custom_controls/output/inline_gdp_life_expectancy_slider_example.html}}

docs/book/src/recipes/financial_charts/time_series_and_date_axes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ The `to_inline_html` method is used to produce the html plot displayed in this p
4242
{{#include ../../../../../examples/financial_charts/src/main.rs:customizing_tick_label_formatting_by_zoom_level}}
4343
```
4444

45-
{{#include ../../../../../examples/financial_charts/output/inline_customizing_tick_label_formatting_by_zoom_level.html}}
45+
{{#include ../../../../../examples/financial_charts/output/inline_customizing_tick_label_formatting_by_zoom_level.html}}
20.7 KB
Loading

docs/book/src/recipes/img/sliders.png

66 KB
Loading

examples/custom_controls/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ authors = ["Michael Freeborn <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]
8-
itertools = "0.10"
8+
itertools = "0.12"
9+
serde = { version = "1.0", features = ["derive"] }
10+
serde_json = "1.0"
11+
csv = "1.3"
12+
ndarray = "0.15"
13+
914
plotly = { path = "../../plotly" }
10-
plotly_utils = { path = "../plotly_utils" }
15+
plotly_utils = { path = "../plotly_utils" }

0 commit comments

Comments
 (0)