layerchart 2.0.0-next.40 → 2.0.0-next.42

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.
@@ -107,7 +107,7 @@
107
107
  yearDays.map((date) => {
108
108
  const cellData = dataByDate.get(date) ?? { date };
109
109
  return {
110
- x: timeWeek.count(timeYear(date), date) * cellSize[0],
110
+ x: timeWeek.count(start, date) * cellSize[0],
111
111
  y: date.getDay() * cellSize[1],
112
112
  color: ctx.config.c ? ctx.cGet(cellData) : 'transparent',
113
113
  data: cellData,
@@ -136,14 +136,19 @@
136
136
 
137
137
  {#if monthPath}
138
138
  {#each yearMonths as date}
139
- <MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'lc-calendar-month-path')} />
139
+ <MonthPath
140
+ {date}
141
+ startOfRange={start}
142
+ {cellSize}
143
+ {...extractLayerProps(monthPath, 'lc-calendar-month-path')}
144
+ />
140
145
  {/each}
141
146
  {/if}
142
147
 
143
148
  {#if monthLabel}
144
149
  {#each yearMonths as date}
145
150
  <Text
146
- x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
151
+ x={timeWeek.count(start, timeWeek.ceil(date)) * cellSize[0]}
147
152
  value={format(date, 'month', { variant: 'short' })}
148
153
  capHeight="7px"
149
154
  {...extractLayerProps(monthLabel, 'lc-calendar-month-label')}
@@ -15,6 +15,11 @@
15
15
  */
16
16
  cellSize: number | [number, number];
17
17
 
18
+ /**
19
+ * The start date of the calendar (used to calculate week offsets).
20
+ */
21
+ startOfRange: Date;
22
+
18
23
  /**
19
24
  * A bindable reference to the underlying `<path>` element.
20
25
  *
@@ -38,6 +43,7 @@
38
43
  let {
39
44
  date,
40
45
  cellSize: cellSizeProp,
46
+ startOfRange,
41
47
  pathRef: pathRefProp = $bindable(),
42
48
  class: className,
43
49
  ...restProps
@@ -54,12 +60,12 @@
54
60
 
55
61
  // start of month
56
62
  const startDayOfWeek = $derived(date.getDay());
57
- const startWeek = $derived(timeWeek.count(timeYear(date), date));
63
+ const startWeek = $derived(timeWeek.count(startOfRange, date));
58
64
 
59
65
  // end of month
60
66
  const monthEnd = $derived(endOfInterval('month', date));
61
67
  const endDayOfWeek = $derived(monthEnd.getDay());
62
- const endWeek = $derived(timeWeek.count(timeYear(monthEnd), monthEnd));
68
+ const endWeek = $derived(timeWeek.count(startOfRange, monthEnd));
63
69
 
64
70
  const pathData = $derived(`
65
71
  M${(startWeek + 1) * cellSize[0]},${startDayOfWeek * cellSize[1]}
@@ -11,6 +11,10 @@ export type MonthPathPropsWithoutHTML = {
11
11
  * - array - sets [width, height].
12
12
  */
13
13
  cellSize: number | [number, number];
14
+ /**
15
+ * The start date of the calendar (used to calculate week offsets).
16
+ */
17
+ startOfRange: Date;
14
18
  /**
15
19
  * A bindable reference to the underlying `<path>` element.
16
20
  *
@@ -192,8 +192,8 @@
192
192
  const ctx = getChartContext();
193
193
  const tooltipCtx = getTooltipContext();
194
194
 
195
- let tooltipWidth = $state(0);
196
- let tooltipHeight = $state(0);
195
+ let tooltipWidth = $state<number | null>(null);
196
+ let tooltipHeight = $state<number | null>(null);
197
197
 
198
198
  function alignValue(value: number, align: Align, additionalOffset: number, tooltipSize: number) {
199
199
  const alignOffset = align === 'center' ? tooltipSize / 2 : align === 'end' ? tooltipSize : 0;
@@ -201,12 +201,11 @@
201
201
  }
202
202
 
203
203
  const positions = $derived.by(() => {
204
- if (!tooltipCtx.data) {
205
- // if no data, fallback?
206
- const tooltipX = untrack(() => tooltipCtx.x);
207
- const tooltipY = untrack(() => tooltipCtx.y);
208
- return { x: tooltipX, y: tooltipY };
204
+ // if no data or tooltip size is not known yet, return null
205
+ if (!tooltipCtx.data || tooltipWidth === null || tooltipHeight === null) {
206
+ return { x: null, y: null };
209
207
  }
208
+
210
209
  const xBandOffset = isScaleBand(ctx.xScale)
211
210
  ? ctx.xScale.step() / 2 - (ctx.xScale.padding() * ctx.xScale.step()) / 2
212
211
  : 0;
@@ -345,8 +344,8 @@
345
344
  };
346
345
  });
347
346
 
348
- const motionX = createMotion(tooltipCtx.x, () => positions.x, motion);
349
- const motionY = createMotion(tooltipCtx.y, () => positions.y, motion);
347
+ const motionX = createMotion(null, () => positions.x, motion);
348
+ const motionY = createMotion(null, () => positions.y, motion);
350
349
 
351
350
  $effect(() => {
352
351
  if (!tooltipCtx.data) {
@@ -63,7 +63,7 @@ function setupTracking(motion, getValue, options) {
63
63
  if (options.controlled)
64
64
  return;
65
65
  $effect(() => {
66
- motion.set(getValue());
66
+ motion.set(getValue(), { instant: motion.target == null });
67
67
  });
68
68
  }
69
69
  export function createMotion(initialValue, getValue, motionProp, options = {}) {
package/package.json CHANGED
@@ -4,7 +4,8 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "2.0.0-next.40",
7
+ "homepage": "https://layerchart.com",
8
+ "version": "2.0.0-next.42",
8
9
  "devDependencies": {
9
10
  "@changesets/cli": "^2.29.6",
10
11
  "@iconify-json/lucide": "^1.2.62",