Skip to content

Commit 23e1290

Browse files
dustypomerleauandrei-ng
authored andcommitted
feat(layout): add LayoutPolar
1 parent 6a51920 commit 23e1290

File tree

3 files changed

+660
-2
lines changed

3 files changed

+660
-2
lines changed

examples/basic_charts/src/main.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use plotly::{
88
Marker, Mode, Orientation, Pattern, PatternShape,
99
},
1010
layout::{
11-
Annotation, Axis, AxisRange, BarMode, CategoryOrder, Layout, LayoutGrid, Legend,
11+
AngularAxis, Annotation, Axis, AxisRange, BarMode, CategoryOrder, Layout, LayoutGrid,
12+
LayoutPolar, Legend, PolarAxisAttributes, PolarAxisTicks, PolarDirection, RadialAxis,
1213
TicksDirection, TraceOrder,
1314
},
1415
sankey::{Line as SankeyLine, Link, Node},
@@ -119,6 +120,29 @@ fn polar_scatter_plot(show: bool, file_name: &str) {
119120
let mut plot = Plot::new();
120121
plot.add_trace(trace);
121122

123+
let ticks = PolarAxisTicks::new().tick_color("#222222");
124+
125+
let axis_attributes = PolarAxisAttributes::new()
126+
.grid_color("#888888")
127+
.ticks(ticks);
128+
129+
let radial_axis = RadialAxis::new()
130+
.title("My Title")
131+
.axis_attributes(axis_attributes.clone());
132+
133+
let angular_axis = AngularAxis::new()
134+
.direction(PolarDirection::Clockwise)
135+
.rotation(45.0)
136+
.axis_attributes(axis_attributes);
137+
138+
let layout_polar = LayoutPolar::new()
139+
.bg_color("#eeeeee")
140+
.radial_axis(radial_axis)
141+
.angular_axis(angular_axis);
142+
143+
let layout = Layout::new().polar(layout_polar);
144+
plot.set_layout(layout);
145+
122146
let path = write_example_to_html(&plot, file_name);
123147
if show {
124148
plot.show_html(path);

plotly/src/layout/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod grid;
1919
mod legend;
2020
mod mapbox;
2121
mod modes;
22+
mod polar;
2223
mod rangebreaks;
2324
mod scene;
2425
mod shape;
@@ -42,6 +43,11 @@ pub use self::mapbox::{Center, Mapbox, MapboxStyle};
4243
pub use self::modes::{
4344
AspectMode, BarMode, BarNorm, BoxMode, ClickMode, UniformTextMode, ViolinMode, WaterfallMode,
4445
};
46+
pub use self::polar::{
47+
AngularAxis, AngularAxisType, AutoRange, AutoRangeOptions, AutoTypeNumbers, AxisLayer,
48+
GridShape, Hole, LayoutPolar, MinorLogLabels, PolarAxisAttributes, PolarAxisTicks,
49+
PolarDirection, PolarTickMode, RadialAxis, RadialAxisType, ThetaUnit,
50+
};
4551
pub use self::rangebreaks::RangeBreak;
4652
pub use self::scene::{
4753
AspectRatio, Camera, CameraCenter, DragMode, DragMode3D, Eye, HoverMode, LayoutScene,
@@ -330,7 +336,7 @@ pub struct LayoutFields {
330336
// ternary: Option<LayoutTernary>,
331337
scene: Option<LayoutScene>,
332338
geo: Option<LayoutGeo>,
333-
// polar: Option<LayoutPolar>,
339+
polar: Option<LayoutPolar>,
334340
annotations: Option<Vec<Annotation>>,
335341
shapes: Option<Vec<Shape>>,
336342
#[serde(rename = "newshape")]

0 commit comments

Comments
 (0)