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

Fix wasm build and examples #37

Merged
merged 2 commits into from
Jan 27, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 7 additions & 16 deletions examples/scatter-panning/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions examples/scatter-panning/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use sg2d::marks::group::{GroupBounds, SceneGroup};
use sg2d::marks::mark::SceneMark;
use sg2d::marks::symbol::{SymbolMark, SymbolShape};
use sg2d::scene_graph::SceneGraph;
use sg2d::value::EncodingValue;
use sg2d_vega::dims::VegaSceneGraphDims;
use sg2d_vega::marks::symbol::shape_to_path;
use sg2d_vega::scene_graph::VegaSceneGraph;
use sg2d_wgpu::canvas::{Canvas, WindowCanvas};
use sg2d_wgpu::canvas::{Canvas, CanvasDimensions, WindowCanvas};
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
use sg2d::marks::value::{ColorOrGradient, EncodingValue};

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -63,21 +62,25 @@ pub async fn run() {

let mut x: Vec<f32> = Vec::new();
let mut y: Vec<f32> = Vec::new();
let mut fill: Vec<[f32; 4]> = Vec::new();
let mut fill: Vec<ColorOrGradient> = Vec::new();
let mut size: Vec<f32> = Vec::new();

let n = 100000;
for _ in 0..n {
x.push(rng.gen::<f32>() * inner_width + margin);
y.push(rng.gen::<f32>() * inner_height + margin);
size.push(rng.gen::<f32>() * 300.0 + 100.0);
fill.push([0.5, 0.5, rng.gen::<f32>(), 0.4]);
fill.push(ColorOrGradient::Color([0.5, 0.5, rng.gen::<f32>(), 0.4]));
}

let scene_graph = make_sg(width, height, &shape, &x, &y, &fill, &size, 0.0, 0.0);

// Save to png
let mut canvas = WindowCanvas::new(window, width, height, scale)
let dimensions = CanvasDimensions {
size: [width, height],
scale:scale,
};
let mut canvas = WindowCanvas::new(window, dimensions)
.await
.unwrap();

Expand Down Expand Up @@ -171,14 +174,14 @@ fn make_sg(
shape: &SymbolShape,
x: &[f32],
y: &[f32],
fill: &[[f32; 4]],
fill: &[ColorOrGradient],
size: &[f32],
x_offset: f32,
y_offset: f32,
) -> SceneGraph {
let x: Vec<f32> = x.iter().map(|v| *v + x_offset).collect();
let y: Vec<f32> = y.iter().map(|v| *v + y_offset).collect();
let fill: Vec<[f32; 4]> = Vec::from(fill);
let fill: Vec<ColorOrGradient> = Vec::from(fill);
let size: Vec<f32> = Vec::from(size);

SceneGraph {
Expand All @@ -192,18 +195,20 @@ fn make_sg(
marks: vec![SceneMark::Symbol(SymbolMark {
name: "scatter".to_string(),
clip: false,
shape: shape.clone(),
shapes: vec![shape.clone()],
stroke_width: None,
len: x.len() as u32,
x: EncodingValue::Array { values: x },
y: EncodingValue::Array { values: y },
fill: EncodingValue::Array { values: fill },
size: EncodingValue::Array { values: size },
stroke: EncodingValue::Scalar {
value: [0.0, 0.0, 0.0, 0.0],
value: ColorOrGradient::Color([0.0, 0.0, 0.0, 0.0]),
},
angle: EncodingValue::Scalar { value: 0.0 },
indices: None,
gradients: vec![],
shape_index: EncodingValue::Scalar { value: 0 }
})],
}],
width,
Expand Down
Loading
Loading