Skip to content

Commit 3a9f7ef

Browse files
tectin0mfreeborn
andauthored
Add LayoutScene (#153)
* added AspectMode and LayoutScene * added Camera for LayoutScene with Eye, Up and Projection (Center is missing) * updated 3d_charts example * added layout_scene test + fixed layout_scene.drag_mode type * implemented CameraCenter + more methods + added documentation and tests * added DragMode3D because not all variants from DragMode are valid in 3D * expanded the customized scatter3d plot in the examples * updated imports in examples/3d_charts * Updated CHANGELOG.md Draft for CHANGELOG.md * fixed typo * default derive instead of manual implementation * appease clippy * update changelog * resolve TODOs --------- Co-authored-by: = <=> Co-authored-by: Michael Freeborn <[email protected]>
1 parent 5112b85 commit 3a9f7ef

File tree

4 files changed

+501
-18
lines changed

4 files changed

+501
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [0.8.5] - 2023-xx-xx
7+
### Added
8+
- [[#153](https://github.com/igiagkiozis/plotly/pull/153)] Added `LayoutScene`
9+
610
## [0.8.4] - 2023-07-09
711
### Added
812
- [[#143](https://github.com/igiagkiozis/plotly/pull/143)] Widen version range of `askama`.

examples/3d_charts/src/main.rs

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
use ndarray::Array;
44
use plotly::{
5-
common::{ColorScale, ColorScalePalette, Marker, MarkerSymbol, Mode, Title},
6-
layout::{Axis, Layout},
5+
color::Rgb,
6+
common::{ColorScale, ColorScalePalette, Font, Marker, MarkerSymbol, Mode, Title},
7+
layout::{Axis, Camera, Layout, LayoutScene, Legend, Margin, ProjectionType},
78
Mesh3D, Plot, Scatter3D, Surface,
89
};
910

@@ -29,6 +30,7 @@ fn customized_scatter3d_plot() {
2930
let sizelookup = z.clone();
3031

3132
let trace = Scatter3D::new(t.clone(), y.clone(), z.iter().map(|i| -i).collect())
33+
.name("Helix 1")
3234
.mode(Mode::Markers)
3335
.marker(
3436
Marker::new()
@@ -42,25 +44,65 @@ fn customized_scatter3d_plot() {
4244
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
4345
);
4446

45-
let trace2 = Scatter3D::new(t, z, y).mode(Mode::Markers).marker(
46-
Marker::new()
47-
.size_array(
48-
sizelookup
49-
.iter()
50-
.map(|i| (i.abs() * 25f64) as usize)
51-
.collect(),
52-
)
53-
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
54-
);
47+
let trace2 = Scatter3D::new(t, z, y)
48+
.name("Helix 2")
49+
.mode(Mode::Markers)
50+
.marker(
51+
Marker::new()
52+
.size_array(
53+
sizelookup
54+
.iter()
55+
.map(|i| (i.abs() * 25f64) as usize)
56+
.collect(),
57+
)
58+
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
59+
);
5560

5661
let mut plot = Plot::new();
5762
plot.add_trace(trace);
5863
plot.add_trace(trace2);
64+
65+
let background_color: Rgb = Rgb::new(70, 70, 70);
66+
let front_color: Rgb = Rgb::new(255, 255, 255);
67+
5968
let layout = Layout::new()
6069
.title("Helix".into())
61-
.x_axis(Axis::new().title("x (A meaningful axis name goes here)".into()))
62-
.y_axis(Axis::new().title(Title::new("This is the label of the Y axis")))
63-
.z_axis(Axis::new().title("z Axis".into()));
70+
.legend(Legend::new().x(0.9).y(0.9))
71+
.font(Font::new().color(front_color))
72+
.paper_background_color(background_color)
73+
.scene(
74+
LayoutScene::new()
75+
.x_axis(
76+
Axis::new()
77+
.title("x (A meaningful axis name goes here)".into())
78+
.tick_angle(0f64)
79+
.grid_color(front_color)
80+
.color(front_color),
81+
)
82+
.y_axis(
83+
Axis::new()
84+
.title(Title::new("This is the label of the Y axis"))
85+
.tick_format(".1f")
86+
.grid_color(front_color)
87+
.color(front_color),
88+
)
89+
.z_axis(Axis::new().title("".into()).tick_values(vec![]))
90+
.aspect_mode(plotly::layout::AspectMode::Manual)
91+
.aspect_ratio((3.0, 1.0, 1.0).into())
92+
.camera(
93+
Camera::new()
94+
.projection(ProjectionType::Orthographic.into())
95+
.eye((0.0, 0.0, 1.0).into())
96+
.up((0.0, 1.0, 0.0).into())
97+
.center((0.0, 0.0, 0.0).into()),
98+
)
99+
.drag_mode(plotly::layout::DragMode3D::Pan)
100+
.hover_mode(plotly::layout::HoverMode::Closest)
101+
.background_color(background_color),
102+
)
103+
.margin(Margin::new().left(0).right(0).top(50).bottom(0))
104+
.width(1000)
105+
.height(500);
64106
plot.set_layout(layout);
65107

66108
plot.show();

plotly/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target/
22
.idea
33
Cargo.lock
44
gh-pages/
5+
.vscode

0 commit comments

Comments
 (0)