* Build a GroupNodeData from a diagram drawing XML string. * Diagram drawings use dsp: namespace (drawingml 2008); structure is dsp:drawing > dsp:spTree > dsp:sp. * Diagram shapes are positioned in the graphicFrame's own coordinate space.
( base: ReturnType<typeof parseBaseProps>, drawingXml: string )
| 183 | * Diagram shapes are positioned in the graphicFrame's own coordinate space. |
| 184 | */ |
| 185 | function buildDiagramGroup( |
| 186 | base: ReturnType<typeof parseBaseProps>, |
| 187 | drawingXml: string |
| 188 | ): GroupNodeData { |
| 189 | const drawingRoot = parseXml(drawingXml) |
| 190 | const spTree = drawingRoot.child('spTree') |
| 191 | if (!spTree.exists()) { |
| 192 | return { |
| 193 | ...base, |
| 194 | nodeType: 'group', |
| 195 | childOffset: { x: 0, y: 0 }, |
| 196 | childExtent: { w: base.size.w, h: base.size.h }, |
| 197 | children: [], |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | const CHILD_TAGS = new Set(['sp', 'pic', 'grpSp', 'graphicFrame', 'cxnSp']) |
| 202 | const children: SafeXmlNode[] = [] |
| 203 | |
| 204 | for (const child of spTree.allChildren()) { |
| 205 | if (CHILD_TAGS.has(child.localName)) { |
| 206 | children.push(child) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Use the graphicFrame's own dimensions as the child coordinate space. |
| 211 | // Diagram shapes are positioned in the frame's coordinate space (EMU converted to px). |
| 212 | // Using frame dimensions gives a 1:1 scale, preserving original positions and sizes. |
| 213 | // This avoids enlarging shapes when the bounding box is smaller than the frame. |
| 214 | const extentW = Math.max(1, base.size.w) |
| 215 | const extentH = Math.max(1, base.size.h) |
| 216 | |
| 217 | return { |
| 218 | ...base, |
| 219 | nodeType: 'group', |
| 220 | childOffset: { x: 0, y: 0 }, |
| 221 | childExtent: { w: extentW, h: extentH }, |
| 222 | children, |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Parse a single child node from spTree, dispatching to the appropriate parser. |
no test coverage detected