Commit beefa2b
fix: Save canvas position (#187)
This pull request enhances viewport management in the GlobalContext and
Viewport classes by adding support for saving, restoring, and centering
the view.
## Key Changes:
### On code
- GlobalContext: Added restorePosition and centerView to manage viewport
state.
- Viewport: Implemented methods to save/restore position and zoom, and
to set the center.
- viewportManager.ts: Automatically centers the viewport after loading a
file.
### On functionalities
- The viewport's position and zoom now persist after reloading.
- Pressing the "New" button centers the viewport in the middle of the
canvas.
- Loading a graph from a file centers the viewport on the graph's
centroid (Similar to a center of mass of a particle system).
## Known Bugs and Enhancements
- Pressing the "New" or "Load" buttons updates the layer in the
selector, but not in the left sidebar, causing inconsistencies in the
UI.
- The canvas boundaries are not visually indicated, which can be
problematic when building a network near the edges without realizing
you've reached the limit.
#### Before pressing new

#### Afther pressing new

#### Before load

#### After load

On both cases, the link layer is selected but the left bar only shows
hosts
Closes #92
---------
Co-authored-by: Tomás Grüner <[email protected]>1 parent ed0c452 commit beefa2b
File tree
4 files changed
+74
-10
lines changed- src
- graphics
- handlers
- types
4 files changed
+74
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
121 | 145 | | |
122 | 146 | | |
123 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | | - | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | | - | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
60 | 95 | | |
61 | 96 | | |
62 | 97 | | |
63 | | - | |
| 98 | + | |
| 99 | + | |
64 | 100 | | |
65 | 101 | | |
66 | 102 | | |
67 | 103 | | |
68 | 104 | | |
69 | 105 | | |
70 | 106 | | |
71 | | - | |
72 | 107 | | |
73 | 108 | | |
74 | 109 | | |
| |||
88 | 123 | | |
89 | 124 | | |
90 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
91 | 130 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | 179 | | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| |||
0 commit comments