Skip to content
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

feat: Customize the shape of the marker #15

Merged
merged 1 commit into from
Sep 13, 2024
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
31 changes: 24 additions & 7 deletions src/aesthetics/mark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotly::common::Marker;

use crate::Rgb;
use crate::{Rgb, Shape};

pub(crate) trait Mark {
fn create_marker(mut opacity: Option<f64>, mut size: Option<usize>) -> Marker {
Expand Down Expand Up @@ -38,12 +38,29 @@ pub(crate) trait Mark {
}
}

// if let Some(colors) = colors {
// if let Some(rgb) = colors.get(index) {
// let group_color = plotly::color::Rgb::new(rgb.0, rgb.1, rgb.2);
// updated_marker = updated_marker.color(group_color);
// }
// }
updated_marker
}

fn set_shape(
marker: &Marker,
shape: &Option<Shape>,
shapes: &Option<Vec<Shape>>,
index: usize,
) -> Marker {
let mut updated_marker = marker.clone();

match shape {
Some(shape) => {
updated_marker = updated_marker.symbol(shape.get_shape());
}
None => {
if let Some(shapes) = shapes {
if let Some(shape) = shapes.get(index) {
updated_marker = updated_marker.symbol(shape.get_shape());
}
}
}
}

updated_marker
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod aesthetics;
mod axis;
mod colors;
mod legend;
mod shapes;
mod texts;
mod traces;
mod traits;
Expand All @@ -16,6 +17,7 @@ pub use crate::aesthetics::{line::LineType, orientation::Orientation};
pub use crate::axis::{Axis, AxisPosition, AxisType, TickDirection, ValueExponent};
pub use crate::colors::Rgb;
pub use crate::legend::Legend;
pub use crate::shapes::Shape;
pub use crate::texts::Text;
pub use crate::traces::barplot::{BarPlot, HorizontalBarPlot, VerticalBarPlot};
pub use crate::traces::boxplot::{BoxPlot, HorizontalBoxPlot, VerticalBoxPlot};
Expand Down
295 changes: 295 additions & 0 deletions src/shapes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
use plotly::common::MarkerSymbol;

pub enum Shape {
Circle,
CircleOpen,
CircleDot,
CircleOpenDot,
Square,
SquareOpen,
SquareDot,
SquareOpenDot,
Diamond,
DiamondOpen,
DiamondDot,
DiamondOpenDot,
Cross,
CrossOpen,
CrossDot,
CrossOpenDot,
X,
XOpen,
XDot,
XOpenDot,
TriangleUp,
TriangleUpOpen,
TriangleUpDot,
TriangleUpOpenDot,
TriangleDown,
TriangleDownOpen,
TriangleDownDot,
TriangleDownOpenDot,
TriangleLeft,
TriangleLeftOpen,
TriangleLeftDot,
TriangleLeftOpenDot,
TriangleRight,
TriangleRightOpen,
TriangleRightDot,
TriangleRightOpenDot,
TriangleNE,
TriangleNEOpen,
TriangleNEDot,
TriangleNEOpenDot,
TriangleSE,
TriangleSEOpen,
TriangleSEDot,
TriangleSEOpenDot,
TriangleSW,
TriangleSWOpen,
TriangleSWDot,
TriangleSWOpenDot,
TriangleNW,
TriangleNWOpen,
TriangleNWDot,
TriangleNWOpenDot,
Pentagon,
PentagonOpen,
PentagonDot,
PentagonOpenDot,
Hexagon,
HexagonOpen,
HexagonDot,
HexagonOpenDot,
Hexagon2,
Hexagon2Open,
Hexagon2Dot,
Hexagon2OpenDot,
Octagon,
OctagonOpen,
OctagonDot,
OctagonOpenDot,
Star,
StarOpen,
StarDot,
StarOpenDot,
Hexagram,
HexagramOpen,
HexagramDot,
HexagramOpenDot,
StarTriangleUp,
StarTriangleUpOpen,
StarTriangleUpDot,
StarTriangleUpOpenDot,
StarTriangleDown,
StarTriangleDownOpen,
StarTriangleDownDot,
StarTriangleDownOpenDot,
StarSquare,
StarSquareOpen,
StarSquareDot,
StarSquareOpenDot,
StarDiamond,
StarDiamondOpen,
StarDiamondDot,
StarDiamondOpenDot,
DiamondTall,
DiamondTallOpen,
DiamondTallDot,
DiamondTallOpenDot,
DiamondWide,
DiamondWideOpen,
DiamondWideDot,
DiamondWideOpenDot,
Hourglass,
HourglassOpen,
BowTie,
BowTieOpen,
CircleCross,
CircleCrossOpen,
CircleX,
CircleXOpen,
SquareCross,
SquareCrossOpen,
SquareX,
SquareXOpen,
DiamondCross,
DiamondCrossOpen,
DiamondX,
DiamondXOpen,
CrossThin,
CrossThinOpen,
XThin,
XThinOpen,
Asterisk,
AsteriskOpen,
Hash,
HashOpen,
HashDot,
HashOpenDot,
YUp,
YUpOpen,
YDown,
YDownOpen,
YLeft,
YLeftOpen,
YRight,
YRightOpen,
LineEW,
LineEWOpen,
LineNS,
LineNSOpen,
LineNE,
LineNEOpen,
LineNW,
LineNWOpen,
}

impl Shape {
pub fn get_shape(&self) -> MarkerSymbol {
match self {
Shape::Circle => MarkerSymbol::Circle,
Shape::CircleOpen => MarkerSymbol::CircleOpen,
Shape::CircleDot => MarkerSymbol::CircleDot,
Shape::CircleOpenDot => MarkerSymbol::CircleOpenDot,
Shape::Square => MarkerSymbol::Square,
Shape::SquareOpen => MarkerSymbol::SquareOpen,
Shape::SquareDot => MarkerSymbol::SquareDot,
Shape::SquareOpenDot => MarkerSymbol::SquareOpenDot,
Shape::Diamond => MarkerSymbol::Diamond,
Shape::DiamondOpen => MarkerSymbol::DiamondOpen,
Shape::DiamondDot => MarkerSymbol::DiamondDot,
Shape::DiamondOpenDot => MarkerSymbol::DiamondOpenDot,
Shape::Cross => MarkerSymbol::Cross,
Shape::CrossOpen => MarkerSymbol::CrossOpen,
Shape::CrossDot => MarkerSymbol::CrossDot,
Shape::CrossOpenDot => MarkerSymbol::CrossOpenDot,
Shape::X => MarkerSymbol::X,
Shape::XOpen => MarkerSymbol::XOpen,
Shape::XDot => MarkerSymbol::XDot,
Shape::XOpenDot => MarkerSymbol::XOpenDot,
Shape::TriangleUp => MarkerSymbol::TriangleUp,
Shape::TriangleUpOpen => MarkerSymbol::TriangleUpOpen,
Shape::TriangleUpDot => MarkerSymbol::TriangleUpDot,
Shape::TriangleUpOpenDot => MarkerSymbol::TriangleUpOpenDot,
Shape::TriangleDown => MarkerSymbol::TriangleDown,
Shape::TriangleDownOpen => MarkerSymbol::TriangleDownOpen,
Shape::TriangleDownDot => MarkerSymbol::TriangleDownDot,
Shape::TriangleDownOpenDot => MarkerSymbol::TriangleDownOpenDot,
Shape::TriangleLeft => MarkerSymbol::TriangleLeft,
Shape::TriangleLeftOpen => MarkerSymbol::TriangleLeftOpen,
Shape::TriangleLeftDot => MarkerSymbol::TriangleLeftDot,
Shape::TriangleLeftOpenDot => MarkerSymbol::TriangleLeftOpenDot,
Shape::TriangleRight => MarkerSymbol::TriangleRight,
Shape::TriangleRightOpen => MarkerSymbol::TriangleRightOpen,
Shape::TriangleRightDot => MarkerSymbol::TriangleRightDot,
Shape::TriangleRightOpenDot => MarkerSymbol::TriangleRightOpenDot,
Shape::TriangleNE => MarkerSymbol::TriangleNE,
Shape::TriangleNEOpen => MarkerSymbol::TriangleNEOpen,
Shape::TriangleNEDot => MarkerSymbol::TriangleNEDot,
Shape::TriangleNEOpenDot => MarkerSymbol::TriangleNEOpenDot,
Shape::TriangleSE => MarkerSymbol::TriangleSE,
Shape::TriangleSEOpen => MarkerSymbol::TriangleSEOpen,
Shape::TriangleSEDot => MarkerSymbol::TriangleSEDot,
Shape::TriangleSEOpenDot => MarkerSymbol::TriangleSEOpenDot,
Shape::TriangleSW => MarkerSymbol::TriangleSW,
Shape::TriangleSWOpen => MarkerSymbol::TriangleSWOpen,
Shape::TriangleSWDot => MarkerSymbol::TriangleSWDot,
Shape::TriangleSWOpenDot => MarkerSymbol::TriangleSWOpenDot,
Shape::TriangleNW => MarkerSymbol::TriangleNW,
Shape::TriangleNWOpen => MarkerSymbol::TriangleNWOpen,
Shape::TriangleNWDot => MarkerSymbol::TriangleNWDot,
Shape::TriangleNWOpenDot => MarkerSymbol::TriangleNWOpenDot,
Shape::Pentagon => MarkerSymbol::Pentagon,
Shape::PentagonOpen => MarkerSymbol::PentagonOpen,
Shape::PentagonDot => MarkerSymbol::PentagonDot,
Shape::PentagonOpenDot => MarkerSymbol::PentagonOpenDot,
Shape::Hexagon => MarkerSymbol::Hexagon,
Shape::HexagonOpen => MarkerSymbol::HexagonOpen,
Shape::HexagonDot => MarkerSymbol::HexagonDot,
Shape::HexagonOpenDot => MarkerSymbol::HexagonOpenDot,
Shape::Hexagon2 => MarkerSymbol::Hexagon2,
Shape::Hexagon2Open => MarkerSymbol::Hexagon2Open,
Shape::Hexagon2Dot => MarkerSymbol::Hexagon2Dot,
Shape::Hexagon2OpenDot => MarkerSymbol::Hexagon2OpenDot,
Shape::Octagon => MarkerSymbol::Octagon,
Shape::OctagonOpen => MarkerSymbol::OctagonOpen,
Shape::OctagonDot => MarkerSymbol::OctagonDot,
Shape::OctagonOpenDot => MarkerSymbol::OctagonOpenDot,
Shape::Star => MarkerSymbol::Star,
Shape::StarOpen => MarkerSymbol::StarOpen,
Shape::StarDot => MarkerSymbol::StarDot,
Shape::StarOpenDot => MarkerSymbol::StarOpenDot,
Shape::Hexagram => MarkerSymbol::Hexagram,
Shape::HexagramOpen => MarkerSymbol::HexagramOpen,
Shape::HexagramDot => MarkerSymbol::HexagramDot,
Shape::HexagramOpenDot => MarkerSymbol::HexagramOpenDot,
Shape::StarTriangleUp => MarkerSymbol::StarTriangleUp,
Shape::StarTriangleUpOpen => MarkerSymbol::StarTriangleUpOpen,
Shape::StarTriangleUpDot => MarkerSymbol::StarTriangleUpDot,
Shape::StarTriangleUpOpenDot => MarkerSymbol::StarTriangleUpOpenDot,
Shape::StarTriangleDown => MarkerSymbol::StarTriangleDown,
Shape::StarTriangleDownOpen => MarkerSymbol::StarTriangleDownOpen,
Shape::StarTriangleDownDot => MarkerSymbol::StarTriangleDownDot,
Shape::StarTriangleDownOpenDot => MarkerSymbol::StarTriangleDownOpenDot,
Shape::StarSquare => MarkerSymbol::StarSquare,
Shape::StarSquareOpen => MarkerSymbol::StarSquareOpen,
Shape::StarSquareDot => MarkerSymbol::StarSquareDot,
Shape::StarSquareOpenDot => MarkerSymbol::StarSquareOpenDot,
Shape::StarDiamond => MarkerSymbol::StarDiamond,
Shape::StarDiamondOpen => MarkerSymbol::StarDiamondOpen,
Shape::StarDiamondDot => MarkerSymbol::StarDiamondDot,
Shape::StarDiamondOpenDot => MarkerSymbol::StarDiamondOpenDot,
Shape::DiamondTall => MarkerSymbol::DiamondTall,
Shape::DiamondTallOpen => MarkerSymbol::DiamondTallOpen,
Shape::DiamondTallDot => MarkerSymbol::DiamondTallDot,
Shape::DiamondTallOpenDot => MarkerSymbol::DiamondTallOpenDot,
Shape::DiamondWide => MarkerSymbol::DiamondWide,
Shape::DiamondWideOpen => MarkerSymbol::DiamondWideOpen,
Shape::DiamondWideDot => MarkerSymbol::DiamondWideDot,
Shape::DiamondWideOpenDot => MarkerSymbol::DiamondWideOpenDot,
Shape::Hourglass => MarkerSymbol::Hourglass,
Shape::HourglassOpen => MarkerSymbol::HourglassOpen,
Shape::BowTie => MarkerSymbol::BowTie,
Shape::BowTieOpen => MarkerSymbol::BowTieOpen,
Shape::CircleCross => MarkerSymbol::CircleCross,
Shape::CircleCrossOpen => MarkerSymbol::CircleCrossOpen,
Shape::CircleX => MarkerSymbol::CircleX,
Shape::CircleXOpen => MarkerSymbol::CircleXOpen,
Shape::SquareCross => MarkerSymbol::SquareCross,
Shape::SquareCrossOpen => MarkerSymbol::SquareCrossOpen,
Shape::SquareX => MarkerSymbol::SquareX,
Shape::SquareXOpen => MarkerSymbol::SquareXOpen,
Shape::DiamondCross => MarkerSymbol::DiamondCross,
Shape::DiamondCrossOpen => MarkerSymbol::DiamondCrossOpen,
Shape::DiamondX => MarkerSymbol::DiamondX,
Shape::DiamondXOpen => MarkerSymbol::DiamondXOpen,
Shape::CrossThin => MarkerSymbol::CrossThin,
Shape::CrossThinOpen => MarkerSymbol::CrossThinOpen,
Shape::XThin => MarkerSymbol::XThin,
Shape::XThinOpen => MarkerSymbol::XThinOpen,
Shape::Asterisk => MarkerSymbol::Asterisk,
Shape::AsteriskOpen => MarkerSymbol::AsteriskOpen,
Shape::Hash => MarkerSymbol::Hash,
Shape::HashOpen => MarkerSymbol::HashOpen,
Shape::HashDot => MarkerSymbol::HashDot,
Shape::HashOpenDot => MarkerSymbol::HashOpenDot,
Shape::YUp => MarkerSymbol::YUp,
Shape::YUpOpen => MarkerSymbol::YUpOpen,
Shape::YDown => MarkerSymbol::YDown,
Shape::YDownOpen => MarkerSymbol::YDownOpen,
Shape::YLeft => MarkerSymbol::YLeft,
Shape::YLeftOpen => MarkerSymbol::YLeftOpen,
Shape::YRight => MarkerSymbol::YRight,
Shape::YRightOpen => MarkerSymbol::YRightOpen,
Shape::LineEW => MarkerSymbol::LineEW,
Shape::LineEWOpen => MarkerSymbol::LineEWOpen,
Shape::LineNS => MarkerSymbol::LineNS,
Shape::LineNSOpen => MarkerSymbol::LineNSOpen,
Shape::LineNE => MarkerSymbol::LineNE,
Shape::LineNEOpen => MarkerSymbol::LineNEOpen,
Shape::LineNW => MarkerSymbol::LineNW,
Shape::LineNWOpen => MarkerSymbol::LineNWOpen,
}
}
}
Loading