Skip to content

Commit

Permalink
Do not use DataItem unnecessarily
Browse files Browse the repository at this point in the history
As `stroke` and `stroke_width` are not dynamic fields
  • Loading branch information
aleics committed Oct 25, 2024
1 parent 07ab6de commit b161400
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
12 changes: 2 additions & 10 deletions bruc-core/src/graph/node/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,10 @@ impl LineOperator {
.shape
.props
.stroke
.as_ref()
.and_then(|stroke| stroke.get_text())
.cloned()
.clone()
.unwrap_or("black".to_string());

let stroke_width = self
.shape
.props
.stroke_width
.as_ref()
.and_then(|stroke_width| stroke_width.get_number().copied())
.unwrap_or(1.0);
let stroke_width = self.shape.props.stroke_width.unwrap_or(1.0);

vec![SceneItem::line(points, stroke, stroke_width)]
}
Expand Down
13 changes: 6 additions & 7 deletions bruc-core/src/spec/shape/line.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::spec::shape::base::BaseShapeProperties;
use crate::spec::shape::DataSource;
use bruc_expression::data::DataItem;

pub(crate) struct LinePropertiesBuilder {

Check warning on line 4 in bruc-core/src/spec/shape/line.rs

View workflow job for this annotation

GitHub Actions / Build, lint, test

struct `LinePropertiesBuilder` is never constructed

Check warning on line 4 in bruc-core/src/spec/shape/line.rs

View workflow job for this annotation

GitHub Actions / Build, lint, test

struct `LinePropertiesBuilder` is never constructed

Check warning on line 4 in bruc-core/src/spec/shape/line.rs

View workflow job for this annotation

GitHub Actions / Bench

struct `LinePropertiesBuilder` is never constructed
x: Option<DataSource>,
y: Option<DataSource>,
interpolate: Interpolate,
stroke: Option<DataItem>,
stroke_width: Option<DataItem>,
stroke: Option<String>,
stroke_width: Option<f32>,
}

impl LinePropertiesBuilder {
Expand Down Expand Up @@ -37,12 +36,12 @@ impl LinePropertiesBuilder {
}

pub(crate) fn with_stroke(mut self, stroke: &str) -> Self {
self.stroke = Some(stroke.to_string().into());
self.stroke = Some(stroke.to_string());
self
}

pub(crate) fn with_stroke_width(mut self, stroke_width: f32) -> Self {
self.stroke_width = Some(stroke_width.into());
self.stroke_width = Some(stroke_width);
self
}

Expand Down Expand Up @@ -78,8 +77,8 @@ impl LineShape {
pub(crate) struct LineProperties {
#[cfg_attr(feature = "serde", serde(default))]
pub(crate) interpolate: Interpolate,
pub(crate) stroke: Option<DataItem>,
pub(crate) stroke_width: Option<DataItem>,
pub(crate) stroke: Option<String>,
pub(crate) stroke_width: Option<f32>,
#[cfg_attr(feature = "serde", serde(flatten))]
pub(crate) base: BaseShapeProperties,
}
Expand Down

0 comments on commit b161400

Please sign in to comment.