layerchart 1.0.1 → 1.0.3

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.
@@ -95,7 +95,7 @@
95
95
  return path(data ?? $contextData);
96
96
  }
97
97
 
98
- $: tweenedOptions = tweened
98
+ const tweenedOptions = tweened
99
99
  ? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
100
100
  : false;
101
101
  $: tweened_d = motionStore(defaultPathData(), { tweened: tweenedOptions });
@@ -65,8 +65,9 @@
65
65
  $: markerEndId = markerEnd || $$slots['markerEnd'] ? uniqueId('marker-') : '';
66
66
 
67
67
  export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
68
- // @ts-expect-error
69
- $: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
68
+ const tweenedOptions = tweened
69
+ ? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
70
+ : false;
70
71
  $: tweened_d = motionStore('', { tweened: tweenedOptions });
71
72
 
72
73
  $: {
@@ -149,8 +149,9 @@
149
149
  }
150
150
 
151
151
  let d: string | null = '';
152
- // @ts-expect-error
153
- $: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
152
+ const tweenedOptions = tweened
153
+ ? { interpolate: interpolatePath, ...(typeof tweened === 'object' ? tweened : null) }
154
+ : false;
154
155
  $: tweened_d = motionStore(defaultPathData(), { tweened: tweenedOptions });
155
156
  $: {
156
157
  const path = $radial
@@ -130,15 +130,15 @@
130
130
  center: { x: number; y: number },
131
131
  rect?: { width: number; height: number }
132
132
  ) {
133
- // TODO: Improve with geo/projection
133
+ const newScale = rect ? ($width < $height ? $width / rect.width : $height / rect.height) : 1;
134
134
 
135
135
  $translate = {
136
- x: $width / 2 - center.x,
137
- y: $height / 2 - center.y,
136
+ x: $width / 2 - center.x * newScale,
137
+ y: $height / 2 - center.y * newScale,
138
138
  };
139
139
 
140
140
  if (rect) {
141
- $scale = $width < $height ? $width / rect.width : $height / rect.height;
141
+ $scale = newScale;
142
142
  }
143
143
  }
144
144
 
