MCPcopy
hub / github.com/simstudioai/sim / initChart

Function initChart

apps/sim/lib/pptx-renderer/renderer/chart-renderer.ts:3380–3413  ·  view source on GitHub ↗

Actually create ECharts instance, set option, and wire up resize + dispose.

(
  container: HTMLElement,
  option: echarts.EChartsOption,
  chartInstances?: Set<echarts.ECharts>
)

Source from the content-addressed store, hash-verified

3378
3379/** Actually create ECharts instance, set option, and wire up resize + dispose. */
3380function initChart(
3381 container: HTMLElement,
3382 option: echarts.EChartsOption,
3383 chartInstances?: Set<echarts.ECharts>
3384): void {
3385 try {
3386 const chart = echarts.init(container)
3387 chart.setOption(option)
3388 chartInstances?.add(chart)
3389
3390 // Handle container resize
3391 const ro = new ResizeObserver(() => {
3392 if (container.isConnected) {
3393 chart.resize()
3394 } else {
3395 // Container removed from DOM — dispose to prevent leaks
3396 ro.disconnect()
3397 if (!chart.isDisposed()) {
3398 chart.dispose()
3399 }
3400 chartInstances?.delete(chart)
3401 }
3402 })
3403 ro.observe(container)
3404 } catch (error) {
3405 logger.warn('Failed to initialize ECharts', { error })
3406 container.style.display = 'flex'
3407 container.style.alignItems = 'center'
3408 container.style.justifyContent = 'center'
3409 container.style.color = '#999'
3410 container.style.fontSize = '12px'
3411 container.textContent = 'Chart render error'
3412 }
3413}

Callers 1

renderChartFunction · 0.85

Calls 6

observeMethod · 0.80
disposeMethod · 0.65
deleteMethod · 0.65
warnMethod · 0.65
addMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected