Skip to content

Commit 2bb1469

Browse files
committed
refactor
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent cd015b0 commit 2bb1469

File tree

5 files changed

+45
-43
lines changed

5 files changed

+45
-43
lines changed

plotly/src/layout/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use plotly_derive::generate_layout_structs;
1+
use plotly_derive::layout_structs;
22
use plotly_derive::FieldSetter;
33
use serde::Serialize;
44
use std::borrow::Cow;
@@ -37,7 +37,7 @@ impl Into<Cow<'static, Template>> for &'static Template {
3737
}
3838
}
3939

40-
#[generate_layout_structs]
40+
#[layout_structs]
4141
pub struct LayoutFields {
4242
title: Option<Title>,
4343
#[serde(rename = "showlegend")]

plotly/src/layout/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ pub use self::layout::{Layout, LayoutTemplate, Template};
3636
pub use self::legend::{Legend, TraceOrder};
3737
pub use self::mapbox::{Mapbox, MapboxStyle};
3838
pub use self::modes::{
39-
BarMode, BarNorm, BoxMode, ClickMode, UniformTextMode, ViolinMode, WaterfallMode,
39+
AspectMode, BarMode, BarNorm, BoxMode, ClickMode, UniformTextMode, ViolinMode, WaterfallMode,
40+
};
41+
pub use self::scene::{
42+
Camera, CameraCenter, DragMode, DragMode3D, HoverMode, LayoutScene, Projection, ProjectionType,
4043
};
41-
pub use self::scene::{DragMode, DragMode3D, HoverMode, LayoutScene, Projection, ProjectionType};
4244
pub use self::shape::{
4345
ActiveShape, DrawDirection, FillRule, NewShape, Shape, ShapeLayer, ShapeLine, ShapeSizeMode,
4446
ShapeType,

plotly/src/layout/modes.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
use serde::{Serialize, Serializer};
22

3+
#[derive(Serialize, Debug, Clone)]
4+
/// If "cube", this scene's axes are drawn as a cube, regardless of the axes'
5+
/// ranges. If "data", this scene's axes are drawn in proportion with the axes'
6+
/// ranges. If "manual", this scene's axes are drawn in proportion with the
7+
/// input of "aspectratio" (the default behavior if "aspectratio" is provided).
8+
/// If "auto", this scene's axes are drawn using the results of "data" except
9+
/// when one axis is more than four times the size of the two others, where in
10+
/// that case the results of "cube" are used.
11+
/// Default: "auto"
12+
#[derive(Default)]
13+
pub enum AspectMode {
14+
#[serde(rename = "auto")]
15+
#[default]
16+
Auto,
17+
#[serde(rename = "cube")]
18+
Cube,
19+
#[serde(rename = "data")]
20+
Data,
21+
#[serde(rename = "manual")]
22+
Manual,
23+
}
24+
325
#[derive(Serialize, Debug, Clone)]
426
#[serde(rename_all = "lowercase")]
527
pub enum BoxMode {
@@ -123,4 +145,19 @@ mod tests {
123145
assert_eq!(to_value(WaterfallMode::Group).unwrap(), json!("group"));
124146
assert_eq!(to_value(WaterfallMode::Overlay).unwrap(), json!("overlay"));
125147
}
148+
149+
#[test]
150+
fn serialize_aspect_mode() {
151+
let aspect_mode = AspectMode::default();
152+
153+
assert_eq!(to_value(aspect_mode).unwrap(), json!("auto"));
154+
155+
let aspect_mode = AspectMode::Data;
156+
157+
assert_eq!(to_value(aspect_mode).unwrap(), json!("data"));
158+
159+
let aspect_mode = AspectMode::Cube;
160+
161+
assert_eq!(to_value(aspect_mode).unwrap(), json!("cube"));
162+
}
126163
}

plotly/src/layout/scene.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,7 @@ use plotly_derive::FieldSetter;
22
use serde::Serialize;
33

44
use crate::color::Color;
5-
use crate::layout::{Annotation, Axis};
6-
7-
#[derive(Serialize, Debug, Clone)]
8-
/// If "cube", this scene's axes are drawn as a cube, regardless of the axes'
9-
/// ranges. If "data", this scene's axes are drawn in proportion with the axes'
10-
/// ranges. If "manual", this scene's axes are drawn in proportion with the
11-
/// input of "aspectratio" (the default behavior if "aspectratio" is provided).
12-
/// If "auto", this scene's axes are drawn using the results of "data" except
13-
/// when one axis is more than four times the size of the two others, where in
14-
/// that case the results of "cube" are used.
15-
/// Default: "auto"
16-
#[derive(Default)]
17-
pub enum AspectMode {
18-
#[serde(rename = "auto")]
19-
#[default]
20-
Auto,
21-
#[serde(rename = "cube")]
22-
Cube,
23-
#[serde(rename = "data")]
24-
Data,
25-
#[serde(rename = "manual")]
26-
Manual,
27-
}
5+
use crate::layout::{Annotation, AspectMode, Axis};
286

297
#[serde_with::skip_serializing_none]
308
#[derive(Serialize, Debug, Clone, FieldSetter)]
@@ -494,21 +472,6 @@ mod tests {
494472
assert_eq!(to_value(camera_center).unwrap(), expected);
495473
}
496474

497-
#[test]
498-
fn serialize_aspect_mode() {
499-
let aspect_mode = AspectMode::default();
500-
501-
assert_eq!(to_value(aspect_mode).unwrap(), json!("auto"));
502-
503-
let aspect_mode = AspectMode::Data;
504-
505-
assert_eq!(to_value(aspect_mode).unwrap(), json!("data"));
506-
507-
let aspect_mode = AspectMode::Cube;
508-
509-
assert_eq!(to_value(aspect_mode).unwrap(), json!("cube"));
510-
}
511-
512475
#[test]
513476
fn serialize_up() {
514477
let up = Up::new();

plotly_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn field_setter(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
1414
}
1515

1616
#[proc_macro_attribute]
17-
pub fn generate_layout_structs(_attr: TokenStream, item: TokenStream) -> TokenStream {
17+
pub fn layout_structs(_attr: TokenStream, item: TokenStream) -> TokenStream {
1818
let input = parse_macro_input!(item as ItemStruct);
1919
let vis = &input.vis;
2020
let fields = &input.fields;

0 commit comments

Comments
 (0)