diff --git a/CHANGELOG.md b/CHANGELOG.md index ac055798..a5ed842b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - [[#414](https://github.com/plotly/plotly.rs/issues/414)] Add `DensityMap` (MapLibre `map` subplot) trace type — density heatmaps with full color-scale and hover support - [[#417](https://github.com/plotly/plotly.rs/issues/417)] Add `ScatterMap` (MapLibre `map` subplot) trace type — the modern counterpart to `ScatterMapbox` - [[#418](https://github.com/plotly/plotly.rs/issues/418)] Add native point clustering to `ScatterMap` via a `Cluster` option +- [[#421](https://github.com/plotly/plotly.rs/pull/421)] Backfill trace attributes on trace types to bring them to parity with plotly.js 3.7 ### Changed diff --git a/plotly/src/common/mod.rs b/plotly/src/common/mod.rs index db2fa08e..05345710 100644 --- a/plotly/src/common/mod.rs +++ b/plotly/src/common/mod.rs @@ -645,6 +645,101 @@ impl Gradient { } } +/// Styles the marker of `selected`/`unselected` points, used by the +/// `selected` and `unselected` attributes of point-marker traces. +#[serde_with::skip_serializing_none] +#[derive(Serialize, Clone, Debug, Default)] +pub struct SelectionMarker { + color: Option>, + opacity: Option, + size: Option>, +} + +/// Sets the style of `selected`/`unselected` points. +#[derive(Serialize, Clone, Debug, Default)] +pub struct Selection { + marker: SelectionMarker, +} + +impl Selection { + pub fn new() -> Self { + Default::default() + } + + /// Sets the marker color of un/selected points. + pub fn color(mut self, color: C) -> Self { + self.marker.color = Some(Box::new(color)); + self + } + + /// Sets the marker opacity of un/selected points. + pub fn opacity(mut self, opacity: f64) -> Self { + self.marker.opacity = Some(opacity); + self + } + + /// Sets the marker size of un/selected points. + pub fn size(mut self, size: usize) -> Self { + self.marker.size = Some(Dim::Scalar(size)); + self + } +} + +/// Alignment of the period on a date axis, controlling where within each +/// period the point is drawn (used by the `xperiodalignment` / +/// `yperiodalignment` trace attributes). +#[derive(Serialize, Clone, Debug)] +#[serde(rename_all = "lowercase")] +pub enum PeriodAlignment { + Start, + Middle, + End, +} + +/// Sets a fill gradient for a scatter trace's filled area, as an alternative to +/// a solid `fill_color`. +#[serde_with::skip_serializing_none] +#[derive(Serialize, Clone, Debug, Default)] +pub struct FillGradient { + #[serde(rename = "type")] + r#type: Option, + start: Option, + stop: Option, + #[serde(rename = "colorscale")] + color_scale: Option, +} + +impl FillGradient { + pub fn new() -> Self { + Default::default() + } + + /// Sets the direction of the gradient (`radial`, `horizontal`, `vertical`). + pub fn type_(mut self, gradient_type: GradientType) -> Self { + self.r#type = Some(gradient_type); + self + } + + /// Sets the gradient start value (in the units of the axis the gradient is + /// aligned with). + pub fn start(mut self, start: f64) -> Self { + self.start = Some(start); + self + } + + /// Sets the gradient stop value. + pub fn stop(mut self, stop: f64) -> Self { + self.stop = Some(stop); + self + } + + /// Sets the color scale used across the gradient. + pub fn color_scale(mut self, color_scale: ColorScale) -> Self { + self.color_scale = Some(color_scale); + self + } +} + #[serde_with::skip_serializing_none] #[derive(Serialize, Clone, Debug, FieldSetter)] pub struct TickFormatStop { diff --git a/plotly/src/traces/bar.rs b/plotly/src/traces/bar.rs index a3e91fe0..4089f204 100644 --- a/plotly/src/traces/bar.rs +++ b/plotly/src/traces/bar.rs @@ -6,8 +6,10 @@ use serde::Serialize; use crate::{ common::{ Calendar, ConstrainText, Dim, ErrorData, Font, HoverInfo, Label, LegendGroupTitle, Marker, - Orientation, PlotType, TextAnchor, TextPosition, Visible, XAxisId, YAxisId, + Orientation, PeriodAlignment, PlotType, Selection, TextAnchor, TextPosition, Visible, + XAxisId, YAxisId, }, + private::{NumOrString, NumOrStringCollection}, Trace, }; @@ -105,6 +107,52 @@ where x_calendar: Option, #[serde(rename = "ycalendar")] y_calendar: Option, + /// Sets the legend rank for this trace. Items and groups with smaller ranks + /// are presented on top/left side while with `"reversed"` + /// `legend.trace_order` they are on bottom/right side. The default + /// legendrank is 1000. + #[serde(rename = "legendrank")] + legend_rank: Option, + /// Sets the width (in px or fraction) of the legend for this trace. + #[serde(rename = "legendwidth")] + legend_width: Option, + /// Controls persistence of user-driven changes to the trace. Defaults to + /// `layout.uirevision`. + #[serde(rename = "uirevision")] + ui_revision: Option, + /// Array of integer indices of the points in this trace that are selected. + #[serde(rename = "selectedpoints")] + selected_points: Option, + /// Sets the style of selected points. + selected: Option, + /// Sets the style of unselected points. + unselected: Option, + /// Sets the layer on which this trace is displayed relative to other SVG + /// traces on the same subplot. A higher `zorder` appears on top. + #[serde(rename = "zorder")] + z_order: Option, + /// Only relevant when the corresponding axis `type` is "date". Sets the + /// period positioning in milliseconds or "M" on the x axis. + #[serde(rename = "xperiod")] + x_period: Option, + /// Only relevant when the axis `type` is "date". Sets the base for period + /// positioning on the x axis. + #[serde(rename = "xperiod0")] + x_period0: Option, + /// Sets the alignment of data points on the x axis relative to the period. + #[serde(rename = "xperiodalignment")] + x_period_alignment: Option, + /// Only relevant when the corresponding axis `type` is "date". Sets the + /// period positioning in milliseconds or "M" on the y axis. + #[serde(rename = "yperiod")] + y_period: Option, + /// Only relevant when the axis `type` is "date". Sets the base for period + /// positioning on the y axis. + #[serde(rename = "yperiod0")] + y_period0: Option, + /// Sets the alignment of data points on the y axis relative to the period. + #[serde(rename = "yperiodalignment")] + y_period_alignment: Option, } impl Bar diff --git a/plotly/src/traces/box_plot.rs b/plotly/src/traces/box_plot.rs index f65ff33f..346b6b9f 100644 --- a/plotly/src/traces/box_plot.rs +++ b/plotly/src/traces/box_plot.rs @@ -6,9 +6,10 @@ use serde::{Serialize, Serializer}; use crate::{ color::Color, common::{ - Calendar, Dim, HoverInfo, Label, LegendGroupTitle, Line, Marker, Orientation, PlotType, - Visible, XAxisId, YAxisId, + Calendar, Dim, HoverInfo, Label, LegendGroupTitle, Line, Marker, Orientation, + PeriodAlignment, PlotType, Selection, Visible, XAxisId, YAxisId, }, + private::{NumOrString, NumOrStringCollection}, Trace, }; @@ -172,6 +173,52 @@ where x_calendar: Option, #[serde(rename = "ycalendar")] y_calendar: Option, + /// Sets the legend rank for this trace. Items and groups with smaller ranks + /// are presented on top/left side while with `"reversed"` + /// `legend.trace_order` they are on bottom/right side. The default + /// legendrank is 1000. + #[serde(rename = "legendrank")] + legend_rank: Option, + /// Sets the width (in px or fraction) of the legend for this trace. + #[serde(rename = "legendwidth")] + legend_width: Option, + /// Controls persistence of user-driven changes to the trace. Defaults to + /// `layout.uirevision`. + #[serde(rename = "uirevision")] + ui_revision: Option, + /// Array of integer indices of the points in this trace that are selected. + #[serde(rename = "selectedpoints")] + selected_points: Option, + /// Sets the style of selected points. + selected: Option, + /// Sets the style of unselected points. + unselected: Option, + /// Sets the layer on which this trace is displayed relative to other SVG + /// traces on the same subplot. A higher `zorder` appears on top. + #[serde(rename = "zorder")] + z_order: Option, + /// Only relevant when the corresponding axis `type` is "date". Sets the + /// period positioning in milliseconds or "M" on the x axis. + #[serde(rename = "xperiod")] + x_period: Option, + /// Only relevant when the axis `type` is "date". Sets the base for period + /// positioning on the x axis. + #[serde(rename = "xperiod0")] + x_period0: Option, + /// Sets the alignment of data points on the x axis relative to the period. + #[serde(rename = "xperiodalignment")] + x_period_alignment: Option, + /// Only relevant when the corresponding axis `type` is "date". Sets the + /// period positioning in milliseconds or "M" on the y axis. + #[serde(rename = "yperiod")] + y_period: Option, + /// Only relevant when the axis `type` is "date". Sets the base for period + /// positioning on the y axis. + #[serde(rename = "yperiod0")] + y_period0: Option, + /// Sets the alignment of data points on the y axis relative to the period. + #[serde(rename = "yperiodalignment")] + y_period_alignment: Option, } impl BoxPlot diff --git a/plotly/src/traces/candlestick.rs b/plotly/src/traces/candlestick.rs index 8728a741..0213a861 100644 --- a/plotly/src/traces/candlestick.rs +++ b/plotly/src/traces/candlestick.rs @@ -3,11 +3,12 @@ use plotly_derive::FieldSetter; use serde::Serialize; +use crate::private::{NumOrString, NumOrStringCollection}; use crate::{ color::NamedColor, common::{ - Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PlotType, Visible, - XAxisId, YAxisId, + Calendar, Dim, Direction, HoverInfo, Label, LegendGroupTitle, Line, PeriodAlignment, + PlotType, Visible, XAxisId, YAxisId, }, Trace, }; @@ -89,6 +90,37 @@ where hover_label: Option