@heyiam/ui 0.0.2 → 0.0.4
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/package.json +4 -2
- package/src/GrowthChart.tsx +8 -4
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyiam/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Shared visualization components for heyi.am",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"types": "src/index.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
9
11
|
"peerDependencies": {
|
|
10
12
|
"react": ">=18",
|
|
11
13
|
"react-dom": ">=18"
|
package/src/GrowthChart.tsx
CHANGED
|
@@ -208,6 +208,10 @@ export function buildGrowthTimeSeries(
|
|
|
208
208
|
return { points, boundaries, totalVisualTime: visualTime };
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
function clamp(v: number, min: number, max: number): number {
|
|
212
|
+
return v < min ? min : v > max ? max : v;
|
|
213
|
+
}
|
|
214
|
+
|
|
211
215
|
/**
|
|
212
216
|
* Build a smooth cubic bezier SVG path through the given points.
|
|
213
217
|
* @internal Exported for testing
|
|
@@ -230,10 +234,10 @@ export function buildSmoothPath(
|
|
|
230
234
|
const p2 = coords[i + 1];
|
|
231
235
|
const p3 = coords[Math.min(coords.length - 1, i + 2)];
|
|
232
236
|
|
|
233
|
-
const cp1x = p1.x + (p2.x - p0.x) * tension;
|
|
234
|
-
const cp1y = p1.y + (p2.y - p0.y) * tension;
|
|
235
|
-
const cp2x = p2.x - (p3.x - p1.x) * tension;
|
|
236
|
-
const cp2y = p2.y - (p3.y - p1.y) * tension;
|
|
237
|
+
const cp1x = clamp(p1.x + (p2.x - p0.x) * tension, p1.x, p2.x);
|
|
238
|
+
const cp1y = clamp(p1.y + (p2.y - p0.y) * tension, Math.min(p1.y, p2.y), Math.max(p1.y, p2.y));
|
|
239
|
+
const cp2x = clamp(p2.x - (p3.x - p1.x) * tension, p1.x, p2.x);
|
|
240
|
+
const cp2y = clamp(p2.y - (p3.y - p1.y) * tension, Math.min(p1.y, p2.y), Math.max(p1.y, p2.y));
|
|
237
241
|
|
|
238
242
|
path += ` C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${p2.x.toFixed(1)},${p2.y.toFixed(1)}`;
|
|
239
243
|
}
|