layerchart 2.0.0-next.3 → 2.0.0-next.31

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.
Files changed (112) hide show
  1. package/dist/components/AnnotationPoint.svelte +16 -9
  2. package/dist/components/AnnotationRange.svelte +3 -3
  3. package/dist/components/Arc.svelte +2 -2
  4. package/dist/components/Axis.svelte +83 -29
  5. package/dist/components/Axis.svelte.d.ts +13 -3
  6. package/dist/components/Bar.svelte +12 -8
  7. package/dist/components/Blur.svelte +5 -3
  8. package/dist/components/Blur.svelte.d.ts +2 -5
  9. package/dist/components/BrushContext.svelte +1 -1
  10. package/dist/components/Calendar.svelte +10 -6
  11. package/dist/components/Calendar.svelte.d.ts +2 -1
  12. package/dist/components/Chart.svelte +39 -3
  13. package/dist/components/Chart.svelte.d.ts +11 -0
  14. package/dist/components/Connector.svelte +2 -2
  15. package/dist/components/Connector.svelte.d.ts +1 -1
  16. package/dist/components/Ellipse.svelte +187 -0
  17. package/dist/components/Ellipse.svelte.d.ts +64 -0
  18. package/dist/components/ForceSimulation.svelte +184 -50
  19. package/dist/components/ForceSimulation.svelte.d.ts +88 -21
  20. package/dist/components/GeoPath.svelte +12 -5
  21. package/dist/components/GeoPoint.svelte +1 -2
  22. package/dist/components/GeoSpline.svelte +4 -4
  23. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  24. package/dist/components/Group.svelte +2 -2
  25. package/dist/components/Highlight.svelte +9 -6
  26. package/dist/components/Hull.svelte +1 -1
  27. package/dist/components/Labels.svelte +3 -2
  28. package/dist/components/Labels.svelte.d.ts +2 -2
  29. package/dist/components/Legend.svelte +19 -12
  30. package/dist/components/Legend.svelte.d.ts +5 -5
  31. package/dist/components/MonthPath.svelte +14 -11
  32. package/dist/components/MonthPath.svelte.d.ts +4 -3
  33. package/dist/components/Polygon.svelte +285 -0
  34. package/dist/components/Polygon.svelte.d.ts +115 -0
  35. package/dist/components/RadialGradient.svelte +1 -3
  36. package/dist/components/Spline.svelte +30 -18
  37. package/dist/components/Spline.svelte.d.ts +12 -4
  38. package/dist/components/Text.svelte +62 -60
  39. package/dist/components/Text.svelte.d.ts +6 -0
  40. package/dist/components/TransformControls.svelte +16 -20
  41. package/dist/components/Treemap.svelte +63 -26
  42. package/dist/components/Treemap.svelte.d.ts +11 -11
  43. package/dist/components/Voronoi.svelte +51 -33
  44. package/dist/components/Voronoi.svelte.d.ts +3 -1
  45. package/dist/components/charts/ArcChart.svelte +5 -3
  46. package/dist/components/charts/AreaChart.svelte +11 -11
  47. package/dist/components/charts/BarChart.svelte +72 -53
  48. package/dist/components/charts/DefaultTooltip.svelte +1 -1
  49. package/dist/components/charts/LineChart.svelte +10 -6
  50. package/dist/components/charts/PieChart.svelte +5 -3
  51. package/dist/components/charts/ScatterChart.svelte +2 -3
  52. package/dist/components/charts/utils.svelte.d.ts +2 -2
  53. package/dist/components/charts/utils.svelte.js +5 -1
  54. package/dist/components/index.d.ts +4 -0
  55. package/dist/components/index.js +5 -1
  56. package/dist/components/layout/Canvas.svelte +67 -49
  57. package/dist/components/layout/Canvas.svelte.d.ts +6 -0
  58. package/dist/components/layout/Layer.svelte +6 -4
  59. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  60. package/dist/components/tooltip/Tooltip.svelte +14 -7
  61. package/dist/components/tooltip/TooltipContext.svelte +136 -43
  62. package/dist/components/tooltip/TooltipContext.svelte.d.ts +3 -3
  63. package/dist/components/tooltip/TooltipHeader.svelte +5 -4
  64. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
  65. package/dist/components/tooltip/TooltipItem.svelte +5 -4
  66. package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
  67. package/dist/components/tooltip/TooltipList.svelte +1 -1
  68. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  69. package/dist/docs/Blockquote.svelte +6 -4
  70. package/dist/docs/Blockquote.svelte.d.ts +4 -19
  71. package/dist/docs/Code.svelte +20 -12
  72. package/dist/docs/Code.svelte.d.ts +9 -23
  73. package/dist/docs/Header1.svelte +4 -2
  74. package/dist/docs/Header1.svelte.d.ts +4 -28
  75. package/dist/docs/Json.svelte +11 -3
  76. package/dist/docs/Json.svelte.d.ts +9 -21
  77. package/dist/docs/Layout.svelte +10 -7
  78. package/dist/docs/Layout.svelte.d.ts +4 -19
  79. package/dist/docs/Link.svelte +7 -3
  80. package/dist/docs/Link.svelte.d.ts +4 -38
  81. package/dist/docs/Preview.svelte +6 -3
  82. package/dist/docs/TilesetField.svelte +20 -19
  83. package/dist/docs/TilesetField.svelte.d.ts +5 -22
  84. package/dist/docs/ViewSourceButton.svelte +9 -6
  85. package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
  86. package/dist/utils/arcText.svelte.js +4 -4
  87. package/dist/utils/array.d.ts +11 -0
  88. package/dist/utils/array.js +23 -0
  89. package/dist/utils/array.test.d.ts +1 -0
  90. package/dist/utils/array.test.js +200 -0
  91. package/dist/utils/canvas.d.ts +77 -0
  92. package/dist/utils/canvas.js +105 -41
  93. package/dist/utils/genData.d.ts +14 -0
  94. package/dist/utils/genData.js +24 -6
  95. package/dist/utils/index.d.ts +1 -0
  96. package/dist/utils/index.js +1 -0
  97. package/dist/utils/path.d.ts +10 -0
  98. package/dist/utils/path.js +30 -0
  99. package/dist/utils/rect.svelte.d.ts +2 -2
  100. package/dist/utils/rect.svelte.js +69 -1
  101. package/dist/utils/scales.svelte.d.ts +3 -2
  102. package/dist/utils/scales.svelte.js +7 -3
  103. package/dist/utils/shape.d.ts +43 -0
  104. package/dist/utils/shape.js +59 -0
  105. package/dist/utils/string.d.ts +49 -0
  106. package/dist/utils/string.js +4 -2
  107. package/dist/utils/ticks.d.ts +15 -4
  108. package/dist/utils/ticks.js +144 -158
  109. package/dist/utils/ticks.test.js +11 -16
  110. package/dist/utils/treemap.d.ts +1 -1
  111. package/package.json +27 -25
  112. package/dist/utils/object.js +0 -2
