@heyiam/ui 0.0.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyiam/ui",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Shared visualization components for heyi.am",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -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
  }