this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

✨ Add moar filters

authored by

Gwenn Le Bihan and committed by
Ewen Le Bihan
d6dc0861 763e2e47

+87 -12
-1
src/canvas.rs
··· 431 431 svg = svg.add(layer.render(self.colormap.clone(), self.cell_size, layer.object_sizes)); 432 432 } 433 433 434 - svg = svg.add(Filter::Glow.definition()); 435 434 436 435 svg.set( 437 436 "viewBox",
+82 -11
src/filter.rs
··· 3 3 use crate::RenderCSS; 4 4 5 5 #[wasm_bindgen] 6 - #[derive(Debug, Clone, Copy)] 7 - pub enum Filter { 6 + #[derive(Debug, Clone, Copy, PartialEq)] 7 + pub enum FilterType { 8 8 Glow, 9 + NaturalShadow, 10 + Saturation, 11 + } 12 + 13 + #[wasm_bindgen] 14 + #[derive(Debug, Clone, Copy)] 15 + pub struct Filter { 16 + pub kind: FilterType, 17 + pub parameter: f32, 9 18 } 10 19 11 20 impl Filter { 21 + pub fn name(&self) -> &str { 22 + match self.kind { 23 + FilterType::Glow => "glow", 24 + FilterType::NaturalShadow => "natural-shadow-filter", 25 + FilterType::Saturation => "saturation", 26 + } 27 + } 28 + 29 + pub fn id(&self) -> String { 30 + format!( 31 + "{}-{}", 32 + self.name(), 33 + self.parameter.to_string().replace(".", "_") 34 + ) 35 + } 36 + 12 37 pub fn definition(&self) -> svg::node::element::Filter { 13 - match self { 14 - Filter::Glow => { 38 + match self.kind { 39 + FilterType::Glow => { 15 40 // format!( 16 41 // r#" 17 42 // <filter id="glow"> ··· 25 50 // 2.5 26 51 // ) // TODO parameterize stdDeviation 27 52 svg::node::element::Filter::new() 28 - .set("id", "glow") 29 53 .add( 30 54 // TODO parameterize stdDeviation 31 55 svg::node::element::FilterEffectGaussianBlur::new() 32 - .set("stdDeviation", 5) 56 + .set("stdDeviation", self.parameter) 33 57 .set("result", "coloredBlur"), 34 58 ) 35 59 .add( ··· 44 68 ), 45 69 ) 46 70 } 71 + FilterType::NaturalShadow => { 72 + /* 73 + <filter id="natural-shadow-filter" x="0" y="0" width="2" height="2"> 74 + <feOffset in="SourceGraphic" dx="3" dy="3" /> 75 + <feGaussianBlur stdDeviation="12" result="blur" /> 76 + <feMerge> 77 + <feMergeNode in="blur" /> 78 + <feMergeNode in="SourceGraphic" /> 79 + </feMerge> 80 + </filter> 81 + */ 82 + svg::node::element::Filter::new() 83 + .add( 84 + svg::node::element::FilterEffectOffset::new() 85 + .set("in", "SourceGraphic") 86 + .set("dx", self.parameter) 87 + .set("dy", self.parameter), 88 + ) 89 + .add( 90 + svg::node::element::FilterEffectGaussianBlur::new() 91 + .set("stdDeviation", self.parameter * 4.0) 92 + .set("result", "blur"), 93 + ) 94 + .add( 95 + svg::node::element::FilterEffectMerge::new() 96 + .add(svg::node::element::FilterEffectMergeNode::new().set("in", "blur")) 97 + .add( 98 + svg::node::element::FilterEffectMergeNode::new() 99 + .set("in", "SourceGraphic"), 100 + ), 101 + ) 102 + } 103 + FilterType::Saturation => { 104 + /* 105 + <filter id="saturation"> 106 + <feColorMatrix type="saturate" values="0.5"/> 107 + </filter> 108 + */ 109 + svg::node::element::Filter::new().add( 110 + svg::node::element::FilterEffectColorMatrix::new() 111 + .set("type", "saturate") 112 + .set("values", self.parameter), 113 + ) 114 + } 47 115 } 48 116 } 49 117 } 50 118 51 119 impl RenderCSS for Filter { 52 120 fn render_fill_css(&self, _colormap: &crate::ColorMapping) -> String { 53 - match self { 54 - Filter::Glow => { 55 - format!("filter: url(#glow);") 56 - } 57 - } 121 + format!("filter: url(#{});", self.name()) 58 122 } 59 123 60 124 fn render_stroke_css(&self, colormap: &crate::ColorMapping) -> String { 61 125 self.render_fill_css(colormap) 62 126 } 63 127 } 128 + 129 + impl PartialEq for Filter { 130 + fn eq(&self, other: &Self) -> bool { 131 + // TODO use way less restrictive epsilon 132 + self.kind == other.kind && (self.parameter - other.parameter).abs() < f32::EPSILON 133 + } 134 + }
+5
src/objects.rs
··· 186 186 .as_ref(); 187 187 188 188 group = group.set("data-object", id).set("style", css); 189 + 190 + for f in filter { 191 + group = group.add(f.definition().set("id", f.id())) 192 + } 193 + 189 194 group 190 195 } 191 196