MCPcopy Index your code
hub / github.com/simstudioai/sim / parseChartXml

Function parseChartXml

apps/sim/lib/pptx-renderer/renderer/chart-renderer.ts:3187–3296  ·  view source on GitHub ↗
(chartXml: SafeXmlNode, ctx: RenderContext)

Source from the content-addressed store, hash-verified

3185 * Exported for unit testing.
3186 */
3187export function parseChartXml(chartXml: SafeXmlNode, ctx: RenderContext): ParseChartResult {
3188 const chartCtx = createChartRenderContext(chartXml, ctx)
3189 const chartPalette = buildChartPalette(chartXml, chartCtx)
3190 // Navigate: chartSpace > chart > plotArea
3191 const chart = chartXml.child('chart')
3192 const plotArea = chart.child('plotArea')
3193
3194 if (!plotArea.exists()) {
3195 return { option: { title: { text: 'Unsupported chart', left: 'center' } } }
3196 }
3197
3198 // Extract background colors
3199 const { chartBg, plotAreaBg } = extractBackgroundColors(chartXml, chart, chartCtx)
3200
3201 const chartTypeEntries = CHART_TYPE_ELEMENTS.map((typeName) => {
3202 const chartTypeNode = plotArea.child(typeName)
3203 if (!chartTypeNode.exists()) return null
3204 const seriesArr = parseSeries(chartTypeNode, chartCtx)
3205 if (seriesArr.length === 0) return null
3206 return { typeName, chartTypeNode, seriesArr }
3207 }).filter(
3208 (
3209 entry
3210 ): entry is { typeName: OoxmlChartType; chartTypeNode: SafeXmlNode; seriesArr: SeriesData[] } =>
3211 entry !== null
3212 )
3213
3214 for (const [index, entry] of chartTypeEntries.entries()) {
3215 let option = buildOptionForChartType(
3216 entry.typeName,
3217 entry.chartTypeNode,
3218 chart,
3219 entry.seriesArr,
3220 chartCtx
3221 )
3222 if (!option) continue
3223
3224 if (index === 0 && chartTypeEntries.length > 1 && isCartesianComboCapable(entry.typeName)) {
3225 for (const comboEntry of chartTypeEntries.slice(1)) {
3226 if (!isCartesianComboCapable(comboEntry.typeName)) continue
3227 const comboOption = buildOptionForChartType(
3228 comboEntry.typeName,
3229 comboEntry.chartTypeNode,
3230 chart,
3231 comboEntry.seriesArr,
3232 chartCtx
3233 )
3234 if (!comboOption) continue
3235 option = mergeCartesianComboOptions(option, comboOption)
3236 }
3237 }
3238
3239 // Apply chart-space default font sizes to text elements that use hardcoded defaults
3240 const defaultFs = extractChartDefaultFontSize(chartXml)
3241 if (defaultFs) {
3242 applyDefaultFontSizes(option, defaultFs)
3243 }
3244 const defaultFontFamily = getChartThemeFontFamily(chartCtx)

Callers 1

renderChartFunction · 0.85

Calls 15

createChartRenderContextFunction · 0.85
buildChartPaletteFunction · 0.85
extractBackgroundColorsFunction · 0.85
parseSeriesFunction · 0.85
buildOptionForChartTypeFunction · 0.85
isCartesianComboCapableFunction · 0.85
applyDefaultFontSizesFunction · 0.85
getChartThemeFontFamilyFunction · 0.85
applyDefaultFontFamilyFunction · 0.85
applyLegendGridMarginsFunction · 0.85

Tested by

no test coverage detected