Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Jan 29, 2024
1 parent 9cb97c4 commit 3c9e88c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
6 changes: 6 additions & 0 deletions avenger-vega/src/image/reqwest_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub struct ReqwestImageFetcher {
client: Client,
}

impl Default for ReqwestImageFetcher {
fn default() -> Self {
Self::new()
}
}

impl ReqwestImageFetcher {
pub fn new() -> Self {
Self {
Expand Down
9 changes: 6 additions & 3 deletions avenger-vega/src/marks/group.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::error::VegaSceneGraphError;
use crate::marks::mark::{VegaMark, VegaMarkItem};
use crate::marks::values::CssColorOrGradient;
use avenger::marks::group::{GroupBounds, SceneGroup};
use avenger::marks::mark::SceneMark;
use avenger::marks::value::Gradient;
use serde::{Deserialize, Serialize};
use avenger::marks::value::{Gradient};
use crate::marks::values::CssColorOrGradient;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct VegaGroupItem {
Expand Down Expand Up @@ -91,7 +91,10 @@ impl VegaGroupItem {
};

Ok(SceneGroup {
name: self.name.clone().unwrap_or_else(|| "group_item".to_string()),
name: self
.name
.clone()
.unwrap_or_else(|| "group_item".to_string()),
bounds: GroupBounds {
x: self.x,
y: self.y,
Expand Down
11 changes: 2 additions & 9 deletions avenger-wgpu/src/marks/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use avenger::marks::group::GroupBounds;
use avenger::marks::text::{
FontStyleSpec, FontWeightNameSpec, FontWeightSpec, TextAlignSpec, TextBaselineSpec, TextMark,
};
use glyphon::fontdb::Database;

use glyphon::{
Attrs, Buffer, Color, ColorMode, Family, FontSystem, Metrics, Resolution, Shaping, SwashCache,
TextArea, TextAtlas, TextBounds, TextRenderer, Weight,
Expand All @@ -23,16 +23,9 @@ lazy_static! {

fn build_font_system() -> FontSystem {
let mut font_system = FontSystem::new();
let swash_cache = SwashCache::new();

let serif_family = Family::Serif;
let sans_serif_family = Family::SansSerif;
let cursive_family = Family::Cursive;
let fantasy_family = Family::Fantasy;
let monospace_family = Family::Monospace;

// Override default families based on what system fonts are available
let mut fontdb = font_system.db_mut();
let fontdb = font_system.db_mut();
let families: HashSet<String> = fontdb
.faces()
.flat_map(|face| {
Expand Down
50 changes: 37 additions & 13 deletions avenger/src/marks/group.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::marks::mark::SceneMark;
use serde::{Deserialize, Serialize};
use crate::marks::rect::RectMark;
use crate::marks::value::{ColorOrGradient, EncodingValue, Gradient};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct GroupBounds {
Expand Down Expand Up @@ -38,14 +38,16 @@ pub struct SceneGroup {
impl SceneGroup {
pub fn make_rect(&self) -> Option<RectMark> {
if self.fill.is_none() && self.stroke.is_none() {
return None
return None;
}
let stroke_width = self.stroke_width.unwrap_or(if self.stroke.is_some() { 1.0 } else { 0.0 });
let stroke_width =
self.stroke_width
.unwrap_or(if self.stroke.is_some() { 1.0 } else { 0.0 });
let stroke_offset = if let Some(stroke_offset) = self.stroke_offset {
stroke_offset
} else {
// From Vega's default stroke offset logic
if (self.stroke.is_some() && stroke_width > 0.5 && stroke_width < 1.5) {
if self.stroke.is_some() && stroke_width > 0.5 && stroke_width < 1.5 {
0.5 - (stroke_width - 1.0).abs()
} else {
0.0
Expand All @@ -56,15 +58,37 @@ impl SceneGroup {
clip: false,
len: 1,
gradients: self.gradients.clone(),
x: EncodingValue::Scalar { value: self.bounds.x + stroke_offset },
y: EncodingValue::Scalar { value: self.bounds.y + stroke_offset },
width: EncodingValue::Scalar { value: self.bounds.width.unwrap_or(0.0) },
height: EncodingValue::Scalar { value: self.bounds.height.unwrap_or(0.0) },
fill: EncodingValue::Scalar {value: self.fill.clone().unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0]))},
stroke: EncodingValue::Scalar {value: self.stroke.clone().unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0]))},
stroke_width: EncodingValue::Scalar { value: stroke_width },
corner_radius: EncodingValue::Scalar { value: self.corner_radius.unwrap_or(0.0) },
x: EncodingValue::Scalar {
value: self.bounds.x + stroke_offset,
},
y: EncodingValue::Scalar {
value: self.bounds.y + stroke_offset,
},
width: EncodingValue::Scalar {
value: self.bounds.width.unwrap_or(0.0),
},
height: EncodingValue::Scalar {
value: self.bounds.height.unwrap_or(0.0),
},
fill: EncodingValue::Scalar {
value: self
.fill
.clone()
.unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0])),
},
stroke: EncodingValue::Scalar {
value: self
.stroke
.clone()
.unwrap_or(ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0])),
},
stroke_width: EncodingValue::Scalar {
value: stroke_width,
},
corner_radius: EncodingValue::Scalar {
value: self.corner_radius.unwrap_or(0.0),
},
indices: None,
})
}
}
}

0 comments on commit 3c9e88c

Please sign in to comment.