* Compose the SVG template
(parsedOptions: ParsedInfographicOptions)
| 133 | * Compose the SVG template |
| 134 | */ |
| 135 | compose(parsedOptions: ParsedInfographicOptions): SVGSVGElement { |
| 136 | const { design, data, themeConfig } = parsedOptions; |
| 137 | const { title, item, items, structure } = design; |
| 138 | const { component: Structure, props: structureProps } = structure; |
| 139 | const Title = title.component; |
| 140 | const Item = item.component; |
| 141 | const Items = items.map((it) => it.component); |
| 142 | |
| 143 | // Apply theme font-family before measurement so measureText uses the correct font |
| 144 | const themeFontFamily = themeConfig?.base?.text?.['font-family']; |
| 145 | const previousDefaultFont = DEFAULT_FONT; |
| 146 | if (themeFontFamily) setDefaultFont(themeFontFamily); |
| 147 | |
| 148 | try { |
| 149 | const svg = renderSVG( |
| 150 | <Structure |
| 151 | data={data} |
| 152 | Title={Title} |
| 153 | Item={Item} |
| 154 | Items={Items} |
| 155 | options={parsedOptions} |
| 156 | {...structureProps} |
| 157 | />, |
| 158 | ); |
| 159 | |
| 160 | const template = parseSVG(svg); |
| 161 | if (!template) { |
| 162 | throw new Error('Failed to parse SVG template'); |
| 163 | } |
| 164 | return template; |
| 165 | } finally { |
| 166 | // Restore previous default font |
| 167 | if (themeFontFamily) setDefaultFont(previousDefaultFont); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | getTypes() { |
| 172 | const parsedOptions = this.parsedOptions; |
no test coverage detected