Actually create ECharts instance, set option, and wire up resize + dispose.
( container: HTMLElement, option: echarts.EChartsOption, chartInstances?: Set<echarts.ECharts> )
| 3378 | |
| 3379 | /** Actually create ECharts instance, set option, and wire up resize + dispose. */ |
| 3380 | function 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 | } |
no test coverage detected