Skip to content

Commit ef25443

Browse files
committed
fixes Pie chart color setting
Closes #347 Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 4b93098 commit ef25443

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

plotly/src/common/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,10 @@ pub struct Marker {
11801180
size_mode: Option<SizeMode>,
11811181
line: Option<Line>,
11821182
gradient: Option<Gradient>,
1183+
/// Marker option specific for Scatter and other common traces
11831184
color: Option<Dim<Box<dyn Color>>>,
1185+
/// Marker option specific for Pie charts to set the colors of the sectors
1186+
colors: Option<Vec<Box<dyn Color>>>,
11841187
cauto: Option<bool>,
11851188
cmin: Option<f64>,
11861189
cmax: Option<f64>,
@@ -1260,6 +1263,11 @@ impl Marker {
12601263
self
12611264
}
12621265

1266+
pub fn colors<C: Color>(mut self, colors: Vec<C>) -> Self {
1267+
self.colors = Some(ColorArray(colors).into());
1268+
self
1269+
}
1270+
12631271
pub fn color_array<C: Color>(mut self, colors: Vec<C>) -> Self {
12641272
self.color = Some(Dim::Vector(ColorArray(colors).into()));
12651273
self
@@ -2330,6 +2338,7 @@ mod tests {
23302338
.line(Line::new())
23312339
.gradient(Gradient::new(GradientType::Radial, "#FFFFFF"))
23322340
.color(NamedColor::Blue)
2341+
.colors(vec![NamedColor::Black, NamedColor::Blue])
23332342
.color_array(vec![NamedColor::Black, NamedColor::Blue])
23342343
.cauto(true)
23352344
.cmin(0.0)
@@ -2359,6 +2368,7 @@ mod tests {
23592368
"line": {},
23602369
"gradient": {"type": "radial", "color": "#FFFFFF"},
23612370
"color": ["black", "blue"],
2371+
"colors": ["black", "blue"],
23622372
"colorbar": {},
23632373
"cauto": true,
23642374
"cmin": 0.0,

0 commit comments

Comments
 (0)