abstract-chart 6.0.0 → 7.0.1
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/CHANGELOG.md +34 -2
- package/lib/axis.d.ts +33 -13
- package/lib/axis.d.ts.map +1 -1
- package/lib/axis.js +63 -36
- package/lib/axis.js.map +1 -1
- package/lib/chart.d.ts +56 -36
- package/lib/chart.d.ts.map +1 -1
- package/lib/chart.js +170 -166
- package/lib/chart.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/axis.ts +112 -58
- package/src/chart.ts +265 -322
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.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
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
|
|
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 -
|
|
107
|
-
const gridHeight = height - padding;
|
|
108
|
-
const xMin = padding;
|
|
109
|
-
const xMax = width - padding;
|
|
110
|
-
const yMin = height -
|
|
111
|
-
const yMax =
|
|
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 =
|
|
133
|
-
const size =
|
|
134
|
-
return
|
|
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
|
-
|
|
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,
|
|
144
|
-
|
|
145
|
-
|
|
127
|
+
function generateXAxisBottom(xNumTicks, axis, xMin, xMax, yMin, yMax, chart) {
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
|
+
const components = Array();
|
|
130
|
+
if (!axis) {
|
|
131
|
+
return AI.createGroup("XAxisBottom", components);
|
|
132
|
+
}
|
|
133
|
+
const axisLabelPosY = yMin + chart.padding.bottom - ((_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : 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
|
-
|
|
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 }, (_b = axis.axisColor) !== null && _b !== void 0 ? _b : AI.gray, (_c = axis.thickness) !== null && _c !== void 0 ? _c : 1), generateXAxisLabels(xMin, xMax, yMin + ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 10), "down", xTicks, axis, chart));
|
|
151
139
|
switch (chart.labelLayout) {
|
|
152
140
|
case "original":
|
|
153
|
-
|
|
141
|
+
components.push(generateXAxisLabel(xMax + chart.padding.right, yMin + ((_e = axis.tickLabelDisp) !== null && _e !== void 0 ? _e : 10), "uniform", "down", axis, chart));
|
|
154
142
|
break;
|
|
155
143
|
case "end":
|
|
156
|
-
|
|
144
|
+
components.push(generateXAxisLabel(xMax, axisLabelPosY, "left", "down", axis, chart));
|
|
157
145
|
break;
|
|
158
146
|
case "center":
|
|
159
|
-
|
|
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
|
|
152
|
+
return AI.createGroup("XAxisBottom", components);
|
|
165
153
|
}
|
|
166
154
|
exports.generateXAxisBottom = generateXAxisBottom;
|
|
167
|
-
function generateXAxisTop(xNumTicks,
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
function generateXAxisTop(xNumTicks, axis, xMin, xMax, yMax, chart) {
|
|
156
|
+
var _a, _b, _c, _d, _e;
|
|
157
|
+
const components = Array();
|
|
158
|
+
if (!axis) {
|
|
159
|
+
return AI.createGroup("XAxisTop", components);
|
|
170
160
|
}
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
const axisLabelPosY = yMax - chart.padding.top + ((_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : 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 }, (_b = axis.axisColor) !== null && _b !== void 0 ? _b : AI.gray, (_c = axis.thickness) !== null && _c !== void 0 ? _c : 1), generateXAxisLabels(xMin, xMax, yMax - ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 13), "up", xTicks, axis, chart));
|
|
175
167
|
switch (chart.labelLayout) {
|
|
176
168
|
case "original":
|
|
177
|
-
|
|
169
|
+
components.push(generateXAxisLabel(xMax + 0.5 * chart.padding.right, yMax - ((_e = axis.tickLabelDisp) !== null && _e !== void 0 ? _e : 13), "uniform", "up", axis, chart));
|
|
178
170
|
break;
|
|
179
171
|
case "end":
|
|
180
|
-
|
|
172
|
+
components.push(generateXAxisLabel(xMax, axisLabelPosY, "left", "up", axis, chart));
|
|
181
173
|
break;
|
|
182
174
|
case "center":
|
|
183
|
-
|
|
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
|
|
180
|
+
return AI.createGroup("XAxisTop", components);
|
|
189
181
|
}
|
|
190
182
|
exports.generateXAxisTop = generateXAxisTop;
|
|
191
|
-
function generateYAxisLeft(yNumTicks,
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
function generateYAxisLeft(yNumTicks, axis, xMin, xMax, yMin, yMax, chart) {
|
|
184
|
+
var _a, _b, _c, _d;
|
|
185
|
+
const components = Array();
|
|
186
|
+
if (!axis) {
|
|
187
|
+
return AI.createGroup("YAxisLeft", components);
|
|
188
|
+
}
|
|
189
|
+
const axisLabelPosX = xMin - chart.padding.left + ((_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : 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
|
-
|
|
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 }, (_b = axis.axisColor) !== null && _b !== void 0 ? _b : AI.gray, (_c = axis.thickness) !== null && _c !== void 0 ? _c : 1), generateYAxisLabels(xMin - ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 7), yMin, yMax, "left", yTicks, axis, chart));
|
|
200
195
|
switch (chart.labelLayout) {
|
|
201
196
|
case "original":
|
|
202
|
-
|
|
197
|
+
components.push(generateYAxisLabel(axisLabelPosX, yMax + 0.5 * chart.padding.bottom, "uniform", "up", axis, chart));
|
|
203
198
|
break;
|
|
204
199
|
case "end":
|
|
205
|
-
|
|
200
|
+
components.push(generateYAxisLabel(axisLabelPosX, yMax, "left", "up", axis, chart));
|
|
206
201
|
break;
|
|
207
202
|
case "center":
|
|
208
|
-
|
|
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
|
|
208
|
+
return AI.createGroup("YAxisLeft", components);
|
|
214
209
|
}
|
|
215
210
|
exports.generateYAxisLeft = generateYAxisLeft;
|
|
216
|
-
function generateYAxisRight(yNumTicks,
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
function generateYAxisRight(yNumTicks, axis, xMax, yMin, yMax, chart) {
|
|
212
|
+
var _a, _b, _c, _d;
|
|
213
|
+
const components = Array();
|
|
214
|
+
if (!axis) {
|
|
215
|
+
return AI.createGroup("YAxisRight", components);
|
|
216
|
+
}
|
|
217
|
+
const axisLabelPosX = xMax + chart.padding.right - ((_a = axis.axisFontSize) !== null && _a !== void 0 ? _a : 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
|
-
|
|
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 }, (_b = axis.axisColor) !== null && _b !== void 0 ? _b : AI.gray, (_c = axis.thickness) !== null && _c !== void 0 ? _c : 1), generateYAxisLabels(xMax + ((_d = axis.tickLabelDisp) !== null && _d !== void 0 ? _d : 7), yMin, yMax, "right", yTicks, axis, chart));
|
|
225
223
|
switch (chart.labelLayout) {
|
|
226
224
|
case "original":
|
|
227
|
-
|
|
225
|
+
components.push(generateYAxisLabel(axisLabelPosX, yMax + 0.5 * chart.padding.bottom, "uniform", "up", axis, chart));
|
|
228
226
|
break;
|
|
229
227
|
case "end":
|
|
230
|
-
|
|
228
|
+
components.push(generateYAxisLabel(axisLabelPosX, yMax, "left", "up", axis, chart));
|
|
231
229
|
break;
|
|
232
230
|
case "center":
|
|
233
|
-
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
286
|
+
polygons.push(AI.createPolygon(points, color, 0, color));
|
|
288
287
|
});
|
|
289
|
-
return
|
|
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
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
|
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
|
|
314
|
+
return AI.createGroup(p.label, [
|
|
315
315
|
shape,
|
|
316
|
-
|
|
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
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
|
331
|
+
return AI.createPolygon(trianglePoints, AI.black, 1, p.color);
|
|
332
332
|
}
|
|
333
333
|
else if (p.shape === "square") {
|
|
334
|
-
const topLeft =
|
|
335
|
-
const bottomRight =
|
|
336
|
-
return
|
|
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 =
|
|
340
|
-
const bottomRight =
|
|
341
|
-
return
|
|
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,
|
|
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 =
|
|
348
|
-
const end =
|
|
349
|
-
return
|
|
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
|
|
351
|
+
return AI.createGroup("Lines", xLines);
|
|
352
352
|
}
|
|
353
353
|
exports.generateXAxisGridLines = generateXAxisGridLines;
|
|
354
|
-
function generateXAxisLabels(xMin, xMax, y, growVertical,
|
|
355
|
-
const xLabels =
|
|
356
|
-
|
|
357
|
-
|
|
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
|
|
360
|
+
return AI.createGroup("Labels", xLabels);
|
|
360
361
|
}
|
|
361
362
|
exports.generateXAxisLabels = generateXAxisLabels;
|
|
362
|
-
function generateXAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection,
|
|
363
|
-
|
|
364
|
-
|
|
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,
|
|
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 =
|
|
371
|
-
const end =
|
|
372
|
-
return
|
|
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
|
|
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
|
-
|
|
380
|
-
|
|
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
|
|
385
|
+
return AI.createGroup("Labels", yLabels);
|
|
383
386
|
}
|
|
384
387
|
exports.generateYAxisLabels = generateYAxisLabels;
|
|
385
|
-
function generateYAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection,
|
|
386
|
-
|
|
387
|
-
|
|
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) {
|