Skip to content

add legend_group_title to existing traces #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.2] - 2022-11-xx
### Added
- [[#110](https://github.com/igiagkiozis/plotly/pull/110)] `LegendGroupTitle` to existing traces.

### Changed
- [[#113](https://github.com/igiagkiozis/plotly/pull/113)] Refactored the structure of the examples to make them more accessible, whilst adding more examples e.g. for `wasm`.
- [[#115](https://github.com/igiagkiozis/plotly/pull/115)] Simplify the function signature of Plot.to_inline_html() so that it just takes `Option<&str>` as an argument.
Expand Down
8 changes: 6 additions & 2 deletions plotly/src/traces/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use serde::Serialize;

use crate::{
common::{
Calendar, ConstrainText, Dim, ErrorData, Font, HoverInfo, Label, Marker, Orientation,
PlotType, TextAnchor, TextPosition, Visible,
Calendar, ConstrainText, Dim, ErrorData, Font, HoverInfo, Label, LegendGroupTitle, Marker,
Orientation, PlotType, TextAnchor, TextPosition, Visible,
},
Trace,
};
Expand Down Expand Up @@ -51,6 +51,8 @@ where
show_legend: Option<bool>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
opacity: Option<f64>,
ids: Option<Vec<String>>,
width: Option<usize>,
Expand Down Expand Up @@ -157,6 +159,7 @@ mod tests {
.inside_text_anchor(TextAnchor::End)
.inside_text_font(Font::new())
.legend_group("legend-group")
.legend_group_title(LegendGroupTitle::new("legend-group-title"))
.marker(Marker::new())
.name("Bar")
.offset(5)
Expand Down Expand Up @@ -191,6 +194,7 @@ mod tests {
"visible": "legendonly",
"showlegend": false,
"legendgroup": "legend-group",
"legendgrouptitle": {"text": "legend-group-title"},
"opacity": 0.5,
"ids": ["1"],
"width": 999,
Expand Down
9 changes: 8 additions & 1 deletion plotly/src/traces/box_plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use serde::{Serialize, Serializer};

use crate::{
color::Color,
common::{Calendar, Dim, HoverInfo, Label, Line, Marker, Orientation, PlotType, Visible},
common::{
Calendar, Dim, HoverInfo, Label, LegendGroupTitle, Line, Marker, Orientation, PlotType,
Visible,
},
Trace,
};

Expand Down Expand Up @@ -108,6 +111,8 @@ where
show_legend: Option<bool>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
opacity: Option<f64>,
ids: Option<Vec<String>>,
width: Option<usize>,
Expand Down Expand Up @@ -278,6 +283,7 @@ mod tests {
.jitter(0.5)
.line(Line::new())
.legend_group("one")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.lower_fence(vec![0., 1.])
.marker(Marker::new())
.mean(vec![12., 13.])
Expand Down Expand Up @@ -320,6 +326,7 @@ mod tests {
"hovertext": ["okey", "dokey"],
"jitter": 0.5,
"legendgroup": "one",
"legendgrouptitle": {"text": "Legend Group Title"},
"line": {},
"lowerfence": [0.0, 1.0],
"marker": {},
Expand Down
8 changes: 7 additions & 1 deletion plotly/src/traces/candlestick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde::Serialize;

use crate::{
color::NamedColor,
common::{Calendar, Dim, Direction, HoverInfo, Label, Line, PlotType, Visible},
common::{
Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PlotType, Visible,
},
Trace,
};

Expand Down Expand Up @@ -61,6 +63,8 @@ where
show_legend: Option<bool>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
opacity: Option<f64>,
text: Option<Dim<String>>,
#[serde(rename = "hovertext")]
Expand Down Expand Up @@ -140,6 +144,7 @@ mod tests {
.visible(Visible::True)
.show_legend(false)
.legend_group("group_1")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.opacity(0.3)
.text_array(vec!["text", "here"])
.text("text here")
Expand All @@ -166,6 +171,7 @@ mod tests {
"visible": true,
"showlegend": false,
"legendgroup": "group_1",
"legendgrouptitle": {"text": "Legend Group Title"},
"opacity": 0.3,
"text": "text here",
"hovertext": "hover text",
Expand Down
13 changes: 12 additions & 1 deletion plotly/src/traces/contour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use serde::Serialize;
use crate::{
color::Color,
common::{
Calendar, ColorBar, ColorScale, Dim, Font, HoverInfo, Label, Line, PlotType, Visible,
Calendar, ColorBar, ColorScale, Dim, Font, HoverInfo, Label, LegendGroupTitle, Line,
PlotType, Visible,
},
private, Trace,
};
Expand Down Expand Up @@ -118,6 +119,8 @@ where
show_legend: Option<bool>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
opacity: Option<f64>,
x: Option<Vec<X>>,
x0: Option<X>,
Expand Down Expand Up @@ -187,6 +190,7 @@ where
visible: None,
show_legend: None,
legend_group: None,
legend_group_title: None,
opacity: None,
x: None,
x0: None,
Expand Down Expand Up @@ -335,6 +339,11 @@ where
Box::new(self)
}

pub fn legend_group_title(mut self, legend_group_title: LegendGroupTitle) -> Box<Self> {
self.legend_group_title = Some(legend_group_title);
Box::new(self)
}

pub fn line(mut self, line: Line) -> Box<Self> {
self.line = Some(line);
Box::new(self)
Expand Down Expand Up @@ -574,6 +583,7 @@ mod tests {
.hover_template_array(vec!["ok {1}", "ok {2}"])
.hover_text(vec!["p3", "p4"])
.legend_group("group_1")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.line(Line::new())
.n_contours(5)
.name("contour trace")
Expand Down Expand Up @@ -611,6 +621,7 @@ mod tests {
"visible": true,
"showlegend": false,
"legendgroup": "group_1",
"legendgrouptitle": {"text": "Legend Group Title"},
"opacity": 0.6,
"text": ["p1", "p2"],
"hovertext": ["p3", "p4"],
Expand Down
8 changes: 7 additions & 1 deletion plotly/src/traces/heat_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use plotly_derive::FieldSetter;
use serde::Serialize;

use crate::{
common::{Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, PlotType, Visible},
common::{
Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, LegendGroupTitle, PlotType, Visible,
},
Trace,
};

Expand Down Expand Up @@ -81,6 +83,8 @@ where
hover_text: Option<Vec<String>>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
name: Option<String>,
opacity: Option<f64>,
#[serde(rename = "reversescale")]
Expand Down Expand Up @@ -198,6 +202,7 @@ mod tests {
.hover_template_array(vec!["tmpl1", "tmpl2"])
.hover_text(vec!["hov", "er"])
.legend_group("1")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.name("name")
.opacity(0.99)
.reverse_scale(false)
Expand Down Expand Up @@ -229,6 +234,7 @@ mod tests {
"hovertemplate": ["tmpl1", "tmpl2"],
"hovertext": ["hov", "er"],
"legendgroup": "1",
"legendgrouptitle": {"text": "Legend Group Title"},
"name": "name",
"opacity": 0.99,
"reversescale": false,
Expand Down
9 changes: 8 additions & 1 deletion plotly/src/traces/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use serde::Serialize;
#[cfg(feature = "plotly_ndarray")]
use crate::ndarray::ArrayTraces;
use crate::{
common::{Calendar, Dim, ErrorData, HoverInfo, Label, Marker, Orientation, PlotType, Visible},
common::{
Calendar, Dim, ErrorData, HoverInfo, Label, LegendGroupTitle, Marker, Orientation,
PlotType, Visible,
},
Trace,
};

Expand Down Expand Up @@ -134,6 +137,8 @@ where
hover_text: Option<Dim<String>>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
marker: Option<Marker>,
#[serde(rename = "nbinsx")]
n_bins_x: Option<usize>,
Expand Down Expand Up @@ -400,6 +405,7 @@ mod tests {
.hover_text("hover_text")
.hover_text_array(vec!["hover_text_1", "hover_text_2"])
.legend_group("legendgroup")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.marker(Marker::new())
.n_bins_x(5)
.n_bins_y(10)
Expand Down Expand Up @@ -433,6 +439,7 @@ mod tests {
"hovertemplate": ["hover_template_1", "hover_template_2"],
"hovertext": ["hover_text_1", "hover_text_2"],
"legendgroup": "legendgroup",
"legendgrouptitle": {"text": "Legend Group Title"},
"marker": {},
"nbinsx": 5,
"nbinsy": 10,
Expand Down
8 changes: 7 additions & 1 deletion plotly/src/traces/ohlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use plotly_derive::FieldSetter;
use serde::Serialize;

use crate::{
common::{Calendar, Dim, Direction, HoverInfo, Label, Line, PlotType, Visible},
common::{
Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PlotType, Visible,
},
Trace,
};

Expand Down Expand Up @@ -58,6 +60,8 @@ where
increasing: Option<Direction>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
line: Option<Line>,
name: Option<String>,
opacity: Option<f64>,
Expand Down Expand Up @@ -129,6 +133,7 @@ mod test {
.hover_text("1")
.increasing(Direction::Increasing { line: Line::new() })
.legend_group("legendgroup")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.line(Line::new())
.name("ohlc_trace")
.opacity(0.4)
Expand All @@ -152,6 +157,7 @@ mod test {
"hovertext": "1",
"increasing": {"line": {}},
"legendgroup": "legendgroup",
"legendgrouptitle": {"text": "Legend Group Title"},
"line": {},
"name": "ohlc_trace",
"opacity": 0.4,
Expand Down
9 changes: 7 additions & 2 deletions plotly/src/traces/scatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::ndarray::ArrayTraces;
use crate::{
color::Color,
common::{
Calendar, Dim, ErrorData, Fill, Font, HoverInfo, HoverOn, Label, Line, Marker, Mode,
Orientation, PlotType, Position, Visible,
Calendar, Dim, ErrorData, Fill, Font, HoverInfo, HoverOn, Label, LegendGroupTitle, Line,
Marker, Mode, Orientation, PlotType, Position, Visible,
},
private::{NumOrString, NumOrStringCollection},
Trace,
Expand Down Expand Up @@ -73,6 +73,9 @@ where
/// same time when toggling legend items.
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
/// Set and style the title to appear for the legend group
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
/// Sets the opacity of the trace.
opacity: Option<f64>,
/// Determines the drawing mode for this scatter trace. If the provided `Mode` includes
Expand Down Expand Up @@ -417,6 +420,7 @@ mod tests {
.hover_template_array(vec!["hover_template"])
.ids(vec!["1"])
.legend_group("legend_group")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.line(Line::new())
.marker(Marker::new())
.meta("meta")
Expand Down Expand Up @@ -464,6 +468,7 @@ mod tests {
"hovertemplate": ["hover_template"],
"ids": ["1"],
"legendgroup": "legend_group",
"legendgrouptitle": {"text": "Legend Group Title"},
"line": {},
"marker": {},
"meta": "meta",
Expand Down
7 changes: 6 additions & 1 deletion plotly/src/traces/scatter_polar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::ndarray::ArrayTraces;
use crate::{
color::Color,
common::{
Dim, Fill, Font, HoverInfo, HoverOn, Label, Line, Marker, Mode, PlotType, Position, Visible,
Dim, Fill, Font, HoverInfo, HoverOn, Label, LegendGroupTitle, Line, Marker, Mode, PlotType,
Position, Visible,
},
private::{NumOrString, NumOrStringCollection},
Trace,
Expand Down Expand Up @@ -55,6 +56,8 @@ where
/// same time when toggling legend items.
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
/// Sets the opacity of the trace.
opacity: Option<f64>,
/// Determines the drawing mode for this scatter trace. If the provided `Mode` includes
Expand Down Expand Up @@ -336,6 +339,7 @@ mod tests {
.hover_text_array(vec!["hover_text"])
.ids(vec!["1"])
.legend_group("legend_group")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.line(Line::new())
.marker(Marker::new())
.meta("meta")
Expand Down Expand Up @@ -373,6 +377,7 @@ mod tests {
"hovertemplate": ["hover_template"],
"ids": ["1"],
"legendgroup": "legend_group",
"legendgrouptitle": {"text": "Legend Group Title"},
"line": {},
"marker": {},
"meta": "meta",
Expand Down
8 changes: 7 additions & 1 deletion plotly/src/traces/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde::Serialize;

use crate::{
color::Color,
common::{Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, PlotType, Visible},
common::{
Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, LegendGroupTitle, PlotType, Visible,
},
Trace,
};

Expand Down Expand Up @@ -147,6 +149,8 @@ where
hover_text: Option<Dim<String>>,
#[serde(rename = "legendgroup")]
legend_group: Option<String>,
#[serde(rename = "legendgrouptitle")]
legend_group_title: Option<LegendGroupTitle>,
#[serde(rename = "lightposition")]
light_position: Option<Position>,
lighting: Option<Lighting>,
Expand Down Expand Up @@ -324,6 +328,7 @@ mod tests {
.hover_text("hover_text")
.hover_text_array(vec!["hover_text_1"])
.legend_group("legend_group")
.legend_group_title(LegendGroupTitle::new("Legend Group Title"))
.lighting(Lighting::new())
.light_position(Position::new(0, 0, 0))
.name("surface_trace")
Expand Down Expand Up @@ -359,6 +364,7 @@ mod tests {
"hovertemplate": ["hover_template_1"],
"hovertext": ["hover_text_1"],
"legendgroup": "legend_group",
"legendgrouptitle": {"text": "Legend Group Title"},
"lighting": {},
"lightposition": {"x": 0, "y": 0, "z": 0},
"name": "surface_trace",
Expand Down