layerchart 2.0.0-next.17 → 2.0.0-next.19

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.
@@ -43,7 +43,7 @@
43
43
  */
44
44
  tooltipContext?: TooltipContextValue;
45
45
 
46
- children?: Snippet<[{ cells: CalendarCell[] }]>;
46
+ children?: Snippet<[{ cells: CalendarCell[]; cellSize: [number, number] }]>;
47
47
  } & Omit<
48
48
  RectPropsWithoutHTML,
49
49
  'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
@@ -117,7 +117,7 @@
117
117
  </script>
118
118
 
119
119
  {#if children}
120
- {@render children({ cells })}
120
+ {@render children({ cells, cellSize })}
121
121
  {:else}
122
122
  {#each cells as cell}
123
123
  <Rect
@@ -37,6 +37,7 @@ export type CalendarPropsWithoutHTML = {
37
37
  tooltipContext?: TooltipContextValue;
38
38
  children?: Snippet<[{
39
39
  cells: CalendarCell[];
40
+ cellSize: [number, number];
40
41
  }]>;
41
42
  } & Omit<RectPropsWithoutHTML, 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'>;
42
43
  export type CalendarProps = CalendarPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
@@ -30,8 +30,8 @@
30
30
  </script>
31
31
 
32
32
  <script lang="ts">
33
- import { timeWeek, timeYear } from 'd3-time';
34
- import { endOfMonth } from 'date-fns';
33
+ import { timeWeek, timeMonth, timeYear } from 'd3-time';
34
+ import { endOfInterval } from '../utils/date.js';
35
35
  import { cls } from '@layerstack/tailwind';
36
36
  import { layerClass } from '../utils/attributes.js';
37
37
  import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
@@ -58,7 +58,7 @@
58
58
  const startWeek = $derived(timeWeek.count(timeYear(date), date));
59
59
 
60
60
  // end of month
61
- const monthEnd = $derived(endOfMonth(date));
61
+ const monthEnd = $derived(endOfInterval(date, timeMonth));
62
62
  const endDayOfWeek = $derived(monthEnd.getDay());
63
63
  const endWeek = $derived(timeWeek.count(timeYear(monthEnd), monthEnd));
64
64
 
@@ -281,27 +281,34 @@
281
281
  // Split each line into words
282
282
  const words = line.split(/(?:(?!\u00A0+)\s+)/);
283
283
 
284
- // Handle word wrapping within each line
285
- return words.reduce((result: { words: string[]; width?: number }[], item) => {
286
- const currentLine = result[result.length - 1];
287
- const itemWidth = getStringWidth(item, style) || 0;
288
-
289
- if (
290
- currentLine &&
291
- (width == null || scaleToFit || (currentLine.width || 0) + itemWidth + spaceWidth < width)
292
- ) {
293
- // Word can be added to an existing line
294
- currentLine.words.push(item);
295
- currentLine.width = currentLine.width || 0;
296
- currentLine.width += itemWidth + spaceWidth;
297
- } else {
298
- // Add first word to line or word is too long to scaleToFit on existing line
299
- const newLine = { words: [item], width: itemWidth };
300
- result.push(newLine);
301
- }
302
-
303
- return result;
304
- }, []);
284
+ if (width == null) {
285
+ // No width specified, only use explicit line breaks (if used)
286
+ return [{ words }];
287
+ } else {
288
+ // Handle word wrapping within each line
289
+ return words.reduce((result: { words: string[]; width?: number }[], item) => {
290
+ const currentLine = result[result.length - 1];
291
+ const itemWidth = getStringWidth(item, style) || 0;
292
+
293
+ if (
294
+ currentLine &&
295
+ (width == null ||
296
+ scaleToFit ||
297
+ (currentLine.width || 0) + itemWidth + spaceWidth < width)
298
+ ) {
299
+ // Word can be added to an existing line
300
+ currentLine.words.push(item);
301
+ currentLine.width = currentLine.width || 0;
302
+ currentLine.width += itemWidth + spaceWidth;
303
+ } else {
304
+ // Add first word to line or word is too long to scaleToFit on existing line
305
+ const newLine = { words: [item], width: itemWidth };
306
+ result.push(newLine);
307
+ }
308
+
309
+ return result;
310
+ }, []);
311
+ }
305
312
  });
306
313
  });
307
314
 
@@ -0,0 +1,8 @@
1
+ import { type TimeInterval } from 'd3-time';
2
+ /**
3
+ * Get the date at the end of the interval
4
+ * Similar to `interval.ceil(date)` except:
5
+ * - returns end of day instead of start of next day
6
+ * - properly handles start of day (i.e. not return same date)
7
+ */
8
+ export declare function endOfInterval(date: Date, interval: TimeInterval): Date;
@@ -0,0 +1,11 @@
1
+ import {} from 'd3-time';
2
+ /**
3
+ * Get the date at the end of the interval
4
+ * Similar to `interval.ceil(date)` except:
5
+ * - returns end of day instead of start of next day
6
+ * - properly handles start of day (i.e. not return same date)
7
+ */
8
+ export function endOfInterval(date, interval) {
9
+ // Can not use `new Date(+interval.ceil(date) - 1)`; as `.ceil()` will return same date when start of the day (matching `.floor()`)
10
+ return new Date(interval.offset(interval.floor(date), 1).getTime() - 1);
11
+ }
@@ -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}`,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "2.0.0-next.17",
7
+ "version": "2.0.0-next.19",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.29.4",
10
10
  "@iconify-json/lucide": "^1.2.44",
@@ -50,12 +50,13 @@
50
50
  "prism-themes": "^1.9.0",
51
51
  "prismjs": "^1.30.0",
52
52
  "rehype-slug": "^6.0.0",
53
+ "rollup-plugin-visualizer": "^6.0.3",
53
54
  "shapefile": "^0.6.6",
54
55
  "solar-calculator": "^0.3.0",
55
56
  "svelte": "5.32.1",
56
57
  "svelte-check": "^4.2.1",
57
58
  "svelte-json-tree": "^2.2.0",
58
- "svelte-ux": "2.0.0-next.2",
59
+ "svelte-ux": "2.0.0-next.8",
59
60
  "svelte2tsx": "^0.7.39",
60
61
  "tailwindcss": "^4.1.7",
61
62
  "topojson-client": "^3.1.0",
@@ -72,10 +73,10 @@
72
73
  "type": "module",
73
74
  "dependencies": {
74
75
  "@dagrejs/dagre": "^1.1.4",
75
- "@layerstack/svelte-actions": "1.0.1-next.4",
76
- "@layerstack/svelte-state": "0.1.0-next.9",
77
- "@layerstack/tailwind": "2.0.0-next.6",
78
- "@layerstack/utils": "2.0.0-next.6",
76
+ "@layerstack/svelte-actions": "1.0.1-next.11",
77
+ "@layerstack/svelte-state": "0.1.0-next.16",
78
+ "@layerstack/tailwind": "2.0.0-next.13",
79
+ "@layerstack/utils": "2.0.0-next.11",
79
80
  "d3-array": "^3.2.4",
80
81
  "d3-color": "^3.1.0",
81
82
  "d3-delaunay": "^6.0.4",
@@ -95,7 +96,6 @@
95
96
  "d3-shape": "^3.2.0",
96
97
  "d3-tile": "^1.0.0",
97
98
  "d3-time": "^3.1.0",
98
- "date-fns": "^4.1.0",
99
99
  "lodash-es": "^4.17.21",
100
100
  "runed": "^0.28.0"
101
101
  },