Skip to content

Commit 793c433

Browse files
committed
feat: add legendgrouptitle too all existing traces
Fixes plotly#109
1 parent c0ca691 commit 793c433

File tree

10 files changed

+75
-12
lines changed

10 files changed

+75
-12
lines changed

plotly/src/traces/bar.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use serde::Serialize;
55

66
use crate::{
77
common::{
8-
Calendar, ConstrainText, Dim, ErrorData, Font, HoverInfo, Label, Marker, Orientation,
9-
PlotType, TextAnchor, TextPosition, Visible,
8+
Calendar, ConstrainText, Dim, ErrorData, Font, HoverInfo, Label, LegendGroupTitle, Marker,
9+
Orientation, PlotType, TextAnchor, TextPosition, Visible,
1010
},
1111
Trace,
1212
};
@@ -51,6 +51,8 @@ where
5151
show_legend: Option<bool>,
5252
#[serde(rename = "legendgroup")]
5353
legend_group: Option<String>,
54+
#[serde(rename = "legendgrouptitle")]
55+
legend_group_title: Option<LegendGroupTitle>,
5456
opacity: Option<f64>,
5557
ids: Option<Vec<String>>,
5658
width: Option<usize>,
@@ -157,6 +159,7 @@ mod tests {
157159
.inside_text_anchor(TextAnchor::End)
158160
.inside_text_font(Font::new())
159161
.legend_group("legend-group")
162+
.legend_group_title(LegendGroupTitle::new("legend-group-title"))
160163
.marker(Marker::new())
161164
.name("Bar")
162165
.offset(5)
@@ -191,6 +194,7 @@ mod tests {
191194
"visible": "legendonly",
192195
"showlegend": false,
193196
"legendgroup": "legend-group",
197+
"legendgrouptitle": {"text": "legend-group-title"},
194198
"opacity": 0.5,
195199
"ids": ["1"],
196200
"width": 999,

plotly/src/traces/box_plot.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use serde::{Serialize, Serializer};
55

66
use crate::{
77
color::Color,
8-
common::{Calendar, Dim, HoverInfo, Label, Line, Marker, Orientation, PlotType, Visible},
8+
common::{
9+
Calendar, Dim, HoverInfo, Label, LegendGroupTitle, Line, Marker, Orientation, PlotType,
10+
Visible,
11+
},
912
Trace,
1013
};
1114

@@ -108,6 +111,8 @@ where
108111
show_legend: Option<bool>,
109112
#[serde(rename = "legendgroup")]
110113
legend_group: Option<String>,
114+
#[serde(rename = "legendgrouptitle")]
115+
legend_group_title: Option<LegendGroupTitle>,
111116
opacity: Option<f64>,
112117
ids: Option<Vec<String>>,
113118
width: Option<usize>,
@@ -278,6 +283,7 @@ mod tests {
278283
.jitter(0.5)
279284
.line(Line::new())
280285
.legend_group("one")
286+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
281287
.lower_fence(vec![0., 1.])
282288
.marker(Marker::new())
283289
.mean(vec![12., 13.])
@@ -320,6 +326,7 @@ mod tests {
320326
"hovertext": ["okey", "dokey"],
321327
"jitter": 0.5,
322328
"legendgroup": "one",
329+
"legendgrouptitle": {"text": "Legend Group Title"},
323330
"line": {},
324331
"lowerfence": [0.0, 1.0],
325332
"marker": {},

plotly/src/traces/candlestick.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use serde::Serialize;
55

66
use crate::{
77
color::NamedColor,
8-
common::{Calendar, Dim, Direction, HoverInfo, Label, Line, PlotType, Visible},
8+
common::{
9+
Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PlotType, Visible,
10+
},
911
Trace,
1012
};
1113

@@ -61,6 +63,8 @@ where
6163
show_legend: Option<bool>,
6264
#[serde(rename = "legendgroup")]
6365
legend_group: Option<String>,
66+
#[serde(rename = "legendgrouptitle")]
67+
legend_group_title: Option<LegendGroupTitle>,
6468
opacity: Option<f64>,
6569
text: Option<Dim<String>>,
6670
#[serde(rename = "hovertext")]
@@ -140,6 +144,7 @@ mod tests {
140144
.visible(Visible::True)
141145
.show_legend(false)
142146
.legend_group("group_1")
147+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
143148
.opacity(0.3)
144149
.text_array(vec!["text", "here"])
145150
.text("text here")
@@ -166,6 +171,7 @@ mod tests {
166171
"visible": true,
167172
"showlegend": false,
168173
"legendgroup": "group_1",
174+
"legendgrouptitle": {"text": "Legend Group Title"},
169175
"opacity": 0.3,
170176
"text": "text here",
171177
"hovertext": "hover text",

plotly/src/traces/contour.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use serde::Serialize;
66
use crate::{
77
color::Color,
88
common::{
9-
Calendar, ColorBar, ColorScale, Dim, Font, HoverInfo, Label, Line, PlotType, Visible,
9+
Calendar, ColorBar, ColorScale, Dim, Font, HoverInfo, Label, LegendGroupTitle, Line,
10+
PlotType, Visible,
1011
},
1112
private, Trace,
1213
};
@@ -118,6 +119,8 @@ where
118119
show_legend: Option<bool>,
119120
#[serde(rename = "legendgroup")]
120121
legend_group: Option<String>,
122+
#[serde(rename = "legendgrouptitle")]
123+
legend_group_title: Option<LegendGroupTitle>,
121124
opacity: Option<f64>,
122125
x: Option<Vec<X>>,
123126
x0: Option<X>,
@@ -187,6 +190,7 @@ where
187190
visible: None,
188191
show_legend: None,
189192
legend_group: None,
193+
legend_group_title: None,
190194
opacity: None,
191195
x: None,
192196
x0: None,
@@ -335,6 +339,11 @@ where
335339
Box::new(self)
336340
}
337341

342+
pub fn legend_group_title(mut self, legend_group_title: LegendGroupTitle) -> Box<Self> {
343+
self.legend_group_title = Some(legend_group_title);
344+
Box::new(self)
345+
}
346+
338347
pub fn line(mut self, line: Line) -> Box<Self> {
339348
self.line = Some(line);
340349
Box::new(self)
@@ -574,6 +583,7 @@ mod tests {
574583
.hover_template_array(vec!["ok {1}", "ok {2}"])
575584
.hover_text(vec!["p3", "p4"])
576585
.legend_group("group_1")
586+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
577587
.line(Line::new())
578588
.n_contours(5)
579589
.name("contour trace")
@@ -611,6 +621,7 @@ mod tests {
611621
"visible": true,
612622
"showlegend": false,
613623
"legendgroup": "group_1",
624+
"legendgrouptitle": {"text": "Legend Group Title"},
614625
"opacity": 0.6,
615626
"text": ["p1", "p2"],
616627
"hovertext": ["p3", "p4"],

plotly/src/traces/heat_map.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use plotly_derive::FieldSetter;
44
use serde::Serialize;
55

66
use crate::{
7-
common::{Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, PlotType, Visible},
7+
common::{
8+
Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, LegendGroupTitle, PlotType, Visible,
9+
},
810
Trace,
911
};
1012

@@ -81,6 +83,8 @@ where
8183
hover_text: Option<Vec<String>>,
8284
#[serde(rename = "legendgroup")]
8385
legend_group: Option<String>,
86+
#[serde(rename = "legendgrouptitle")]
87+
legend_group_title: Option<LegendGroupTitle>,
8488
name: Option<String>,
8589
opacity: Option<f64>,
8690
#[serde(rename = "reversescale")]
@@ -198,6 +202,7 @@ mod tests {
198202
.hover_template_array(vec!["tmpl1", "tmpl2"])
199203
.hover_text(vec!["hov", "er"])
200204
.legend_group("1")
205+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
201206
.name("name")
202207
.opacity(0.99)
203208
.reverse_scale(false)
@@ -229,6 +234,7 @@ mod tests {
229234
"hovertemplate": ["tmpl1", "tmpl2"],
230235
"hovertext": ["hov", "er"],
231236
"legendgroup": "1",
237+
"legendgrouptitle": {"text": "Legend Group Title"},
232238
"name": "name",
233239
"opacity": 0.99,
234240
"reversescale": false,

plotly/src/traces/histogram.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use serde::Serialize;
88
#[cfg(feature = "plotly_ndarray")]
99
use crate::ndarray::ArrayTraces;
1010
use crate::{
11-
common::{Calendar, Dim, ErrorData, HoverInfo, Label, Marker, Orientation, PlotType, Visible},
11+
common::{
12+
Calendar, Dim, ErrorData, HoverInfo, Label, LegendGroupTitle, Marker, Orientation,
13+
PlotType, Visible,
14+
},
1215
Trace,
1316
};
1417

@@ -134,6 +137,8 @@ where
134137
hover_text: Option<Dim<String>>,
135138
#[serde(rename = "legendgroup")]
136139
legend_group: Option<String>,
140+
#[serde(rename = "legendgrouptitle")]
141+
legend_group_title: Option<LegendGroupTitle>,
137142
marker: Option<Marker>,
138143
#[serde(rename = "nbinsx")]
139144
n_bins_x: Option<usize>,
@@ -397,6 +402,7 @@ mod tests {
397402
.hover_text("hover_text")
398403
.hover_text_array(vec!["hover_text_1", "hover_text_2"])
399404
.legend_group("legendgroup")
405+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
400406
.marker(Marker::new())
401407
.n_bins_x(5)
402408
.n_bins_y(10)
@@ -430,6 +436,7 @@ mod tests {
430436
"hovertemplate": ["hover_template_1", "hover_template_2"],
431437
"hovertext": ["hover_text_1", "hover_text_2"],
432438
"legendgroup": "legendgroup",
439+
"legendgrouptitle": {"text": "Legend Group Title"},
433440
"marker": {},
434441
"nbinsx": 5,
435442
"nbinsy": 10,

plotly/src/traces/ohlc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use plotly_derive::FieldSetter;
44
use serde::Serialize;
55

66
use crate::{
7-
common::{Calendar, Dim, Direction, HoverInfo, Label, Line, PlotType, Visible},
7+
common::{
8+
Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PlotType, Visible,
9+
},
810
Trace,
911
};
1012

@@ -58,6 +60,8 @@ where
5860
increasing: Option<Direction>,
5961
#[serde(rename = "legendgroup")]
6062
legend_group: Option<String>,
63+
#[serde(rename = "legendgrouptitle")]
64+
legend_group_title: Option<LegendGroupTitle>,
6165
line: Option<Line>,
6266
name: Option<String>,
6367
opacity: Option<f64>,
@@ -129,6 +133,7 @@ mod test {
129133
.hover_text("1")
130134
.increasing(Direction::Increasing { line: Line::new() })
131135
.legend_group("legendgroup")
136+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
132137
.line(Line::new())
133138
.name("ohlc_trace")
134139
.opacity(0.4)
@@ -152,6 +157,7 @@ mod test {
152157
"hovertext": "1",
153158
"increasing": {"line": {}},
154159
"legendgroup": "legendgroup",
160+
"legendgrouptitle": {"text": "Legend Group Title"},
155161
"line": {},
156162
"name": "ohlc_trace",
157163
"opacity": 0.4,

plotly/src/traces/scatter.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::ndarray::ArrayTraces;
1010
use crate::{
1111
color::Color,
1212
common::{
13-
Calendar, Dim, ErrorData, Fill, Font, HoverInfo, HoverOn, Label, Line, Marker, Mode,
14-
Orientation, PlotType, Position, Visible,
13+
Calendar, Dim, ErrorData, Fill, Font, HoverInfo, HoverOn, Label, LegendGroupTitle, Line,
14+
Marker, Mode, Orientation, PlotType, Position, Visible,
1515
},
1616
private::{NumOrString, NumOrStringCollection},
1717
Trace,
@@ -73,6 +73,9 @@ where
7373
/// same time when toggling legend items.
7474
#[serde(rename = "legendgroup")]
7575
legend_group: Option<String>,
76+
/// Set and style the title to appear for the legend group
77+
#[serde(rename = "legendgrouptitle")]
78+
legend_group_title: Option<LegendGroupTitle>,
7679
/// Sets the opacity of the trace.
7780
opacity: Option<f64>,
7881
/// Determines the drawing mode for this scatter trace. If the provided `Mode` includes
@@ -414,6 +417,7 @@ mod tests {
414417
.hover_template_array(vec!["hover_template"])
415418
.ids(vec!["1"])
416419
.legend_group("legend_group")
420+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
417421
.line(Line::new())
418422
.marker(Marker::new())
419423
.meta("meta")
@@ -461,6 +465,7 @@ mod tests {
461465
"hovertemplate": ["hover_template"],
462466
"ids": ["1"],
463467
"legendgroup": "legend_group",
468+
"legendgrouptitle": {"text": "Legend Group Title"},
464469
"line": {},
465470
"marker": {},
466471
"meta": "meta",

plotly/src/traces/scatter_polar.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::ndarray::ArrayTraces;
1010
use crate::{
1111
color::Color,
1212
common::{
13-
Dim, Fill, Font, HoverInfo, HoverOn, Label, Line, Marker, Mode, PlotType, Position, Visible,
13+
Dim, Fill, Font, HoverInfo, HoverOn, Label, LegendGroupTitle, Line, Marker, Mode, PlotType,
14+
Position, Visible,
1415
},
1516
private::{NumOrString, NumOrStringCollection},
1617
Trace,
@@ -55,6 +56,8 @@ where
5556
/// same time when toggling legend items.
5657
#[serde(rename = "legendgroup")]
5758
legend_group: Option<String>,
59+
#[serde(rename = "legendgrouptitle")]
60+
legend_group_title: Option<LegendGroupTitle>,
5861
/// Sets the opacity of the trace.
5962
opacity: Option<f64>,
6063
/// Determines the drawing mode for this scatter trace. If the provided `Mode` includes
@@ -333,6 +336,7 @@ mod tests {
333336
.hover_text_array(vec!["hover_text"])
334337
.ids(vec!["1"])
335338
.legend_group("legend_group")
339+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
336340
.line(Line::new())
337341
.marker(Marker::new())
338342
.meta("meta")
@@ -370,6 +374,7 @@ mod tests {
370374
"hovertemplate": ["hover_template"],
371375
"ids": ["1"],
372376
"legendgroup": "legend_group",
377+
"legendgrouptitle": {"text": "Legend Group Title"},
373378
"line": {},
374379
"marker": {},
375380
"meta": "meta",

plotly/src/traces/surface.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use serde::Serialize;
55

66
use crate::{
77
color::Color,
8-
common::{Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, PlotType, Visible},
8+
common::{
9+
Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, LegendGroupTitle, PlotType, Visible,
10+
},
911
Trace,
1012
};
1113

@@ -147,6 +149,8 @@ where
147149
hover_text: Option<Dim<String>>,
148150
#[serde(rename = "legendgroup")]
149151
legend_group: Option<String>,
152+
#[serde(rename = "legendgrouptitle")]
153+
legend_group_title: Option<LegendGroupTitle>,
150154
#[serde(rename = "lightposition")]
151155
light_position: Option<Position>,
152156
lighting: Option<Lighting>,
@@ -324,6 +328,7 @@ mod tests {
324328
.hover_text("hover_text")
325329
.hover_text_array(vec!["hover_text_1"])
326330
.legend_group("legend_group")
331+
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
327332
.lighting(Lighting::new())
328333
.light_position(Position::new(0, 0, 0))
329334
.name("surface_trace")
@@ -359,6 +364,7 @@ mod tests {
359364
"hovertemplate": ["hover_template_1"],
360365
"hovertext": ["hover_text_1"],
361366
"legendgroup": "legend_group",
367+
"legendgrouptitle": {"text": "Legend Group Title"},
362368
"lighting": {},
363369
"lightposition": {"x": 0, "y": 0, "z": 0},
364370
"name": "surface_trace",

0 commit comments

Comments
 (0)