| 80 | // that the circles drawn around nodes’ center points don't get cut off. |
| 81 | |
| 82 | class Scale { |
| 83 | constructor(layout, width, height) { |
| 84 | let xs = layout.map(node => node.x); |
| 85 | let ys = layout.map(node => node.y); |
| 86 | let minX = Math.min(...xs); |
| 87 | let minY = Math.min(...ys); |
| 88 | let maxX = Math.max(...xs); |
| 89 | let maxY = Math.max(...ys); |
| 90 | |
| 91 | this.offsetX = minX; this.offsetY = minY; |
| 92 | this.scaleX = (width - 2 * nodeSize) / (maxX - minX); |
| 93 | this.scaleY = (height - 2 * nodeSize) / (maxY - minY); |
| 94 | } |
| 95 | |
| 96 | // The `x` and `y` methods convert from graph coordinates into |
| 97 | // canvas coordinates. |
| 98 | x(x) { |
| 99 | return this.scaleX * (x - this.offsetX) + nodeSize; |
| 100 | } |
| 101 | y(y) { |
| 102 | return this.scaleY * (y - this.offsetY) + nodeSize; |
| 103 | } |
| 104 | } |
nothing calls this directly
no outgoing calls
no test coverage detected