use crate::data::DataFrame;
use super::dodge::dodge_rows;
use super::{Position, PositionParams};
#[derive(Clone, Debug, PartialEq)]
pub struct PositionDodge2 {
pub padding: f64,
pub width: Option<f64>,
pub reverse: bool,
}
impl PositionDodge2 {
pub fn new(padding: f64) -> Self {
PositionDodge2 {
padding,
..Default::default()
}
}
pub fn with_width(mut self, width: f64) -> Self {
self.width = Some(width);
self
}
pub fn with_reverse(mut self, reverse: bool) -> Self {
self.reverse = reverse;
self
}
}
impl Default for PositionDodge2 {
fn default() -> Self {
PositionDodge2 {
padding: 0.1,
width: None,
reverse: false,
}
}
}
impl Position for PositionDodge2 {
fn compute(&self, data: &mut DataFrame, params: &PositionParams) {
dodge_rows(
data,
self.width.unwrap_or(params.width),
Some(self.padding),
self.reverse,
);
}
fn name(&self) -> &str {
"dodge2"
}
}