@constela/core 0.20.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 +72 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3542,6 +3542,73 @@ function getRadarGridPolygons(cx, cy, radius, sides, levels) {
|
|
|
3542
3542
|
}
|
|
3543
3543
|
return result;
|
|
3544
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
|
+
}
|
|
3545
3612
|
var GLOBAL_FUNCTIONS = {
|
|
3546
3613
|
// Date helpers
|
|
3547
3614
|
getCalendarDays: (year, month) => getCalendarDays(year, month),
|
|
@@ -3584,7 +3651,11 @@ var GLOBAL_FUNCTIONS = {
|
|
|
3584
3651
|
getRoundedBarPath: (x, y, width, height, radius) => getRoundedBarPath(x, y, width, height, radius),
|
|
3585
3652
|
getDonutArcPath: (cx, cy, outerR, innerR, startAngle, endAngle) => getDonutArcPath(cx, cy, outerR, innerR, startAngle, endAngle),
|
|
3586
3653
|
getSliceLabelPosition: (cx, cy, radius, startAngle, endAngle) => getSliceLabelPosition(cx, cy, radius, startAngle, endAngle),
|
|
3587
|
-
getRadarGridPolygons: (cx, cy, radius, sides, levels) => getRadarGridPolygons(cx, cy, radius, sides, levels)
|
|
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)
|
|
3588
3659
|
};
|
|
3589
3660
|
function callGlobalFunction(method, args) {
|
|
3590
3661
|
const fn = GLOBAL_FUNCTIONS[method];
|