@@ -1,4 +1,4 @@
1
- import { addMinutes, startOfDay, startOfToday, subDays } from 'date-fns';
1
+ import { timeMinute, timeDay } from 'd3-time';
2
2
  import { cumsum } from 'd3-array';
3
3
  import { randomNormal } from 'd3-random';
4
4
  import { degreesToRadians, radiansToDegrees } from './math.js';
@@ -44,14 +44,14 @@ export function createSeries(options) {
44
44
  });
45
45
  }
46
46
  export function createDateSeries(options) {
47
- const now = startOfToday();
47
+ const now = timeDay.floor(new Date());
48
48
  const count = options.count ?? 10;
49
49
  const min = options.min;
50
50
  const max = options.max;
51
51
  const keys = options.keys ?? ['value'];
52
52
  return Array.from({ length: count }).map((_, i) => {
53
53
  return {
54
- date: subDays(now, count - i - 1),
54
+ date: timeDay.offset(now, -count + i),
55
55
  ...Object.fromEntries(keys.map((key) => {
56
56
  return [
57
57
  key,
@@ -66,10 +66,10 @@ export function createTimeSeries(options) {
66
66
  const min = options.min;
67
67
  const max = options.max;
68
68
  const keys = options.keys ?? ['value'];
69
- let lastStartDate = startOfDay(new Date());
69
+ let lastStartDate = timeDay.floor(new Date());
70
70
  const timeSeries = Array.from({ length: count }).map((_, i) => {
71
- const startDate = addMinutes(lastStartDate, getRandomInteger(0, 60));
72
- const endDate = addMinutes(startDate, getRandomInteger(5, 60));
71
+ const startDate = timeMinute.offset(lastStartDate, getRandomInteger(0, 60));
72
+ const endDate = timeMinute.offset(startDate, getRandomInteger(5, 60));
73
73
  lastStartDate = startDate;
74
74
  return {
75
75
  name: `item ${i + 1}`,
@@ -124,3 +124,21 @@ export function getSpiral({ angle, radius, count, width, height, }) {
124
124
  };
125
125
  });
126
126
  }
127
+ export function generateSineWave(options) {
128
+ const { numPoints, frequency = 1, amplitude = 1, noiseLevel = 0, phase = 0, xMin = 0, xMax = 2 * Math.PI, } = options;
129
+ if (numPoints <= 0) {
130
+ throw new Error('Number of points must be greater than 0');
131
+ }
132
+ const points = [];
133
+ const xStep = (xMax - xMin) / (numPoints - 1);
134
+ for (let i = 0; i < numPoints; i++) {
135
+ const x = xMin + i * xStep;
136
+ // Generate base sine wave
137
+ const sineValue = amplitude * Math.sin(frequency * x + phase);
138
+ // Add random noise if specified
139
+ const noise = noiseLevel > 0 ? (Math.random() - 0.5) * 2 * noiseLevel : 0;
140
+ const y = sineValue + noise;
141
+ points.push({ x, y });
142
+ }
143
+ return points;
144
+ }
@@ -1,3 +1,4 @@
1
+ export { applyLanes } from './array.js';
1
2
  export * from './canvas.js';
2
3
  export * from './common.js';
3
4
  export * from './geo.js';
@@ -1,3 +1,4 @@
1
+ export { applyLanes } from './array.js';
1
2
  export * from './canvas.js';
2
3
  export * from './common.js';
3
4
  export * from './geo.js';
@@ -17,5 +17,15 @@ export declare function spikePath({ x, y, width, height, }: {
17
17
  width: number;
18
18
  height: number;
19
19
  }): string;
20
+ /** Create rounded polygon path
21
+ *
22
+ * @param coords - Array of points (x, y)
23
+ * @param radius - Radius of the curve
24
+ * @returns String of path data
25
+ */
26
+ export declare function roundedPolygonPath(coords: {
27
+ x: number;
28
+ y: number;
29
+ }[], radius: number): string;
20
30
  /** Flatten all `y` coordinates to `0` */
21
31
  export declare function flattenPathData(pathData: string, yOverride?: number): string;
@@ -36,6 +36,36 @@ export function spikePath({ x, y, width, height, }) {
36
36
  `;
37
37
  return pathData;
38
38
  }
39
+ /** Create rounded polygon path
40
+ *
41
+ * @param coords - Array of points (x, y)
42
+ * @param radius - Radius of the curve
43
+ * @returns String of path data
44
+ */
45
+ export function roundedPolygonPath(coords, radius) {
46
+ if (radius === 0) {
47
+ // Simple polygon with straight lines
48
+ return `M${coords[0].x},${coords[0].y}${coords
49
+ .slice(1)
50
+ .map((p) => `L${p.x},${p.y}`)
51
+ .join('')}Z`;
52
+ }
53
+ let path = '';
54
+ const length = coords.length + 1;
55
+ for (let i = 0; i < length; i++) {
56
+ const a = coords[i % coords.length];
57
+ const b = coords[(i + 1) % coords.length];
58
+ const t = Math.min(radius / Math.hypot(b.x - a.x, b.y - a.y), 0.5);
59
+ if (i == 0)
60
+ path += `M${a.x * (1 - t) + b.x * t},${a.y * (1 - t) + b.y * t}`;
61
+ if (i > 0)
62
+ path += `Q${a.x},${a.y} ${a.x * (1 - t) + b.x * t},${a.y * (1 - t) + b.y * t}`;
63
+ if (i < length - 1)
64
+ path += `L${a.x * t + b.x * (1 - t)},${a.y * t + b.y * (1 - t)}`;
65
+ }
66
+ path += 'Z';
67
+ return path;
68
+ }
39
69
  /** Flatten all `y` coordinates to `0` */
40
70
  export function flattenPathData(pathData, yOverride = 0) {
41
71
  let result = pathData;
@@ -36,10 +36,10 @@ export declare function createDimensionGetter<TData>(ctx: ChartContextValue<TDat
36
36
  y: any;
37
37
  width: number;
38
38
  height: number;
39
- };
39
+ } | undefined;
40
40
  /**
41
41
  * If value is an array, returns first item, else returns original value
42
42
  * Useful when x/y getters for band scale are an array (such as for histograms)
43
43
  */
44
- export declare function firstValue(value: number | number[]): number;
44
+ export declare function firstValue(value: number | number[] | undefined): number | undefined;
45
45
  export {};
@@ -59,7 +59,7 @@ export function createDimensionGetter(ctx, getOptions) {
59
59
  const width = Math.max(0, ctx.xScale(right) - ctx.xScale(left) - insets.left - insets.right);
60
60
  return { x, y, width, height };
61
61
  }
62
- else {
62
+ else if (isScaleBand(ctx.xScale)) {
63
63
  // Vertical band or linear
64
64
  const x = firstValue(ctx.xScale(_x(item))) + (ctx.x1Scale ? ctx.x1Scale(_x1(item)) : 0) + insets.left;
65
65
  const width = Math.max(0, ctx.xScale.bandwidth
@@ -94,6 +94,74 @@ export function createDimensionGetter(ctx, getOptions) {
94
94
  const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
95
95
  return { x, y, width, height };
96
96
  }
97
+ else if (ctx.xInterval) {
98
+ // x-axis time scale with interval
99
+ const xValue = _x(item);
100
+ const start = ctx.xInterval.floor(xValue);
101
+ const end = ctx.xInterval.offset(start);
102
+ const x = ctx.xScale(start) + insets.left;
103
+ const width = ctx.xScale(end) - x - insets.right;
104
+ const yValue = _y(item);
105
+ let top = 0;
106
+ let bottom = 0;
107
+ if (Array.isArray(yValue)) {
108
+ // Array contains both top and bottom values (stack, etc);
109
+ top = max(yValue);
110
+ bottom = min(yValue);
111
+ }
112
+ else if (yValue == null) {
113
+ // null/undefined value
114
+ top = 0;
115
+ bottom = 0;
116
+ }
117
+ else if (yValue > 0) {
118
+ // Positive value
119
+ top = yValue;
120
+ bottom = max([0, yDomainMinMax[0]]);
121
+ }
122
+ else {
123
+ // Negative value
124
+ top = min([0, yDomainMinMax[1]]);
125
+ bottom = yValue;
126
+ }
127
+ const y = ctx.yScale(top) + insets.top;
128
+ const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
129
+ return { x, y, width, height };
130
+ }
131
+ else if (ctx.yInterval) {
132
+ // y-axis time scale with interval
133
+ const yValue = _y(item);
134
+ const start = ctx.yInterval.floor(yValue);
135
+ const end = ctx.yInterval.offset(start);
136
+ const y = ctx.yScale(start) + insets.top;
137
+ const height = ctx.yScale(end) - y - insets.bottom;
138
+ const xValue = _x(item);
139
+ let left = 0;
140
+ let right = 0;
141
+ if (Array.isArray(xValue)) {
142
+ // Array contains both top and bottom values (stack, etc);
143
+ left = min(xValue);
144
+ right = max(xValue);
145
+ }
146
+ else if (xValue == null) {
147
+ // null/undefined value
148
+ left = 0;
149
+ right = 0;
150
+ }
151
+ else if (xValue > 0) {
152
+ // Positive value
153
+ left = max([0, xDomainMinMax[0]]);
154
+ right = xValue;
155
+ }
156
+ else {
157
+ // Negative value
158
+ left = xValue;
159
+ right = min([0, xDomainMinMax[1]]);
160
+ }
161
+ const x = ctx.xScale(left) + insets.left;
162
+ const width = ctx.xScale(right) - x - insets.right;
163
+ return { x, y, width, height };
164
+ }
97
165
  };
98
166
  }
99
167
  /**
@@ -1,4 +1,4 @@
1
- import { type ScaleBand } from 'd3-scale';
1
+ import { type ScaleBand, type ScaleTime } from 'd3-scale';
2
2
  import { type MotionProp, type MotionOptions, type SpringOptions, type TweenOptions } from './motion.svelte.js';
3
3
  import type { Accessor } from './common.js';
4
4
  import type { OnlyObjects } from './types.js';
@@ -23,6 +23,8 @@ export type AnyScale<TInput extends SingleDomainType = any, TOutput extends Sing
23
23
  thresholds?: () => TInput[];
24
24
  quantiles?: () => TInput[];
25
25
  };
26
+ export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
27
+ export declare function isScaleTime(scale: AnyScale<any, any>): scale is ScaleTime<any, any>;
26
28
  export declare function getRange(scale: any): any[];
27
29
  export type SingleDomainType = number | string | Date | null | undefined;
28
30
  export type DomainType = (number | string | Date | null | undefined)[] | null | undefined;
@@ -45,7 +47,6 @@ export declare function createMotionScale<Domain, Range>(scale: AnyScale, motion
45
47
  * https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
46
48
  */
47
49
  export declare function scaleBandInvert(scale: ScaleBand<any>): (value: number) => any;
48
- export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
49
50
  /**
50
51
  * Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
51
52
  * Useful to map mouse event location (x,y) to domain value
@@ -5,6 +5,13 @@ import { Spring, Tween } from 'svelte/motion';
5
5
  function isAnyScale(scale) {
6
6
  return typeof scale === 'function' && typeof scale.range === 'function';
7
7
  }
8
+ export function isScaleBand(scale) {
9
+ return typeof scale.bandwidth === 'function';
10
+ }
11
+ export function isScaleTime(scale) {
12
+ const domain = scale.domain();
13
+ return domain[0] instanceof Date || domain[1] instanceof Date;
14
+ }
8
15
  export function getRange(scale) {
9
16
  if (isAnyScale(scale)) {
10
17
  return scale.range();
@@ -54,9 +61,6 @@ export function scaleBandInvert(scale) {
54
61
  return domain[Math.max(0, Math.min(index, domain.length - 1))];
55
62
  };
56
63
  }
57
- export function isScaleBand(scale) {
58
- return typeof scale.bandwidth === 'function';
59
- }
60
64
  /**
61
65
  * Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
62
66
  * Useful to map mouse event location (x,y) to domain value
@@ -0,0 +1,43 @@
1
+ /** Get points to create a polygon with given number of points and radius
2
+ *
3
+ * @param count - Number of points
4
+ * @param radius - Radius of the polygon
5
+ * @returns Array of points (angle, radius)
6
+ */
7
+ export declare function polygonPoints(count: number, radius: number, rotate?: number): {
8
+ angle: number;
9
+ radius: number;
10
+ }[];
11
+ /** Create polygon
12
+ *
13
+ * @param cx - Center x coordinate
14
+ * @param cy - Center y coordinate
15
+ * @param count - Number of points
16
+ * @param radius - Radius of the polygon
17
+ * @param rotate - Rotation of the polygon (degrees)
18
+ * @param inset - Percent to inset odd points (<1 inset, >1 outset)
19
+ * @param scaleX - Horizontal stretch factor
20
+ * @param scaleY - Vertical stretch factor
21
+ * @param skewX - Skew angle in degrees along the X axis
22
+ * @param skewY - Skew angle in degrees along the Y axis
23
+ * @param tiltX - Tilt factor for x-coordinates (0 = no tilt, positive moves points top => down, negative moves points bottom => up)
24
+ * @param tiltY - Tilt factor for y-coordinates (0 = no tilt, positive moves points left => right, negative moves points right => left)
25
+ * @returns Array of points (x, y)
26
+ */
27
+ export declare function polygon(options: {
28
+ cx: number;
29
+ cy: number;
30
+ count: number;
31
+ radius: number;
32
+ rotate?: number;
33
+ inset?: number;
34
+ scaleX?: number;
35
+ scaleY?: number;
36
+ skewX?: number;
37
+ skewY?: number;
38
+ tiltX?: number;
39
+ tiltY?: number;
40
+ }): {
41
+ x: number;
42
+ y: number;
43
+ }[];
@@ -0,0 +1,59 @@
1
+ import { range } from 'd3-array';
2
+ import { degreesToRadians } from './math.js';
3
+ /** Get points to create a polygon with given number of points and radius
4
+ *
5
+ * @param count - Number of points
6
+ * @param radius - Radius of the polygon
7
+ * @returns Array of points (angle, radius)
8
+ */
9
+ export function polygonPoints(count, radius, rotate = 0) {
10
+ const angle = 360 / count;
11
+ return range(count).map((index) => {
12
+ return {
13
+ angle: degreesToRadians(angle * index) + degreesToRadians(rotate),
14
+ radius,
15
+ };
16
+ });
17
+ }
18
+ /** Create polygon
19
+ *
20
+ * @param cx - Center x coordinate
21
+ * @param cy - Center y coordinate
22
+ * @param count - Number of points
23
+ * @param radius - Radius of the polygon
24
+ * @param rotate - Rotation of the polygon (degrees)
25
+ * @param inset - Percent to inset odd points (<1 inset, >1 outset)
26
+ * @param scaleX - Horizontal stretch factor
27
+ * @param scaleY - Vertical stretch factor
28
+ * @param skewX - Skew angle in degrees along the X axis
29
+ * @param skewY - Skew angle in degrees along the Y axis
30
+ * @param tiltX - Tilt factor for x-coordinates (0 = no tilt, positive moves points top => down, negative moves points bottom => up)
31
+ * @param tiltY - Tilt factor for y-coordinates (0 = no tilt, positive moves points left => right, negative moves points right => left)
32
+ * @returns Array of points (x, y)
33
+ */
34
+ export function polygon(options) {
35
+ const { cx, cy, count, radius, rotate = 0, inset = 1, scaleX = 1, scaleY = 1, skewX = 0, skewY = 0, tiltX = 0, tiltY = 0, } = options;
36
+ const skewXRad = degreesToRadians(skewX);
37
+ const skewYRad = degreesToRadians(skewY);
38
+ return polygonPoints(count, radius, rotate).map(({ angle, radius }, i) => {
39
+ // inset
40
+ const insetScale = i % 2 == 0 ? 1 : 1 - inset;
41
+ // scale
42
+ let x = radius * insetScale * Math.cos(angle) * scaleX;
43
+ let y = radius * insetScale * Math.sin(angle) * scaleY;
44
+ // tilt
45
+ const normalizedY = (y + radius) / (2 * radius);
46
+ const normalizedX = (x + radius) / (2 * radius);
47
+ const tiltScaleX = tiltX > 0 ? 1 + tiltX * (1 - normalizedY) : 1 - tiltX * normalizedY;
48
+ const tiltScaleY = tiltY > 0 ? 1 + tiltY * (1 - normalizedX) : 1 - tiltY * normalizedX;
49
+ x *= tiltScaleX;
50
+ y *= tiltScaleY;
51
+ // skew
52
+ const xSkewed = x + Math.tan(skewXRad) * y;
53
+ const ySkewed = y + Math.tan(skewYRad) * x;
54
+ return {
55
+ x: cx + xSkewed,
56
+ y: cy + ySkewed,
57
+ };
58
+ });
59
+ }
@@ -0,0 +1,49 @@
1
+ export declare const getStringWidth: any;
2
+ export type RasterizeTextOptions = {
3
+ fontSize?: string;
4
+ fontWeight?: number;
5
+ fontFamily?: string;
6
+ textAlign?: CanvasTextAlign;
7
+ textBaseline?: CanvasTextBaseline;
8
+ spacing?: number;
9
+ width?: number;
10
+ height?: number;
11
+ x?: number;
12
+ y?: number;
13
+ };
14
+ export declare function rasterizeText(text: string, options?: RasterizeTextOptions): number[][];
15
+ export declare function toTitleCase(str: string): string;
16
+ export type TruncateTextOptions = {
17
+ /**
18
+ * The maximum pixel width (optional if maxChars is provided).
19
+ */
20
+ maxWidth?: number;
21
+ /**
22
+ * CSS style for width calculation
23
+ */
24
+ style?: CSSStyleDeclaration;
25
+ /**
26
+ * The maximum character count
27
+ */
28
+ maxChars?: number;
29
+ /**
30
+ * Where to place the ellipsis: 'start', 'middle', or 'end'
31
+ *
32
+ * @default 'end'
33
+ */
34
+ position?: 'start' | 'middle' | 'end';
35
+ /**
36
+ * The character(s) to use as the ellipsis
37
+ *
38
+ * @default '…'
39
+ */
40
+ ellipsis?: string;
41
+ };
42
+ /**
43
+ * Truncates a string to fit within a specified pixel width or character count.
44
+ * If the string's width exceeds the maxWidth, it will be truncated. If the character
45
+ * count exceeds maxChars, it will also be truncated.
46
+ *
47
+ * The ellipsis can be placed at the start, middle, or end of the string.
48
+ */
49
+ export declare function truncateText(text: string, { position, ellipsis, maxWidth, style, maxChars }: TruncateTextOptions): string;
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash-es';
1
+ import memoize from 'memoize';
2
2
  const MEASUREMENT_ELEMENT_ID = '__text_measurement_id';
3
3
  function _getStringWidth(str, style) {
4
4
  try {
@@ -24,7 +24,9 @@ function _getStringWidth(str, style) {
24
24
  return null;
25
25
  }
26
26
  }
27
- export const getStringWidth = memoize(_getStringWidth, (str, style) => `${str}_${JSON.stringify(style)}`);
27
+ export const getStringWidth = memoize(_getStringWidth, {
28
+ cacheKey: ([str, style]) => `${str}_${JSON.stringify(style)}`,
29
+ });
28
30
  export function rasterizeText(text, options = {}) {
29
31
  const fontSize = options.fontSize ?? '200px';
30
32
  const fontWeight = options.fontWeight ?? 600;
@@ -1,9 +1,20 @@
1
1
  import { type TimeInterval } from 'd3-time';
2
+ import { Duration, type FormatType, type FormatConfig } from '@layerstack/utils';
2
3
  import { type AnyScale } from './scales.svelte.js';
3
- export declare function getMajorTicks(start: Date, end: Date): TimeInterval | null;
4
- export declare function formatMajorTick(date: Date, rangeStart: Date, rangeEnd: Date): string;
5
- export declare function getMinorTicks(start: Date, end: Date): TimeInterval | null;
4
+ import type { AxisProps } from '../components/Axis.svelte';
5
+ export declare function getDurationFormat(duration: Duration, options?: {
6
+ multiline?: boolean;
7
+ placement?: AxisProps['placement'];
8
+ }): (date: Date, i: number) => string;
6
9
  export type TicksConfig = number | any[] | ((scale: AnyScale) => any[] | undefined) | {
7
10
  interval: TimeInterval | null;
8
11
  } | null;
9
- export declare function resolveTickVals(scale: AnyScale, ticks?: TicksConfig, placement?: 'radius' | 'top' | 'bottom' | 'left' | 'right' | 'angle'): any[];
12
+ export declare function resolveTickVals(scale: AnyScale, ticks?: TicksConfig, count?: number, interval?: TimeInterval | null): any[];
13
+ export declare function resolveTickFormat(options: {
14
+ scale: AnyScale;
15
+ ticks?: TicksConfig;
16
+ count?: number;
17
+ formatType?: FormatType | FormatConfig;
18
+ multiline?: boolean;
19
+ placement?: AxisProps['placement'];
20
+ }): (date: Date, i: number) => string;