@constela/core 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +162 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3458,6 +3458,157 @@ function downsampleLTTB(data, targetCount) {
|
|
|
3458
3458
|
result.push(data[data.length - 1]);
|
|
3459
3459
|
return result;
|
|
3460
3460
|
}
|
|
3461
|
+
function getChartGridLines(min, max, height, padTop, padBottom, count) {
|
|
3462
|
+
if (typeof min !== "number" || typeof max !== "number" || typeof height !== "number" || typeof padTop !== "number" || typeof padBottom !== "number" || typeof count !== "number") {
|
|
3463
|
+
return [];
|
|
3464
|
+
}
|
|
3465
|
+
if (count <= 0) {
|
|
3466
|
+
return [];
|
|
3467
|
+
}
|
|
3468
|
+
const ticks = generateTicks(min, max, count);
|
|
3469
|
+
const result = [];
|
|
3470
|
+
for (const tick of ticks) {
|
|
3471
|
+
const y = scaleChartY(tick, min, max, height, padTop, padBottom);
|
|
3472
|
+
if (y === void 0) {
|
|
3473
|
+
continue;
|
|
3474
|
+
}
|
|
3475
|
+
result.push({
|
|
3476
|
+
y,
|
|
3477
|
+
value: tick,
|
|
3478
|
+
label: tick.toString()
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
return result;
|
|
3482
|
+
}
|
|
3483
|
+
function getRoundedBarPath(x, y, width, height, radius) {
|
|
3484
|
+
if (typeof x !== "number" || typeof y !== "number" || typeof width !== "number" || typeof height !== "number" || typeof radius !== "number") {
|
|
3485
|
+
return "";
|
|
3486
|
+
}
|
|
3487
|
+
if (width <= 0 || height <= 0) {
|
|
3488
|
+
return "";
|
|
3489
|
+
}
|
|
3490
|
+
const r = Math.min(radius, width / 2, height);
|
|
3491
|
+
if (r <= 0) {
|
|
3492
|
+
return `M${x},${y + height}L${x},${y}L${x + width},${y}L${x + width},${y + height}Z`;
|
|
3493
|
+
}
|
|
3494
|
+
return `M${x},${y + height}L${x},${y + r}Q${x},${y} ${x + r},${y}L${x + width - r},${y}Q${x + width},${y} ${x + width},${y + r}L${x + width},${y + height}Z`;
|
|
3495
|
+
}
|
|
3496
|
+
function getDonutArcPath(cx, cy, outerR, innerR, startAngle, endAngle) {
|
|
3497
|
+
if (typeof cx !== "number" || typeof cy !== "number" || typeof outerR !== "number" || typeof innerR !== "number" || typeof startAngle !== "number" || typeof endAngle !== "number") {
|
|
3498
|
+
return "";
|
|
3499
|
+
}
|
|
3500
|
+
if (innerR >= outerR || outerR <= 0 || innerR < 0) {
|
|
3501
|
+
return "";
|
|
3502
|
+
}
|
|
3503
|
+
const outerX1 = cx + outerR * Math.cos(startAngle - Math.PI / 2);
|
|
3504
|
+
const outerY1 = cy + outerR * Math.sin(startAngle - Math.PI / 2);
|
|
3505
|
+
const outerX2 = cx + outerR * Math.cos(endAngle - Math.PI / 2);
|
|
3506
|
+
const outerY2 = cy + outerR * Math.sin(endAngle - Math.PI / 2);
|
|
3507
|
+
const innerX1 = cx + innerR * Math.cos(startAngle - Math.PI / 2);
|
|
3508
|
+
const innerY1 = cy + innerR * Math.sin(startAngle - Math.PI / 2);
|
|
3509
|
+
const innerX2 = cx + innerR * Math.cos(endAngle - Math.PI / 2);
|
|
3510
|
+
const innerY2 = cy + innerR * Math.sin(endAngle - Math.PI / 2);
|
|
3511
|
+
const angleDiff = endAngle - startAngle;
|
|
3512
|
+
const largeArcFlag = Math.abs(angleDiff) > Math.PI ? 1 : 0;
|
|
3513
|
+
return `M${outerX1},${outerY1}A${outerR},${outerR} 0 ${largeArcFlag},1 ${outerX2},${outerY2}L${innerX2},${innerY2}A${innerR},${innerR} 0 ${largeArcFlag},0 ${innerX1},${innerY1}Z`;
|
|
3514
|
+
}
|
|
3515
|
+
function getSliceLabelPosition(cx, cy, radius, startAngle, endAngle) {
|
|
3516
|
+
if (typeof cx !== "number" || typeof cy !== "number" || typeof radius !== "number" || typeof startAngle !== "number" || typeof endAngle !== "number") {
|
|
3517
|
+
return void 0;
|
|
3518
|
+
}
|
|
3519
|
+
const midAngle = (startAngle + endAngle) / 2;
|
|
3520
|
+
const x = cx + radius * Math.cos(midAngle - Math.PI / 2);
|
|
3521
|
+
const y = cy + radius * Math.sin(midAngle - Math.PI / 2);
|
|
3522
|
+
return { x, y };
|
|
3523
|
+
}
|
|
3524
|
+
function getRadarGridPolygons(cx, cy, radius, sides, levels) {
|
|
3525
|
+
if (typeof cx !== "number" || typeof cy !== "number" || typeof radius !== "number" || typeof sides !== "number" || typeof levels !== "number") {
|
|
3526
|
+
return [];
|
|
3527
|
+
}
|
|
3528
|
+
if (sides < 3 || levels < 1) {
|
|
3529
|
+
return [];
|
|
3530
|
+
}
|
|
3531
|
+
const result = [];
|
|
3532
|
+
for (let i = 1; i <= levels; i++) {
|
|
3533
|
+
const levelRadius = radius * (i / levels);
|
|
3534
|
+
const points = [];
|
|
3535
|
+
for (let j = 0; j < sides; j++) {
|
|
3536
|
+
const angle = 2 * Math.PI * j / sides - Math.PI / 2;
|
|
3537
|
+
const x = cx + levelRadius * Math.cos(angle);
|
|
3538
|
+
const y = cy + levelRadius * Math.sin(angle);
|
|
3539
|
+
points.push(`${x},${y}`);
|
|
3540
|
+
}
|
|
3541
|
+
result.push(points.join(" "));
|
|
3542
|
+
}
|
|
3543
|
+
return result;
|
|
3544
|
+
}
|
|
3545
|
+
function getActivityRingArcPath(cx, cy, radius, startAngle, endAngle) {
|
|
3546
|
+
if (typeof cx !== "number" || typeof cy !== "number" || typeof radius !== "number" || typeof startAngle !== "number" || typeof endAngle !== "number") {
|
|
3547
|
+
return "";
|
|
3548
|
+
}
|
|
3549
|
+
const angleDiff = endAngle - startAngle;
|
|
3550
|
+
if (Math.abs(angleDiff) > 2 * Math.PI - 0.01) {
|
|
3551
|
+
const midAngle = startAngle + angleDiff / 2;
|
|
3552
|
+
const x12 = cx + radius * Math.cos(startAngle - Math.PI / 2);
|
|
3553
|
+
const y12 = cy + radius * Math.sin(startAngle - Math.PI / 2);
|
|
3554
|
+
const xMid = cx + radius * Math.cos(midAngle - Math.PI / 2);
|
|
3555
|
+
const yMid = cy + radius * Math.sin(midAngle - Math.PI / 2);
|
|
3556
|
+
const x22 = cx + radius * Math.cos(endAngle - Math.PI / 2);
|
|
3557
|
+
const y22 = cy + radius * Math.sin(endAngle - Math.PI / 2);
|
|
3558
|
+
const halfDiff = angleDiff / 2;
|
|
3559
|
+
const largeArc1 = Math.abs(halfDiff) > Math.PI ? 1 : 0;
|
|
3560
|
+
const largeArc2 = Math.abs(halfDiff) > Math.PI ? 1 : 0;
|
|
3561
|
+
return `M${x12},${y12}A${radius},${radius} 0 ${largeArc1},1 ${xMid},${yMid}A${radius},${radius} 0 ${largeArc2},1 ${x22},${y22}`;
|
|
3562
|
+
}
|
|
3563
|
+
const x1 = cx + radius * Math.cos(startAngle - Math.PI / 2);
|
|
3564
|
+
const y1 = cy + radius * Math.sin(startAngle - Math.PI / 2);
|
|
3565
|
+
const x2 = cx + radius * Math.cos(endAngle - Math.PI / 2);
|
|
3566
|
+
const y2 = cy + radius * Math.sin(endAngle - Math.PI / 2);
|
|
3567
|
+
const largeArcFlag = Math.abs(angleDiff) > Math.PI ? 1 : 0;
|
|
3568
|
+
return `M${x1},${y1}A${radius},${radius} 0 ${largeArcFlag},1 ${x2},${y2}`;
|
|
3569
|
+
}
|
|
3570
|
+
function getActivityRingLayout(data, valueKey, cx, cy, outerRadius, ringWidth, ringGap) {
|
|
3571
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
3572
|
+
return [];
|
|
3573
|
+
}
|
|
3574
|
+
if (typeof valueKey !== "string") {
|
|
3575
|
+
return [];
|
|
3576
|
+
}
|
|
3577
|
+
if (typeof cx !== "number" || typeof cy !== "number" || typeof outerRadius !== "number" || typeof ringWidth !== "number" || typeof ringGap !== "number") {
|
|
3578
|
+
return [];
|
|
3579
|
+
}
|
|
3580
|
+
const numOuterRadius = outerRadius;
|
|
3581
|
+
const numRingWidth = ringWidth;
|
|
3582
|
+
const numRingGap = ringGap;
|
|
3583
|
+
const values = data.map((d) => {
|
|
3584
|
+
const v = d[valueKey];
|
|
3585
|
+
return typeof v === "number" ? v : 0;
|
|
3586
|
+
});
|
|
3587
|
+
const max = Math.max(...values);
|
|
3588
|
+
if (max === 0) {
|
|
3589
|
+
return data.map((_, i) => ({
|
|
3590
|
+
radius: numOuterRadius - numRingWidth / 2 - i * (numRingWidth + numRingGap),
|
|
3591
|
+
angle: 0,
|
|
3592
|
+
maxAngle: 2 * Math.PI
|
|
3593
|
+
}));
|
|
3594
|
+
}
|
|
3595
|
+
return data.map((_, i) => ({
|
|
3596
|
+
radius: numOuterRadius - numRingWidth / 2 - i * (numRingWidth + numRingGap),
|
|
3597
|
+
angle: (values[i] ?? 0) / max * 2 * Math.PI,
|
|
3598
|
+
maxAngle: 2 * Math.PI
|
|
3599
|
+
}));
|
|
3600
|
+
}
|
|
3601
|
+
function getChartDefaultColors(palette) {
|
|
3602
|
+
const palettes = {
|
|
3603
|
+
health: ["#FF3B30", "#FF9500", "#FFCC00", "#34C759", "#007AFF", "#5856D6", "#AF52DE"],
|
|
3604
|
+
activity: ["#FA114F", "#A8FF04", "#00D4FF"],
|
|
3605
|
+
vibrant: ["#FF2D55", "#FF9500", "#5AC8FA", "#007AFF", "#4CD964", "#FF3B30"]
|
|
3606
|
+
};
|
|
3607
|
+
if (typeof palette !== "string" || !(palette in palettes)) {
|
|
3608
|
+
return palettes["health"];
|
|
3609
|
+
}
|
|
3610
|
+
return palettes[palette];
|
|
3611
|
+
}
|
|
3461
3612
|
var GLOBAL_FUNCTIONS = {
|
|
3462
3613
|
// Date helpers
|
|
3463
3614
|
getCalendarDays: (year, month) => getCalendarDays(year, month),
|
|
@@ -3494,7 +3645,17 @@ var GLOBAL_FUNCTIONS = {
|
|
|
3494
3645
|
// Chart helpers - Data aggregation
|
|
3495
3646
|
binData: (data, valueKey, binCount) => binData(data, valueKey, binCount),
|
|
3496
3647
|
aggregateData: (data, groupKey, valueKey, aggregation) => aggregateData(data, groupKey, valueKey, aggregation),
|
|
3497
|
-
downsample: (data, targetCount, method) => downsample(data, targetCount, method)
|
|
3648
|
+
downsample: (data, targetCount, method) => downsample(data, targetCount, method),
|
|
3649
|
+
// Chart helpers - Grid & redesign
|
|
3650
|
+
getChartGridLines: (min, max, height, padTop, padBottom, count) => getChartGridLines(min, max, height, padTop, padBottom, count),
|
|
3651
|
+
getRoundedBarPath: (x, y, width, height, radius) => getRoundedBarPath(x, y, width, height, radius),
|
|
3652
|
+
getDonutArcPath: (cx, cy, outerR, innerR, startAngle, endAngle) => getDonutArcPath(cx, cy, outerR, innerR, startAngle, endAngle),
|
|
3653
|
+
getSliceLabelPosition: (cx, cy, radius, startAngle, endAngle) => getSliceLabelPosition(cx, cy, radius, startAngle, endAngle),
|
|
3654
|
+
getRadarGridPolygons: (cx, cy, radius, sides, levels) => getRadarGridPolygons(cx, cy, radius, sides, levels),
|
|
3655
|
+
// Chart helpers - Activity Ring
|
|
3656
|
+
getActivityRingArcPath: (cx, cy, radius, startAngle, endAngle) => getActivityRingArcPath(cx, cy, radius, startAngle, endAngle),
|
|
3657
|
+
getActivityRingLayout: (data, valueKey, cx, cy, outerRadius, ringWidth, ringGap) => getActivityRingLayout(data, valueKey, cx, cy, outerRadius, ringWidth, ringGap),
|
|
3658
|
+
getChartDefaultColors: (palette) => getChartDefaultColors(palette)
|
|
3498
3659
|
};
|
|
3499
3660
|
function callGlobalFunction(method, args) {
|
|
3500
3661
|
const fn = GLOBAL_FUNCTIONS[method];
|