layerchart 0.51.2 → 0.52.0

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.
@@ -1,11 +1,13 @@
1
1
  <script generics="TData">import {} from 'svelte';
2
- import { scaleLinear, scaleTime } from 'd3-scale';
2
+ import { scaleLinear, scaleOrdinal, scaleTime } from 'd3-scale';
3
3
  import { format } from '@layerstack/utils';
4
4
  import Axis from '../Axis.svelte';
5
5
  import Chart from '../Chart.svelte';
6
6
  import Highlight from '../Highlight.svelte';
7
7
  import Labels from '../Labels.svelte';
8
+ import Legend from '../Legend.svelte';
8
9
  import Points from '../Points.svelte';
10
+ import Rule from '../Rule.svelte';
9
11
  import Svg from '../layout/Svg.svelte';
10
12
  import * as Tooltip from '../tooltip/index.js';
11
13
  import { accessor, chartDataArray } from '../../utils/common.js';
@@ -15,9 +17,11 @@ export let y = undefined;
15
17
  export let series = [{ key: 'default', data: chartDataArray(data), color: 'hsl(var(--color-primary))' }];
16
18
  export let axis = true;
17
19
  export let labels = false;
20
+ export let legend = false;
21
+ export let rule = true;
22
+ export let props = {};
18
23
  // Default xScale based on first data's `x` value
19
24
  $: xScale = accessor(x)(chartDataArray(data)[0]) instanceof Date ? scaleTime() : scaleLinear();
20
- export let props = {};
21
25
  let chartData = series
22
26
  .flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
23
27
  .filter((d) => d);
@@ -33,7 +37,7 @@ let chartData = series
33
37
  ? undefined
34
38
  : {
35
39
  left: axis === true || axis === 'y' ? 16 : 0,
36
- bottom: axis === true || axis === 'x' ? 16 : 0,
40
+ bottom: (axis === true || axis === 'x' ? 16 : 0) + (legend === true ? 32 : 0),
37
41
  }}
38
42
  tooltip={{ mode: 'voronoi' }}
39
43
  {...$$restProps}
@@ -61,7 +65,6 @@ let chartData = series
61
65
  <Axis
62
66
  placement="left"
63
67
  grid
64
- rule
65
68
  format={(value) => format(value, undefined, { variant: 'short' })}
66
69
  {...typeof axis === 'object' ? axis : null}
67
70
  {...props.yAxis}
@@ -72,12 +75,15 @@ let chartData = series
72
75
  <Axis
73
76
  placement="bottom"
74
77
  grid
75
- rule
76
78
  format={(value) => format(value, undefined, { variant: 'short' })}
77
79
  {...typeof axis === 'object' ? axis : null}
78
80
  {...props.xAxis}
79
81
  />
80
82
  {/if}