@@ -103,6 +103,7 @@
103
103
  export let props: {
104
104
  area?: Partial<ComponentProps<Area>>;
105
105
  brush?: Partial<ComponentProps<BrushContext>>;
106
+ canvas?: Partial<ComponentProps<Canvas>>;
106
107
  grid?: Partial<ComponentProps<Grid>>;
107
108
  highlight?: Partial<ComponentProps<Highlight>>;
108
109
  labels?: Partial<ComponentProps<Labels>>;
@@ -110,6 +111,7 @@
110
111
  line?: Partial<ComponentProps<Line>>;
111
112
  points?: Partial<ComponentProps<Points>>;
112
113
  rule?: Partial<ComponentProps<Rule>>;
114
+ svg?: Partial<ComponentProps<Svg>>;
113
115
  tooltip?: {
114
116
  context?: Partial<ComponentProps<Tooltip.Context>>;
115
117
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -173,7 +175,7 @@
173
175
  highlightSeriesKey = seriesKey;
174
176
  }
175
177
 
176
- function getAreaProps(s: (typeof series)[number], i: number) {
178
+ $: getAreaProps = (s: (typeof series)[number], i: number) => {
177
179
  const lineProps = {
178
180
  ...props.line,
179
181
  ...(typeof props.area?.line === 'object' ? props.area.line : null),
@@ -217,7 +219,7 @@
217
219
  };
218
220
 
219
221
  return areaProps;
220
- }
222
+ };
221
223
 
222
224
  function getPointsProps(s: (typeof series)[number], i: number) {
223
225
  const pointsProps: ComponentProps<Points> = {
@@ -350,7 +352,12 @@
350
352
  <slot {...slotProps}>
351
353
  <slot name="belowContext" {...slotProps} />
352
354
 
353
- <svelte:component this={renderContext === 'canvas' ? Canvas : Svg} center={radial} {debug}>
355
+ <svelte:component
356
+ this={renderContext === 'canvas' ? Canvas : Svg}
357
+ {...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
358
+ center={radial}
359
+ {debug}
360
+ >
354
361
  <slot name="grid" {...slotProps}>
355
362
  {#if grid}
356
363
  <Grid x={radial} y {...typeof grid === 'object' ? grid : null} {...props.grid} />
@@ -135,12 +135,14 @@
135
135
  export let props: {
136
136
  xAxis?: Partial<ComponentProps<Axis>>;
137
137
  yAxis?: Partial<ComponentProps<Axis>>;
138
+ canvas?: Partial<ComponentProps<Canvas>>;
138
139
  grid?: Partial<ComponentProps<Grid>>;
139
140
  rule?: Partial<ComponentProps<Rule>>;
140
141
  bars?: Partial<ComponentProps<Bars>>;
141
142
  legend?: Partial<ComponentProps<Legend>>;
142
143
  highlight?: Partial<ComponentProps<Highlight>>;
143
144
  labels?: Partial<ComponentProps<Labels>>;
145
+ svg?: Partial<ComponentProps<Svg>>;
144
146
  tooltip?: {
145
147
  context?: Partial<ComponentProps<Tooltip.Context>>;
146
148
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -203,7 +205,7 @@
203
205
  highlightSeriesKey = seriesKey;
204
206
  }
205
207
 
206
- function getBarsProps(s: (typeof series)[number], i: number) {
208
+ $: getBarsProps = (s: (typeof series)[number], i: number) => {
207
209
  const isFirst = i == 0;
208
210
  const isLast = i == visibleSeries.length - 1;
209
211
 
@@ -252,7 +254,7 @@
252
254
  };
253
255
 
254
256
  return barsProps;
255
- }
257
+ };
256
258
 
257
259
  function getLabelsProps(s: (typeof series)[number], i: number) {
258
260
  const labelsProps: ComponentProps<Labels> = {
@@ -356,7 +358,11 @@
356
358
  <slot {...slotProps}>
357
359
  <slot name="belowContext" {...slotProps} />
358
360
 
359
- <svelte:component this={renderContext === 'canvas' ? Canvas : Svg} {debug}>
361
+ <svelte:component
362
+ this={renderContext === 'canvas' ? Canvas : Svg}
363
+ {...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
364
+ {debug}
365
+ >
360
366
  <slot name="grid" {...slotProps}>
361
367
  {#if grid}
362
368
  <Grid
@@ -94,6 +94,7 @@
94
94
 
95
95
  export let props: {
96
96
  brush?: Partial<ComponentProps<BrushContext>>;
97
+ canvas?: Partial<ComponentProps<Canvas>>;
97
98
  grid?: Partial<ComponentProps<Grid>>;
98
99
  highlight?: Partial<ComponentProps<Highlight>>;
99
100
  labels?: Partial<ComponentProps<Labels>>;
@@ -101,6 +102,7 @@
101
102
  points?: Partial<ComponentProps<Points>>;
102
103
  rule?: Partial<ComponentProps<Rule>>;
103
104
  spline?: Partial<ComponentProps<Spline>>;
105
+ svg?: Partial<ComponentProps<Svg>>;
104
106
  tooltip?: {
105
107
  context?: Partial<ComponentProps<Tooltip.Context>>;
106
108
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -139,7 +141,7 @@
139
141
  highlightSeriesKey = seriesKey;
140
142
  }
141
143
 
142
- function getSplineProps(s: (typeof series)[number], i: number) {
144
+ $: getSplineProps = (s: (typeof series)[number], i: number) => {
143
145
  const splineProps: ComponentProps<Spline> = {
144
146
  data: s.data,
145
147
  y: s.value ?? (s.data ? undefined : s.key),
@@ -159,7 +161,7 @@
159
161
  };
160
162
 
161
163
  return splineProps;
162
- }
164
+ };
163
165
 
164
166
  function getPointsProps(s: (typeof series)[number], i: number) {
165
167
  const pointsProps: ComponentProps<Points> = {
@@ -280,7 +282,12 @@
280
282
  <slot {...slotProps}>
281
283
  <slot name="belowContext" {...slotProps} />
282
284
 
283
- <svelte:component this={renderContext === 'canvas' ? Canvas : Svg} center={radial} {debug}>
285
+ <svelte:component
286
+ this={renderContext === 'canvas' ? Canvas : Svg}
287
+ {...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
288
+ center={radial}
289
+ {debug}
290
+ >
284
291
  <slot name="grid" {...slotProps}>
285
292
  {#if grid}
286
293
  <Grid x={radial} y {...typeof grid === 'object' ? grid : null} {...props.grid} />
@@ -15,6 +15,7 @@
15
15
  import * as Tooltip from '../tooltip/index.js';
16
16
 
17
17
  import { accessor, chartDataArray, type Accessor } from '../../utils/common.js';
18
+ import { asAny } from '../../utils/types.js';
18
19
 
19
20
  interface $$Props extends ComponentProps<Chart<TData>> {
20
21
  cornerRadius?: typeof cornerRadius;
@@ -119,6 +120,8 @@
119
120
  group?: Partial<ComponentProps<Group>>;
120
121
  arc?: Partial<ComponentProps<Arc>>;
121
122
  legend?: Partial<ComponentProps<Legend>>;
123
+ canvas?: Partial<ComponentProps<Canvas>>;
124
+ svg?: Partial<ComponentProps<Svg>>;
122
125
  tooltip?: {
123
126
  context?: Partial<ComponentProps<Tooltip.Context>>;
124
127
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -223,7 +226,12 @@
223
226
  <slot {...slotProps}>
224
227
  <slot name="belowContext" {...slotProps} />
225
228
 
226
- <svelte:component this={renderContext === 'canvas' ? Canvas : Svg} {center} {debug}>
229
+ <svelte:component
230
+ this={renderContext === 'canvas' ? Canvas : Svg}
231
+ {...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
232
+ {center}
233
+ {debug}
234
+ >
227
235
  <slot name="belowMarks" {...slotProps} />
228
236
 
229
237
  <slot name="marks" {...slotProps}>
@@ -1,9 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import { type ComponentProps } from 'svelte';
3
3
  import Arc from '../Arc.svelte';
4
+ import Canvas from '../layout/Canvas.svelte';
4
5
  import Group from '../Group.svelte';
5
6
  import Legend from '../Legend.svelte';
6
7
  import Pie from '../Pie.svelte';
8
+ import Svg from '../layout/Svg.svelte';
7
9
  import * as Tooltip from '../tooltip/index.js';
8
10
  import { type Accessor } from '../../utils/common.js';
9
11
  declare class __sveltets_Render<TData> {
@@ -294,6 +296,8 @@ declare class __sveltets_Render<TData> {
294
296
  group?: Partial<ComponentProps<Group>>;
295
297
  arc?: Partial<ComponentProps<Arc>>;
296
298
  legend?: Partial<ComponentProps<Legend>>;
299
+ canvas?: Partial<ComponentProps<Canvas>>;
300
+ svg?: Partial<ComponentProps<Svg>>;
297
301
  tooltip?: {
298
302
  context?: Partial<ComponentProps<Tooltip.Context>>;
299
303
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -25,6 +25,7 @@
25
25
  defaultChartPadding,
26
26
  type Accessor,
27
27
  } from '../../utils/common.js';
28
+ import { asAny } from '../../utils/types.js';
28
29
 
29
30
  interface $$Props extends ComponentProps<Chart<TData>> {
30
31
  axis?: typeof axis;
@@ -72,6 +73,7 @@
72
73
 
73
74
  export let props: {
74
75
  brush?: Partial<ComponentProps<BrushContext>>;
76
+ canvas?: Partial<ComponentProps<Canvas>>;
75
77
  debug?: typeof debug;
76
78
  grid?: Partial<ComponentProps<Grid>>;
77
79
  highlight?: Partial<ComponentProps<Highlight>>;
@@ -80,6 +82,7 @@
80
82
  points?: Partial<ComponentProps<Points>>;
81
83
  profile?: typeof profile;
82
84
  rule?: Partial<ComponentProps<Rule>>;
85
+ svg?: Partial<ComponentProps<Svg>>;
83
86
  tooltip?: {
84
87
  context?: Partial<ComponentProps<Tooltip.Context>>;
85
88
  root?: Partial<ComponentProps<Tooltip.Root>>;
@@ -120,7 +123,7 @@
120
123
  highlightSeriesKey = seriesKey ?? null;
121
124
  }
122
125
 
123
- function getPointsProps(s: (typeof series)[number], i: number) {
126
+ $: getPointsProps = (s: (typeof series)[number], i: number) => {
124
127
  const pointsProps: ComponentProps<Points> = {
125
128
  data: s.data,
126
129
  stroke: s.color,
@@ -137,7 +140,7 @@
137
140
  };
138
141
 
139
142
  return pointsProps;
140
- }
143
+ };
141
144
 
142
145
  function getLabelsProps(s: (typeof series)[number], i: number) {
143
146
  const labelsProps: ComponentProps<Labels> = {
@@ -246,7 +249,11 @@
246
249
  <slot {...slotProps}>
247
250
  <slot name="belowContext" {...slotProps} />
248
251
 
249
- <svelte:component this={renderContext === 'canvas' ? Canvas : Svg} {debug}>
252
+ <svelte:component
253
+ this={renderContext === 'canvas' ? Canvas : Svg}
254
+ {...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
255
+ {debug}
256
+ >
250
257
  <slot name="grid" {...slotProps}>
251
258
  {#if grid}
252
259
  <Grid x y {...typeof grid === 'object' ? grid : null} {...props.grid} />
@@ -192,7 +192,7 @@
192
192
  const point = localPoint(e, containerNode);
193
193
 
194
194
  if (
195
- mode !== 'manual' &&
195
+ tooltipData == null && // mode !== 'manual' but support annotations
196
196
  (point.x < tooltipContextNode.offsetLeft ||
197
197
  point.x > tooltipContextNode.offsetLeft + tooltipContextNode.offsetWidth ||
198
198
  point.y < tooltipContextNode.offsetTop ||
@@ -0,0 +1,2 @@
1
+ import { memoize } from 'lodash-es';
2
+ export const memoizeObject = memoize((obj) => obj, (obj) => JSON.stringify(obj));
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": "1.0.1",
7
+ "version": "1.0.3",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.28.1",
10
10
  "@mdi/js": "^7.4.47",