@file-viewer/renderer-spreadsheet 3.3.4 → 3.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/spreadsheet/chartRenderer.js +203 -132
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +3 -0
- package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +1 -1
- package/dist/spreadsheet/worker/sheetjs/chartParser.js +130 -24
- package/dist/spreadsheet/worker/type.d.ts +13 -0
- package/dist/worker/sheet.worker.js +49 -49
- package/package.json +3 -3
|
@@ -61,20 +61,20 @@ const showsSeriesLine = (chart, series) => {
|
|
|
61
61
|
if (series.lineVisible === false) {
|
|
62
62
|
return false;
|
|
63
63
|
}
|
|
64
|
-
return chart.type !== 'scatter' || ((_a = chart.scatterStyle) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'marker';
|
|
64
|
+
return (series.type || chart.type) !== 'scatter' || ((_a = chart.scatterStyle) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'marker';
|
|
65
65
|
};
|
|
66
66
|
const showsSeriesMarker = (chart, series) => {
|
|
67
67
|
if (series.marker) {
|
|
68
68
|
return series.marker.symbol.toLowerCase() !== 'none';
|
|
69
69
|
}
|
|
70
|
-
if (chart.type !== 'scatter') {
|
|
70
|
+
if ((series.type || chart.type) !== 'scatter') {
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
73
|
const scatterStyle = (chart.scatterStyle || 'lineMarker').toLowerCase();
|
|
74
74
|
return scatterStyle === 'marker' || scatterStyle.endsWith('marker');
|
|
75
75
|
};
|
|
76
|
-
const categoryLabelIndexes = (count, plotWidth) => {
|
|
77
|
-
const limit = Math.max(2, Math.floor(plotWidth /
|
|
76
|
+
const categoryLabelIndexes = (count, plotWidth, labelWidth = 28) => {
|
|
77
|
+
const limit = Math.max(2, Math.floor(plotWidth / labelWidth));
|
|
78
78
|
if (count <= limit) {
|
|
79
79
|
return Array.from({ length: count }, (_, index) => index);
|
|
80
80
|
}
|
|
@@ -157,14 +157,18 @@ const drawSeriesMarker = (documentRef, svg, series, color, x, y) => {
|
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
159
|
const categoryLabels = (chart) => {
|
|
160
|
-
const
|
|
160
|
+
const matching = chart.categoryAxisId
|
|
161
|
+
? chart.series.filter(series => series.categoryAxisId === chart.categoryAxisId)
|
|
162
|
+
: [];
|
|
163
|
+
const candidates = matching.some(series => series.categories.length) ? matching : chart.series;
|
|
164
|
+
const labels = candidates.reduce((longest, series) => series.categories.length > longest.length ? series.categories : longest, []);
|
|
161
165
|
const valueCount = chart.series.reduce((count, series) => Math.max(count, series.values.length), 0);
|
|
162
166
|
return labels.length ? labels : Array.from({ length: valueCount }, (_, index) => `${index + 1}`);
|
|
163
167
|
};
|
|
164
|
-
const valueDomain = (
|
|
168
|
+
const valueDomain = (seriesList) => {
|
|
165
169
|
let min = 0;
|
|
166
170
|
let max = 0;
|
|
167
|
-
|
|
171
|
+
seriesList.forEach((series) => {
|
|
168
172
|
series.values.forEach((value) => {
|
|
169
173
|
if (!Number.isFinite(value)) {
|
|
170
174
|
return;
|
|
@@ -178,14 +182,16 @@ const valueDomain = (chart) => {
|
|
|
178
182
|
}
|
|
179
183
|
return { min, max, span: max - min };
|
|
180
184
|
};
|
|
181
|
-
const createPlot = (chart) => {
|
|
185
|
+
const createPlot = (chart, rightAxis = false) => {
|
|
182
186
|
const hasTitle = !!chart.title;
|
|
183
187
|
const hasLegend = !!chart.legendPosition;
|
|
184
188
|
const rightLegend = chart.legendPosition === 'right';
|
|
185
|
-
const
|
|
186
|
-
const
|
|
189
|
+
const topLegend = chart.legendPosition === 'top';
|
|
190
|
+
const legendRows = Math.ceil(Math.min(chart.series.length, MAX_LEGEND_ITEMS) / 4);
|
|
191
|
+
const top = (hasTitle ? 48 : 24) + (topLegend ? legendRows * 20 : 0);
|
|
192
|
+
const bottom = hasLegend && !rightLegend && !topLegend ? 302 : 326;
|
|
187
193
|
const left = chart.valueAxisTitle ? 76 : 58;
|
|
188
|
-
const right = rightLegend ? 492 : 612;
|
|
194
|
+
const right = (rightLegend ? 492 : 612) - (rightAxis ? 42 : 0);
|
|
189
195
|
return {
|
|
190
196
|
left,
|
|
191
197
|
top,
|
|
@@ -194,76 +200,90 @@ const createPlot = (chart) => {
|
|
|
194
200
|
bottom
|
|
195
201
|
};
|
|
196
202
|
};
|
|
197
|
-
const drawValueGrid = (documentRef, svg, plot, domain, fontSize = 10) => {
|
|
203
|
+
const drawValueGrid = (documentRef, svg, plot, domain, fontSize = 10, axis) => {
|
|
204
|
+
const right = (axis === null || axis === void 0 ? void 0 : axis.position) === 'right';
|
|
205
|
+
const edge = right ? plot.left + plot.width : plot.left;
|
|
206
|
+
if (right) {
|
|
207
|
+
svg.appendChild(svgElement(documentRef, 'line', {
|
|
208
|
+
x1: edge, x2: edge, y1: plot.top, y2: plot.bottom, stroke: '#9ca3af'
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
198
211
|
const tickCount = 5;
|
|
199
212
|
for (let index = 0; index <= tickCount; index += 1) {
|
|
200
213
|
const ratio = index / tickCount;
|
|
201
214
|
const y = plot.bottom - ratio * plot.height;
|
|
202
215
|
const value = domain.min + ratio * domain.span;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
if (!right)
|
|
217
|
+
svg.appendChild(svgElement(documentRef, 'line', {
|
|
218
|
+
x1: plot.left,
|
|
219
|
+
y1: y,
|
|
220
|
+
x2: plot.left + plot.width,
|
|
221
|
+
y2: y,
|
|
222
|
+
stroke: index === 0 ? '#9ca3af' : '#e5e7eb',
|
|
223
|
+
'stroke-width': 1
|
|
224
|
+
}));
|
|
225
|
+
if (!(axis === null || axis === void 0 ? void 0 : axis.hidden)) {
|
|
226
|
+
const label = svgText(documentRef, Number.isInteger(value) ? `${value}` : value.toFixed(1), edge + (right ? 8 : -8), y + fontSize / 3, {
|
|
227
|
+
anchor: right ? 'start' : 'end',
|
|
228
|
+
size: fontSize
|
|
229
|
+
});
|
|
230
|
+
if (axis) {
|
|
231
|
+
label.classList.add('excel-chart-value-label');
|
|
232
|
+
label.dataset.axisId = axis.id;
|
|
233
|
+
label.dataset.axisSide = axis.position;
|
|
234
|
+
}
|
|
235
|
+
svg.appendChild(label);
|
|
236
|
+
}
|
|
215
237
|
}
|
|
216
238
|
};
|
|
217
|
-
const drawCategoryLabels = (documentRef, svg, chart, plot, pointAxis = false) => {
|
|
239
|
+
const drawCategoryLabels = (documentRef, svg, chart, plot, pointAxis = false, bandCount) => {
|
|
218
240
|
const categories = categoryLabels(chart);
|
|
219
241
|
if (!categories.length) {
|
|
220
242
|
return;
|
|
221
243
|
}
|
|
222
244
|
const categorySeries = chart.series.find(series => series.categories === categories);
|
|
223
245
|
const sourcePointCount = Math.max(...chart.series.map(series => series.sourcePointCount || Math.max(series.values.length, series.categories.length)), categories.length);
|
|
224
|
-
const step = plot.width / categories.length;
|
|
246
|
+
const step = plot.width / (bandCount || categories.length);
|
|
225
247
|
const visible = categories.flatMap((label, i) => label ? [i] : []);
|
|
226
|
-
|
|
248
|
+
const fontSize = axisFontSize(chart, chart.categoryAxisFontSize, 10);
|
|
249
|
+
const dateLabelWidth = chart.categoryAxisDate ? categories.reduce((width, label) => Math.max(width, label.length * fontSize * (/[^\x00-\x7f]/.test(label) ? 0.8 : 0.55) + 8), 28) : 28;
|
|
250
|
+
categoryLabelIndexes(visible.length, plot.width, dateLabelWidth).forEach((visibleIndex) => {
|
|
227
251
|
var _a, _b;
|
|
228
252
|
const index = visible[visibleIndex];
|
|
229
253
|
const category = categories[index];
|
|
230
254
|
const maxLength = categories.length > 8 ? 8 : 14;
|
|
231
|
-
const label = category.length > maxLength ? `${category.slice(0, maxLength - 1)}…` : category;
|
|
255
|
+
const label = !chart.categoryAxisDate && category.length > maxLength ? `${category.slice(0, maxLength - 1)}…` : category;
|
|
232
256
|
const sourceIndex = (_b = (_a = categorySeries === null || categorySeries === void 0 ? void 0 : categorySeries.sourcePointIndexes) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : index;
|
|
233
257
|
const x = pointAxis && categories.length > 1
|
|
234
258
|
? plot.left + (sourceIndex / Math.max(sourcePointCount - 1, 1)) * plot.width
|
|
235
|
-
: plot.left + (index + 0.5) * step;
|
|
259
|
+
: plot.left + ((bandCount ? sourceIndex : index) + 0.5) * step;
|
|
236
260
|
const labelElement = svgText(documentRef, label, x, plot.bottom + 17, {
|
|
237
261
|
anchor: 'middle',
|
|
238
|
-
size:
|
|
262
|
+
size: fontSize
|
|
239
263
|
});
|
|
240
264
|
labelElement.classList.add('excel-chart-category-label');
|
|
241
265
|
labelElement.dataset.categoryIndex = `${sourceIndex}`;
|
|
242
266
|
svg.appendChild(labelElement);
|
|
243
267
|
});
|
|
244
268
|
};
|
|
245
|
-
const
|
|
246
|
-
const domain = valueDomain(chart);
|
|
247
|
-
const categories = categoryLabels(chart);
|
|
248
|
-
const categoryCount = Math.max(categories.length, chart.series.reduce((count, series) => Math.max(count, series.values.length), 0), 1);
|
|
269
|
+
const drawColumnSeries = (documentRef, svg, plot, entries, categoryCount, domainFor) => {
|
|
249
270
|
const groupWidth = plot.width / categoryCount;
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
chart.series.forEach((series, seriesIndex) => {
|
|
271
|
+
const slotWidth = (groupWidth * 0.76) / Math.max(entries.length, 1);
|
|
272
|
+
entries.forEach(({ series, index }, slot) => {
|
|
273
|
+
const domain = domainFor(series);
|
|
274
|
+
const zeroY = plot.bottom - ((0 - domain.min) / domain.span) * plot.height;
|
|
255
275
|
series.values.forEach((value, valueIndex) => {
|
|
256
276
|
if (!Number.isFinite(value))
|
|
257
277
|
return;
|
|
258
278
|
const valueY = plot.bottom - ((value - domain.min) / domain.span) * plot.height;
|
|
259
|
-
const x = plot.left + valueIndex * groupWidth + groupWidth * 0.12 +
|
|
279
|
+
const x = plot.left + valueIndex * groupWidth + groupWidth * 0.12 + slot * slotWidth;
|
|
260
280
|
const y = Math.min(zeroY, valueY);
|
|
261
281
|
const rect = svgElement(documentRef, 'rect', {
|
|
262
282
|
x,
|
|
263
283
|
y,
|
|
264
284
|
width: Math.max(1, slotWidth - 2),
|
|
265
285
|
height: Math.max(1, Math.abs(zeroY - valueY)),
|
|
266
|
-
fill: seriesColor(series,
|
|
286
|
+
fill: seriesColor(series, index),
|
|
267
287
|
rx: 1
|
|
268
288
|
});
|
|
269
289
|
const title = svgElement(documentRef, 'title');
|
|
@@ -272,10 +292,16 @@ const drawColumnChart = (documentRef, svg, chart, plot) => {
|
|
|
272
292
|
svg.appendChild(rect);
|
|
273
293
|
});
|
|
274
294
|
});
|
|
295
|
+
};
|
|
296
|
+
const drawColumnChart = (documentRef, svg, chart, plot) => {
|
|
297
|
+
const domain = valueDomain(chart.series);
|
|
298
|
+
const categoryCount = chart.series.reduce((count, series) => Math.max(count, series.values.length, series.categories.length), 1);
|
|
299
|
+
drawValueGrid(documentRef, svg, plot, domain, axisFontSize(chart, chart.valueAxisFontSize, 10));
|
|
300
|
+
drawColumnSeries(documentRef, svg, plot, chart.series.map((series, index) => ({ series, index })), categoryCount, () => domain);
|
|
275
301
|
drawCategoryLabels(documentRef, svg, chart, plot);
|
|
276
302
|
};
|
|
277
303
|
const drawHorizontalBarChart = (documentRef, svg, chart, plot) => {
|
|
278
|
-
const domain = valueDomain(chart);
|
|
304
|
+
const domain = valueDomain(chart.series);
|
|
279
305
|
const categories = categoryLabels(chart);
|
|
280
306
|
const categoryCount = Math.max(categories.length, chart.series.reduce((count, series) => Math.max(count, series.values.length), 0), 1);
|
|
281
307
|
const groupHeight = plot.height / categoryCount;
|
|
@@ -317,76 +343,111 @@ const drawHorizontalBarChart = (documentRef, svg, chart, plot) => {
|
|
|
317
343
|
}));
|
|
318
344
|
});
|
|
319
345
|
};
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
for (const index of pointIndexes) {
|
|
332
|
-
const value = series.values[index];
|
|
333
|
-
if (!Number.isFinite(value)) {
|
|
334
|
-
if (spanning.has(index))
|
|
335
|
-
continue;
|
|
336
|
-
if (segment.length)
|
|
337
|
-
segments.push(segment);
|
|
338
|
-
segment = [];
|
|
346
|
+
const drawLineSeries = (documentRef, svg, chart, plot, entry, domain, xAt, fillArea = false) => {
|
|
347
|
+
var _a, _b;
|
|
348
|
+
const { series, index: seriesIndex } = entry;
|
|
349
|
+
const pointIndexes = extremaPointIndexes(series.values, Math.max(64, Math.floor(plot.width * MAX_LINE_POINTS_PER_PIXEL)), series.spanBlankIndexes);
|
|
350
|
+
const spanning = new Set(series.spanBlankIndexes || []);
|
|
351
|
+
const segments = [];
|
|
352
|
+
let segment = [];
|
|
353
|
+
for (const index of pointIndexes) {
|
|
354
|
+
const value = series.values[index];
|
|
355
|
+
if (!Number.isFinite(value)) {
|
|
356
|
+
if (spanning.has(index))
|
|
339
357
|
continue;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
segment
|
|
343
|
-
|
|
344
|
-
y: plot.bottom - ((value - domain.min) / domain.span) * plot.height
|
|
345
|
-
});
|
|
358
|
+
if (segment.length)
|
|
359
|
+
segments.push(segment);
|
|
360
|
+
segment = [];
|
|
361
|
+
continue;
|
|
346
362
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
const color = seriesColor(series, seriesIndex);
|
|
368
|
-
const dashArray = seriesDashArray(series);
|
|
369
|
-
if (showsSeriesLine(chart, series)) {
|
|
363
|
+
const sourceIndex = (_b = (_a = series.sourcePointIndexes) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : index;
|
|
364
|
+
segment.push({
|
|
365
|
+
x: xAt(sourceIndex),
|
|
366
|
+
y: plot.bottom - ((value - domain.min) / domain.span) * plot.height
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
if (segment.length)
|
|
370
|
+
segments.push(segment);
|
|
371
|
+
const points = segments.flat();
|
|
372
|
+
if (!points.length)
|
|
373
|
+
return;
|
|
374
|
+
const pathFor = (points) => points
|
|
375
|
+
.map((point, index) => `${index ? 'L' : 'M'}${point.x},${point.y}`).join(' ');
|
|
376
|
+
const pathData = segments.map(pathFor).join(' ');
|
|
377
|
+
if (fillArea) {
|
|
378
|
+
const zeroY = plot.bottom - ((0 - domain.min) / domain.span) * plot.height;
|
|
379
|
+
for (const points of segments) {
|
|
380
|
+
if (points.length < 2)
|
|
381
|
+
continue;
|
|
370
382
|
svg.appendChild(svgElement(documentRef, 'path', {
|
|
371
|
-
class: 'excel-chart-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
'data-rendered-point-count': points.length,
|
|
375
|
-
d: pathData,
|
|
376
|
-
fill: 'none',
|
|
377
|
-
stroke: color,
|
|
378
|
-
'stroke-width': seriesStrokeWidth(series),
|
|
379
|
-
...(dashArray ? { 'stroke-dasharray': dashArray } : {}),
|
|
380
|
-
'stroke-linejoin': 'round',
|
|
381
|
-
'stroke-linecap': 'round'
|
|
383
|
+
class: 'excel-chart-area',
|
|
384
|
+
d: `${pathFor(points)} L${points[points.length - 1].x},${zeroY} L${points[0].x},${zeroY} Z`,
|
|
385
|
+
fill: seriesColor(series, seriesIndex), opacity: 0.2
|
|
382
386
|
}));
|
|
383
387
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
+
}
|
|
389
|
+
const color = seriesColor(series, seriesIndex);
|
|
390
|
+
const dashArray = seriesDashArray(series);
|
|
391
|
+
if (showsSeriesLine(chart, series)) {
|
|
392
|
+
svg.appendChild(svgElement(documentRef, 'path', {
|
|
393
|
+
class: 'excel-chart-series-line',
|
|
394
|
+
...(series.valueAxisId ? { 'data-axis-id': series.valueAxisId } : {}),
|
|
395
|
+
'data-source-point-count': series.sourcePointCount || series.values.length,
|
|
396
|
+
'data-transferred-point-count': series.values.length,
|
|
397
|
+
'data-rendered-point-count': points.length,
|
|
398
|
+
d: pathData,
|
|
399
|
+
fill: 'none',
|
|
400
|
+
stroke: color,
|
|
401
|
+
'stroke-width': seriesStrokeWidth(series),
|
|
402
|
+
...(dashArray ? { 'stroke-dasharray': dashArray } : {}),
|
|
403
|
+
'stroke-linejoin': 'round',
|
|
404
|
+
'stroke-linecap': 'round'
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
if (showsSeriesMarker(chart, series)) {
|
|
408
|
+
points.forEach((point) => drawSeriesMarker(documentRef, svg, series, color, point.x, point.y));
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const drawLineChart = (documentRef, svg, chart, plot, fillArea) => {
|
|
412
|
+
const domain = valueDomain(chart.series);
|
|
413
|
+
const count = chart.series.reduce((pointCount, series) => Math.max(pointCount, series.sourcePointCount || series.values.length), 1);
|
|
414
|
+
const xAt = (index) => plot.left + plot.width * (count > 1 ? index / (count - 1) : 0.5);
|
|
415
|
+
drawValueGrid(documentRef, svg, plot, domain, axisFontSize(chart, chart.valueAxisFontSize, 10));
|
|
416
|
+
chart.series.forEach((series, index) => drawLineSeries(documentRef, svg, chart, plot, { series, index }, domain, xAt, fillArea));
|
|
388
417
|
drawCategoryLabels(documentRef, svg, chart, plot, true);
|
|
389
418
|
};
|
|
419
|
+
const drawCombinationChart = (documentRef, svg, chart, plot) => {
|
|
420
|
+
var _a, _b;
|
|
421
|
+
const byAxis = new Map();
|
|
422
|
+
const entries = chart.series.map((series, index) => {
|
|
423
|
+
const group = byAxis.get(series.valueAxisId);
|
|
424
|
+
if (group)
|
|
425
|
+
group.push(series);
|
|
426
|
+
else
|
|
427
|
+
byAxis.set(series.valueAxisId, [series]);
|
|
428
|
+
return { series, index };
|
|
429
|
+
});
|
|
430
|
+
const domains = new Map([...byAxis].map(([id, series]) => [id, valueDomain(series)]));
|
|
431
|
+
const fallback = valueDomain(chart.series);
|
|
432
|
+
const domainFor = (series) => domains.get(series.valueAxisId) || fallback;
|
|
433
|
+
const left = (_a = chart.valueAxes) === null || _a === void 0 ? void 0 : _a.find(axis => axis.position === 'left');
|
|
434
|
+
const right = (_b = chart.valueAxes) === null || _b === void 0 ? void 0 : _b.find(axis => axis.position === 'right' && !axis.hidden);
|
|
435
|
+
drawValueGrid(documentRef, svg, plot, domains.get(left === null || left === void 0 ? void 0 : left.id) || fallback, axisFontSize(chart, (left === null || left === void 0 ? void 0 : left.fontSize) || chart.valueAxisFontSize, 10), left);
|
|
436
|
+
if (right) {
|
|
437
|
+
drawValueGrid(documentRef, svg, plot, domains.get(right.id) || fallback, axisFontSize(chart, right.fontSize, 10), right);
|
|
438
|
+
if (right.title) {
|
|
439
|
+
svg.appendChild(svgText(documentRef, right.title, plot.left + plot.width + 62, plot.top + plot.height / 2, { anchor: 'middle', size: 11, rotate: 90 }));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const count = chart.series.reduce((length, series) => Math.max(length, series.sourcePointCount || series.values.length, series.categories.length), 1);
|
|
443
|
+
drawColumnSeries(documentRef, svg, plot, entries.filter(({ series }) => series.type === 'bar'), count, domainFor);
|
|
444
|
+
for (const entry of entries) {
|
|
445
|
+
if (entry.series.type === 'line') {
|
|
446
|
+
drawLineSeries(documentRef, svg, chart, plot, entry, domainFor(entry.series), index => plot.left + (index + 0.5) * plot.width / count);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
drawCategoryLabels(documentRef, svg, chart, plot, false, count);
|
|
450
|
+
};
|
|
390
451
|
const polarPoint = (cx, cy, radius, angle) => {
|
|
391
452
|
const radians = ((angle - 90) * Math.PI) / 180;
|
|
392
453
|
return {
|
|
@@ -448,6 +509,7 @@ const drawLegend = (documentRef, svg, chart) => {
|
|
|
448
509
|
return;
|
|
449
510
|
}
|
|
450
511
|
const right = chart.legendPosition === 'right';
|
|
512
|
+
const top = chart.legendPosition === 'top';
|
|
451
513
|
const categorySeries = chart.type === 'pie' || chart.type === 'doughnut' ? chart.series[0] : undefined;
|
|
452
514
|
const entries = chart.type === 'pie' || chart.type === 'doughnut'
|
|
453
515
|
? ((categorySeries === null || categorySeries === void 0 ? void 0 : categorySeries.values) || []).slice(0, MAX_LEGEND_ITEMS).map((_, index) => ({
|
|
@@ -458,9 +520,12 @@ const drawLegend = (documentRef, svg, chart) => {
|
|
|
458
520
|
: chart.series;
|
|
459
521
|
entries.slice(0, MAX_LEGEND_ITEMS).forEach((series, index) => {
|
|
460
522
|
const x = right ? 510 : 76 + (index % 4) * 136;
|
|
461
|
-
const y = right ? 72 + index * 28 :
|
|
523
|
+
const y = right ? 72 + index * 28 : top
|
|
524
|
+
? (chart.title ? 48 : 24) + Math.floor(index / 4) * 20
|
|
525
|
+
: 342 - Math.floor(index / 4) * 20;
|
|
462
526
|
const color = seriesColor(series, index);
|
|
463
|
-
const
|
|
527
|
+
const seriesType = series.type || chart.type;
|
|
528
|
+
const lineLike = seriesType === 'line' || seriesType === 'scatter' || seriesType === 'radar';
|
|
464
529
|
if (lineLike) {
|
|
465
530
|
if (showsSeriesLine(chart, series)) {
|
|
466
531
|
const dashArray = seriesDashArray(series);
|
|
@@ -492,6 +557,7 @@ const drawLegend = (documentRef, svg, chart) => {
|
|
|
492
557
|
});
|
|
493
558
|
};
|
|
494
559
|
export const renderSpreadsheetChart = (documentRef, chart) => {
|
|
560
|
+
var _a;
|
|
495
561
|
const container = documentRef.createElement('div');
|
|
496
562
|
container.className = 'excel-chart';
|
|
497
563
|
container.dataset.chartId = chart.id;
|
|
@@ -522,32 +588,37 @@ export const renderSpreadsheetChart = (documentRef, chart) => {
|
|
|
522
588
|
fill: '#1f2937'
|
|
523
589
|
}));
|
|
524
590
|
}
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
break;
|
|
530
|
-
case 'doughnut':
|
|
531
|
-
drawPieChart(documentRef, svg, chart, true);
|
|
532
|
-
break;
|
|
533
|
-
case 'line':
|
|
534
|
-
case 'scatter':
|
|
535
|
-
case 'radar':
|
|
536
|
-
drawLineChart(documentRef, svg, chart, plot, false);
|
|
537
|
-
break;
|
|
538
|
-
case 'area':
|
|
539
|
-
drawLineChart(documentRef, svg, chart, plot, true);
|
|
540
|
-
break;
|
|
541
|
-
case 'bar':
|
|
542
|
-
default:
|
|
543
|
-
if (chart.barDirection === 'bar') {
|
|
544
|
-
drawHorizontalBarChart(documentRef, svg, chart, plot);
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
drawColumnChart(documentRef, svg, chart, plot);
|
|
548
|
-
}
|
|
549
|
-
break;
|
|
591
|
+
const rightAxis = (_a = chart.valueAxes) === null || _a === void 0 ? void 0 : _a.find(axis => axis.position === 'right' && !axis.hidden);
|
|
592
|
+
const plot = createPlot(chart, !!rightAxis);
|
|
593
|
+
if (chart.series.some(series => series.type === 'bar') && chart.series.some(series => series.type === 'line')) {
|
|
594
|
+
drawCombinationChart(documentRef, svg, chart, plot);
|
|
550
595
|
}
|
|
596
|
+
else
|
|
597
|
+
switch (chart.type) {
|
|
598
|
+
case 'pie':
|
|
599
|
+
drawPieChart(documentRef, svg, chart, false);
|
|
600
|
+
break;
|
|
601
|
+
case 'doughnut':
|
|
602
|
+
drawPieChart(documentRef, svg, chart, true);
|
|
603
|
+
break;
|
|
604
|
+
case 'line':
|
|
605
|
+
case 'scatter':
|
|
606
|
+
case 'radar':
|
|
607
|
+
drawLineChart(documentRef, svg, chart, plot, false);
|
|
608
|
+
break;
|
|
609
|
+
case 'area':
|
|
610
|
+
drawLineChart(documentRef, svg, chart, plot, true);
|
|
611
|
+
break;
|
|
612
|
+
case 'bar':
|
|
613
|
+
default:
|
|
614
|
+
if (chart.barDirection === 'bar') {
|
|
615
|
+
drawHorizontalBarChart(documentRef, svg, chart, plot);
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
drawColumnChart(documentRef, svg, chart, plot);
|
|
619
|
+
}
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
551
622
|
if (chart.categoryAxisTitle && chart.type !== 'pie' && chart.type !== 'doughnut') {
|
|
552
623
|
svg.appendChild(svgText(documentRef, chart.categoryAxisTitle, plot.left + plot.width / 2, 324, {
|
|
553
624
|
anchor: 'middle',
|
|
@@ -539,7 +539,10 @@ class SheetJsModel {
|
|
|
539
539
|
type: chart.type,
|
|
540
540
|
title: chart.title,
|
|
541
541
|
categoryAxisTitle: chart.categoryAxisTitle,
|
|
542
|
+
categoryAxisId: chart.categoryAxisId,
|
|
543
|
+
categoryAxisDate: chart.categoryAxisDate,
|
|
542
544
|
valueAxisTitle: chart.valueAxisTitle,
|
|
545
|
+
valueAxes: chart.valueAxes,
|
|
543
546
|
categoryAxisFontSize: chart.categoryAxisFontSize,
|
|
544
547
|
valueAxisFontSize: chart.valueAxisFontSize,
|
|
545
548
|
barDirection: chart.barDirection,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type XmlReadBudget } from './xmlBudget.js';
|
|
2
2
|
import { type Document as XmlDocument, type Element as XmlElement, type Node as XmlNode } from '@xmldom/xmldom';
|
|
3
3
|
import JSZip from 'jszip';
|
|
4
|
-
import type
|
|
4
|
+
import { type WorkBook } from 'styled-exceljs';
|
|
5
5
|
import type { SheetChartDefinition } from '../type.js';
|
|
6
6
|
export type Relationship = {
|
|
7
7
|
id: string;
|