Skip to content

Commit fcfb2ff

Browse files
committed
fix maps examples
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent fd36405 commit fcfb2ff

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

examples/maps/src/main.rs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ use plotly::{
66
layout::{
77
Axis, Center, DragMode, LayoutGeo, Mapbox, MapboxStyle, Margin, Projection, Rotation,
88
},
9-
DensityMapbox, Layout, Plot, ScatterGeo, ScatterMapbox,
9+
Configuration, DensityMapbox, Layout, Plot, ScatterGeo, ScatterMapbox,
1010
};
1111
use plotly_utils::write_example_to_html;
1212

1313
fn scatter_mapbox(show: bool, file_name: &str) {
1414
let trace = ScatterMapbox::new(vec![45.5017], vec![-73.5673])
1515
.marker(Marker::new().size(25).opacity(0.9));
1616

17-
let layout = Layout::new()
18-
.drag_mode(DragMode::Zoom)
19-
.margin(Margin::new().top(0).left(0).bottom(0).right(0))
20-
.mapbox(
21-
Mapbox::new()
22-
.style(MapboxStyle::OpenStreetMap)
23-
.center(Center::new(45.5017, -73.5673))
24-
.zoom(5),
25-
);
17+
let layout = Layout::new().drag_mode(DragMode::Zoom).mapbox(
18+
Mapbox::new()
19+
.style(MapboxStyle::OpenStreetMap)
20+
.center(Center::new(45.5017, -73.5673))
21+
.zoom(5),
22+
);
2623

2724
let mut plot = Plot::new();
2825
plot.add_trace(trace);
2926
plot.set_layout(layout);
27+
plot.set_configuration(Configuration::default().responsive(true).fill_frame(true));
3028

3129
let path = write_example_to_html(&plot, file_name);
3230
if show {
@@ -100,35 +98,33 @@ fn scatter_geo(show: bool, file_name: &str) {
10098
plot.add_trace(trace);
10199
}
102100

103-
let layout = Layout::new()
104-
.drag_mode(DragMode::Zoom)
105-
.margin(Margin::new().top(0).left(0).bottom(0).right(0))
106-
.geo(
107-
LayoutGeo::new()
108-
.showocean(true)
109-
.showlakes(true)
110-
.showcountries(true)
111-
.showland(true)
112-
.oceancolor(Rgb::new(0, 255, 255))
113-
.lakecolor(Rgb::new(0, 255, 255))
114-
.landcolor(Rgb::new(230, 145, 56))
115-
.lataxis(
116-
Axis::new()
117-
.show_grid(true)
118-
.grid_color(Rgb::new(102, 102, 102)),
119-
)
120-
.lonaxis(
121-
Axis::new()
122-
.show_grid(true)
123-
.grid_color(Rgb::new(102, 102, 102)),
124-
)
125-
.projection(
126-
Projection::new()
127-
.projection_type(plotly::layout::ProjectionType::Orthographic)
128-
.rotation(Rotation::new().lon(-100.0).lat(40.0)),
129-
),
130-
);
131-
101+
let layout = Layout::new().drag_mode(DragMode::Zoom).geo(
102+
LayoutGeo::new()
103+
.showocean(true)
104+
.showlakes(true)
105+
.showcountries(true)
106+
.showland(true)
107+
.oceancolor(Rgb::new(0, 255, 255))
108+
.lakecolor(Rgb::new(0, 255, 255))
109+
.landcolor(Rgb::new(230, 145, 56))
110+
.lataxis(
111+
Axis::new()
112+
.show_grid(true)
113+
.grid_color(Rgb::new(102, 102, 102)),
114+
)
115+
.lonaxis(
116+
Axis::new()
117+
.show_grid(true)
118+
.grid_color(Rgb::new(102, 102, 102)),
119+
)
120+
.projection(
121+
Projection::new()
122+
.projection_type(plotly::layout::ProjectionType::Orthographic)
123+
.rotation(Rotation::new().lon(-100.0).lat(40.0)),
124+
),
125+
);
126+
127+
plot.set_configuration(Configuration::default().responsive(true).fill_frame(true));
132128
plot.set_layout(layout);
133129

134130
let path = write_example_to_html(&plot, file_name);
@@ -140,19 +136,17 @@ fn scatter_geo(show: bool, file_name: &str) {
140136
fn density_mapbox(show: bool, file_name: &str) {
141137
let trace = DensityMapbox::new(vec![45.5017], vec![-73.5673], vec![0.75]).zauto(true);
142138

143-
let layout = Layout::new()
144-
.drag_mode(DragMode::Zoom)
145-
.margin(Margin::new().top(0).left(0).bottom(0).right(0))
146-
.mapbox(
147-
Mapbox::new()
148-
.style(MapboxStyle::OpenStreetMap)
149-
.center(Center::new(45.5017, -73.5673))
150-
.zoom(5),
151-
);
139+
let layout = Layout::new().drag_mode(DragMode::Zoom).mapbox(
140+
Mapbox::new()
141+
.style(MapboxStyle::OpenStreetMap)
142+
.center(Center::new(45.5017, -73.5673))
143+
.zoom(5),
144+
);
152145

153146
let mut plot = Plot::new();
154147
plot.add_trace(trace);
155148
plot.set_layout(layout);
149+
plot.set_configuration(Configuration::default().responsive(true).fill_frame(true));
156150

157151
let path = write_example_to_html(&plot, file_name);
158152
if show {

0 commit comments

Comments
 (0)