(s, u)
| 40 | // Change the scaling for the svg to s, keeping the point denoted |
| 41 | // by u (in svg coordinates]) fixed at the same screen location. |
| 42 | function rescale(s, u) { |
| 43 | // Limit to a good range. |
| 44 | if (s < 0.2) s = 0.2; |
| 45 | if (s > 10.0) s = 10.0; |
| 46 | |
| 47 | currentScale = s; |
| 48 | |
| 49 | // svg.viewBox defines the visible portion of the user coordinate |
| 50 | // system. So to magnify by s, divide the visible portion by s, |
| 51 | // which will then be stretched to fit the viewport. |
| 52 | const vb = svg.viewBox; |
| 53 | const w1 = vb.baseVal.width; |
| 54 | const w2 = initWidth / s; |
| 55 | const h1 = vb.baseVal.height; |
| 56 | const h2 = initHeight / s; |
| 57 | vb.baseVal.width = w2; |
| 58 | vb.baseVal.height = h2; |
| 59 | |
| 60 | // We also want to adjust vb.baseVal.x so that u.x remains at same |
| 61 | // screen X coordinate. In other words, want to change it from x1 to x2 |
| 62 | // so that: |
| 63 | // (u.x - x1) / w1 = (u.x - x2) / w2 |
| 64 | // Simplifying that, we get |
| 65 | // (u.x - x1) * (w2 / w1) = u.x - x2 |
| 66 | // x2 = u.x - (u.x - x1) * (w2 / w1) |
| 67 | vb.baseVal.x = u.x - (u.x - vb.baseVal.x) * (w2 / w1); |
| 68 | vb.baseVal.y = u.y - (u.y - vb.baseVal.y) * (h2 / h1); |
| 69 | } |
| 70 | |
| 71 | function handleWheel(e) { |
| 72 | if (e.deltaY == 0) return; |
no outgoing calls
no test coverage detected
searching dependent graphs…