import { s8 , Node , createDiv , rectangle } from '@topology/core' ; export const echartsObjs = { } ; export function echarts ( ctx , node ) { rectangle ( ctx , node ) ; let echarts = echartsObjs . echarts ; if ( ! echarts && window ) { echarts = window [ 'echarts' ] ; } if ( ! node . data || ! echarts ) { return ; } if ( typeof node . data === 'string' ) { node . data = JSON . parse ( node . data ) ; } if ( ! node . data . echarts ) { return ; } if ( node . elementId === undefined || node . elementId === null ) { node . elementId = s8 ( ) ; } if ( ! node . elementLoaded ) { echartsObjs [ node . id ] = { div : createDiv ( node ) , } ; node . elementLoaded = true ; document . body . appendChild ( echartsObjs [ node . id ] . div ) ; node . addToDiv ( ) ; echartsObjs [ node . id ] . chart = echarts . init ( echartsObjs [ node . id ] . div , node . data . echarts . theme ) ; node . elementRendered = false ; setTimeout ( ( ) => { echartsObjs [ node . id ] . chart . resize ( ) ; } ) ; } if ( ! node . elementRendered ) { setTimeout ( ( ) => { echartsObjs [ node . id ] . chart . setOption ( node . data . echarts . option , true ) ; echartsObjs [ node . id ] . chart . resize ( ) ; node . elementRendered = true ; setTimeout ( ( ) => { const img = new Image ( ) ; img . src = echartsObjs [ node . id ] . chart . getDataURL ( { pixelRatio : 2 } ) ; node . img = img ; } , 100 ) ; } ) ; } }