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/src/chart.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
import * as AI from "abstract-image";
|
|
4
3
|
import {
|
|
5
4
|
Axis,
|
|
6
5
|
AxisBase,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
transformPoint,
|
|
12
11
|
DiscreteAxisPoint,
|
|
13
12
|
} from "./axis.js";
|
|
13
|
+
import { AbstractImage, black, Color, Component, createAbstractImage, createEllipse, createGroup, createLine, createPoint, createPolygon, createPolyLine, createRectangle, createSize, createText, gray, GrowthDirection, lightGray, Point, Polygon, Size, solidLine, transparent, white } from "abstract-image";
|
|
14
14
|
|
|
15
15
|
// tslint:disable:max-file-line-count
|
|
16
16
|
|
|
@@ -36,13 +36,13 @@ export interface Chart {
|
|
|
36
36
|
readonly xAxisesTop: ReadonlyArray<Axis>;
|
|
37
37
|
readonly yAxisesLeft: ReadonlyArray<Axis>;
|
|
38
38
|
readonly yAxisesRight: ReadonlyArray<Axis>;
|
|
39
|
-
readonly backgroundColor:
|
|
39
|
+
readonly backgroundColor: Color;
|
|
40
40
|
readonly xGrid: ChartGrid;
|
|
41
41
|
readonly yGrid: ChartGrid;
|
|
42
42
|
readonly font: string;
|
|
43
43
|
readonly fontSize: number;
|
|
44
|
-
readonly textColor:
|
|
45
|
-
readonly textOutlineColor:
|
|
44
|
+
readonly textColor: Color;
|
|
45
|
+
readonly textOutlineColor: Color;
|
|
46
46
|
readonly labelLayout: LabelLayout;
|
|
47
47
|
readonly padding: Padding;
|
|
48
48
|
readonly axisWidth: Padding;
|
|
@@ -50,7 +50,7 @@ export interface Chart {
|
|
|
50
50
|
readonly yPixelsPerTick: number;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export type ChartGrid = { readonly color:
|
|
53
|
+
export type ChartGrid = { readonly color: Color; readonly thickness: number };
|
|
54
54
|
|
|
55
55
|
export type ChartProps = Partial<Chart>;
|
|
56
56
|
|
|
@@ -71,11 +71,11 @@ export function createChart(props: ChartProps): Chart {
|
|
|
71
71
|
xAxisesTop: props.xAxisesTop ?? [],
|
|
72
72
|
yAxisesLeft: props.yAxisesLeft ?? [],
|
|
73
73
|
yAxisesRight: props.yAxisesRight ?? [],
|
|
74
|
-
backgroundColor: props.backgroundColor ??
|
|
74
|
+
backgroundColor: props.backgroundColor ?? white,
|
|
75
75
|
font: props.font ?? "Arial",
|
|
76
76
|
fontSize: props.fontSize ?? 12,
|
|
77
|
-
textColor: props.textColor ??
|
|
78
|
-
textOutlineColor: props.textOutlineColor ??
|
|
77
|
+
textColor: props.textColor ?? black,
|
|
78
|
+
textOutlineColor: props.textOutlineColor ?? transparent,
|
|
79
79
|
labelLayout: props.labelLayout ?? "original",
|
|
80
80
|
padding: {
|
|
81
81
|
top: props.padding?.top ?? 10,
|
|
@@ -89,8 +89,8 @@ export function createChart(props: ChartProps): Chart {
|
|
|
89
89
|
bottom: props.axisWidth?.bottom ?? 50,
|
|
90
90
|
left: props.axisWidth?.left ?? 50,
|
|
91
91
|
},
|
|
92
|
-
xGrid: { color: props.xGrid?.color ??
|
|
93
|
-
yGrid: { color: props.yGrid?.color ??
|
|
92
|
+
xGrid: { color: props.xGrid?.color ?? gray, thickness: props.xGrid?.thickness ?? 1 },
|
|
93
|
+
yGrid: { color: props.yGrid?.color ?? gray, thickness: props.yGrid?.thickness ?? 1 },
|
|
94
94
|
xPixelsPerTick: props.xPixelsPerTick ?? 40,
|
|
95
95
|
yPixelsPerTick: props.yPixelsPerTick ?? 40,
|
|
96
96
|
};
|
|
@@ -102,9 +102,9 @@ export type XAxis = "bottom" | "top";
|
|
|
102
102
|
export type YAxis = "left" | "right";
|
|
103
103
|
|
|
104
104
|
export interface ChartArea {
|
|
105
|
-
readonly points: ReadonlyArray<
|
|
106
|
-
readonly color:
|
|
107
|
-
readonly strokeColor:
|
|
105
|
+
readonly points: ReadonlyArray<Point>;
|
|
106
|
+
readonly color: Color;
|
|
107
|
+
readonly strokeColor: Color;
|
|
108
108
|
readonly strokeThickness: number;
|
|
109
109
|
readonly xAxis: XAxis;
|
|
110
110
|
readonly xAxisIx: number;
|
|
@@ -117,10 +117,10 @@ export type ChartPointShape = "circle" | "triangle" | "square";
|
|
|
117
117
|
|
|
118
118
|
export interface ChartPoint {
|
|
119
119
|
readonly shape: ChartPointShape;
|
|
120
|
-
readonly position:
|
|
121
|
-
readonly size:
|
|
122
|
-
readonly color:
|
|
123
|
-
readonly strokeColor:
|
|
120
|
+
readonly position: Point;
|
|
121
|
+
readonly size: Size;
|
|
122
|
+
readonly color: Color;
|
|
123
|
+
readonly strokeColor: Color;
|
|
124
124
|
readonly strokeThickness: number;
|
|
125
125
|
readonly label: string;
|
|
126
126
|
readonly xAxis: XAxis;
|
|
@@ -128,8 +128,8 @@ export interface ChartPoint {
|
|
|
128
128
|
readonly yAxis: YAxis;
|
|
129
129
|
readonly yAxisIx: number;
|
|
130
130
|
readonly fontSize?: number;
|
|
131
|
-
readonly textColor?:
|
|
132
|
-
readonly textOutlineColor?:
|
|
131
|
+
readonly textColor?: Color;
|
|
132
|
+
readonly textOutlineColor?: Color;
|
|
133
133
|
readonly id?: string;
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -141,7 +141,7 @@ export interface ChartBars {
|
|
|
141
141
|
readonly yAxis: YAxis;
|
|
142
142
|
readonly yAxisIx: number;
|
|
143
143
|
readonly width: number;
|
|
144
|
-
readonly radius?:
|
|
144
|
+
readonly radius?: Point;
|
|
145
145
|
readonly spacing?: number;
|
|
146
146
|
readonly bars: ReadonlyArray<ChartBar>;
|
|
147
147
|
}
|
|
@@ -149,13 +149,13 @@ export interface ChartBars {
|
|
|
149
149
|
export interface ChartBar {
|
|
150
150
|
readonly min?: number | undefined;
|
|
151
151
|
readonly max: number;
|
|
152
|
-
readonly color:
|
|
152
|
+
readonly color: Color;
|
|
153
153
|
readonly label?: string;
|
|
154
|
-
readonly strokeColor?:
|
|
154
|
+
readonly strokeColor?: Color;
|
|
155
155
|
readonly strokeThickness?: number;
|
|
156
156
|
readonly fontSize?: number;
|
|
157
|
-
readonly textColor?:
|
|
158
|
-
readonly textOutlineColor?:
|
|
157
|
+
readonly textColor?: Color;
|
|
158
|
+
readonly textOutlineColor?: Color;
|
|
159
159
|
readonly id?: string;
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -164,8 +164,8 @@ export type ChartAreaProps = Partial<ChartArea>;
|
|
|
164
164
|
export function createChartArea(props?: ChartAreaProps): ChartArea {
|
|
165
165
|
const {
|
|
166
166
|
points = [],
|
|
167
|
-
color =
|
|
168
|
-
strokeColor =
|
|
167
|
+
color = lightGray,
|
|
168
|
+
strokeColor = transparent,
|
|
169
169
|
strokeThickness = 0,
|
|
170
170
|
xAxis = "bottom",
|
|
171
171
|
xAxisIx = 0,
|
|
@@ -191,11 +191,11 @@ export type ChartPointProps = Partial<ChartPoint>;
|
|
|
191
191
|
export function createChartPoint(props?: ChartPointProps): ChartPoint {
|
|
192
192
|
const {
|
|
193
193
|
shape = "circle",
|
|
194
|
-
position =
|
|
195
|
-
color =
|
|
196
|
-
strokeColor =
|
|
194
|
+
position = createPoint(0, 0),
|
|
195
|
+
color = black,
|
|
196
|
+
strokeColor = black,
|
|
197
197
|
strokeThickness = 1,
|
|
198
|
-
size =
|
|
198
|
+
size = createSize(6, 6),
|
|
199
199
|
label = "",
|
|
200
200
|
xAxis = "bottom",
|
|
201
201
|
xAxisIx = 0,
|
|
@@ -226,8 +226,8 @@ export function createChartPoint(props?: ChartPointProps): ChartPoint {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
export interface ChartLine {
|
|
229
|
-
readonly points: Array<
|
|
230
|
-
readonly color:
|
|
229
|
+
readonly points: Array<Point>;
|
|
230
|
+
readonly color: Color;
|
|
231
231
|
readonly thickness: number;
|
|
232
232
|
readonly label: string;
|
|
233
233
|
readonly xAxis: XAxis;
|
|
@@ -235,8 +235,8 @@ export interface ChartLine {
|
|
|
235
235
|
readonly yAxis: YAxis;
|
|
236
236
|
readonly yAxisIx: number;
|
|
237
237
|
readonly fontSize?: number;
|
|
238
|
-
readonly textColor?:
|
|
239
|
-
readonly textOutlineColor?:
|
|
238
|
+
readonly textColor?: Color;
|
|
239
|
+
readonly textOutlineColor?: Color;
|
|
240
240
|
readonly id?: string;
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -245,7 +245,7 @@ export type ChartLineProps = Partial<ChartLine>;
|
|
|
245
245
|
export function createChartLine(props: ChartLineProps): ChartLine {
|
|
246
246
|
const {
|
|
247
247
|
points = [],
|
|
248
|
-
color =
|
|
248
|
+
color = black,
|
|
249
249
|
thickness = 1,
|
|
250
250
|
label = "",
|
|
251
251
|
xAxis = "bottom",
|
|
@@ -261,7 +261,7 @@ export function createChartLine(props: ChartLineProps): ChartLine {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
export interface ChartStackConfig {
|
|
264
|
-
readonly color:
|
|
264
|
+
readonly color: Color;
|
|
265
265
|
readonly label: string;
|
|
266
266
|
readonly id?: string;
|
|
267
267
|
}
|
|
@@ -269,7 +269,7 @@ export interface ChartStackConfig {
|
|
|
269
269
|
export type ChartStackConfigProps = Partial<ChartStackConfig>;
|
|
270
270
|
|
|
271
271
|
export function createChartStackConfig(props: ChartStackConfigProps): ChartStackConfig {
|
|
272
|
-
const { color =
|
|
272
|
+
const { color = black, label = "" } = props || {};
|
|
273
273
|
return { color, label };
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -302,18 +302,18 @@ export function createChartStack(props: ChartStackProps): ChartStack {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
export type ChartDataAxis = AxisBase & {
|
|
305
|
-
readonly points: Array<
|
|
305
|
+
readonly points: Array<Point>;
|
|
306
306
|
};
|
|
307
307
|
|
|
308
308
|
export function createChartDataAxis(
|
|
309
|
-
points: Array<
|
|
309
|
+
points: Array<Point>,
|
|
310
310
|
label: string,
|
|
311
311
|
labelRotation?: number,
|
|
312
312
|
tickLabelDisp?: number,
|
|
313
|
-
labelColor?:
|
|
314
|
-
tickLabelColor?:
|
|
313
|
+
labelColor?: Color,
|
|
314
|
+
tickLabelColor?: Color,
|
|
315
315
|
thickness?: number,
|
|
316
|
-
axisColor?:
|
|
316
|
+
axisColor?: Color,
|
|
317
317
|
tickFontSize?: number,
|
|
318
318
|
axisFontSize?: number,
|
|
319
319
|
id?: string
|
|
@@ -334,13 +334,13 @@ export function createChartDataAxis(
|
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
export function inverseTransformPoint(
|
|
337
|
-
point:
|
|
337
|
+
point: Point,
|
|
338
338
|
chart: Chart,
|
|
339
339
|
xAxis: XAxis,
|
|
340
340
|
xAxisIx: number,
|
|
341
341
|
yAxis: YAxis,
|
|
342
342
|
yAxisIx: number
|
|
343
|
-
):
|
|
343
|
+
): Point | undefined {
|
|
344
344
|
const padding = finalPadding(chart);
|
|
345
345
|
const xMin = padding.left;
|
|
346
346
|
const xMax = chart.width - padding.right;
|
|
@@ -361,7 +361,7 @@ export function inverseTransformPoint(
|
|
|
361
361
|
if (x === undefined || y === undefined) {
|
|
362
362
|
return undefined;
|
|
363
363
|
}
|
|
364
|
-
return
|
|
364
|
+
return createPoint(x, y);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
function finalPadding(chart: Chart): Padding {
|
|
@@ -389,7 +389,7 @@ function finalPadding(chart: Chart): Padding {
|
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
export function renderChart(chart: Chart):
|
|
392
|
+
export function renderChart(chart: Chart): AbstractImage {
|
|
393
393
|
const { width, height, xAxisesBottom, xAxisesTop, yAxisesLeft, yAxisesRight } = chart;
|
|
394
394
|
|
|
395
395
|
const padding = finalPadding(chart);
|
|
@@ -523,16 +523,16 @@ export function renderChart(chart: Chart): AI.AbstractImage {
|
|
|
523
523
|
renderedDataAxisesLeft,
|
|
524
524
|
renderedDataAxisesRight,
|
|
525
525
|
];
|
|
526
|
-
const topLeft =
|
|
527
|
-
const size =
|
|
528
|
-
return
|
|
526
|
+
const topLeft = createPoint(0, 0);
|
|
527
|
+
const size = createSize(width, height);
|
|
528
|
+
return createAbstractImage(topLeft, size, white, components);
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
export function generateBackground(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
532
|
-
return
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
531
|
+
export function generateBackground(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
532
|
+
return createRectangle(
|
|
533
|
+
createPoint(xMin, yMax),
|
|
534
|
+
createPoint(xMax, yMin),
|
|
535
|
+
transparent,
|
|
536
536
|
0,
|
|
537
537
|
chart.backgroundColor
|
|
538
538
|
);
|
|
@@ -549,9 +549,9 @@ export function xAxises(
|
|
|
549
549
|
xMinLineThicknessAdjustment: number,
|
|
550
550
|
xMaxLineThicknessAdjustment: number,
|
|
551
551
|
chart: Chart
|
|
552
|
-
): readonly [
|
|
553
|
-
const components = Array<
|
|
554
|
-
const gridLineComponents = Array<
|
|
552
|
+
): readonly [Component, Component] {
|
|
553
|
+
const components = Array<Component>();
|
|
554
|
+
const gridLineComponents = Array<Component>();
|
|
555
555
|
let lineY = xAxis === "bottom" ? yMin : yMax;
|
|
556
556
|
const [dirFactor, axisWidth] = xAxis === "bottom" ? [1, chart.axisWidth.bottom] : [-1, chart.axisWidth.top];
|
|
557
557
|
for (const [ix, axis] of axises.entries()) {
|
|
@@ -565,10 +565,10 @@ export function xAxises(
|
|
|
565
565
|
const thickness = axis.thickness ?? 1;
|
|
566
566
|
const lineDisp = ix == 0 ? (xAxis === "bottom" ? thickness / 2 : -thickness / 2) : 0;
|
|
567
567
|
components.push(
|
|
568
|
-
|
|
568
|
+
createLine(
|
|
569
569
|
{ x: xMin - (ix == 0 ? xMinLineThicknessAdjustment : chart.xGrid.thickness / 2), y: lineY + lineDisp },
|
|
570
570
|
{ x: xMax + (ix == 0 ? xMaxLineThicknessAdjustment : chart.xGrid.thickness / 2), y: lineY + lineDisp },
|
|
571
|
-
axis.axisColor ??
|
|
571
|
+
axis.axisColor ?? gray,
|
|
572
572
|
thickness
|
|
573
573
|
)
|
|
574
574
|
);
|
|
@@ -607,7 +607,7 @@ export function xAxises(
|
|
|
607
607
|
lineY += dirFactor * axisWidth;
|
|
608
608
|
}
|
|
609
609
|
|
|
610
|
-
return [
|
|
610
|
+
return [createGroup(xAxis + "XAxis", components), createGroup(xAxis + "XAxisGridLines", gridLineComponents)];
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
export function yAxises(
|
|
@@ -621,9 +621,9 @@ export function yAxises(
|
|
|
621
621
|
yMinLineThicknessAdjustment: number,
|
|
622
622
|
yMaxLineThicknessAdjustment: number,
|
|
623
623
|
chart: Chart
|
|
624
|
-
): readonly [
|
|
625
|
-
const components = Array<
|
|
626
|
-
const gridLineComponents = Array<
|
|
624
|
+
): readonly [Component, Component] {
|
|
625
|
+
const components = Array<Component>();
|
|
626
|
+
const gridLineComponents = Array<Component>();
|
|
627
627
|
let lineX = yAxis === "left" ? xMin : xMax;
|
|
628
628
|
const [dirFactor, axisWidth] = yAxis === "left" ? [-1, chart.axisWidth.left] : [1, chart.axisWidth.right];
|
|
629
629
|
|
|
@@ -647,10 +647,10 @@ export function yAxises(
|
|
|
647
647
|
const thickness = axis.thickness ?? 1;
|
|
648
648
|
const lineDisp = ix == 0 ? (yAxis === "left" ? -thickness / 2 : thickness / 2) : 0;
|
|
649
649
|
components.push(
|
|
650
|
-
|
|
650
|
+
createLine(
|
|
651
651
|
{ x: lineX + lineDisp, y: yMin + (ix == 0 ? yMinLineThicknessAdjustment : chart.yGrid.thickness / 2) },
|
|
652
652
|
{ x: lineX + lineDisp, y: yMax - (ix == 0 ? yMaxLineThicknessAdjustment : chart.yGrid.thickness / 2) },
|
|
653
|
-
axis.axisColor ??
|
|
653
|
+
axis.axisColor ?? gray,
|
|
654
654
|
axis.thickness ?? 1
|
|
655
655
|
)
|
|
656
656
|
);
|
|
@@ -682,7 +682,7 @@ export function yAxises(
|
|
|
682
682
|
lineX += dirFactor * axisWidth;
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
return [
|
|
685
|
+
return [createGroup("YAxisLeft", components), createGroup("YAxisLeftGridLines", gridLineComponents)];
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
export function generateDataAxisesX(
|
|
@@ -694,8 +694,8 @@ export function generateDataAxisesX(
|
|
|
694
694
|
yMin: number,
|
|
695
695
|
yMax: number,
|
|
696
696
|
chart: Chart
|
|
697
|
-
):
|
|
698
|
-
const components = Array<
|
|
697
|
+
): Component {
|
|
698
|
+
const components = Array<Component>();
|
|
699
699
|
let lineY =
|
|
700
700
|
xAxis === "bottom"
|
|
701
701
|
? yMin + chart.xAxisesBottom.length * chart.axisWidth.bottom
|
|
@@ -739,24 +739,24 @@ export function generateDataAxisesX(
|
|
|
739
739
|
...yValues.flatMap((y) => {
|
|
740
740
|
const tickX = findX(y);
|
|
741
741
|
const x = transformValue(tickX, xMin, xMax, chart.xAxisesBottom[0]);
|
|
742
|
-
const start =
|
|
743
|
-
const end =
|
|
744
|
-
const textPos =
|
|
742
|
+
const start = createPoint(x, lineY2);
|
|
743
|
+
const end = createPoint(x, lineY2 + dirFactor * 10);
|
|
744
|
+
const textPos = createPoint(x, lineY2 + dirFactor * 12);
|
|
745
745
|
return [
|
|
746
|
-
|
|
747
|
-
|
|
746
|
+
createLine(start, end, chart.xGrid.color, chart.xGrid.thickness),
|
|
747
|
+
createText(
|
|
748
748
|
textPos,
|
|
749
749
|
formatNumber(y),
|
|
750
750
|
chart.font,
|
|
751
751
|
axis.tickFontSize ?? chart.fontSize,
|
|
752
|
-
axis.labelColor ??
|
|
752
|
+
axis.labelColor ?? black,
|
|
753
753
|
"normal",
|
|
754
754
|
axis.labelRotation ?? 0,
|
|
755
755
|
"center",
|
|
756
756
|
"uniform",
|
|
757
757
|
xAxis === "bottom" ? "down" : "up",
|
|
758
758
|
0,
|
|
759
|
-
axis.labelColor ??
|
|
759
|
+
axis.labelColor ?? black,
|
|
760
760
|
false
|
|
761
761
|
),
|
|
762
762
|
];
|
|
@@ -764,7 +764,7 @@ export function generateDataAxisesX(
|
|
|
764
764
|
);
|
|
765
765
|
|
|
766
766
|
components.push(
|
|
767
|
-
|
|
767
|
+
createLine({ x: xMin, y: lineY }, { x: xMax, y: lineY }, axis.axisColor ?? gray, axis.thickness ?? 1)
|
|
768
768
|
);
|
|
769
769
|
|
|
770
770
|
const axisLabelPosY = lineY + dirFactor * (axisWidth - (axis.axisFontSize ?? chart.fontSize));
|
|
@@ -792,7 +792,7 @@ export function generateDataAxisesX(
|
|
|
792
792
|
}
|
|
793
793
|
lineY += dirFactor * axisWidth;
|
|
794
794
|
}
|
|
795
|
-
return
|
|
795
|
+
return createGroup(xAxis + "XDataAxis", components);
|
|
796
796
|
}
|
|
797
797
|
|
|
798
798
|
export function generateDataAxisesY(
|
|
@@ -804,8 +804,8 @@ export function generateDataAxisesY(
|
|
|
804
804
|
yMin: number,
|
|
805
805
|
yMax: number,
|
|
806
806
|
chart: Chart
|
|
807
|
-
):
|
|
808
|
-
const components = Array<
|
|
807
|
+
): Component {
|
|
808
|
+
const components = Array<Component>();
|
|
809
809
|
let lineX =
|
|
810
810
|
yAxis === "left"
|
|
811
811
|
? xMin - chart.yAxisesLeft.length * chart.axisWidth.left
|
|
@@ -849,24 +849,24 @@ export function generateDataAxisesY(
|
|
|
849
849
|
...yValues.flatMap((y) => {
|
|
850
850
|
const tickY = findX(y);
|
|
851
851
|
const yPx = transformValue(tickY, yMin, yMax, chart.yAxisesLeft[0]);
|
|
852
|
-
const start =
|
|
853
|
-
const end =
|
|
854
|
-
const textPos =
|
|
852
|
+
const start = createPoint(lineX2, yPx);
|
|
853
|
+
const end = createPoint(lineX2 + dirFactor * 10, yPx);
|
|
854
|
+
const textPos = createPoint(lineX2 + dirFactor * 12, yPx);
|
|
855
855
|
return [
|
|
856
|
-
|
|
857
|
-
|
|
856
|
+
createLine(start, end, chart.xGrid.color, chart.xGrid.thickness),
|
|
857
|
+
createText(
|
|
858
858
|
textPos,
|
|
859
859
|
formatNumber(y),
|
|
860
860
|
chart.font,
|
|
861
861
|
axis.tickFontSize ?? chart.fontSize,
|
|
862
|
-
axis.labelColor ??
|
|
862
|
+
axis.labelColor ?? black,
|
|
863
863
|
"normal",
|
|
864
864
|
0,
|
|
865
865
|
"center",
|
|
866
866
|
yAxis,
|
|
867
867
|
"uniform",
|
|
868
868
|
0,
|
|
869
|
-
axis.labelColor ??
|
|
869
|
+
axis.labelColor ?? black,
|
|
870
870
|
false
|
|
871
871
|
),
|
|
872
872
|
];
|
|
@@ -874,7 +874,7 @@ export function generateDataAxisesY(
|
|
|
874
874
|
);
|
|
875
875
|
|
|
876
876
|
components.push(
|
|
877
|
-
|
|
877
|
+
createLine({ x: lineX, y: yMin }, { x: lineX, y: yMax }, axis.axisColor ?? gray, axis.thickness ?? 1)
|
|
878
878
|
);
|
|
879
879
|
const rotation = yAxis === "left" ? -90 : 90;
|
|
880
880
|
const axisLabelPosX = lineX + dirFactor * (axisWidth - (axis.axisFontSize ?? chart.fontSize));
|
|
@@ -905,10 +905,10 @@ export function generateDataAxisesY(
|
|
|
905
905
|
}
|
|
906
906
|
lineX += dirFactor * axisWidth;
|
|
907
907
|
}
|
|
908
|
-
return
|
|
908
|
+
return createGroup(yAxis + "YDataAxis", components);
|
|
909
909
|
}
|
|
910
910
|
|
|
911
|
-
export function generateStack(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
911
|
+
export function generateStack(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
912
912
|
const pointsPos = chart.chartStack.points.map((stackPoint) => ({
|
|
913
913
|
x: stackPoint.x,
|
|
914
914
|
ys: [...stackPoint.ys.map((y) => Math.min(0, y))],
|
|
@@ -929,12 +929,12 @@ export function generateStack(xMin: number, xMax: number, yMin: number, yMax: nu
|
|
|
929
929
|
chartStack: { ...chart.chartStack, points: pointsNeg },
|
|
930
930
|
});
|
|
931
931
|
|
|
932
|
-
return
|
|
932
|
+
return createGroup("Stacks", [stackPos, stackNeg]);
|
|
933
933
|
}
|
|
934
934
|
|
|
935
|
-
function generateUnsignedStack(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
935
|
+
function generateUnsignedStack(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
936
936
|
if (chart.chartStack.points.length < 2) {
|
|
937
|
-
return
|
|
937
|
+
return createGroup("stack", []);
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
const xAxis =
|
|
@@ -950,13 +950,13 @@ function generateUnsignedStack(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
950
950
|
let sumY = 0;
|
|
951
951
|
const points = stackPoints.ys.map((y) => {
|
|
952
952
|
sumY += y;
|
|
953
|
-
return transformPoint(
|
|
953
|
+
return transformPoint(createPoint(stackPoints.x, sumY), xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
954
954
|
});
|
|
955
955
|
return points;
|
|
956
956
|
});
|
|
957
957
|
|
|
958
958
|
// Transpose the xPoints data to lines.
|
|
959
|
-
const lines: Array<Array<
|
|
959
|
+
const lines: Array<Array<Point>> = [];
|
|
960
960
|
for (let i = 0; i < (xPoints[0]?.length ?? 0); ++i) {
|
|
961
961
|
lines[i] = [];
|
|
962
962
|
for (const points of xPoints) {
|
|
@@ -964,9 +964,9 @@ function generateUnsignedStack(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
964
964
|
}
|
|
965
965
|
}
|
|
966
966
|
|
|
967
|
-
const polygons: Array<
|
|
967
|
+
const polygons: Array<Polygon> = [];
|
|
968
968
|
let lastLine = chart.chartStack.points.map((stackPoint) =>
|
|
969
|
-
transformPoint(
|
|
969
|
+
transformPoint(createPoint(stackPoint.x, 0), xMin, xMax, yMin, yMax, xAxis, yAxis)
|
|
970
970
|
);
|
|
971
971
|
lines.forEach((line, index) => {
|
|
972
972
|
const config = chart.chartStack.config[index];
|
|
@@ -976,16 +976,16 @@ function generateUnsignedStack(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
976
976
|
const color = config.color;
|
|
977
977
|
const points = [...line, ...lastLine.slice().reverse()];
|
|
978
978
|
lastLine = line;
|
|
979
|
-
polygons.push(
|
|
979
|
+
polygons.push(createPolygon(points, color, 0, color, config.id));
|
|
980
980
|
});
|
|
981
981
|
|
|
982
|
-
return
|
|
982
|
+
return createGroup("Stack", polygons);
|
|
983
983
|
}
|
|
984
984
|
|
|
985
|
-
export function generateLines(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
985
|
+
export function generateLines(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
986
986
|
const lines = chart.chartLines.map((l: ChartLine) => {
|
|
987
987
|
if (l.points.length < 2) {
|
|
988
|
-
return
|
|
988
|
+
return createGroup(l.label.split("<")[0] ?? "UNKNOWN", []);
|
|
989
989
|
}
|
|
990
990
|
const xAxis = l.xAxis === "top" ? chart.xAxisesTop[l.xAxisIx] : chart.xAxisesBottom[l.xAxisIx];
|
|
991
991
|
const yAxis = l.yAxis === "right" ? chart.yAxisesRight[l.yAxisIx] : chart.yAxisesLeft[l.yAxisIx];
|
|
@@ -994,16 +994,16 @@ export function generateLines(xMin: number, xMax: number, yMin: number, yMax: nu
|
|
|
994
994
|
const components = [];
|
|
995
995
|
const outlineColor = l.textOutlineColor ?? chart.textOutlineColor;
|
|
996
996
|
for (const segment of segments) {
|
|
997
|
-
components.push(
|
|
997
|
+
components.push(createPolyLine(segment.slice(), l.color, l.thickness));
|
|
998
998
|
if (l.id !== undefined) {
|
|
999
|
-
components.push(
|
|
999
|
+
components.push(createPolyLine(segment.slice(), transparent, l.thickness + 8, l.id));
|
|
1000
1000
|
}
|
|
1001
1001
|
}
|
|
1002
1002
|
const lastSeg = segments.at(-1);
|
|
1003
1003
|
const last = lastSeg?.at(-1);
|
|
1004
1004
|
if (last) {
|
|
1005
1005
|
components.push(
|
|
1006
|
-
|
|
1006
|
+
createText(
|
|
1007
1007
|
last,
|
|
1008
1008
|
l.label,
|
|
1009
1009
|
chart.font,
|
|
@@ -1014,16 +1014,16 @@ export function generateLines(xMin: number, xMax: number, yMin: number, yMax: nu
|
|
|
1014
1014
|
"center",
|
|
1015
1015
|
textHorizontalGrowth(last.x, xMin, xMax),
|
|
1016
1016
|
textVerticalGrowth(last.y, yMin, yMax),
|
|
1017
|
-
outlineColor !==
|
|
1017
|
+
outlineColor !== transparent ? 3 : 0,
|
|
1018
1018
|
outlineColor,
|
|
1019
1019
|
false,
|
|
1020
1020
|
l.id
|
|
1021
1021
|
)
|
|
1022
1022
|
);
|
|
1023
1023
|
}
|
|
1024
|
-
return
|
|
1024
|
+
return createGroup(l.label.split("<")[0] ?? "UNKNOWN", components);
|
|
1025
1025
|
});
|
|
1026
|
-
return
|
|
1026
|
+
return createGroup("Lines", lines);
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
1029
|
function getLineSegmentsInsideChart(
|
|
@@ -1031,11 +1031,11 @@ function getLineSegmentsInsideChart(
|
|
|
1031
1031
|
xMax: number,
|
|
1032
1032
|
yMin: number,
|
|
1033
1033
|
yMax: number,
|
|
1034
|
-
points: ReadonlyArray<
|
|
1035
|
-
): ReadonlyArray<ReadonlyArray<
|
|
1036
|
-
const segments: Array<ReadonlyArray<
|
|
1037
|
-
let segment: Array<
|
|
1038
|
-
let prev:
|
|
1034
|
+
points: ReadonlyArray<Point>
|
|
1035
|
+
): ReadonlyArray<ReadonlyArray<Point>> {
|
|
1036
|
+
const segments: Array<ReadonlyArray<Point>> = [];
|
|
1037
|
+
let segment: Array<Point> = [];
|
|
1038
|
+
let prev: Point | undefined;
|
|
1039
1039
|
for (const point of points) {
|
|
1040
1040
|
const prevInside = prev && isInside(xMin, xMax, yMin, yMax, prev);
|
|
1041
1041
|
const inside = isInside(xMin, xMax, yMin, yMax, point);
|
|
@@ -1064,7 +1064,7 @@ function getLineSegmentsInsideChart(
|
|
|
1064
1064
|
return segments;
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
1067
|
-
function isInside(xMin: number, xMax: number, yMin: number, yMax: number, p:
|
|
1067
|
+
function isInside(xMin: number, xMax: number, yMin: number, yMax: number, p: Point): boolean {
|
|
1068
1068
|
return p.x >= xMin && p.x <= xMax && p.y <= yMin && p.y >= yMax;
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
@@ -1073,13 +1073,13 @@ function moveInside(
|
|
|
1073
1073
|
xMax: number,
|
|
1074
1074
|
yMin: number,
|
|
1075
1075
|
yMax: number,
|
|
1076
|
-
inside:
|
|
1077
|
-
outside:
|
|
1078
|
-
):
|
|
1079
|
-
const xMinYMin =
|
|
1080
|
-
const xMinYMax =
|
|
1081
|
-
const xMaxYMin =
|
|
1082
|
-
const xMaxYMax =
|
|
1076
|
+
inside: Point,
|
|
1077
|
+
outside: Point
|
|
1078
|
+
): Point {
|
|
1079
|
+
const xMinYMin = createPoint(xMin, yMin);
|
|
1080
|
+
const xMinYMax = createPoint(xMin, yMax);
|
|
1081
|
+
const xMaxYMin = createPoint(xMax, yMin);
|
|
1082
|
+
const xMaxYMax = createPoint(xMax, yMax);
|
|
1083
1083
|
return (
|
|
1084
1084
|
lineLine(inside, outside, xMinYMin, xMaxYMin) ??
|
|
1085
1085
|
lineLine(inside, outside, xMinYMax, xMaxYMax) ??
|
|
@@ -1089,32 +1089,32 @@ function moveInside(
|
|
|
1089
1089
|
);
|
|
1090
1090
|
}
|
|
1091
1091
|
|
|
1092
|
-
function lineLine(a0:
|
|
1093
|
-
const da =
|
|
1094
|
-
const db =
|
|
1095
|
-
const dab =
|
|
1092
|
+
function lineLine(a0: Point, a1: Point, b0: Point, b1: Point): Point | undefined {
|
|
1093
|
+
const da = createPoint(a1.x - a0.x, a1.y - a0.y);
|
|
1094
|
+
const db = createPoint(b1.x - b0.x, b1.y - b0.y);
|
|
1095
|
+
const dab = createPoint(a0.x - b0.x, a0.y - b0.y);
|
|
1096
1096
|
const uA = (db.x * dab.y - db.y * dab.x) / (db.y * da.x - db.x * da.y);
|
|
1097
1097
|
const uB = (da.x * dab.y - da.y * dab.x) / (db.y * da.x - db.x * da.y);
|
|
1098
1098
|
|
|
1099
1099
|
// if uA and uB are between 0-1, lines are colliding
|
|
1100
1100
|
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
|
|
1101
|
-
return
|
|
1101
|
+
return createPoint(a0.x + uA * da.x, a0.y + uA * da.y);
|
|
1102
1102
|
}
|
|
1103
1103
|
return undefined;
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
|
-
export function generateAreas(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
1106
|
+
export function generateAreas(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
1107
1107
|
const areas = chart.chartAreas.map((a) => {
|
|
1108
1108
|
const xAxis = a.xAxis === "top" ? chart.xAxisesTop[a.xAxisIx] : chart.xAxisesBottom[a.xAxisIx];
|
|
1109
1109
|
const yAxis = a.yAxis === "right" ? chart.yAxisesRight[a.yAxisIx] : chart.yAxisesLeft[a.yAxisIx];
|
|
1110
1110
|
const points = a.points.map((p) => transformPoint(p, xMin, xMax, yMin, yMax, xAxis, yAxis));
|
|
1111
|
-
const components = [
|
|
1112
|
-
return
|
|
1111
|
+
const components = [createPolygon(points, a.strokeColor, a.strokeThickness, a.color, a.id)];
|
|
1112
|
+
return createGroup("UNKNOWN", components);
|
|
1113
1113
|
});
|
|
1114
|
-
return
|
|
1114
|
+
return createGroup("Areas", areas);
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
|
-
export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
1117
|
+
export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
1118
1118
|
const points = chart.chartPoints.map((p) => {
|
|
1119
1119
|
const xAxis = p.xAxis === "top" ? chart.xAxisesTop[p.xAxisIx] : chart.xAxisesBottom[p.xAxisIx];
|
|
1120
1120
|
const yAxis = p.yAxis === "right" ? chart.yAxisesRight[p.yAxisIx] : chart.yAxisesLeft[p.yAxisIx];
|
|
@@ -1122,7 +1122,7 @@ export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
1122
1122
|
const outlineColor = p.textOutlineColor ?? chart.textOutlineColor;
|
|
1123
1123
|
const components = [
|
|
1124
1124
|
generatePointShape(p, position, undefined),
|
|
1125
|
-
|
|
1125
|
+
createText(
|
|
1126
1126
|
position,
|
|
1127
1127
|
p.label,
|
|
1128
1128
|
chart.font,
|
|
@@ -1133,7 +1133,7 @@ export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
1133
1133
|
"center",
|
|
1134
1134
|
textHorizontalGrowth(position.x, xMin, xMax),
|
|
1135
1135
|
textVerticalGrowth(position.y, yMin, yMax),
|
|
1136
|
-
outlineColor !==
|
|
1136
|
+
outlineColor !== transparent ? 3 : 0,
|
|
1137
1137
|
outlineColor,
|
|
1138
1138
|
false
|
|
1139
1139
|
),
|
|
@@ -1143,8 +1143,8 @@ export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
1143
1143
|
generatePointShape(
|
|
1144
1144
|
{
|
|
1145
1145
|
...p,
|
|
1146
|
-
color:
|
|
1147
|
-
strokeColor:
|
|
1146
|
+
color: transparent,
|
|
1147
|
+
strokeColor: transparent,
|
|
1148
1148
|
strokeThickness: 0,
|
|
1149
1149
|
size: { width: p.size.width + 10, height: p.size.height + 10 },
|
|
1150
1150
|
},
|
|
@@ -1153,13 +1153,13 @@ export function generatePoints(xMin: number, xMax: number, yMin: number, yMax: n
|
|
|
1153
1153
|
)
|
|
1154
1154
|
);
|
|
1155
1155
|
}
|
|
1156
|
-
return
|
|
1156
|
+
return createGroup(p.label.split("<")[0] ?? "UNKNOWN", components);
|
|
1157
1157
|
});
|
|
1158
|
-
return
|
|
1158
|
+
return createGroup("Points", points);
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
|
-
export function generateBars(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart):
|
|
1162
|
-
const components = Array<
|
|
1161
|
+
export function generateBars(xMin: number, xMax: number, yMin: number, yMax: number, chart: Chart): Component {
|
|
1162
|
+
const components = Array<Component>();
|
|
1163
1163
|
|
|
1164
1164
|
for (const bars of chart.chartBars) {
|
|
1165
1165
|
const xAxis = bars.xAxis === "top" ? chart.xAxisesTop[bars.xAxisIx] : chart.xAxisesBottom[bars.xAxisIx];
|
|
@@ -1179,33 +1179,33 @@ export function generateBars(xMin: number, xMax: number, yMin: number, yMax: num
|
|
|
1179
1179
|
const [tl, middle, br] =
|
|
1180
1180
|
bars.direction === "x"
|
|
1181
1181
|
? [
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1182
|
+
createPoint(b.min ?? xMinValue, barPos + bars.width / 2),
|
|
1183
|
+
createPoint((b.max + (b.min ?? xMinValue)) / 2, barPos),
|
|
1184
|
+
createPoint(b.max, barPos - bars.width / 2),
|
|
1185
1185
|
]
|
|
1186
1186
|
: [
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1187
|
+
createPoint(barPos - bars.width / 2, b.max),
|
|
1188
|
+
createPoint(barPos, (b.max + (b.min ?? yMinValue)) / 2),
|
|
1189
|
+
createPoint(barPos + bars.width / 2, b.min ?? yMinValue),
|
|
1190
1190
|
];
|
|
1191
1191
|
const pos = transformPoint(middle, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
1192
1192
|
const topLeft = transformPoint(tl, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
1193
1193
|
const bottomRight = transformPoint(br, xMin, xMax, yMin, yMax, xAxis, yAxis);
|
|
1194
1194
|
components.push(
|
|
1195
|
-
|
|
1195
|
+
createRectangle(
|
|
1196
1196
|
topLeft,
|
|
1197
1197
|
bottomRight,
|
|
1198
|
-
b.strokeColor ??
|
|
1198
|
+
b.strokeColor ?? transparent,
|
|
1199
1199
|
b.strokeThickness ?? 0,
|
|
1200
1200
|
b.color,
|
|
1201
1201
|
b.id,
|
|
1202
|
-
|
|
1202
|
+
solidLine,
|
|
1203
1203
|
bars.radius
|
|
1204
1204
|
)
|
|
1205
1205
|
);
|
|
1206
1206
|
if (b.label) {
|
|
1207
1207
|
components.push(
|
|
1208
|
-
|
|
1208
|
+
createText(
|
|
1209
1209
|
pos,
|
|
1210
1210
|
b.label,
|
|
1211
1211
|
chart.font,
|
|
@@ -1216,7 +1216,7 @@ export function generateBars(xMin: number, xMax: number, yMin: number, yMax: num
|
|
|
1216
1216
|
"center",
|
|
1217
1217
|
"uniform",
|
|
1218
1218
|
"uniform",
|
|
1219
|
-
outlineColor !==
|
|
1219
|
+
outlineColor !== transparent ? 3 : 0,
|
|
1220
1220
|
outlineColor,
|
|
1221
1221
|
false
|
|
1222
1222
|
)
|
|
@@ -1225,35 +1225,35 @@ export function generateBars(xMin: number, xMax: number, yMin: number, yMax: num
|
|
|
1225
1225
|
}
|
|
1226
1226
|
}
|
|
1227
1227
|
|
|
1228
|
-
return
|
|
1228
|
+
return createGroup("Bars", components);
|
|
1229
1229
|
}
|
|
1230
1230
|
|
|
1231
|
-
function textHorizontalGrowth(position: number, xMin: number, xMax: number):
|
|
1231
|
+
function textHorizontalGrowth(position: number, xMin: number, xMax: number): GrowthDirection {
|
|
1232
1232
|
return position > (xMin + xMax) * 0.5 ? "left" : "right";
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
|
-
function textVerticalGrowth(position: number, yMin: number, yMax: number):
|
|
1235
|
+
function textVerticalGrowth(position: number, yMin: number, yMax: number): GrowthDirection {
|
|
1236
1236
|
return position < (yMin + yMax) * 0.5 ? "down" : "up";
|
|
1237
1237
|
}
|
|
1238
1238
|
|
|
1239
|
-
function generatePointShape(p: ChartPoint, position:
|
|
1239
|
+
function generatePointShape(p: ChartPoint, position: Point, id: string | undefined): Component {
|
|
1240
1240
|
const halfWidth = p.size.width * 0.5;
|
|
1241
1241
|
const halfHeight = p.size.height * 0.5;
|
|
1242
1242
|
if (p.shape === "triangle") {
|
|
1243
1243
|
const trianglePoints = [
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1244
|
+
createPoint(position.x, position.y + halfHeight),
|
|
1245
|
+
createPoint(position.x - halfWidth, position.y - halfHeight),
|
|
1246
|
+
createPoint(position.x + halfWidth, position.y - halfHeight),
|
|
1247
1247
|
];
|
|
1248
|
-
return
|
|
1248
|
+
return createPolygon(trianglePoints, p.strokeColor, p.strokeThickness, p.color, id);
|
|
1249
1249
|
} else if (p.shape === "square") {
|
|
1250
|
-
const topLeft =
|
|
1251
|
-
const bottomRight =
|
|
1252
|
-
return
|
|
1250
|
+
const topLeft = createPoint(position.x - halfWidth, position.y - halfHeight);
|
|
1251
|
+
const bottomRight = createPoint(position.x + halfWidth, position.y + halfHeight);
|
|
1252
|
+
return createRectangle(topLeft, bottomRight, p.strokeColor, p.strokeThickness, p.color, id);
|
|
1253
1253
|
} else {
|
|
1254
|
-
const topLeft =
|
|
1255
|
-
const bottomRight =
|
|
1256
|
-
return
|
|
1254
|
+
const topLeft = createPoint(position.x - halfWidth, position.y - halfHeight);
|
|
1255
|
+
const bottomRight = createPoint(position.x + halfWidth, position.y + halfHeight);
|
|
1256
|
+
return createEllipse(topLeft, bottomRight, p.strokeColor, p.strokeThickness, p.color, id);
|
|
1257
1257
|
}
|
|
1258
1258
|
}
|
|
1259
1259
|
|
|
@@ -1264,30 +1264,30 @@ export function generateXAxisGridLines(
|
|
|
1264
1264
|
yMax: number,
|
|
1265
1265
|
xTicks: ReadonlyArray<DiscreteAxisPoint>,
|
|
1266
1266
|
xAxis: Axis,
|
|
1267
|
-
xGrid: { readonly color:
|
|
1268
|
-
):
|
|
1267
|
+
xGrid: { readonly color: Color; readonly thickness: number }
|
|
1268
|
+
): Component {
|
|
1269
1269
|
const xLines = xTicks.map((l) => {
|
|
1270
1270
|
const x = transformValue(l.value, xMin, xMax, xAxis);
|
|
1271
|
-
const start =
|
|
1272
|
-
const end =
|
|
1273
|
-
return
|
|
1271
|
+
const start = createPoint(x, yMin);
|
|
1272
|
+
const end = createPoint(x, yMax);
|
|
1273
|
+
return createLine(start, end, xGrid.color, xGrid.thickness);
|
|
1274
1274
|
});
|
|
1275
1275
|
|
|
1276
|
-
return
|
|
1276
|
+
return createGroup("Lines", xLines);
|
|
1277
1277
|
}
|
|
1278
1278
|
|
|
1279
1279
|
export function generateXAxisLabels(
|
|
1280
1280
|
xMin: number,
|
|
1281
1281
|
xMax: number,
|
|
1282
1282
|
y: number,
|
|
1283
|
-
growVertical:
|
|
1283
|
+
growVertical: GrowthDirection,
|
|
1284
1284
|
ticks: ReadonlyArray<DiscreteAxisPoint>,
|
|
1285
1285
|
axis: Axis,
|
|
1286
1286
|
chart: Chart
|
|
1287
|
-
):
|
|
1287
|
+
): Component {
|
|
1288
1288
|
const rotation = axis.labelRotation ?? 0;
|
|
1289
1289
|
|
|
1290
|
-
const horizontalGrowth:
|
|
1290
|
+
const horizontalGrowth: GrowthDirection = (() => {
|
|
1291
1291
|
if (rotation === 0) {
|
|
1292
1292
|
return "uniform";
|
|
1293
1293
|
}
|
|
@@ -1298,48 +1298,48 @@ export function generateXAxisLabels(
|
|
|
1298
1298
|
}
|
|
1299
1299
|
})();
|
|
1300
1300
|
const xLabels = ticks.map((l) => {
|
|
1301
|
-
const position =
|
|
1302
|
-
return
|
|
1301
|
+
const position = createPoint(transformValue(l.value, xMin, xMax, axis), y);
|
|
1302
|
+
return createText(
|
|
1303
1303
|
position,
|
|
1304
1304
|
l.label ?? formatNumber(l.value),
|
|
1305
1305
|
chart.font,
|
|
1306
1306
|
axis.tickFontSize ?? chart.fontSize,
|
|
1307
|
-
axis.labelColor ??
|
|
1307
|
+
axis.labelColor ?? black,
|
|
1308
1308
|
"normal",
|
|
1309
1309
|
rotation,
|
|
1310
1310
|
"center",
|
|
1311
1311
|
horizontalGrowth,
|
|
1312
1312
|
growVertical,
|
|
1313
1313
|
0,
|
|
1314
|
-
axis.labelColor ??
|
|
1314
|
+
axis.labelColor ?? black,
|
|
1315
1315
|
false
|
|
1316
1316
|
);
|
|
1317
1317
|
});
|
|
1318
|
-
return
|
|
1318
|
+
return createGroup("Labels", xLabels);
|
|
1319
1319
|
}
|
|
1320
1320
|
|
|
1321
1321
|
export function generateXAxisLabel(
|
|
1322
1322
|
x: number,
|
|
1323
1323
|
y: number,
|
|
1324
|
-
horizontalGrowthDirection:
|
|
1325
|
-
verticalGrowthDirection:
|
|
1324
|
+
horizontalGrowthDirection: GrowthDirection,
|
|
1325
|
+
verticalGrowthDirection: GrowthDirection,
|
|
1326
1326
|
axis: Axis,
|
|
1327
1327
|
chart: Chart
|
|
1328
|
-
):
|
|
1329
|
-
const position =
|
|
1330
|
-
return
|
|
1328
|
+
): Component {
|
|
1329
|
+
const position = createPoint(x, y);
|
|
1330
|
+
return createText(
|
|
1331
1331
|
position,
|
|
1332
1332
|
axis.label ?? "",
|
|
1333
1333
|
chart.font,
|
|
1334
1334
|
axis.axisFontSize ?? chart.fontSize,
|
|
1335
|
-
axis.labelColor ??
|
|
1335
|
+
axis.labelColor ?? black,
|
|
1336
1336
|
"normal",
|
|
1337
1337
|
0,
|
|
1338
1338
|
"center",
|
|
1339
1339
|
horizontalGrowthDirection,
|
|
1340
1340
|
verticalGrowthDirection,
|
|
1341
1341
|
0,
|
|
1342
|
-
axis.labelColor ??
|
|
1342
|
+
axis.labelColor ?? black,
|
|
1343
1343
|
false,
|
|
1344
1344
|
axis.id
|
|
1345
1345
|
);
|
|
@@ -1352,29 +1352,29 @@ export function generateYAxisLines(
|
|
|
1352
1352
|
yMax: number,
|
|
1353
1353
|
yTicks: ReadonlyArray<DiscreteAxisPoint>,
|
|
1354
1354
|
yAxis: Axis,
|
|
1355
|
-
yGrid: { readonly color:
|
|
1356
|
-
xGrid: { readonly color:
|
|
1357
|
-
):
|
|
1355
|
+
yGrid: { readonly color: Color; readonly thickness: number },
|
|
1356
|
+
xGrid: { readonly color: Color; readonly thickness: number }
|
|
1357
|
+
): Component {
|
|
1358
1358
|
const yLines = yTicks.map((l) => {
|
|
1359
1359
|
const y = transformValue(l.value, yMin, yMax, yAxis);
|
|
1360
|
-
const start =
|
|
1361
|
-
const end =
|
|
1362
|
-
return
|
|
1360
|
+
const start = createPoint(xMin - xGrid.thickness / 2, y);
|
|
1361
|
+
const end = createPoint(xMax + xGrid.thickness / 2, y);
|
|
1362
|
+
return createLine(start, end, yGrid.color, yGrid.thickness);
|
|
1363
1363
|
});
|
|
1364
|
-
return
|
|
1364
|
+
return createGroup("Lines", yLines);
|
|
1365
1365
|
}
|
|
1366
1366
|
|
|
1367
1367
|
export function generateYAxisLabels(
|
|
1368
1368
|
x: number,
|
|
1369
1369
|
yMin: number,
|
|
1370
1370
|
yMax: number,
|
|
1371
|
-
growHorizontal:
|
|
1371
|
+
growHorizontal: GrowthDirection,
|
|
1372
1372
|
yTicks: ReadonlyArray<DiscreteAxisPoint>,
|
|
1373
1373
|
yAxis: Axis,
|
|
1374
1374
|
chart: Chart
|
|
1375
|
-
):
|
|
1375
|
+
): Component {
|
|
1376
1376
|
const rotation = yAxis.labelRotation ?? 0;
|
|
1377
|
-
const growVertical:
|
|
1377
|
+
const growVertical: GrowthDirection = (() => {
|
|
1378
1378
|
if (rotation === 0) {
|
|
1379
1379
|
return "uniform";
|
|
1380
1380
|
}
|
|
@@ -1386,49 +1386,49 @@ export function generateYAxisLabels(
|
|
|
1386
1386
|
})();
|
|
1387
1387
|
|
|
1388
1388
|
const yLabels = yTicks.map((l) => {
|
|
1389
|
-
const position =
|
|
1390
|
-
return
|
|
1389
|
+
const position = createPoint(x, transformValue(l.value, yMin, yMax, yAxis));
|
|
1390
|
+
return createText(
|
|
1391
1391
|
position,
|
|
1392
1392
|
l.label ?? formatNumber(l.value),
|
|
1393
1393
|
chart.font,
|
|
1394
1394
|
yAxis.tickFontSize ?? chart.fontSize,
|
|
1395
|
-
yAxis.labelColor ??
|
|
1395
|
+
yAxis.labelColor ?? black,
|
|
1396
1396
|
"normal",
|
|
1397
1397
|
rotation,
|
|
1398
1398
|
"center",
|
|
1399
1399
|
growHorizontal,
|
|
1400
1400
|
growVertical,
|
|
1401
1401
|
0,
|
|
1402
|
-
yAxis.labelColor ??
|
|
1402
|
+
yAxis.labelColor ?? black,
|
|
1403
1403
|
false
|
|
1404
1404
|
);
|
|
1405
1405
|
});
|
|
1406
|
-
return
|
|
1406
|
+
return createGroup("Labels", yLabels);
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
1409
|
export function generateYAxisLabel(
|
|
1410
1410
|
x: number,
|
|
1411
1411
|
y: number,
|
|
1412
1412
|
rotation: number,
|
|
1413
|
-
horizontalGrowthDirection:
|
|
1414
|
-
verticalGrowthDirection:
|
|
1413
|
+
horizontalGrowthDirection: GrowthDirection,
|
|
1414
|
+
verticalGrowthDirection: GrowthDirection,
|
|
1415
1415
|
axis: Axis,
|
|
1416
1416
|
chart: Chart
|
|
1417
|
-
):
|
|
1418
|
-
const position =
|
|
1419
|
-
return
|
|
1417
|
+
): Component {
|
|
1418
|
+
const position = createPoint(x, y);
|
|
1419
|
+
return createText(
|
|
1420
1420
|
position,
|
|
1421
1421
|
axis.label ?? "",
|
|
1422
1422
|
chart.font,
|
|
1423
1423
|
axis.axisFontSize ?? chart.fontSize,
|
|
1424
|
-
axis.labelColor ??
|
|
1424
|
+
axis.labelColor ?? black,
|
|
1425
1425
|
"normal",
|
|
1426
1426
|
rotation,
|
|
1427
1427
|
"center",
|
|
1428
1428
|
horizontalGrowthDirection,
|
|
1429
1429
|
verticalGrowthDirection,
|
|
1430
1430
|
0,
|
|
1431
|
-
axis.labelColor ??
|
|
1431
|
+
axis.labelColor ?? black,
|
|
1432
1432
|
false,
|
|
1433
1433
|
axis.id
|
|
1434
1434
|
);
|