-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: zoom and panning added + improved loading of graphml files
- Loading branch information
Showing
27 changed files
with
695 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,50 @@ | ||
use web_sys::CanvasRenderingContext2d; | ||
|
||
use super::closest_corner::calc_closest_corner; | ||
use crate::models::GridNode; | ||
use crate::{ | ||
components::CanvasState, | ||
models::GridNode, | ||
}; | ||
|
||
pub fn draw_edge( | ||
from: GridNode, | ||
to: GridNode, | ||
steps: &[GridNode], | ||
canvas: &CanvasRenderingContext2d, | ||
square_size: u32, | ||
state: CanvasState, | ||
) { | ||
let from_pos = from.to_canvas_pos(square_size); | ||
let to_pos = to.to_canvas_pos(square_size); | ||
let from_pos = from.to_canvas_pos(state); | ||
let to_pos = to.to_canvas_pos(state); | ||
|
||
let (from_x, from_y) = calc_closest_corner( | ||
from_pos, | ||
steps | ||
.first() | ||
.map_or(to_pos, |s| s.to_canvas_pos(square_size)), | ||
square_size, | ||
.map_or(to_pos, |s| s.to_canvas_pos(state)), | ||
state, | ||
); | ||
canvas.move_to(from_x, from_y); | ||
|
||
let mut last_is = state.is_on_canvas(from); | ||
for step in steps { | ||
let (step_x, step_y) = step.to_canvas_pos(square_size); | ||
let (step_x, step_y) = step.to_canvas_pos(state); | ||
|
||
let step_is = state.is_on_canvas(*step); | ||
if !last_is && !step_is { | ||
canvas.move_to(step_x, step_y); | ||
continue; | ||
} | ||
last_is = step_is; | ||
|
||
canvas.line_to(step_x, step_y); | ||
} | ||
|
||
let (to_x, to_y) = calc_closest_corner( | ||
to_pos, | ||
steps | ||
.last() | ||
.map_or(from_pos, |s| { | ||
s.to_canvas_pos(square_size) | ||
}), | ||
square_size, | ||
.map_or(from_pos, |s| s.to_canvas_pos(state)), | ||
state, | ||
); | ||
canvas.line_to(to_x, to_y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ mod state; | |
|
||
pub use pages::Home; | ||
pub use state::{ | ||
CanvasState, | ||
MapState, | ||
StateProvider, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.