Chart -> ChartOutput

This commit is contained in:
Simon Gardling 2022-02-16 09:45:53 -05:00
parent 7c122b24d3
commit 28a656bd91
2 changed files with 6 additions and 6 deletions

View File

@ -5,7 +5,7 @@ use std::panic;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use web_sys::HtmlCanvasElement; use web_sys::HtmlCanvasElement;
mod misc; mod misc;
use crate::misc::{Chart, DrawResult, Cache}; use crate::misc::{ChartOutput, DrawResult, Cache};
#[global_allocator] #[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
@ -118,7 +118,7 @@ impl ChartManager {
pub fn update( pub fn update(
&mut self, canvas: HtmlCanvasElement, func_str: &str, min_x: f32, max_x: f32, min_y: f32, &mut self, canvas: HtmlCanvasElement, func_str: &str, min_x: f32, max_x: f32, min_y: f32,
max_y: f32, num_interval: usize, resolution: i32, max_y: f32, num_interval: usize, resolution: i32,
) -> Result<Chart, JsValue> { ) -> Result<ChartOutput, JsValue> {
let underlying_update = (*func_str != self.func_str) let underlying_update = (*func_str != self.func_str)
| (min_x != self.min_x) | (min_x != self.min_x)
| (max_x != self.max_x) | (max_x != self.max_x)
@ -158,12 +158,12 @@ impl ChartManager {
let draw_output = self.draw(canvas).map_err(|err| err.to_string())?; let draw_output = self.draw(canvas).map_err(|err| err.to_string())?;
let map_coord = draw_output.0; let map_coord = draw_output.0;
let chart = Chart { let chart_output = ChartOutput {
convert: Box::new(move |coord| map_coord(coord).map(|(x, y)| (x, y))), convert: Box::new(move |coord| map_coord(coord).map(|(x, y)| (x, y))),
area: draw_output.1, area: draw_output.1,
}; };
Ok(chart) Ok(chart_output)
} }
// Creates and does the math for creating all the rectangles under the graph // Creates and does the math for creating all the rectangles under the graph

View File

@ -16,13 +16,13 @@ impl Point {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub struct Chart { pub struct ChartOutput {
pub(crate) convert: Box<dyn Fn((i32, i32)) -> Option<(f32, f32)>>, pub(crate) convert: Box<dyn Fn((i32, i32)) -> Option<(f32, f32)>>,
pub(crate) area: f32, pub(crate) area: f32,
} }
#[wasm_bindgen] #[wasm_bindgen]
impl Chart { impl ChartOutput {
pub fn get_area(&self) -> f32 { self.area } pub fn get_area(&self) -> f32 { self.area }
pub fn coord(&self, x: i32, y: i32) -> Option<Point> { pub fn coord(&self, x: i32, y: i32) -> Option<Point> {