abstract-chart 12.0.45 → 12.0.46
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/axis.d.ts +8 -8
- package/lib/axis.d.ts.map +1 -1
- package/lib/axis.js +2 -2
- package/lib/axis.js.map +1 -1
- package/lib/chart.d.ts +47 -47
- package/lib/chart.d.ts.map +1 -1
- package/lib/chart.js +98 -98
- package/lib/chart.js.map +1 -1
- package/package.json +2 -2
- package/src/axis.ts +13 -13
- package/src/chart.ts +205 -205
package/lib/chart.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
import * as AI from "abstract-image";
|
|
4
3
|
import { inverseTransformValue, getTicks, createLinearAxis, transformValue, transformPoint, } from "./axis.js";
|
|
4
|
+
import { black, createAbstractImage, createEllipse, createGroup, createLine, createPoint, createPolygon, createPolyLine, createRectangle, createSize, createText, gray, lightGray, solidLine, transparent, white } from "abstract-image";
|
|
5
5
|
const axisLabelPosFactor = 0.65;
|
|
6
6
|
export function createChart(props) {
|
|
7
7
|
return {
|
|
@@ -20,11 +20,11 @@ export function createChart(props) {
|
|
|
20
20
|
xAxisesTop: props.xAxisesTop ?? [],
|
|
21
21
|
yAxisesLeft: props.yAxisesLeft ?? [],
|
|
22
22
|
yAxisesRight: props.yAxisesRight ?? [],
|
|
23
|
-
backgroundColor: props.backgroundColor ??
|
|
23
|
+
backgroundColor: props.backgroundColor ?? white,
|
|
24
24
|
font: props.font ?? "Arial",
|
|
25
25
|
fontSize: props.fontSize ?? 12,
|
|
26
|
-
textColor: props.textColor ??
|
|
27
|
-
textOutlineColor: props.textOutlineColor ??
|
|
26
|
+
textColor: props.textColor ?? black,
|
|
27
|
+
textOutlineColor: props.textOutlineColor ?? transparent,
|
|
28
28
|
labelLayout: props.labelLayout ?? "original",
|
|
29
29
|
padding: {
|
|
30
30
|
top: props.padding?.top ?? 10,
|
|
@@ -38,14 +38,14 @@ export function createChart(props) {
|
|
|
38
38
|
bottom: props.axisWidth?.bottom ?? 50,
|
|
39
39
|
left: props.axisWidth?.left ?? 50,
|
|
40
40
|
},
|
|
41
|
-
xGrid: { color: props.xGrid?.color ??
|
|
42
|
-
yGrid: { color: props.yGrid?.color ??
|
|
41
|
+
xGrid: { color: props.xGrid?.color ?? gray, thickness: props.xGrid?.thickness ?? 1 },
|
|
42
|
+
yGrid: { color: props.yGrid?.color ?? gray, thickness: props.yGrid?.thickness ?? 1 },
|
|
43
43
|
xPixelsPerTick: props.xPixelsPerTick ?? 40,
|
|
44
44
|
yPixelsPerTick: props.yPixelsPerTick ?? 40,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export function createChartArea(props) {
|
|
48
|
-
const { points = [], color =
|
|
48
|
+
const { points = [], color = lightGray, strokeColor = transparent, strokeThickness = 0, xAxis = "bottom", xAxisIx = 0, yAxis = "left", yAxisIx = 0, id, } = props || {};
|
|
49
49
|
return {
|
|
50
50
|
points,
|
|
51
51
|
color,
|
|
@@ -59,7 +59,7 @@ export function createChartArea(props) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
export function createChartPoint(props) {
|
|
62
|
-
const { shape = "circle", position =
|
|
62
|
+
const { shape = "circle", position = createPoint(0, 0), color = black, strokeColor = black, strokeThickness = 1, size = createSize(6, 6), label = "", xAxis = "bottom", xAxisIx = 0, yAxis = "left", yAxisIx = 0, fontSize, textColor, textOutlineColor, id, } = props || {};
|
|
63
63
|
return {
|
|
64
64
|
shape,
|
|
65
65
|
position,
|
|
@@ -79,11 +79,11 @@ export function createChartPoint(props) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
export function createChartLine(props) {
|
|
82
|
-
const { points = [], color =
|
|
82
|
+
const { points = [], color = black, thickness = 1, label = "", xAxis = "bottom", xAxisIx = 0, yAxis = "left", yAxisIx = 0, fontSize, textColor, textOutlineColor, id, } = props || {};
|
|
83
83
|
return { points, color, thickness, label, xAxis, xAxisIx, yAxis, yAxisIx, fontSize, textColor, textOutlineColor, id };
|
|
84
84
|
}
|
|
85
85
|
export function createChartStackConfig(props) {
|
|
86
|
-
const { color =
|
|
86
|
+
const { color = black, label = "" } = props || {};
|
|
87
87
|
return { color, label };
|
|
88
88
|
}
|
|
89
89
|
export function createChartStack(props) {
|
|
@@ -116,7 +116,7 @@ export function inverseTransformPoint(point, chart, xAxis, xAxisIx, yAxis, yAxis
|
|
|
116
116
|
if (x === undefined || y === undefined) {
|
|
117
117
|
return undefined;
|
|
118
118
|
}
|
|
119
|
-
return
|
|
119
|
+
return createPoint(x, y);
|
|
120
120
|
}
|
|
121
121
|
function finalPadding(chart) {
|
|
122
122
|
return {
|
|
@@ -193,12 +193,12 @@ export function renderChart(chart) {
|
|
|
193
193
|
renderedDataAxisesLeft,
|
|
194
194
|
renderedDataAxisesRight,
|
|
195
195
|
];
|
|
196
|
-
const topLeft =
|
|
197
|
-
const size =
|
|
198
|
-
return
|
|
196
|
+
const topLeft = createPoint(0, 0);
|
|
197
|
+
const size = createSize(width, height);
|
|
198
|
+
return createAbstractImage(topLeft, size, white, components);
|
|
199
199
|
}
|
|
200
200
|
export function generateBackground(xMin, xMax, yMin, yMax, chart) {
|
|
201
|
-
return
|
|
201
|
+
return createRectangle(createPoint(xMin, yMax), createPoint(xMax, yMin), transparent, 0, chart.backgroundColor);
|
|
202
202
|
}
|
|
203
203
|
export function xAxises(xAxis, xNumTicks, axises, xMin, xMax, yMin, yMax, xMinLineThicknessAdjustment, xMaxLineThicknessAdjustment, chart) {
|
|
204
204
|
const components = Array();
|
|
@@ -213,7 +213,7 @@ export function xAxises(xAxis, xNumTicks, axises, xMin, xMax, yMin, yMax, xMinLi
|
|
|
213
213
|
}
|
|
214
214
|
const thickness = axis.thickness ?? 1;
|
|
215
215
|
const lineDisp = ix == 0 ? (xAxis === "bottom" ? thickness / 2 : -thickness / 2) : 0;
|
|
216
|
-
components.push(
|
|
216
|
+
components.push(createLine({ x: xMin - (ix == 0 ? xMinLineThicknessAdjustment : chart.xGrid.thickness / 2), y: lineY + lineDisp }, { x: xMax + (ix == 0 ? xMaxLineThicknessAdjustment : chart.xGrid.thickness / 2), y: lineY + lineDisp }, axis.axisColor ?? gray, thickness));
|
|
217
217
|
if (!axis.noTicks) {
|
|
218
218
|
components.push(generateXAxisLabels(xMin, xMax, lineY + dirFactor * 12, xAxis === "bottom" ? "down" : "up", xTicks, axis, chart));
|
|
219
219
|
}
|
|
@@ -235,7 +235,7 @@ export function xAxises(xAxis, xNumTicks, axises, xMin, xMax, yMin, yMax, xMinLi
|
|
|
235
235
|
}
|
|
236
236
|
lineY += dirFactor * axisWidth;
|
|
237
237
|
}
|
|
238
|
-
return [
|
|
238
|
+
return [createGroup(xAxis + "XAxis", components), createGroup(xAxis + "XAxisGridLines", gridLineComponents)];
|
|
239
239
|
}
|
|
240
240
|
export function yAxises(yAxis, yNumTicks, axises, xMin, xMax, yMin, yMax, yMinLineThicknessAdjustment, yMaxLineThicknessAdjustment, chart) {
|
|
241
241
|
const components = Array();
|
|
@@ -250,7 +250,7 @@ export function yAxises(yAxis, yNumTicks, axises, xMin, xMax, yMin, yMax, yMinLi
|
|
|
250
250
|
}
|
|
251
251
|
const thickness = axis.thickness ?? 1;
|
|
252
252
|
const lineDisp = ix == 0 ? (yAxis === "left" ? -thickness / 2 : thickness / 2) : 0;
|
|
253
|
-
components.push(
|
|
253
|
+
components.push(createLine({ x: lineX + lineDisp, y: yMin + (ix == 0 ? yMinLineThicknessAdjustment : chart.yGrid.thickness / 2) }, { x: lineX + lineDisp, y: yMax - (ix == 0 ? yMaxLineThicknessAdjustment : chart.yGrid.thickness / 2) }, axis.axisColor ?? gray, axis.thickness ?? 1));
|
|
254
254
|
if (!axis.noTicks) {
|
|
255
255
|
components.push(generateYAxisLabels(lineX + dirFactor * 12, yMin, yMax, yAxis, yTicks, axis, chart));
|
|
256
256
|
}
|
|
@@ -273,7 +273,7 @@ export function yAxises(yAxis, yNumTicks, axises, xMin, xMax, yMin, yMax, yMinLi
|
|
|
273
273
|
}
|
|
274
274
|
lineX += dirFactor * axisWidth;
|
|
275
275
|
}
|
|
276
|
-
return [
|
|
276
|
+
return [createGroup("YAxisLeft", components), createGroup("YAxisLeftGridLines", gridLineComponents)];
|
|
277
277
|
}
|
|
278
278
|
export function generateDataAxisesX(xAxis, axises, numTicks, xMin, xMax, yMin, yMax, chart) {
|
|
279
279
|
const components = Array();
|
|
@@ -308,15 +308,15 @@ export function generateDataAxisesX(xAxis, axises, numTicks, xMin, xMax, yMin, y
|
|
|
308
308
|
components.push(...yValues.flatMap((y) => {
|
|
309
309
|
const tickX = findX(y);
|
|
310
310
|
const x = transformValue(tickX, xMin, xMax, chart.xAxisesBottom[0]);
|
|
311
|
-
const start =
|
|
312
|
-
const end =
|
|
313
|
-
const textPos =
|
|
311
|
+
const start = createPoint(x, lineY2);
|
|
312
|
+
const end = createPoint(x, lineY2 + dirFactor * 10);
|
|
313
|
+
const textPos = createPoint(x, lineY2 + dirFactor * 12);
|
|
314
314
|
return [
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
createLine(start, end, chart.xGrid.color, chart.xGrid.thickness),
|
|
316
|
+
createText(textPos, formatNumber(y), chart.font, axis.tickFontSize ?? chart.fontSize, axis.labelColor ?? black, "normal", axis.labelRotation ?? 0, "center", "uniform", xAxis === "bottom" ? "down" : "up", 0, axis.labelColor ?? black, false),
|
|
317
317
|
];
|
|
318
318
|
}));
|
|
319
|
-
components.push(
|
|
319
|
+
components.push(createLine({ x: xMin, y: lineY }, { x: xMax, y: lineY }, axis.axisColor ?? gray, axis.thickness ?? 1));
|
|
320
320
|
const axisLabelPosY = lineY + dirFactor * (axisWidth - (axis.axisFontSize ?? chart.fontSize));
|
|
321
321
|
switch (chart.labelLayout) {
|
|
322
322
|
case "original":
|
|
@@ -333,7 +333,7 @@ export function generateDataAxisesX(xAxis, axises, numTicks, xMin, xMax, yMin, y
|
|
|
333
333
|
}
|
|
334
334
|
lineY += dirFactor * axisWidth;
|
|
335
335
|
}
|
|
336
|
-
return
|
|
336
|
+
return createGroup(xAxis + "XDataAxis", components);
|
|
337
337
|
}
|
|
338
338
|
export function generateDataAxisesY(yAxis, axises, numTicks, xMin, xMax, yMin, yMax, chart) {
|
|
339
339
|
const components = Array();
|
|
@@ -368,15 +368,15 @@ export function generateDataAxisesY(yAxis, axises, numTicks, xMin, xMax, yMin, y
|
|
|
368
368
|
components.push(...yValues.flatMap((y) => {
|
|
369
369
|
const tickY = findX(y);
|
|
370
370
|
const yPx = transformValue(tickY, yMin, yMax, chart.yAxisesLeft[0]);
|
|
371
|
-
const start =
|
|
372
|
-
const end =
|
|
373
|
-
const textPos =
|
|
371
|
+
const start = createPoint(lineX2, yPx);
|
|
372
|
+
const end = createPoint(lineX2 + dirFactor * 10, yPx);
|
|
373
|
+
const textPos = createPoint(lineX2 + dirFactor * 12, yPx);
|
|
374
374
|
return [
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
createLine(start, end, chart.xGrid.color, chart.xGrid.thickness),
|
|
376
|
+
createText(textPos, formatNumber(y), chart.font, axis.tickFontSize ?? chart.fontSize, axis.labelColor ?? black, "normal", 0, "center", yAxis, "uniform", 0, axis.labelColor ?? black, false),
|
|
377
377
|
];
|
|
378
378
|
}));
|
|
379
|
-
components.push(
|
|
379
|
+
components.push(createLine({ x: lineX, y: yMin }, { x: lineX, y: yMax }, axis.axisColor ?? gray, axis.thickness ?? 1));
|
|
380
380
|
const rotation = yAxis === "left" ? -90 : 90;
|
|
381
381
|
const axisLabelPosX = lineX + dirFactor * (axisWidth - (axis.axisFontSize ?? chart.fontSize));
|
|
382
382
|
switch (chart.labelLayout) {
|
|
@@ -394,7 +394,7 @@ export function generateDataAxisesY(yAxis, axises, numTicks, xMin, xMax, yMin, y
|
|
|
394
394
|
}
|
|
395
395
|
lineX += dirFactor * axisWidth;
|
|
396
396
|
}
|
|
397
|
-
return
|
|
397
|
+
return createGroup(yAxis + "YDataAxis", components);
|
|
398
398
|
}
|
|
399
399
|
export function generateStack(xMin, xMax, yMin, yMax, chart) {
|
|
400
400
|
const pointsPos = chart.chartStack.points.map((stackPoint) => ({
|
|
@@ -413,11 +413,11 @@ export function generateStack(xMin, xMax, yMin, yMax, chart) {
|
|
|
413
413
|
...chart,
|
|
414
414
|
chartStack: { ...chart.chartStack, points: pointsNeg },
|
|
415
415
|
});
|
|
416
|
-
return
|
|
416
|
+
return createGroup("Stacks", [stackPos, stackNeg]);
|
|
417
417
|
}
|
|
418
418
|
function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
|
|
419
419
|
if (chart.chartStack.points.length < 2) {
|
|
420
|
-
return
|
|
420
|
+
return createGroup("stack", []);
|
|
421
421
|
}
|
|
422
422
|
const xAxis = chart.chartStack.xAxis === "top"
|
|
423
423
|
? chart.xAxisesTop[chart.chartStack.xAxisIx]
|
|
@@ -429,7 +429,7 @@ function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
|
|
|
429
429
|
let sumY = 0;
|
|
430
430
|
const points = stackPoints.ys.map((y) => {
|
|
431
431
|
sumY += y;
|
|
432
|
-
return transformPoint(
|
|
432
|
+
return transformPoint(createPoint(stackPoints.x, sumY), xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
433
433
|
});
|
|
434
434
|
return points;
|
|
435
435
|
});
|
|
@@ -442,7 +442,7 @@ function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
|
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
const polygons = [];
|
|
445
|
-
let lastLine = chart.chartStack.points.map((stackPoint) => transformPoint(
|
|
445
|
+
let lastLine = chart.chartStack.points.map((stackPoint) => transformPoint(createPoint(stackPoint.x, 0), xMin, xMax, yMin, yMax, xAxis, yAxis));
|
|
446
446
|
lines.forEach((line, index) => {
|
|
447
447
|
const config = chart.chartStack.config[index];
|
|
448
448
|
if (!config) {
|
|
@@ -451,14 +451,14 @@ function generateUnsignedStack(xMin, xMax, yMin, yMax, chart) {
|
|
|
451
451
|
const color = config.color;
|
|
452
452
|
const points = [...line, ...lastLine.slice().reverse()];
|
|
453
453
|
lastLine = line;
|
|
454
|
-
polygons.push(
|
|
454
|
+
polygons.push(createPolygon(points, color, 0, color, config.id));
|
|
455
455
|
});
|
|
456
|
-
return
|
|
456
|
+
return createGroup("Stack", polygons);
|
|
457
457
|
}
|
|
458
458
|
export function generateLines(xMin, xMax, yMin, yMax, chart) {
|
|
459
459
|
const lines = chart.chartLines.map((l) => {
|
|
460
460
|
if (l.points.length < 2) {
|
|
461
|
-
return
|
|
461
|
+
return createGroup(l.label.split("<")[0] ?? "UNKNOWN", []);
|
|
462
462
|
}
|
|
463
463
|
const xAxis = l.xAxis === "top" ? chart.xAxisesTop[l.xAxisIx] : chart.xAxisesBottom[l.xAxisIx];
|
|
464
464
|
const yAxis = l.yAxis === "right" ? chart.yAxisesRight[l.yAxisIx] : chart.yAxisesLeft[l.yAxisIx];
|
|
@@ -467,19 +467,19 @@ export function generateLines(xMin, xMax, yMin, yMax, chart) {
|
|
|
467
467
|
const components = [];
|
|
468
468
|
const outlineColor = l.textOutlineColor ?? chart.textOutlineColor;
|
|
469
469
|
for (const segment of segments) {
|
|
470
|
-
components.push(
|
|
470
|
+
components.push(createPolyLine(segment.slice(), l.color, l.thickness));
|
|
471
471
|
if (l.id !== undefined) {
|
|
472
|
-
components.push(
|
|
472
|
+
components.push(createPolyLine(segment.slice(), transparent, l.thickness + 8, l.id));
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
const lastSeg = segments.at(-1);
|
|
476
476
|
const last = lastSeg?.at(-1);
|
|
477
477
|
if (last) {
|
|
478
|
-
components.push(
|
|
478
|
+
components.push(createText(last, l.label, chart.font, l.fontSize ?? chart.fontSize, l.textColor ?? chart.textColor, "normal", 0, "center", textHorizontalGrowth(last.x, xMin, xMax), textVerticalGrowth(last.y, yMin, yMax), outlineColor !== transparent ? 3 : 0, outlineColor, false, l.id));
|
|
479
479
|
}
|
|
480
|
-
return
|
|
480
|
+
return createGroup(l.label.split("<")[0] ?? "UNKNOWN", components);
|
|
481
481
|
});
|
|
482
|
-
return
|
|
482
|
+
return createGroup("Lines", lines);
|
|
483
483
|
}
|
|
484
484
|
function getLineSegmentsInsideChart(xMin, xMax, yMin, yMax, points) {
|
|
485
485
|
const segments = [];
|
|
@@ -520,10 +520,10 @@ function isInside(xMin, xMax, yMin, yMax, p) {
|
|
|
520
520
|
return p.x >= xMin && p.x <= xMax && p.y <= yMin && p.y >= yMax;
|
|
521
521
|
}
|
|
522
522
|
function moveInside(xMin, xMax, yMin, yMax, inside, outside) {
|
|
523
|
-
const xMinYMin =
|
|
524
|
-
const xMinYMax =
|
|
525
|
-
const xMaxYMin =
|
|
526
|
-
const xMaxYMax =
|
|
523
|
+
const xMinYMin = createPoint(xMin, yMin);
|
|
524
|
+
const xMinYMax = createPoint(xMin, yMax);
|
|
525
|
+
const xMaxYMin = createPoint(xMax, yMin);
|
|
526
|
+
const xMaxYMax = createPoint(xMax, yMax);
|
|
527
527
|
return (lineLine(inside, outside, xMinYMin, xMaxYMin) ??
|
|
528
528
|
lineLine(inside, outside, xMinYMax, xMaxYMax) ??
|
|
529
529
|
lineLine(inside, outside, xMinYMin, xMinYMax) ??
|
|
@@ -531,14 +531,14 @@ function moveInside(xMin, xMax, yMin, yMax, inside, outside) {
|
|
|
531
531
|
inside);
|
|
532
532
|
}
|
|
533
533
|
function lineLine(a0, a1, b0, b1) {
|
|
534
|
-
const da =
|
|
535
|
-
const db =
|
|
536
|
-
const dab =
|
|
534
|
+
const da = createPoint(a1.x - a0.x, a1.y - a0.y);
|
|
535
|
+
const db = createPoint(b1.x - b0.x, b1.y - b0.y);
|
|
536
|
+
const dab = createPoint(a0.x - b0.x, a0.y - b0.y);
|
|
537
537
|
const uA = (db.x * dab.y - db.y * dab.x) / (db.y * da.x - db.x * da.y);
|
|
538
538
|
const uB = (da.x * dab.y - da.y * dab.x) / (db.y * da.x - db.x * da.y);
|
|
539
539
|
// if uA and uB are between 0-1, lines are colliding
|
|
540
540
|
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
|
|
541
|
-
return
|
|
541
|
+
return createPoint(a0.x + uA * da.x, a0.y + uA * da.y);
|
|
542
542
|
}
|
|
543
543
|
return undefined;
|
|
544
544
|
}
|
|
@@ -547,10 +547,10 @@ export function generateAreas(xMin, xMax, yMin, yMax, chart) {
|
|
|
547
547
|
const xAxis = a.xAxis === "top" ? chart.xAxisesTop[a.xAxisIx] : chart.xAxisesBottom[a.xAxisIx];
|
|
548
548
|
const yAxis = a.yAxis === "right" ? chart.yAxisesRight[a.yAxisIx] : chart.yAxisesLeft[a.yAxisIx];
|
|
549
549
|
const points = a.points.map((p) => transformPoint(p, xMin, xMax, yMin, yMax, xAxis, yAxis));
|
|
550
|
-
const components = [
|
|
551
|
-
return
|
|
550
|
+
const components = [createPolygon(points, a.strokeColor, a.strokeThickness, a.color, a.id)];
|
|
551
|
+
return createGroup("UNKNOWN", components);
|
|
552
552
|
});
|
|
553
|
-
return
|
|
553
|
+
return createGroup("Areas", areas);
|
|
554
554
|
}
|
|
555
555
|
export function generatePoints(xMin, xMax, yMin, yMax, chart) {
|
|
556
556
|
const points = chart.chartPoints.map((p) => {
|
|
@@ -560,20 +560,20 @@ export function generatePoints(xMin, xMax, yMin, yMax, chart) {
|
|
|
560
560
|
const outlineColor = p.textOutlineColor ?? chart.textOutlineColor;
|
|
561
561
|
const components = [
|
|
562
562
|
generatePointShape(p, position, undefined),
|
|
563
|
-
|
|
563
|
+
createText(position, p.label, chart.font, p.fontSize ?? chart.fontSize, p.textColor ?? chart.textColor, "normal", 0, "center", textHorizontalGrowth(position.x, xMin, xMax), textVerticalGrowth(position.y, yMin, yMax), outlineColor !== transparent ? 3 : 0, outlineColor, false),
|
|
564
564
|
];
|
|
565
565
|
if (p.id !== undefined) {
|
|
566
566
|
components.push(generatePointShape({
|
|
567
567
|
...p,
|
|
568
|
-
color:
|
|
569
|
-
strokeColor:
|
|
568
|
+
color: transparent,
|
|
569
|
+
strokeColor: transparent,
|
|
570
570
|
strokeThickness: 0,
|
|
571
571
|
size: { width: p.size.width + 10, height: p.size.height + 10 },
|
|
572
572
|
}, position, p.id));
|
|
573
573
|
}
|
|
574
|
-
return
|
|
574
|
+
return createGroup(p.label.split("<")[0] ?? "UNKNOWN", components);
|
|
575
575
|
});
|
|
576
|
-
return
|
|
576
|
+
return createGroup("Points", points);
|
|
577
577
|
}
|
|
578
578
|
export function generateBars(xMin, xMax, yMin, yMax, chart) {
|
|
579
579
|
const components = Array();
|
|
@@ -590,25 +590,25 @@ export function generateBars(xMin, xMax, yMin, yMax, chart) {
|
|
|
590
590
|
const outlineColor = b.textOutlineColor ?? chart.textOutlineColor;
|
|
591
591
|
const [tl, middle, br] = bars.direction === "x"
|
|
592
592
|
? [
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
593
|
+
createPoint(b.min ?? xMinValue, barPos + bars.width / 2),
|
|
594
|
+
createPoint((b.max + (b.min ?? xMinValue)) / 2, barPos),
|
|
595
|
+
createPoint(b.max, barPos - bars.width / 2),
|
|
596
596
|
]
|
|
597
597
|
: [
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
598
|
+
createPoint(barPos - bars.width / 2, b.max),
|
|
599
|
+
createPoint(barPos, (b.max + (b.min ?? yMinValue)) / 2),
|
|
600
|
+
createPoint(barPos + bars.width / 2, b.min ?? yMinValue),
|
|
601
601
|
];
|
|
602
602
|
const pos = transformPoint(middle, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
603
603
|
const topLeft = transformPoint(tl, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
604
604
|
const bottomRight = transformPoint(br, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
605
|
-
components.push(
|
|
605
|
+
components.push(createRectangle(topLeft, bottomRight, b.strokeColor ?? transparent, b.strokeThickness ?? 0, b.color, b.id, solidLine, bars.radius));
|
|
606
606
|
if (b.label) {
|
|
607
|
-
components.push(
|
|
607
|
+
components.push(createText(pos, b.label, chart.font, b.fontSize ?? chart.fontSize, b.textColor ?? chart.textColor, "normal", textRot, "center", "uniform", "uniform", outlineColor !== transparent ? 3 : 0, outlineColor, false));
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
|
-
return
|
|
611
|
+
return createGroup("Bars", components);
|
|
612
612
|
}
|
|
613
613
|
function textHorizontalGrowth(position, xMin, xMax) {
|
|
614
614
|
return position > (xMin + xMax) * 0.5 ? "left" : "right";
|
|
@@ -621,31 +621,31 @@ function generatePointShape(p, position, id) {
|
|
|
621
621
|
const halfHeight = p.size.height * 0.5;
|
|
622
622
|
if (p.shape === "triangle") {
|
|
623
623
|
const trianglePoints = [
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
624
|
+
createPoint(position.x, position.y + halfHeight),
|
|
625
|
+
createPoint(position.x - halfWidth, position.y - halfHeight),
|
|
626
|
+
createPoint(position.x + halfWidth, position.y - halfHeight),
|
|
627
627
|
];
|
|
628
|
-
return
|
|
628
|
+
return createPolygon(trianglePoints, p.strokeColor, p.strokeThickness, p.color, id);
|
|
629
629
|
}
|
|
630
630
|
else if (p.shape === "square") {
|
|
631
|
-
const topLeft =
|
|
632
|
-
const bottomRight =
|
|
633
|
-
return
|
|
631
|
+
const topLeft = createPoint(position.x - halfWidth, position.y - halfHeight);
|
|
632
|
+
const bottomRight = createPoint(position.x + halfWidth, position.y + halfHeight);
|
|
633
|
+
return createRectangle(topLeft, bottomRight, p.strokeColor, p.strokeThickness, p.color, id);
|
|
634
634
|
}
|
|
635
635
|
else {
|
|
636
|
-
const topLeft =
|
|
637
|
-
const bottomRight =
|
|
638
|
-
return
|
|
636
|
+
const topLeft = createPoint(position.x - halfWidth, position.y - halfHeight);
|
|
637
|
+
const bottomRight = createPoint(position.x + halfWidth, position.y + halfHeight);
|
|
638
|
+
return createEllipse(topLeft, bottomRight, p.strokeColor, p.strokeThickness, p.color, id);
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
export function generateXAxisGridLines(xMin, xMax, yMin, yMax, xTicks, xAxis, xGrid) {
|
|
642
642
|
const xLines = xTicks.map((l) => {
|
|
643
643
|
const x = transformValue(l.value, xMin, xMax, xAxis);
|
|
644
|
-
const start =
|
|
645
|
-
const end =
|
|
646
|
-
return
|
|
644
|
+
const start = createPoint(x, yMin);
|
|
645
|
+
const end = createPoint(x, yMax);
|
|
646
|
+
return createLine(start, end, xGrid.color, xGrid.thickness);
|
|
647
647
|
});
|
|
648
|
-
return
|
|
648
|
+
return createGroup("Lines", xLines);
|
|
649
649
|
}
|
|
650
650
|
export function generateXAxisLabels(xMin, xMax, y, growVertical, ticks, axis, chart) {
|
|
651
651
|
const rotation = axis.labelRotation ?? 0;
|
|
@@ -661,23 +661,23 @@ export function generateXAxisLabels(xMin, xMax, y, growVertical, ticks, axis, ch
|
|
|
661
661
|
}
|
|
662
662
|
})();
|
|
663
663
|
const xLabels = ticks.map((l) => {
|
|
664
|
-
const position =
|
|
665
|
-
return
|
|
664
|
+
const position = createPoint(transformValue(l.value, xMin, xMax, axis), y);
|
|
665
|
+
return createText(position, l.label ?? formatNumber(l.value), chart.font, axis.tickFontSize ?? chart.fontSize, axis.labelColor ?? black, "normal", rotation, "center", horizontalGrowth, growVertical, 0, axis.labelColor ?? black, false);
|
|
666
666
|
});
|
|
667
|
-
return
|
|
667
|
+
return createGroup("Labels", xLabels);
|
|
668
668
|
}
|
|
669
669
|
export function generateXAxisLabel(x, y, horizontalGrowthDirection, verticalGrowthDirection, axis, chart) {
|
|
670
|
-
const position =
|
|
671
|
-
return
|
|
670
|
+
const position = createPoint(x, y);
|
|
671
|
+
return createText(position, axis.label ?? "", chart.font, axis.axisFontSize ?? chart.fontSize, axis.labelColor ?? black, "normal", 0, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, axis.labelColor ?? black, false, axis.id);
|
|
672
672
|
}
|
|
673
673
|
export function generateYAxisLines(xMin, xMax, yMin, yMax, yTicks, yAxis, yGrid, xGrid) {
|
|
674
674
|
const yLines = yTicks.map((l) => {
|
|
675
675
|
const y = transformValue(l.value, yMin, yMax, yAxis);
|
|
676
|
-
const start =
|
|
677
|
-
const end =
|
|
678
|
-
return
|
|
676
|
+
const start = createPoint(xMin - xGrid.thickness / 2, y);
|
|
677
|
+
const end = createPoint(xMax + xGrid.thickness / 2, y);
|
|
678
|
+
return createLine(start, end, yGrid.color, yGrid.thickness);
|
|
679
679
|
});
|
|
680
|
-
return
|
|
680
|
+
return createGroup("Lines", yLines);
|
|
681
681
|
}
|
|
682
682
|
export function generateYAxisLabels(x, yMin, yMax, growHorizontal, yTicks, yAxis, chart) {
|
|
683
683
|
const rotation = yAxis.labelRotation ?? 0;
|
|
@@ -693,14 +693,14 @@ export function generateYAxisLabels(x, yMin, yMax, growHorizontal, yTicks, yAxis
|
|
|
693
693
|
}
|
|
694
694
|
})();
|
|
695
695
|
const yLabels = yTicks.map((l) => {
|
|
696
|
-
const position =
|
|
697
|
-
return
|
|
696
|
+
const position = createPoint(x, transformValue(l.value, yMin, yMax, yAxis));
|
|
697
|
+
return createText(position, l.label ?? formatNumber(l.value), chart.font, yAxis.tickFontSize ?? chart.fontSize, yAxis.labelColor ?? black, "normal", rotation, "center", growHorizontal, growVertical, 0, yAxis.labelColor ?? black, false);
|
|
698
698
|
});
|
|
699
|
-
return
|
|
699
|
+
return createGroup("Labels", yLabels);
|
|
700
700
|
}
|
|
701
701
|
export function generateYAxisLabel(x, y, rotation, horizontalGrowthDirection, verticalGrowthDirection, axis, chart) {
|
|
702
|
-
const position =
|
|
703
|
-
return
|
|
702
|
+
const position = createPoint(x, y);
|
|
703
|
+
return createText(position, axis.label ?? "", chart.font, axis.axisFontSize ?? chart.fontSize, axis.labelColor ?? black, "normal", rotation, "center", horizontalGrowthDirection, verticalGrowthDirection, 0, axis.labelColor ?? black, false, axis.id);
|
|
704
704
|
}
|
|
705
705
|
function formatNumber(n) {
|
|
706
706
|
if (n >= 10000000) {
|