83
+
84
+ {#if rule}
85
+ <Rule x={0} y={0} {...typeof rule === 'object' ? rule : null} {...props.rule} />
86
+ {/if}
81
87
  {/if}
82
88
  </slot>
83
89
 
@@ -111,6 +117,21 @@ let chartData = series
111
117
  {/if}
112
118
  </Svg>
113
119
 
120
+ <slot name="legend" {...slotProps}>
121
+ {#if legend}
122
+ <Legend
123
+ scale={scaleOrdinal(
124
+ series.map((s) => s.key),
125
+ series.map((s) => s.color)
126
+ )}
127
+ placement="bottom"
128
+ variant="swatches"
129
+ {...props.legend}
130
+ {...typeof legend === 'object' ? legend : null}
131
+ />
132
+ {/if}
133
+ </slot>
134
+
114
135
  <slot name="tooltip" {...slotProps}>
115
136
  <Tooltip.Root let:data>
116
137
  {#if activeSeries?.key !== 'default'}
@@ -3,7 +3,9 @@ import { type ComponentProps } from 'svelte';
3
3
  import Axis from '../Axis.svelte';
4
4
  import Highlight from '../Highlight.svelte';
5
5
  import Labels from '../Labels.svelte';
6
+ import Legend from '../Legend.svelte';
6
7
  import Points from '../Points.svelte';
8
+ import Rule from '../Rule.svelte';
7
9
  import { type Accessor } from '../../utils/common.js';
8
10
  declare class __sveltets_Render<TData> {
9
11
  props(): {
@@ -177,35 +179,56 @@ declare class __sveltets_Render<TData> {
177
179
  }> | undefined;
178
180
  transformContext?: import("..").TransformContext;
179
181
  } & {
180
- series?: {
181
- key: string;
182
- label?: string;
183
- data: TData[];
184
- color?: string;
185
- props?: Partial<ComponentProps<Points>>;
186
- }[] | undefined;
187
- labels?: boolean | {
188
- [x: string]: any;
189
- placement?: ("inside" | "outside" | "center") | undefined;
190
- offset?: number | undefined;
191
- format?: import("@layerstack/utils").FormatType | undefined;
192
- };
193
182
  axis?: boolean | "x" | "y" | {
183
+ [x: string]: any;
194
184
  placement: "top" | "bottom" | "left" | "right" | "angle" | "radius";
195
- label?: string;
196
- labelPlacement?: "start" | "middle" | "end";
185
+ label?: string | undefined;
186
+ labelPlacement?: ("start" | "middle" | "end") | undefined;
197
187
  labelProps?: Partial<ComponentProps<import("..").Text>> | undefined;
198
- rule?: boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">;
199
- grid?: boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">;
188
+ rule?: (boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">) | undefined;
189
+ grid?: (boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">) | undefined;
200
190
  ticks?: number | any[] | ((scale: import("../../utils/scales").AnyScale) => any) | null | undefined;
201
- tickLength?: number;
191
+ tickLength?: number | undefined;
202
192
  format?: import("@layerstack/utils").FormatType | undefined;
203
193
  tickLabelProps?: Partial<ComponentProps<import("..").Text>> | undefined;
204
194
  spring?: boolean | Parameters<typeof import("svelte/motion").spring>[1];
205
195
  tweened?: boolean | Parameters<typeof import("svelte/motion").tweened>[1];
206
- transitionIn?: typeof import("svelte/transition").fade | (() => {});
207
- transitionInParams?: import("svelte-ux").TransitionParams;
196
+ transitionIn?: (typeof import("svelte/transition").fade | (() => {})) | undefined;
197
+ transitionInParams?: import("svelte-ux").TransitionParams | undefined;
208
198
  scale?: any;
199
+ classes?: {
200
+ root?: string;
201
+ label?: string;
202
+ } | undefined;
203
+ };
204
+ labels?: boolean | {
205
+ [x: string]: any;
206
+ placement?: ("inside" | "outside" | "center") | undefined;
207
+ offset?: number | undefined;
208
+ format?: import("@layerstack/utils").FormatType | undefined;
209
+ };
210
+ legend?: boolean | {
211
+ [x: string]: any;
212
+ scale?: any;
213
+ title?: string | undefined;
214
+ width?: number | undefined;
215
+ height?: number | undefined;
216
+ ticks?: number | undefined;
217
+ tickFormat?: import("@layerstack/utils").FormatType | undefined;
218
+ tickValues?: any[] | undefined;
219
+ tickFontSize?: number | undefined;
220
+ tickLength?: number | undefined;
221
+ placement?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
222
+ orientation?: ("horizontal" | "vertical") | undefined;
223
+ variant?: ("ramp" | "swatches") | undefined;
224
+ classes?: {
225
+ root?: string;
226
+ title?: string;
227
+ label?: string;
228
+ tick?: string;
229
+ swatches?: string;
230
+ swatch?: string;
231
+ } | undefined;
209
232
  };
210
233
  props?: {
211
234
  xAxis?: Partial<ComponentProps<Axis>>;
@@ -213,7 +236,16 @@ declare class __sveltets_Render<TData> {
213
236
  points?: Partial<ComponentProps<Points>>;
214
237
  highlight?: Partial<ComponentProps<Highlight>>;
215
238
  labels?: Partial<ComponentProps<Labels>>;
239
+ legend?: Partial<ComponentProps<Legend>>;
240
+ rule?: Partial<ComponentProps<Rule>>;
216
241
  } | undefined;
242
+ series?: {
243
+ key: string;
244
+ label?: string;
245
+ data: TData[];
246
+ color?: string;
247
+ props?: Partial<ComponentProps<Points>>;
248
+ }[] | undefined;
217
249
  };
218
250
  events(): {} & {
219
251
  [evt: string]: CustomEvent<any>;
@@ -225,6 +257,7 @@ declare class __sveltets_Render<TData> {
225
257
  marks: any;
226
258
  'above-marks': any;
227
259
  highlight: any;
260
+ legend: any;
228
261
  tooltip: any;
229
262
  };
230
263
  }
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": "0.51.2",
7
+ "version": "0.52.0",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.7",
10
10
  "@mdi/js": "^7.4.47",