diff --git a/CHANGELOG.md b/CHANGELOG.md index b685ab0a..f3b03c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/plotly/src/traces/bar.rs b/plotly/src/traces/bar.rs index cd768273..16300ae6 100644 --- a/plotly/src/traces/bar.rs +++ b/plotly/src/traces/bar.rs @@ -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, }; @@ -51,6 +51,8 @@ where show_legend: Option, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, opacity: Option, ids: Option>, width: Option, @@ -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) @@ -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, diff --git a/plotly/src/traces/box_plot.rs b/plotly/src/traces/box_plot.rs index 35b39f1f..5b8e9c91 100644 --- a/plotly/src/traces/box_plot.rs +++ b/plotly/src/traces/box_plot.rs @@ -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, }; @@ -108,6 +111,8 @@ where show_legend: Option, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, opacity: Option, ids: Option>, width: Option, @@ -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.]) @@ -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": {}, diff --git a/plotly/src/traces/candlestick.rs b/plotly/src/traces/candlestick.rs index e1b96d0a..2fe6a197 100644 --- a/plotly/src/traces/candlestick.rs +++ b/plotly/src/traces/candlestick.rs @@ -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, }; @@ -61,6 +63,8 @@ where show_legend: Option, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, opacity: Option, text: Option>, #[serde(rename = "hovertext")] @@ -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") @@ -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", diff --git a/plotly/src/traces/contour.rs b/plotly/src/traces/contour.rs index fbf5ee15..844f55c2 100644 --- a/plotly/src/traces/contour.rs +++ b/plotly/src/traces/contour.rs @@ -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, }; @@ -118,6 +119,8 @@ where show_legend: Option, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, opacity: Option, x: Option>, x0: Option, @@ -187,6 +190,7 @@ where visible: None, show_legend: None, legend_group: None, + legend_group_title: None, opacity: None, x: None, x0: None, @@ -335,6 +339,11 @@ where Box::new(self) } + pub fn legend_group_title(mut self, legend_group_title: LegendGroupTitle) -> Box { + self.legend_group_title = Some(legend_group_title); + Box::new(self) + } + pub fn line(mut self, line: Line) -> Box { self.line = Some(line); Box::new(self) @@ -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") @@ -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"], diff --git a/plotly/src/traces/heat_map.rs b/plotly/src/traces/heat_map.rs index f2ac561c..151b6941 100644 --- a/plotly/src/traces/heat_map.rs +++ b/plotly/src/traces/heat_map.rs @@ -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, }; @@ -81,6 +83,8 @@ where hover_text: Option>, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, name: Option, opacity: Option, #[serde(rename = "reversescale")] @@ -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) @@ -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, diff --git a/plotly/src/traces/histogram.rs b/plotly/src/traces/histogram.rs index dc64609c..f5824057 100644 --- a/plotly/src/traces/histogram.rs +++ b/plotly/src/traces/histogram.rs @@ -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, }; @@ -134,6 +137,8 @@ where hover_text: Option>, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, marker: Option, #[serde(rename = "nbinsx")] n_bins_x: Option, @@ -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) @@ -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, diff --git a/plotly/src/traces/ohlc.rs b/plotly/src/traces/ohlc.rs index 137be680..cf1b4e50 100644 --- a/plotly/src/traces/ohlc.rs +++ b/plotly/src/traces/ohlc.rs @@ -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, }; @@ -58,6 +60,8 @@ where increasing: Option, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, line: Option, name: Option, opacity: Option, @@ -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) @@ -152,6 +157,7 @@ mod test { "hovertext": "1", "increasing": {"line": {}}, "legendgroup": "legendgroup", + "legendgrouptitle": {"text": "Legend Group Title"}, "line": {}, "name": "ohlc_trace", "opacity": 0.4, diff --git a/plotly/src/traces/scatter.rs b/plotly/src/traces/scatter.rs index 09bcebe7..f171602b 100644 --- a/plotly/src/traces/scatter.rs +++ b/plotly/src/traces/scatter.rs @@ -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, @@ -73,6 +73,9 @@ where /// same time when toggling legend items. #[serde(rename = "legendgroup")] legend_group: Option, + /// Set and style the title to appear for the legend group + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, /// Sets the opacity of the trace. opacity: Option, /// Determines the drawing mode for this scatter trace. If the provided `Mode` includes @@ -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") @@ -464,6 +468,7 @@ mod tests { "hovertemplate": ["hover_template"], "ids": ["1"], "legendgroup": "legend_group", + "legendgrouptitle": {"text": "Legend Group Title"}, "line": {}, "marker": {}, "meta": "meta", diff --git a/plotly/src/traces/scatter_polar.rs b/plotly/src/traces/scatter_polar.rs index 2f5130f2..a406a90e 100644 --- a/plotly/src/traces/scatter_polar.rs +++ b/plotly/src/traces/scatter_polar.rs @@ -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, @@ -55,6 +56,8 @@ where /// same time when toggling legend items. #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, /// Sets the opacity of the trace. opacity: Option, /// Determines the drawing mode for this scatter trace. If the provided `Mode` includes @@ -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") @@ -373,6 +377,7 @@ mod tests { "hovertemplate": ["hover_template"], "ids": ["1"], "legendgroup": "legend_group", + "legendgrouptitle": {"text": "Legend Group Title"}, "line": {}, "marker": {}, "meta": "meta", diff --git a/plotly/src/traces/surface.rs b/plotly/src/traces/surface.rs index d8beb80b..b4110d3b 100644 --- a/plotly/src/traces/surface.rs +++ b/plotly/src/traces/surface.rs @@ -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, }; @@ -147,6 +149,8 @@ where hover_text: Option>, #[serde(rename = "legendgroup")] legend_group: Option, + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, #[serde(rename = "lightposition")] light_position: Option, lighting: Option, @@ -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") @@ -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",