abstract-chart 6.0.0 → 7.0.0

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/lib/chart.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,95 +24,77 @@ var __importStar = (this && this.__importStar) || function (mod) {
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
26
  exports.generateYAxisLabel = exports.generateYAxisLabels = exports.generateYAxisLines = exports.generateXAxisLabel = exports.generateXAxisLabels = exports.generateXAxisGridLines = exports.generatePoints = exports.generateLines = exports.generateStack = exports.generateYAxisRight = exports.generateYAxisLeft = exports.generateXAxisTop = exports.generateXAxisBottom = exports.generateBackground = exports.renderChart = exports.inverseTransformPoint = exports.createChartStack = exports.createChartStackConfig = exports.createChartLine = exports.createChartPoint = exports.createChart = void 0;
23
- const AbstractImage = __importStar(require("abstract-image"));
27
+ const AI = __importStar(require("abstract-image"));
24
28
  const Axis = __importStar(require("./axis"));
25
29
  const ts_exhaustive_check_1 = require("ts-exhaustive-check");
26
30
  function createChart(props) {
27
- const { width = 600, height = 400, chartPoints = [], chartLines = [], chartStack = createChartStack({}), xAxisBottom = Axis.createLinearAxis(0, 100, ""), xAxisTop = undefined, yAxisLeft = Axis.createLinearAxis(0, 100, ""), yAxisRight = undefined, backgroundColor = AbstractImage.white, gridColor = AbstractImage.gray, gridThickness = 1, font = "Arial", fontSize = 12, labelLayout = "original", } = props || {};
31
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
28
32
  return {
29
- width,
30
- height,
31
- chartPoints,
32
- chartLines,
33
- chartStack,
34
- xAxisBottom,
35
- xAxisTop,
36
- yAxisLeft,
37
- yAxisRight,
38
- backgroundColor,
39
- gridColor,
40
- gridThickness,
41
- font,
42
- fontSize,
43
- labelLayout,
33
+ width: (_a = props.width) !== null && _a !== void 0 ? _a : 600,
34
+ height: (_b = props.height) !== null && _b !== void 0 ? _b : 600,
35
+ chartPoints: (_c = props.chartPoints) !== null && _c !== void 0 ? _c : [],
36
+ chartLines: (_d = props.chartLines) !== null && _d !== void 0 ? _d : [],
37
+ chartStack: (_e = props.chartStack) !== null && _e !== void 0 ? _e : createChartStack({}),
38
+ xAxisBottom: (_f = props.xAxisBottom) !== null && _f !== void 0 ? _f : Axis.createLinearAxis(0, 100, ""),
39
+ xAxisTop: (_g = props.xAxisTop) !== null && _g !== void 0 ? _g : undefined,
40
+ yAxisLeft: (_h = props.yAxisLeft) !== null && _h !== void 0 ? _h : Axis.createLinearAxis(0, 100, ""),
41
+ yAxisRight: (_j = props.yAxisRight) !== null && _j !== void 0 ? _j : undefined,
42
+ backgroundColor: (_k = props.backgroundColor) !== null && _k !== void 0 ? _k : AI.white,
43
+ font: (_l = props.font) !== null && _l !== void 0 ? _l : "Arial",
44
+ fontSize: (_m = props.fontSize) !== null && _m !== void 0 ? _m : 12,
45
+ labelLayout: (_o = props.labelLayout) !== null && _o !== void 0 ? _o : "original",
46
+ padding: {
47
+ top: (_q = (_p = props.padding) === null || _p === void 0 ? void 0 : _p.top) !== null && _q !== void 0 ? _q : (props.xAxisTop !== undefined ? 45 : 10),
48
+ right: (_s = (_r = props.padding) === null || _r === void 0 ? void 0 : _r.right) !== null && _s !== void 0 ? _s : (props.yAxisRight !== undefined ? 45 : 10),
49
+ bottom: (_u = (_t = props.padding) === null || _t === void 0 ? void 0 : _t.bottom) !== null && _u !== void 0 ? _u : (props.xAxisBottom === undefined ? 10 : 45),
50
+ left: (_w = (_v = props.padding) === null || _v === void 0 ? void 0 : _v.left) !== null && _w !== void 0 ? _w : (!props.yAxisLeft === undefined ? 10 : 45),
51
+ },
52
+ xGrid: { color: (_y = (_x = props.xGrid) === null || _x === void 0 ? void 0 : _x.color) !== null && _y !== void 0 ? _y : AI.gray, thickness: (_0 = (_z = props.xGrid) === null || _z === void 0 ? void 0 : _z.thickness) !== null && _0 !== void 0 ? _0 : 1 },
53
+ yGrid: { color: (_2 = (_1 = props.yGrid) === null || _1 === void 0 ? void 0 : _1.color) !== null && _2 !== void 0 ? _2 : AI.gray, thickness: (_4 = (_3 = props.yGrid) === null || _3 === void 0 ? void 0 : _3.thickness) !== null && _4 !== void 0 ? _4 : 1 },
44
54
  };
45
55
  }
46
56
  exports.createChart = createChart;
47
57
  function createChartPoint(props) {
48
- const { shape = "circle", position = AbstractImage.createPoint(0, 0), color = AbstractImage.black, size = AbstractImage.createSize(6, 6), label = "", xAxis = "bottom", yAxis = "left", } = props || {};
49
- return {
50
- shape,
51
- position,
52
- color,
53
- size,
54
- label,
55
- xAxis,
56
- yAxis,
57
- };
58
+ const { shape = "circle", position = AI.createPoint(0, 0), color = AI.black, size = AI.createSize(6, 6), label = "", xAxis = "bottom", yAxis = "left", } = props || {};
59
+ return { shape, position, color, size, label, xAxis, yAxis };
58
60
  }
59
61
  exports.createChartPoint = createChartPoint;
60
62
  function createChartLine(props) {
61
- const { points = [], color = AbstractImage.black, thickness = 1, label = "", xAxis = "bottom", yAxis = "left", } = props || {};
62
- return {
63
- points,
64
- color,
65
- thickness,
66
- label,
67
- xAxis,
68
- yAxis,
69
- };
63
+ const { points = [], color = AI.black, thickness = 1, label = "", xAxis = "bottom", yAxis = "left" } = props || {};
64
+ return { points, color, thickness, label, xAxis, yAxis };
70
65
  }
71
66
  exports.createChartLine = createChartLine;
72
67
  function createChartStackConfig(props) {
73
- const { color = AbstractImage.black, label = "" } = props || {};
74
- return {
75
- color,
76
- label,
77
- };
68
+ const { color = AI.black, label = "" } = props || {};
69
+ return { color, label };
78
70
  }
79
71
  exports.createChartStackConfig = createChartStackConfig;
80
72
  function createChartStack(props) {
81
73
  const { points = [], xAxis = "bottom", yAxis = "left", config = [createChartStackConfig({})] } = props || {};
82
- return {
83
- points,
84
- xAxis,
85
- yAxis,
86
- config,
87
- };
74
+ return { points, xAxis, yAxis, config };
88
75
  }
89
76
  exports.createChartStack = createChartStack;
90
- const padding = 80;
91
- function inverseTransformPoint(point, chart, xAxis, yAxis) {
92
- const xMin = padding;
93
- const xMax = chart.width - padding;
94
- const yMin = chart.height - 0.5 * padding;
95
- const yMax = 0.5 * padding;
77
+ function inverseTransformPoint(point, chart, xAxis, yAxis, padding) {
78
+ const xMin = padding.left;
79
+ const xMax = chart.width - padding.right;
80
+ const yMin = chart.height - padding.bottom;
81
+ const yMax = padding.top;
96
82
  const x = Axis.inverseTransformValue(point.x, xMin, xMax, xAxis === "top" ? chart.xAxisTop : chart.xAxisBottom);
97
83
  const y = Axis.inverseTransformValue(point.y, yMin, yMax, yAxis === "right" ? chart.yAxisRight : chart.yAxisLeft);
98
84
  if (x === undefined || y === undefined) {
99
85
  return undefined;
100
86
  }
101
- return AbstractImage.createPoint(x, y);
87
+ return AI.createPoint(x, y);
102
88
  }
103
89
  exports.inverseTransformPoint = inverseTransformPoint;
104
90
  function renderChart(chart) {
105
- const { width, height, xAxisBottom, xAxisTop, yAxisLeft, yAxisRight } = chart;
106
- const gridWidth = width - 2 * padding;
107
- const gridHeight = height - padding;
108
- const xMin = padding;
109
- const xMax = width - padding;
110
- const yMin = height - 0.5 * padding;
111
- const yMax = 0.5 * padding;
91
+ const { width, height, xAxisBottom, xAxisTop, yAxisLeft, yAxisRight, padding } = chart;
92
+ const gridWidth = width - padding.left - padding.right;
93
+ const gridHeight = height - padding.bottom - padding.top;
94
+ const xMin = padding.left;
95
+ const xMax = width - padding.right;
96
+ const yMin = height - padding.bottom;
97
+ const yMax = padding.top;
112
98
  const renderedBackground = generateBackground(xMin, xMax, yMin, yMax, chart);
113
99
  const xNumTicks = gridWidth / 40;
114
100
  const renderedXAxisBottom = generateXAxisBottom(xNumTicks, xAxisBottom, xMin, xMax, yMin, yMax, chart);
@@ -129,113 +115,125 @@ function renderChart(chart) {
129
115
  renderedLines,
130
116
  renderedPoints,
131
117
  ];
132
- const topLeft = AbstractImage.createPoint(0, 0);
133
- const size = AbstractImage.createSize(width, height);
134
- return AbstractImage.createAbstractImage(topLeft, size, AbstractImage.white, components);
118
+ const topLeft = AI.createPoint(0, 0);
119
+ const size = AI.createSize(width, height);
120
+ return AI.createAbstractImage(topLeft, size, AI.white, components);
135
121
  }
136
122
  exports.renderChart = renderChart;
137
123
  function generateBackground(xMin, xMax, yMin, yMax, chart) {
138
- const topLeft = AbstractImage.createPoint(xMin, yMax);
139
- const bottomRight = AbstractImage.createPoint(xMax, yMin);
140
- return AbstractImage.createRectangle(topLeft, bottomRight, chart.gridColor, chart.gridThickness, chart.backgroundColor);
124
+ return AI.createRectangle(AI.createPoint(xMin, yMax), AI.createPoint(xMax, yMin), AI.transparent, 0, chart.backgroundColor);
141
125
  }
142
126
  exports.generateBackground = generateBackground;
143
- function generateXAxisBottom(xNumTicks, xAxisBottom, xMin, xMax, yMin, yMax, chart) {
144
- if (!xAxisBottom) {
145
- return AbstractImage.createGroup("XAxisBottom", []);
127
+ function generateXAxisBottom(xNumTicks, axis, xMin, xMax, yMin, yMax, chart) {
128
+ var _a, _b, _c, _d;
129
+ const components = Array();
130
+ if (!axis) {
131
+ return AI.createGroup("XAxisBottom", components);
132
+ }
133
+ const axisLabelPosY = yMin + chart.padding.bottom - chart.fontSize;
134
+ const xTicks = Axis.getTicks(xNumTicks, axis);
135
+ if (chart.xGrid) {
136
+ components.push(generateXAxisGridLines(xMin, xMax, yMin + 10, yMax, xTicks, axis, chart.xGrid));
146
137
  }
147
- const xTicks = Axis.getTicks(xNumTicks, xAxisBottom);
148
- const xLines = generateXAxisGridLines(xMin, xMax, yMin + 10, yMax, xTicks, xAxisBottom, chart);
149
- const xLabels = generateXAxisLabels(xMin, xMax, yMin + 10, "down", xTicks, xAxisBottom, chart);
150
- let xLabel;
138
+ components.push(AI.createLine({ x: xMin, y: yMin }, { x: xMax, y: yMin }, (_a = axis.axisColor) !== null && _a !== void 0 ? _a : AI.gray, (_b = axis.thickness) !== null && _b !== void 0 ? _b : 1), generateXAxisLabels(xMin, xMax, yMin + ((_c = axis.tickLabelDisp) !== null && _c !== void 0 ? _c : 10), "down", xTicks, axis, chart));
151
139
  switch (chart.labelLayout) {
152
140
  case "original":
153
- xLabel = generateXAxisLabel(xMax + 0.5 * padding, yMin + 10, "uniform", "down", xAxisBottom.label, chart);
141
+ components.push(generateXAxisLabel(xMax + chart.padding.right, yMin + ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 10), "uniform", "down", axis, chart));
154
142
  break;
155
143
  case "end":
156
- xLabel = generateXAxisLabel(xMax, yMin + 25, "left", "down", xAxisBottom.label, chart);
144
+ components.push(generateXAxisLabel(xMax, axisLabelPosY, "left", "down", axis, chart));
157
145
  break;
158
146
  case "center":
159
- xLabel = generateXAxisLabel((xMin + xMax) / 2, yMin + 25, "uniform", "down", xAxisBottom.label, chart);
147
+ components.push(generateXAxisLabel((xMin + xMax) / 2, axisLabelPosY, "uniform", "down", axis, chart));
160
148
  break;
161
149
  default:
162
150
  return (0, ts_exhaustive_check_1.exhaustiveCheck)(chart.labelLayout);
163
151
  }
164
- return AbstractImage.createGroup("XAxisBottom", [xLines, xLabels, xLabel]);
152
+ return AI.createGroup("XAxisBottom", components);
165
153
  }
166
154
  exports.generateXAxisBottom = generateXAxisBottom;
167
- function generateXAxisTop(xNumTicks, xAxisTop, xMin, xMax, yMax, chart) {
168
- if (!xAxisTop) {
169
- return AbstractImage.createGroup("XAxisTop", []);
155
+ function generateXAxisTop(xNumTicks, axis, xMin, xMax, yMax, chart) {
156
+ var _a, _b, _c, _d;
157
+ const components = Array();
158
+ if (!axis) {
159
+ return AI.createGroup("XAxisTop", components);
170
160
  }
171
- const xTicks2 = Axis.getTicks(xNumTicks, xAxisTop);
172
- const xLines2 = generateXAxisGridLines(xMin, xMax, yMax - 10, yMax, xTicks2, xAxisTop, chart);
173
- const xLabels2 = generateXAxisLabels(xMin, xMax, yMax - 13, "up", xTicks2, xAxisTop, chart);
174
- let xLabel2;
161
+ const axisLabelPosY = yMax - chart.padding.top + chart.fontSize;
162
+ const xTicks = Axis.getTicks(xNumTicks, axis);
163
+ if (chart.xGrid) {
164
+ components.push(generateXAxisGridLines(xMin, xMax, yMax - 10, yMax, xTicks, axis, chart.xGrid));
165
+ }
166
+ components.push(AI.createLine({ x: xMin, y: yMax }, { x: xMax, y: yMax }, (_a = axis.axisColor) !== null && _a !== void 0 ? _a : AI.gray, (_b = axis.thickness) !== null && _b !== void 0 ? _b : 1), generateXAxisLabels(xMin, xMax, yMax - ((_c = axis.tickLabelDisp) !== null && _c !== void 0 ? _c : 13), "up", xTicks, axis, chart));
175
167
  switch (chart.labelLayout) {
176
168
  case "original":
177
- xLabel2 = generateXAxisLabel(xMax + 0.5 * padding, yMax - 13, "uniform", "up", xAxisTop.label, chart);
169
+ components.push(generateXAxisLabel(xMax + 0.5 * chart.padding.right, yMax - ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 13), "uniform", "up", axis, chart));
178
170
  break;
179
171
  case "end":
180
- xLabel2 = generateXAxisLabel(xMax, yMax - 30, "left", "up", xAxisTop.label, chart);
172
+ components.push(generateXAxisLabel(xMax, axisLabelPosY, "left", "up", axis, chart));
181
173
  break;
182
174
  case "center":
183
- xLabel2 = generateXAxisLabel((xMin + xMax) / 2, yMax - 30, "uniform", "up", xAxisTop.label, chart);
175
+ components.push(generateXAxisLabel((xMin + xMax) / 2, axisLabelPosY, "uniform", "up", axis, chart));
184
176
  break;
185
177
  default:
186
178
  return (0, ts_exhaustive_check_1.exhaustiveCheck)(chart.labelLayout);
187
179
  }
188
- return AbstractImage.createGroup("XAxisTop", [xLines2, xLabels2, xLabel2]);
180
+ return AI.createGroup("XAxisTop", components);
189
181
  }
190
182
  exports.generateXAxisTop = generateXAxisTop;
191
- function generateYAxisLeft(yNumTicks, yAxisLeft, xMin, xMax, yMin, yMax, chart) {
192
- if (!yAxisLeft) {
193
- return AbstractImage.createGroup("YAxisLeft", []);
183
+ function generateYAxisLeft(yNumTicks, axis, xMin, xMax, yMin, yMax, chart) {
184
+ var _a, _b, _c;
185
+ const components = Array();
186
+ if (!axis) {
187
+ return AI.createGroup("YAxisLeft", components);
188
+ }
189
+ const axisLabelPosX = xMin - chart.padding.left + chart.fontSize;
190
+ const yTicks = Axis.getTicks(yNumTicks, axis);
191
+ if (chart.yGrid) {
192
+ components.push(generateYAxisLines(xMin - 5, xMax, yMin, yMax, yTicks, axis, chart.yGrid));
194
193
  }
195
- const yTicks = Axis.getTicks(yNumTicks, yAxisLeft);
196
- const yLines = generateYAxisLines(xMin - 5, xMax, yMin, yMax, yTicks, yAxisLeft, chart);
197
- const yLabels = generateYAxisLabels(xMin - 7, yMin, yMax, "left", yTicks, yAxisLeft, chart);
198
- const labelPaddingLeft = 5 + labelPadding(formatNumber(yAxisLeft.max).length, chart.fontSize, 0.5);
199
- let yLabel;
194
+ components.push(AI.createLine({ x: xMin, y: yMin }, { x: xMin, y: yMax }, (_a = axis.axisColor) !== null && _a !== void 0 ? _a : AI.gray, (_b = axis.thickness) !== null && _b !== void 0 ? _b : 1), generateYAxisLabels(xMin - ((_c = axis.tickLabelDisp) !== null && _c !== void 0 ? _c : 7), yMin, yMax, "left", yTicks, axis, chart));
200
195
  switch (chart.labelLayout) {
201
196
  case "original":
202
- yLabel = generateYAxisLabel(xMin - labelPaddingLeft, yMax + 0.5 * padding, "uniform", "up", yAxisLeft.label, chart);
197
+ components.push(generateYAxisLabel(axisLabelPosX, yMax + 0.5 * chart.padding.bottom, "uniform", "up", axis, chart));
203
198
  break;
204
199
  case "end":
205
- yLabel = generateYAxisLabel(xMin - labelPaddingLeft, yMax, "left", "up", yAxisLeft.label, chart);
200
+ components.push(generateYAxisLabel(axisLabelPosX, yMax, "left", "up", axis, chart));
206
201
  break;
207
202
  case "center":
208
- yLabel = generateYAxisLabel(xMin - labelPaddingLeft, (yMin + yMax) / 2, "uniform", "up", yAxisLeft.label, chart);
203
+ components.push(generateYAxisLabel(axisLabelPosX, (yMin + yMax) / 2, "uniform", "up", axis, chart));
209
204
  break;
210
205
  default:
211
206
  return (0, ts_exhaustive_check_1.exhaustiveCheck)(chart.labelLayout);
212
207
  }
213
- return AbstractImage.createGroup("YAxisLeft", [yLines, yLabels, yLabel]);
208
+ return AI.createGroup("YAxisLeft", components);
214
209
  }
215
210
  exports.generateYAxisLeft = generateYAxisLeft;
216
- function generateYAxisRight(yNumTicks, yAxisRight, xMax, yMin, yMax, chart) {
217
- if (!yAxisRight) {
218
- return AbstractImage.createGroup("YAxisRight", []);
211
+ function generateYAxisRight(yNumTicks, axis, xMax, yMin, yMax, chart) {
212
+ var _a, _b, _c;
213
+ const components = Array();
214
+ if (!axis) {
215
+ return AI.createGroup("YAxisRight", components);
216
+ }
217
+ const axisLabelPosX = xMax + chart.padding.right - chart.fontSize;
218
+ const yTicks = Axis.getTicks(yNumTicks, axis);
219
+ if (chart.yGrid) {
220
+ components.push(generateYAxisLines(xMax - 5, xMax + 5, yMin, yMax, yTicks, axis, chart.yGrid));
219
221
  }
220
- const yTicks2 = Axis.getTicks(yNumTicks, yAxisRight);
221
- const yLines2 = generateYAxisLines(xMax - 5, xMax + 5, yMin, yMax, yTicks2, yAxisRight, chart);
222
- const yLabels2 = generateYAxisLabels(xMax + 7, yMin, yMax, "right", yTicks2, yAxisRight, chart);
223
- const labelPaddingRight = 7 + labelPadding(formatNumber(yAxisRight.max).length, chart.fontSize, 1.5);
224
- let yLabel2;
222
+ components.push(AI.createLine({ x: xMax, y: yMin }, { x: xMax, y: yMax }, (_a = axis.axisColor) !== null && _a !== void 0 ? _a : AI.gray, (_b = axis.thickness) !== null && _b !== void 0 ? _b : 1), generateYAxisLabels(xMax + ((_c = axis.tickLabelDisp) !== null && _c !== void 0 ? _c : 7), yMin, yMax, "right", yTicks, axis, chart));
225
223
  switch (chart.labelLayout) {
226
224
  case "original":
227
- yLabel2 = generateYAxisLabel(xMax + labelPaddingRight, yMax + 0.5 * padding, "uniform", "up", yAxisRight.label, chart);
225
+ components.push(generateYAxisLabel(axisLabelPosX, yMax + 0.5 * chart.padding.bottom, "uniform", "up", axis, chart));
228
226
  break;
229
227
  case "end":
230
- yLabel2 = generateYAxisLabel(xMax + labelPaddingRight, yMax, "left", "up", yAxisRight.label, chart);
228
+ components.push(generateYAxisLabel(axisLabelPosX, yMax, "left", "up", axis, chart));
231
229
  break;
232
230
  case "center":
233
- yLabel2 = generateYAxisLabel(xMax + labelPaddingRight, (yMin + yMax) / 2, "uniform", "up", yAxisRight.label, chart);
231
+ components.push(generateYAxisLabel(axisLabelPosX, (yMin + yMax) / 2, "uniform", "up", axis, chart));
234
232
  break;
235
233
  default:
236
234
  return (0, ts_exhaustive_check_1.exhaustiveCheck)(chart.labelLayout);
237
235
  }
238
- return AbstractImage.createGroup("YAxisRight", [yLines2, yLabels2, yLabel2]);
236
+ return AI.createGroup("YAxisRight", components);
239
237
  }
240
238
  exports.generateYAxisRight = generateYAxisRight;
241
239
  function generateStack(xMin, xMax, yMin, yMax, chart) {
@@ -249,12 +247,13 @@ function generateStack(xMin, xMax, yMin, yMax, chart) {
249
247
  ys: [...stackPoint.ys.map((y) => Math.max(0, y))],
250
248
  }));
251
249
  const stackNeg = generateUnsignedStack(xMin, xMax, yMin, yMax, Object.assign(Object.assign({}, chart), { chartStack: Object.assign(Object.assign({}, chart.chartStack), { points: pointsNeg }) }));
252
- return AbstractImage.createGroup("Stacks", [stackPos, stackNeg]);
250
+ return AI.createGroup("Stacks", [stackPos, stackNeg]);
253
251
  }
254
252
  exports.generateStack = generateStack;
255
253
  function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
254
+ var _a, _b;
256
255
  if (chart.chartStack.points.length < 2) {
257
- return AbstractImage.createGroup("stack", []);
256
+ return AI.createGroup("stack", []);
258
257
  }
259
258
  const xAxis = chart.chartStack.xAxis === "top" ? chart.xAxisTop : chart.xAxisBottom;
260
259
  const yAxis = chart.chartStack.yAxis === "right" ? chart.yAxisRight : chart.yAxisLeft;
@@ -262,20 +261,20 @@ function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
262
261
  let sumY = 0;
263
262
  const points = stackPoints.ys.map((y) => {
264
263
  sumY += y;
265
- return Axis.transformPoint(AbstractImage.createPoint(stackPoints.x, sumY), xMin, xMax, yMin, yMax, xAxis, yAxis);
264
+ return Axis.transformPoint(AI.createPoint(stackPoints.x, sumY), xMin, xMax, yMin, yMax, xAxis, yAxis);
266
265
  });
267
266
  return points;
268
267
  });
269
268
  // Transpose the xPoints data to lines.
270
269
  const lines = [];
271
- for (let i = 0; i < xPoints[0].length; ++i) {
270
+ for (let i = 0; i < ((_b = (_a = xPoints[0]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); ++i) {
272
271
  lines[i] = [];
273
272
  for (const points of xPoints) {
274
273
  lines[i].push(points[i]);
275
274
  }
276
275
  }
277
276
  const polygons = [];
278
- let lastLine = chart.chartStack.points.map((stackPoint) => Axis.transformPoint(AbstractImage.createPoint(stackPoint.x, 0), xMin, xMax, yMin, yMax, xAxis, yAxis));
277
+ let lastLine = chart.chartStack.points.map((stackPoint) => Axis.transformPoint(AI.createPoint(stackPoint.x, 0), xMin, xMax, yMin, yMax, xAxis, yAxis));
279
278
  lines.forEach((line, index) => {
280
279
  const config = chart.chartStack.config[index];
281
280
  if (!config) {
@@ -284,39 +283,40 @@ function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
284
283
  const color = config.color;
285
284
  const points = [...line, ...lastLine.slice().reverse()];
286
285
  lastLine = line;
287
- polygons.push(AbstractImage.createPolygon(points, color, 0, color));
286
+ polygons.push(AI.createPolygon(points, color, 0, color));
288
287
  });
289
- return AbstractImage.createGroup("Stack", polygons);
288
+ return AI.createGroup("Stack", polygons);
290
289
  }
291
290
  function generateLines(xMin, xMax, yMin, yMax, chart) {
292
291
  const lines = chart.chartLines.map((l) => {
292
+ var _a;
293
293
  if (l.points.length < 2) {
294
- return AbstractImage.createGroup(l.label, []);
294
+ return AI.createGroup(l.label, []);
295
295
  }
296
296
  const xAxis = l.xAxis === "top" ? chart.xAxisTop : chart.xAxisBottom;
297
297
  const yAxis = l.yAxis === "right" ? chart.yAxisRight : chart.yAxisLeft;
298
298
  const points = l.points.map((p) => Axis.transformPoint(p, xMin, xMax, yMin, yMax, xAxis, yAxis));
299
- const last = points[points.length - 1];
300
- return AbstractImage.createGroup(l.label, [
301
- AbstractImage.createPolyLine(points, l.color, l.thickness),
302
- AbstractImage.createText(last, l.label, chart.font, chart.fontSize, AbstractImage.black, "normal", 0, "center", "right", "down", 0, AbstractImage.black, false),
299
+ return AI.createGroup(l.label, [
300
+ AI.createPolyLine(points, l.color, l.thickness),
301
+ AI.createText(points.at(-1), l.label, chart.font, (_a = l.fontSize) !== null && _a !== void 0 ? _a : chart.fontSize, AI.black, "normal", 0, "center", "right", "down", 0, AI.black, false),
303
302
  ]);
304
303
  });
305
- return AbstractImage.createGroup("Lines", lines);
304
+ return AI.createGroup("Lines", lines);
306
305
  }
307
306
  exports.generateLines = generateLines;
308
307
  function generatePoints(xMin, xMax, yMin, yMax, chart) {
309
308
  const points = chart.chartPoints.map((p) => {
309
+ var _a;
310
310
  const xAxis = p.xAxis === "top" ? chart.xAxisTop : chart.xAxisBottom;
311
311
  const yAxis = p.yAxis === "right" ? chart.yAxisRight : chart.yAxisLeft;
312
312
  const position = Axis.transformPoint(p.position, xMin, xMax, yMin, yMax, xAxis, yAxis);
313
313
  const shape = generatePointShape(p, position);
314
- return AbstractImage.createGroup(p.label, [
314
+ return AI.createGroup(p.label, [
315
315
  shape,
316
- AbstractImage.createText(position, p.label, chart.font, chart.fontSize, AbstractImage.black, "normal", 0, "center", "right", "down", 0, AbstractImage.black, false),
316
+ AI.createText(position, p.label, chart.font, (_a = p.fontSize) !== null && _a !== void 0 ? _a : chart.fontSize, AI.black, "normal", 0, "center", "right", "down", 0, AI.black, false),
317
317
  ]);
318
318
  });
319
- return AbstractImage.createGroup("Points", points);
319
+ return AI.createGroup("Points", points);
320
320
  }
321
321
  exports.generatePoints = generatePoints;
322
322
  function generatePointShape(p, position) {
@@ -324,67 +324,71 @@ function generatePointShape(p, position) {
324
324
  const halfHeight = p.size.height * 0.5;
325
325
  if (p.shape === "triangle") {
326
326
  const trianglePoints = [
327
- AbstractImage.createPoint(position.x, position.y + halfHeight),
328
- AbstractImage.createPoint(position.x - halfWidth, position.y - halfHeight),
329
- AbstractImage.createPoint(position.x + halfWidth, position.y - halfHeight),
327
+ AI.createPoint(position.x, position.y + halfHeight),
328
+ AI.createPoint(position.x - halfWidth, position.y - halfHeight),
329
+ AI.createPoint(position.x + halfWidth, position.y - halfHeight),
330
330
  ];
331
- return AbstractImage.createPolygon(trianglePoints, AbstractImage.black, 1, p.color);
331
+ return AI.createPolygon(trianglePoints, AI.black, 1, p.color);
332
332
  }
333
333
  else if (p.shape === "square") {
334
- const topLeft = AbstractImage.createPoint(position.x - halfWidth, position.y - halfHeight);
335
- const bottomRight = AbstractImage.createPoint(position.x + halfWidth, position.y + halfHeight);
336
- return AbstractImage.createRectangle(topLeft, bottomRight, AbstractImage.black, 1, p.color);
334
+ const topLeft = AI.createPoint(position.x - halfWidth, position.y - halfHeight);
335
+ const bottomRight = AI.createPoint(position.x + halfWidth, position.y + halfHeight);
336
+ return AI.createRectangle(topLeft, bottomRight, AI.black, 1, p.color);
337
337
  }
338
338
  else {
339
- const topLeft = AbstractImage.createPoint(position.x - halfWidth, position.y - halfHeight);
340
- const bottomRight = AbstractImage.createPoint(position.x + halfWidth, position.y + halfHeight);
341
- return AbstractImage.createEllipse(topLeft, bottomRight, AbstractImage.black, 1, p.color);
339
+ const topLeft = AI.createPoint(position.x - halfWidth, position.y - halfHeight);
340
+ const bottomRight = AI.createPoint(position.x + halfWidth, position.y + halfHeight);
341
+ return AI.createEllipse(topLeft, bottomRight, AI.black, 1, p.color);
342
342
  }
343
343
  }
344
- function generateXAxisGridLines(xMin, xMax, yMin, yMax, xTicks, xAxis, chart) {
344
+ function generateXAxisGridLines(xMin, xMax, yMin, yMax, xTicks, xAxis, grid) {
345
345
  const xLines = xTicks.map((l) => {
346
- const x = Axis.transformValue(l, xMin, xMax, xAxis);
347
- const start = AbstractImage.createPoint(x, yMin);
348
- const end = AbstractImage.createPoint(x, yMax);
349
- return AbstractImage.createLine(start, end, chart.gridColor, chart.gridThickness);
346
+ const x = Axis.transformValue(l.value, xMin, xMax, xAxis);
347
+ const start = AI.createPoint(x, yMin);
348
+ const end = AI.createPoint(x, yMax);
349
+ return AI.createLine(start, end, grid.color, grid.thickness);
350
350
  });
351
- return AbstractImage.createGroup("Lines", xLines);
351
+ return AI.createGroup("Lines", xLines);
352
352
  }
353
353
  exports.generateXAxisGridLines = generateXAxisGridLines;
354
- function generateXAxisLabels(xMin, xMax, y, growVertical, xTicks, xAxis, chart) {
355
- const xLabels = xTicks.map((l) => {
356
- const position = AbstractImage.createPoint(Axis.transformValue(l, xMin, xMax, xAxis), y);
357
- return AbstractImage.createText(position, formatNumber(l), chart.font, chart.fontSize, AbstractImage.black, "normal", 0, "center", "uniform", growVertical, 0, AbstractImage.black, false);
354
+ function generateXAxisLabels(xMin, xMax, y, growVertical, ticks, axis, chart) {
355
+ const xLabels = ticks.map((l) => {
356
+ var _a, _b, _c, _d, _e;
357
+ const position = AI.createPoint(Axis.transformValue(l.value, xMin, xMax, axis), y);
358
+ return AI.createText(position, (_a = l.label) !== null && _a !== void 0 ? _a : formatNumber(l.value), chart.font, (_b = axis.tickFontSize) !== null && _b !== void 0 ? _b : chart.fontSize, (_c = axis.labelColor) !== null && _c !== void 0 ? _c : AI.black, "normal", (_d = axis.labelRotation) !== null && _d !== void 0 ? _d : 0, "center", "uniform", growVertical, 0, (_e = axis.labelColor) !== null && _e !== void 0 ? _e : AI.black, false);
358
359
  });
359
- return AbstractImage.createGroup("Labels", xLabels);
360
+ return AI.createGroup("Labels", xLabels);
360
361
  }
361
362
  exports.generateXAxisLabels = generateXAxisLabels;
362
- function generateXAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection, label, chart) {
363
- const position = AbstractImage.createPoint(x, y);
364
- return AbstractImage.createText(position, label, chart.font, chart.fontSize, AbstractImage.black, "normal", 0, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, AbstractImage.black, false);
363
+ function generateXAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection, axis, chart) {
364
+ var _a, _b, _c;
365
+ const position = AI.createPoint(x, y);
366
+ return AI.createText(position, axis.label, chart.font, (_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : chart.fontSize, (_b = axis.labelColor) !== null && _b !== void 0 ? _b : AI.black, "normal", 0, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, (_c = axis.labelColor) !== null && _c !== void 0 ? _c : AI.black, false);
365
367
  }
366
368
  exports.generateXAxisLabel = generateXAxisLabel;
367
- function generateYAxisLines(xMin, xMax, yMin, yMax, yTicks, yAxis, chart) {
369
+ function generateYAxisLines(xMin, xMax, yMin, yMax, yTicks, yAxis, grid) {
368
370
  const yLines = yTicks.map((l) => {
369
- const y = Axis.transformValue(l, yMin, yMax, yAxis);
370
- const start = AbstractImage.createPoint(xMin, y);
371
- const end = AbstractImage.createPoint(xMax, y);
372
- return AbstractImage.createLine(start, end, chart.gridColor, chart.gridThickness);
371
+ const y = Axis.transformValue(l.value, yMin, yMax, yAxis);
372
+ const start = AI.createPoint(xMin, y);
373
+ const end = AI.createPoint(xMax, y);
374
+ return AI.createLine(start, end, grid.color, grid.thickness);
373
375
  });
374
- return AbstractImage.createGroup("Lines", yLines);
376
+ return AI.createGroup("Lines", yLines);
375
377
  }
376
378
  exports.generateYAxisLines = generateYAxisLines;
377
379
  function generateYAxisLabels(x, yMin, yMax, growHorizontal, yTicks, yAxis, chart) {
378
380
  const yLabels = yTicks.map((l) => {
379
- const position = AbstractImage.createPoint(x, Axis.transformValue(l, yMin, yMax, yAxis));
380
- return AbstractImage.createText(position, formatNumber(l), chart.font, chart.fontSize, AbstractImage.black, "normal", 0, "center", growHorizontal, "uniform", 0, AbstractImage.black, false);
381
+ var _a, _b, _c, _d, _e;
382
+ const position = AI.createPoint(x, Axis.transformValue(l.value, yMin, yMax, yAxis));
383
+ return AI.createText(position, (_a = l.label) !== null && _a !== void 0 ? _a : formatNumber(l.value), chart.font, (_b = yAxis.tickFontSize) !== null && _b !== void 0 ? _b : chart.fontSize, (_c = yAxis.labelColor) !== null && _c !== void 0 ? _c : AI.black, "normal", (_d = yAxis.labelRotation) !== null && _d !== void 0 ? _d : 0, "center", growHorizontal, "uniform", 0, (_e = yAxis.labelColor) !== null && _e !== void 0 ? _e : AI.black, false);
381
384
  });
382
- return AbstractImage.createGroup("Labels", yLabels);
385
+ return AI.createGroup("Labels", yLabels);
383
386
  }
384
387
  exports.generateYAxisLabels = generateYAxisLabels;
385
- function generateYAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection, label, chart) {
386
- const position = AbstractImage.createPoint(x, y);
387
- return AbstractImage.createText(position, label, chart.font, chart.fontSize, AbstractImage.black, "normal", -90, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, AbstractImage.black, false);
388
+ function generateYAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection, axis, chart) {
389
+ var _a, _b, _c;
390
+ const position = AI.createPoint(x, y);
391
+ return AI.createText(position, axis.label, chart.font, (_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : chart.fontSize, (_b = axis.labelColor) !== null && _b !== void 0 ? _b : AI.black, "normal", -90, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, (_c = axis.labelColor) !== null && _c !== void 0 ? _c : AI.black, false);
388
392
  }
389
393
  exports.generateYAxisLabel = generateYAxisLabel;
390
394
  function formatNumber(n) {