| 156 | } |
| 157 | |
| 158 | function ensureGraphSvg() { |
| 159 | // Get latest width/height from state.js |
| 160 | let svgEl = d3.select('#graph').select('svg'); |
| 161 | if (svgEl.empty()) { |
| 162 | svgEl = d3.select('#graph').append('svg') |
| 163 | .attr('width', width) |
| 164 | .attr('height', height) |
| 165 | .attr('id', 'graph-svg'); |
| 166 | } else { |
| 167 | svgEl.attr('width', width).attr('height', height); |
| 168 | } |
| 169 | let gEl = svgEl.select('g'); |
| 170 | if (gEl.empty()) { |
| 171 | gEl = svgEl.append('g'); |
| 172 | } |
| 173 | return { svg: svgEl, g: gEl }; |
| 174 | } |
| 175 | |
| 176 | function applyDragHandlersToAllNodes() { |
| 177 | if (!g) return; |