Skip to content

Commit b9379c0

Browse files
committed
wip
1 parent c955dc4 commit b9379c0

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ export class Model extends EventBus<any> implements CommandDispatcher {
713713
let data = createEmptyExcelWorkbookData();
714714
for (const handler of this.handlers) {
715715
if (handler instanceof BasePlugin) {
716+
console.log(handler.constructor.name);
716717
handler.exportForExcel(data);
717718
}
718719
}

src/plugins/core/carousel.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { FIGURE_ID_SPLITTER } from "../../constants";
2+
import { UuidGenerator } from "../../helpers";
23
import {
34
Carousel,
45
CarouselItem,
56
CommandResult,
67
CoreCommand,
8+
ExcelWorkbookData,
79
UID,
810
UpdateCarouselCommand,
911
WorkbookData,
@@ -139,4 +141,36 @@ export class CarouselPlugin extends CorePlugin<CarouselState> implements Carouse
139141
}
140142
}
141143
}
144+
145+
exportForExcel(data: ExcelWorkbookData): void {
146+
// TODO ask around: should I create mock figure here, or at the xlsx_writer ? The problem of creating here is that the
147+
// figures are only in the workbook, making calls to getters wrong inside the plugins following this
148+
const uuidGenerator = new UuidGenerator();
149+
for (const sheet of data.sheets) {
150+
for (const carouselId in this.carousels[sheet.id] || {}) {
151+
const carouselFigure = sheet.figures.find((fig) => fig.id === carouselId);
152+
const carousel = this.carousels[sheet.id]?.[carouselId];
153+
if (!carouselFigure || !carousel) {
154+
continue;
155+
}
156+
sheet.figures = sheet.figures.filter((fig) => fig.id !== carouselId);
157+
158+
let offset = 0;
159+
for (const item of carousel.items) {
160+
if (item.type === "chart") {
161+
const chartData = sheet.charts[item.chartId];
162+
const newFigure = {
163+
...carouselFigure,
164+
id: uuidGenerator.smallUuid(),
165+
tag: "chart",
166+
offset: { x: carouselFigure.offset.x + offset, y: carouselFigure.offset.y },
167+
};
168+
offset += 20;
169+
chartData.figureId = newFigure.id;
170+
sheet.figures.push(newFigure);
171+
}
172+
}
173+
}
174+
}
175+
}
142176
}

src/plugins/core/chart.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CreateChartCommand,
1313
DeleteChartCommand,
1414
DOMDimension,
15+
ExcelWorkbookData,
1516
HeaderIndex,
1617
PixelPosition,
1718
UID,
@@ -235,6 +236,10 @@ export class ChartPlugin extends CorePlugin<ChartState> implements ChartState {
235236
}
236237
}
237238

239+
exportForExcel(data: ExcelWorkbookData): void {
240+
this.export(data);
241+
}
242+
238243
// ---------------------------------------------------------------------------
239244
// Private
240245
// ---------------------------------------------------------------------------

src/plugins/ui_core_views/evaluation_chart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ export class EvaluationChartPlugin extends CoreViewPlugin<EvaluationChartState>
9595

9696
exportForExcel(data: ExcelWorkbookData) {
9797
for (const sheet of data.sheets) {
98-
for (const chartId of this.getters.getChartIds(sheet.id)) {
98+
for (const chartId of Object.keys(sheet.charts || {})) {
9999
const chart = this.getters.getChart(chartId);
100100
const excelDefinition = chart?.getDefinitionForExcel(this.getters);
101-
const figureId = this.getters.getFigureIdFromChartId(chartId);
101+
const figureId = sheet.charts[chartId].figureId;
102102

103103
if (excelDefinition) {
104-
sheet.charts[chartId] = { figureId, chart: excelDefinition };
104+
sheet.charts[chartId].chart = excelDefinition;
105105
} else {
106106
const type = this.getters.getChartType(chartId);
107107
const runtime = this.getters.getChartRuntime(chartId);

0 commit comments

Comments
 (0)