@@ -66,13 +66,15 @@ export class WidgetDoughnut extends LitElement {
6666 this . resizeObserver . observe ( this )
6767
6868 this . template = {
69- title : {
70- text : 'Pie' ,
71- left : 'center' ,
72- textStyle : {
73- fontSize : 10
69+ title : [
70+ {
71+ text : 'Pie' ,
72+ left : 'center' ,
73+ textStyle : {
74+ fontSize : 10
75+ }
7476 }
75- } ,
77+ ] ,
7678 color : undefined ,
7779 // toolbox: {
7880 // show: true,
@@ -158,14 +160,6 @@ export class WidgetDoughnut extends LitElement {
158160 this . themeTitleColor = cssTextColor || this . theme ?. theme_object ?. title ?. textStyle ?. color
159161 this . themeSubtitleColor =
160162 cssTextColor || this . theme ?. theme_object ?. title ?. subtextStyle ?. color || this . themeTitleColor
161- console . log (
162- 'Theme colors' ,
163- this . themeBgColor ,
164- this . themeTitleColor ,
165- this . themeSubtitleColor ,
166- cssBgColor ,
167- cssTextColor
168- )
169163 if ( ! theme || ! theme . theme_object || ! theme . theme_name ) return
170164
171165 echarts . registerTheme ( theme . theme_name , theme . theme_object )
@@ -248,7 +242,10 @@ export class WidgetDoughnut extends LitElement {
248242 async transformData ( ) {
249243 if ( ! this ?. inputData ?. dataseries ?. length ) return
250244 // reset all existing chart dataseries
251- this . canvasList . forEach ( ( chartM : ChartCombination ) => ( chartM . dataSets = [ ] ) )
245+ this . canvasList . forEach ( ( chartM ) => {
246+ chartM . dataSets = [ ]
247+ chartM . doomed = true
248+ } )
252249 this . inputData . dataseries . forEach ( ( ds ) => {
253250 ds . label = ds . label ?? ''
254251
@@ -306,9 +303,17 @@ export class WidgetDoughnut extends LitElement {
306303 }
307304 } )
308305 } )
309- // prevent duplicate transformation
310- // this.inputData.dataseries = []
311- // console.log('new doughnut datasets', this.canvasList)
306+
307+ const doomedCharts : string [ ] = [ ]
308+ // remove all doomed charts
309+ this . canvasList . forEach ( ( chart , label ) => {
310+ if ( ! chart . doomed ) return
311+ chart . echart ?. dispose ( )
312+ chart . element ?. remove ( )
313+ doomedCharts . push ( label )
314+ } )
315+
316+ doomedCharts . forEach ( ( label ) => this . canvasList . delete ( label ) )
312317 }
313318
314319 async applyData ( ) {
@@ -318,13 +323,13 @@ export class WidgetDoughnut extends LitElement {
318323 this . canvasList . forEach ( ( chartM , label ) => {
319324 for ( const ds of chartM . dataSets ) {
320325 // const option = this.canvasList[ds.label].getOption()
321- const option : any = structuredClone ( this . template )
326+ const option : any = chartM . echart ?. getOption ( ) ?? window . structuredClone ( this . template )
322327 const series = option . series [ 0 ] ,
323328 series2 = option . series [ 1 ]
324329
325330 // Title
326- option . title . text = ds . label
327- option . title . textStyle . fontSize = 18 * modifier
331+ option . title [ 0 ] . text = ds . label
332+ option . title [ 0 ] . textStyle . fontSize = 18 * modifier
328333 // option.color = ds.sections?.[0]?.map((d) => d.color)
329334
330335 series . radius [ 0 ] = String ( parseFloat ( ds . settings ?. cutout ?? '50%' ) * 0.6 ) + '%'
@@ -341,9 +346,7 @@ export class WidgetDoughnut extends LitElement {
341346 series2 . label . fontSize = 14 * modifier
342347
343348 // Apply
344- const oldOption : any = chartM . echart ?. getOption ( ) ?? { }
345- const notMerge = oldOption . series ?. length !== chartM . dataSets . length
346- chartM . echart ?. setOption ( option , { notMerge } )
349+ chartM . echart ?. setOption ( option )
347350 }
348351 } )
349352 }
@@ -375,7 +378,6 @@ export class WidgetDoughnut extends LitElement {
375378
376379 const theme =
377380 this . theme ?. theme_name === '---' || ! this . theme ?. theme_name ? 'light' : this . theme ?. theme_name
378- console . log ( 'Using theme' , theme )
379381 const newChart = echarts . init ( newContainer , theme )
380382 const chart = {
381383 echart : newChart ,
0 commit comments