@@ -12,7 +12,6 @@ import {
1212 CreateChartCommand ,
1313 DeleteChartCommand ,
1414 DOMDimension ,
15- FigureData ,
1615 HeaderIndex ,
1716 PixelPosition ,
1817 UID ,
@@ -212,59 +211,26 @@ export class ChartPlugin extends CorePlugin<ChartState> implements ChartState {
212211
213212 import ( data : WorkbookData ) {
214213 for ( const sheet of data . sheets ) {
215- if ( sheet . figures ) {
216- for ( const figure of sheet . figures ) {
217- // TODO:
218- // figure data should be external IMO => chart should be in sheet.chart
219- // instead of in figure.data
220- if ( figure . tag === "chart" ) {
221- const chartId = figure . data . chartId ;
222- const chart = this . createChart ( figure . id , figure . data , sheet . id ) ;
223- this . charts [ chartId ] = { chart, figureId : figure . id } ;
224- } else if ( figure . tag === "carousel" ) {
225- for ( const chartId in figure . data . chartDefinitions || { } ) {
226- const chartDefinition = figure . data . chartDefinitions [ chartId ] ;
227- const chart = this . createChart ( figure . id , chartDefinition , sheet . id ) ;
228- this . charts [ chartId ] = { chart, figureId : figure . id } ;
229- }
230- }
231- }
214+ for ( const chartId in sheet . charts ) {
215+ const { figureId, chart : chartData } = sheet . charts [ chartId ] ;
216+ const chart = this . createChart ( figureId , chartData , sheet . id ) ;
217+ this . charts [ chartId ] = { chart, figureId } ;
232218 }
233219 }
234220 }
235221
236222 export ( data : WorkbookData ) {
237223 if ( data . sheets ) {
238224 for ( const sheet of data . sheets ) {
239- // TODO This code is false, if two plugins want to insert figures on the sheet, it will crash !
240- const sheetFigures = this . getters . getFigures ( sheet . id ) ;
241- const figures : FigureData < any > [ ] = [ ] ;
242- for ( const sheetFigure of sheetFigures ) {
243- const figure = sheetFigure as FigureData < any > ;
244- const chartId = Object . keys ( this . charts ) . find (
245- ( chartId ) => this . charts [ chartId ] ?. figureId === sheetFigure . id
246- ) ;
247- if ( figure && figure . tag === "chart" && chartId ) {
248- const data = this . charts [ chartId ] ?. chart . getDefinition ( ) ;
249- if ( data ) {
250- figure . data = { ...data , chartId } ;
251- figures . push ( figure ) ;
252- }
253- } else if ( figure && figure . tag === "carousel" ) {
254- const chartIds = Object . keys ( this . charts ) . filter (
255- ( chartId ) => this . charts [ chartId ] ?. figureId === sheetFigure . id
256- ) ;
257- const data = { } ;
258- for ( const chartId of chartIds ) {
259- data [ chartId ] = this . charts [ chartId ] ?. chart . getDefinition ( ) ;
260- }
261- figure . data = { chartDefinitions : data } ;
262- figures . push ( figure ) ;
263- } else {
264- figures . push ( figure ) ;
225+ for ( const chartId of this . getChartIds ( sheet . id ) ) {
226+ const figureChart = this . charts [ chartId ] ;
227+ if ( figureChart ) {
228+ sheet . charts [ chartId ] = {
229+ figureId : figureChart . figureId ,
230+ chart : figureChart . chart . getDefinition ( ) ,
231+ } ;
265232 }
266233 }
267- sheet . figures = figures ;
268234 }
269235 }
270236 }
0 commit comments