|
1 | 1 | import { XmlHelper } from './xml-helper'; |
2 | | -import { ChartData, ChartColumn, ChartBubble } from '../types/chart-types'; |
| 2 | +import { ChartData, ChartColumn, ChartBubble, ChartSlot, ChartCategory } from '../types/chart-types'; |
3 | 3 | import { FrameCoordinates, Workbook } from '../types/types'; |
4 | | -import { ModifyChartspace } from '../modify/chartspace'; |
5 | | -import { ModifyWorkbook } from '../modify/workbook'; |
| 4 | +import { ModifyChart } from '../modify/chart'; |
6 | 5 |
|
7 | 6 | export const setSolidFill = (element: XMLDocument): void => { |
8 | 7 | element |
@@ -52,102 +51,87 @@ export const setChartData = (data: ChartData) => ( |
52 | 51 | chart: Document, |
53 | 52 | workbook: Workbook, |
54 | 53 | ): void => { |
55 | | - const columns = [] as ChartColumn[]; |
56 | | - |
| 54 | + |
| 55 | + const slots = [] as ChartSlot[] |
57 | 56 | data.series.forEach((series, s) => { |
58 | | - columns.push({ |
59 | | - series: s, |
60 | | - label: `${series.label}`, |
61 | | - worksheet: (ctx, point: number, r: number) => |
62 | | - ctx.pattern(ctx.rowValues(r, s + 1, point)), |
63 | | - chart: (ctx, point: number, r: number, category) => { |
64 | | - return { |
65 | | - 'c:val': ctx.point(r, s + 1, point), |
66 | | - 'c:cat': ctx.point(r, 0, category.label), |
67 | | - }; |
68 | | - }, |
69 | | - isStrRef: true, |
70 | | - }); |
| 57 | + slots.push({ |
| 58 | + index: s, |
| 59 | + series: series, |
| 60 | + targetCol: s + 1, |
| 61 | + type: 'defaultSeries', |
| 62 | + }) |
71 | 63 | }); |
72 | 64 |
|
73 | | - new ModifyChartspace(chart, data, columns).setChart(); |
74 | | - new ModifyWorkbook(workbook, data, columns).setWorkbook(); |
| 65 | + new ModifyChart(chart, workbook, data, slots).modify(); |
| 66 | + |
| 67 | + // XmlHelper.dump(chart) |
75 | 68 | }; |
76 | 69 |
|
77 | 70 | export const setChartVerticalLines = (data: ChartData) => ( |
78 | 71 | element: XMLDocument, |
79 | 72 | chart: Document, |
80 | 73 | workbook: Workbook, |
81 | 74 | ): void => { |
82 | | - const columns = [] as ChartColumn[]; |
| 75 | + const slots = [] as ChartSlot[] |
83 | 76 |
|
84 | | - columns.push({ |
| 77 | + slots.push({ |
85 | 78 | label: `Y-Values`, |
86 | | - worksheet: (ctx, point, r: number, category) => |
87 | | - ctx.pattern(ctx.rowValues(r, 1, category.y)), |
| 79 | + mapData: (point: number, category: ChartCategory) => category.y, |
| 80 | + targetCol: 1, |
88 | 81 | }); |
89 | 82 |
|
90 | 83 | data.series.forEach((series, s) => { |
91 | | - columns.push({ |
92 | | - series: s, |
93 | | - label: `${series.label}`, |
94 | | - worksheet: (ctx, point: number, r: number) => |
95 | | - ctx.pattern(ctx.rowValues(r, s + 2, point)), |
96 | | - chart: (ctx, point: number, r: number, category) => { |
97 | | - return { |
98 | | - 'c:xVal': ctx.point(r, s + 2, point), |
99 | | - 'c:yVal': ctx.point(r, 1, category.y), |
100 | | - }; |
101 | | - }, |
102 | | - isStrRef: true, |
103 | | - }); |
| 84 | + slots.push({ |
| 85 | + index: s, |
| 86 | + series: series, |
| 87 | + targetCol: s + 2, |
| 88 | + type: 'xySeries', |
| 89 | + }) |
104 | 90 | }); |
105 | 91 |
|
106 | | - new ModifyChartspace(chart, data, columns).setChart(); |
107 | | - new ModifyWorkbook(workbook, data, columns).setWorkbook(); |
| 92 | + new ModifyChart(chart, workbook, data, slots).modify(); |
108 | 93 | }; |
109 | 94 |
|
110 | 95 | export const setChartBubbles = (data: ChartData) => ( |
111 | 96 | element: XMLDocument, |
112 | 97 | chart: Document, |
113 | 98 | workbook: Workbook, |
114 | 99 | ): void => { |
115 | | - const columns = [] as ChartColumn[]; |
| 100 | + const slots = [] as ChartSlot[] |
116 | 101 |
|
117 | 102 | data.series.forEach((series, s) => { |
118 | 103 | const colId = s * 3; |
119 | | - columns.push({ |
120 | | - series: s, |
121 | | - label: `${series.label}`, |
122 | | - worksheet: (ctx, point: ChartBubble, r: number) => |
123 | | - ctx.pattern(ctx.rowValues(r, colId + 1, point.x)), |
124 | | - chart: (ctx, point: ChartBubble, r: number) => { |
125 | | - return { 'c:xVal': ctx.point(r, colId + 1, point.x) }; |
126 | | - }, |
127 | | - isStrRef: true, |
128 | | - }); |
129 | | - columns.push({ |
130 | | - series: s, |
| 104 | + slots.push({ |
| 105 | + index: s, |
| 106 | + series: series, |
| 107 | + targetCol: colId + 1, |
| 108 | + type: 'customSeries', |
| 109 | + tag: 'c:xVal', |
| 110 | + mapData: (point: ChartBubble): number => point.x, |
| 111 | + }) |
| 112 | + slots.push({ |
131 | 113 | label: `${series.label}-Y-Value`, |
132 | | - worksheet: (ctx, point: ChartBubble, r: number) => |
133 | | - ctx.pattern(ctx.rowValues(r, colId + 2, point.y)), |
134 | | - chart: (ctx, point: ChartBubble, r: number) => { |
135 | | - return { 'c:yVal': ctx.point(r, colId + 2, point.y) }; |
136 | | - }, |
137 | | - }); |
138 | | - columns.push({ |
139 | | - series: s, |
| 114 | + index: s, |
| 115 | + series: series, |
| 116 | + targetCol: colId + 2, |
| 117 | + type: 'customSeries', |
| 118 | + tag: 'c:yVal', |
| 119 | + mapData: (point: ChartBubble): number => point.y, |
| 120 | + isStrRef: false |
| 121 | + }) |
| 122 | + slots.push({ |
140 | 123 | label: `${series.label}-Size`, |
141 | | - worksheet: (ctx, point: ChartBubble, r: number) => |
142 | | - ctx.pattern(ctx.rowValues(r, colId + 3, point.size)), |
143 | | - chart: (ctx, point: ChartBubble, r: number) => { |
144 | | - return { 'c:bubbleSize': ctx.point(r, colId + 3, point.size) }; |
145 | | - }, |
146 | | - }); |
| 124 | + index: s, |
| 125 | + series: series, |
| 126 | + targetCol: colId + 3, |
| 127 | + type: 'customSeries', |
| 128 | + tag: 'c:bubbleSize', |
| 129 | + mapData: (point: ChartBubble): number => point.size, |
| 130 | + isStrRef: false |
| 131 | + }) |
147 | 132 | }); |
148 | 133 |
|
149 | | - new ModifyChartspace(chart, data, columns).setChart(); |
150 | | - new ModifyWorkbook(workbook, data, columns).setWorkbook(); |
| 134 | + new ModifyChart(chart, workbook, data, slots).modify(); |
151 | 135 | }; |
152 | 136 |
|
153 | 137 | export const dump = (element: XMLDocument | Document): void => { |
|
0 commit comments