Skip to content

Commit

Permalink
Failing code for graphviz webworker
Browse files Browse the repository at this point in the history
  • Loading branch information
oskari1 committed Dec 2, 2023
1 parent 477d6d3 commit 0c5428e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
16 changes: 5 additions & 11 deletions axiom-profiler-GUI/src/results/svg_result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::results;

use self::colors::HSVColour;
use super::{filters::{
filter_chain::{FilterChain, Msg as FilterChainMsg},
Expand All @@ -20,7 +22,6 @@ use smt_log_parser::{
},
};
use std::num::NonZeroUsize;
use viz_js::VizInstance;
use web_sys::window;
use yew::prelude::*;

Expand Down Expand Up @@ -106,6 +107,7 @@ impl Component for SVGResult {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::WorkerOutput(out) => {
ctx.link().send_message(Msg::UpdateSvgText(AttrValue::from(out.svg_text)));
false
}
Msg::ApplyFilter(filter) => {
Expand Down Expand Up @@ -173,16 +175,8 @@ impl Component for SVGResult {
);
log::debug!("Finished building dot output");
let link = ctx.link().clone();
wasm_bindgen_futures::spawn_local(async move {
let graphviz = VizInstance::new().await;
let options = viz_js::Options::default();
// options.engine = "twopi".to_string();
let svg = graphviz
.render_svg_element(dot_output, options)
.expect("Could not render graphviz");
let svg_text = svg.outer_html();
link.send_message(Msg::UpdateSvgText(AttrValue::from(svg_text)));
});
self.reset_worker(link);
self.send_worker_input(results::worker::WorkerInput { dot_file: dot_output });
// only need to re-render once the new SVG has been set
false
} else {
Expand Down
31 changes: 15 additions & 16 deletions axiom-profiler-GUI/src/results/worker.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use serde::{Deserialize, Serialize};
use yew_agent::{HandlerId, Private, WorkerLink};
use viz_js::VizInstance;

pub struct Worker {
link: WorkerLink<Self>,
}

#[derive(Serialize, Deserialize)]
pub struct WorkerInput {
pub n: u32,
pub dot_file: String,
}

#[derive(Serialize, Deserialize)]
pub struct WorkerOutput {
pub input: u32,
pub value: u32,
pub svg_text: String,
}

impl yew_agent::Worker for Worker {
Expand All @@ -34,19 +34,18 @@ impl yew_agent::Worker for Worker {
// this runs in a web worker
// and does not block the main
// browser thread!

let n = msg.n;

fn fib(n: u32) -> u32 {
if n <= 1 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}

let output = Self::Output { input: n, value: fib(n) };
self.link.respond(id, output);
let dot_file = msg.dot_file;
let link = self.link.clone();
wasm_bindgen_futures::spawn_local(async move {
let graphviz = VizInstance::new().await;
let options = viz_js::Options::default();
// options.engine = "twopi".to_string();
let svg = graphviz
.render_svg_element(dot_file, options)
.expect("Could not render graphviz");
let svg_text = svg.outer_html();
link.respond(id, Self::Output { svg_text } );
});
}

fn name_of_resource() -> &'static str {
Expand Down

0 comments on commit 0c5428e

Please sign in to comment.