Skip to content

Commit 53bae5c

Browse files
committed
separate remaining larger types
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 332bab2 commit 53bae5c

File tree

4 files changed

+769
-730
lines changed

4 files changed

+769
-730
lines changed

plotly/src/layout/mapbox.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use plotly_derive::FieldSetter;
2+
use serde::Serialize;
3+
4+
use crate::common::Domain;
5+
6+
/// Defines the latitude and longitude at which a map will be centered.
7+
#[derive(Serialize, Clone, Debug)]
8+
pub struct Center {
9+
lat: f64,
10+
lon: f64,
11+
}
12+
13+
impl Center {
14+
/// Create a new instance of `Center`.
15+
///
16+
/// `lat` is the number of degrees north, `lon` is the number of degrees
17+
/// east.
18+
pub fn new(lat: f64, lon: f64) -> Self {
19+
Center { lat, lon }
20+
}
21+
}
22+
23+
#[derive(Serialize, Clone, Debug)]
24+
#[serde(rename_all = "kebab-case")]
25+
pub enum MapboxStyle {
26+
#[serde(rename = "carto-darkmatter")]
27+
CartoDarkMatter,
28+
CartoPositron,
29+
OpenStreetMap,
30+
StamenTerrain,
31+
StamenToner,
32+
StamenWatercolor,
33+
WhiteBg,
34+
Basic,
35+
Streets,
36+
Outdoors,
37+
Light,
38+
Dark,
39+
Satellite,
40+
SatelliteStreets,
41+
}
42+
43+
#[derive(Serialize, Clone, Debug, FieldSetter)]
44+
pub struct Mapbox {
45+
/// Sets the mapbox access token to be used for this mapbox map. Note that
46+
/// `access_token`s are only required when `style` (e.g with values: basic,
47+
/// streets, outdoors, light, dark, satellite, satellite-streets)
48+
/// and/or a layout layer references the Mapbox server.
49+
#[serde(rename = "accesstoken")]
50+
access_token: Option<String>,
51+
/// Sets the bearing angle of the map in degrees counter-clockwise from
52+
/// North.
53+
bearing: Option<f64>,
54+
/// Sets the latitude and longitude of the center of the map.
55+
center: Option<Center>,
56+
/// Sets the domain within which the mapbox will be drawn.
57+
domain: Option<Domain>,
58+
/// Sets the pitch angle of the map in degrees, where `0` means
59+
/// perpendicular to the surface of the map.
60+
pitch: Option<f64>,
61+
/// Sets the style of the map.
62+
style: Option<MapboxStyle>,
63+
/// Sets the zoom level of the map.
64+
zoom: Option<u8>,
65+
}
66+
67+
impl Mapbox {
68+
pub fn new() -> Self {
69+
Default::default()
70+
}
71+
}
72+
73+
#[cfg(test)]
74+
mod tests {
75+
use super::*;
76+
use serde_json::{json, to_value};
77+
78+
#[test]
79+
#[rustfmt::skip]
80+
fn serialize_mapbox_style() {
81+
assert_eq!(to_value(MapboxStyle::CartoDarkMatter).unwrap(), json!("carto-darkmatter"));
82+
assert_eq!(to_value(MapboxStyle::CartoPositron).unwrap(), json!("carto-positron"));
83+
assert_eq!(to_value(MapboxStyle::OpenStreetMap).unwrap(), json!("open-street-map"));
84+
assert_eq!(to_value(MapboxStyle::StamenTerrain).unwrap(), json!("stamen-terrain"));
85+
assert_eq!(to_value(MapboxStyle::StamenToner).unwrap(), json!("stamen-toner"));
86+
assert_eq!(to_value(MapboxStyle::StamenWatercolor).unwrap(), json!("stamen-watercolor"));
87+
assert_eq!(to_value(MapboxStyle::WhiteBg).unwrap(), json!("white-bg"));
88+
assert_eq!(to_value(MapboxStyle::Basic).unwrap(), json!("basic"));
89+
assert_eq!(to_value(MapboxStyle::Streets).unwrap(), json!("streets"));
90+
assert_eq!(to_value(MapboxStyle::Outdoors).unwrap(), json!("outdoors"));
91+
assert_eq!(to_value(MapboxStyle::Light).unwrap(), json!("light"));
92+
assert_eq!(to_value(MapboxStyle::Dark).unwrap(), json!("dark"));
93+
assert_eq!(to_value(MapboxStyle::Satellite).unwrap(), json!("satellite"));
94+
assert_eq!(to_value(MapboxStyle::SatelliteStreets).unwrap(), json!("satellite-streets"));
95+
}
96+
}

0 commit comments

Comments
 (0)