()
| 213 | } |
| 214 | |
| 215 | private _relayout() { |
| 216 | if (!this.state.data) return; |
| 217 | |
| 218 | this.g |
| 219 | .selectAll<SVGGElement, INode>(childSelector<SVGGElement>(SELECTOR_NODE)) |
| 220 | .selectAll<SVGForeignObjectElement, INode>( |
| 221 | childSelector<SVGForeignObjectElement>('foreignObject'), |
| 222 | ) |
| 223 | .each(function (d) { |
| 224 | const el = this.firstChild?.firstChild as HTMLDivElement; |
| 225 | const newSize: [number, number] = [el.scrollWidth, el.scrollHeight]; |
| 226 | d.state.size = newSize; |
| 227 | }); |
| 228 | |
| 229 | const { lineWidth, paddingX, spacingHorizontal, spacingVertical } = |
| 230 | this.options; |
| 231 | const layout = flextree<INode>({}) |
| 232 | .children((d) => { |
| 233 | if (!d.payload?.fold) return d.children; |
| 234 | }) |
| 235 | .nodeSize((node) => { |
| 236 | const [width, height] = node.data.state.size; |
| 237 | return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal]; |
| 238 | }) |
| 239 | .spacing((a, b) => { |
| 240 | return ( |
| 241 | (a.parent === b.parent ? spacingVertical : spacingVertical * 2) + |
| 242 | lineWidth(a.data) |
| 243 | ); |
| 244 | }); |
| 245 | const tree = layout.hierarchy(this.state.data); |
| 246 | layout(tree); |
| 247 | const fnodes = tree.descendants(); |
| 248 | fnodes.forEach((fnode) => { |
| 249 | const node = fnode.data; |
| 250 | node.state.rect = { |
| 251 | x: fnode.y, |
| 252 | y: fnode.x - fnode.xSize / 2, |
| 253 | width: fnode.ySize - spacingHorizontal, |
| 254 | height: fnode.xSize, |
| 255 | }; |
| 256 | }); |
| 257 | this.state.rect = { |
| 258 | x1: min(fnodes, (fnode) => fnode.data.state.rect.x) || 0, |
| 259 | y1: min(fnodes, (fnode) => fnode.data.state.rect.y) || 0, |
| 260 | x2: |
| 261 | max( |
| 262 | fnodes, |
| 263 | (fnode) => fnode.data.state.rect.x + fnode.data.state.rect.width, |
| 264 | ) || 0, |
| 265 | y2: |
| 266 | max( |
| 267 | fnodes, |
| 268 | (fnode) => fnode.data.state.rect.y + fnode.data.state.rect.height, |
| 269 | ) || 0, |
| 270 | }; |
| 271 | } |
| 272 |
no test coverage detected