layerchart 0.56.0 → 0.58.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.
@@ -35,6 +35,8 @@
35
35
  export let placement: Placement | undefined = undefined;
36
36
  export let orientation: 'horizontal' | 'vertical' = 'horizontal';
37
37
 
38
+ export let onClick: ((tick: any) => any) | undefined = undefined;
39
+
38
40
  /** Determine display ramp (individual color swatches or continuous ramp)*/
39
41
  export let variant: 'ramp' | 'swatches' = 'ramp';
40
42
 
@@ -208,15 +210,19 @@
208
210
  )}
209
211
  >
210
212
  {#each tickValues ?? xScale?.ticks?.(ticks) ?? [] as tick}
211
- <div class="flex gap-1">
213
+ {@const color = scale(tick)}
214
+ <button
215
+ class={cls('flex gap-1', !onClick && 'cursor-auto')}
216
+ on:click={() => onClick?.({ tick, color })}
217
+ >
212
218
  <div
213
219
  class={cls('h-4 w-4 rounded-full', classes.swatch)}
214
- style:background-color={scale(tick)}
220
+ style:background-color={color}
215
221
  ></div>
216
222
  <div class={cls('text-xs text-surface-content whitespace-nowrap', classes.label)}>
217
223
  {tickFormat ? format(tick, tickFormat) : tick}
218
224
  </div>
219
- </div>
225
+ </button>
220
226
  {/each}
221
227
  </div>
222
228
  {/if}
@@ -14,6 +14,7 @@ declare const __propDef: {
14
14
  tickLength?: number | undefined;
15
15
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
16
16
  orientation?: ("horizontal" | "vertical") | undefined;
17
+ onClick?: ((tick: any) => any) | undefined;
17
18
  variant?: ("ramp" | "swatches") | undefined;
18
19
  classes?: {
19
20
  root?: string;
@@ -64,6 +64,8 @@
64
64
  */
65
65
  export let tooltip: TooltipContextValue | undefined = undefined;
66
66
 
67
+ export let sort: ((a: any, b: any) => number) | null | undefined = undefined;
68
+
67
69
  const { data: contextData, x, y, xRange, c, cScale, config, width, height } = chartContext();
68
70
 
69
71
  // @ts-expect-error
@@ -71,12 +73,21 @@
71
73
  let tweened_endAngle = motionStore(0, { spring, tweened });
72
74
  $: tweened_endAngle.set(resolved_endAngle);
73
75
 
74
- $: pie = d3pie<any>()
75
- // @ts-expect-error
76
- .startAngle(startAngle ?? degreesToRadians($config.xRange ? min($xRange) : min(range)))
77
- .endAngle($tweened_endAngle)
78
- .padAngle(padAngle)
79
- .value($x);
76
+ let pie: ReturnType<typeof d3pie<any>>;
77
+ $: {
78
+ pie = d3pie<any>()
79
+ // @ts-expect-error
80
+ .startAngle(startAngle ?? degreesToRadians($config.xRange ? min($xRange) : min(range)))
81
+ .endAngle($tweened_endAngle)
82
+ .padAngle(padAngle)
83
+ .value($x);
84
+
85
+ if (sort === null) {
86
+ pie = pie.sort(null);
87
+ } else if (sort) {
88
+ pie = pie.sort(sort);
89
+ }
90
+ }
80
91
 
81
92
  $: arcs = pie(data ?? (Array.isArray($contextData) ? $contextData : []));
82
93
  </script>
@@ -33,6 +33,7 @@ declare const __propDef: {
33
33
  /**
34
34
  * Tooltip context to setup pointer events to show tooltip for related data
35
35
  */ tooltip?: TooltipContextValue | undefined;
36
+ sort?: ((a: any, b: any) => number) | null | undefined;
36
37
  };
37
38
  events: {
38
39
  [evt: string]: CustomEvent<any>;
@@ -256,6 +256,7 @@ declare class __sveltets_Render<TData> {
256
256
  tickLength?: number | undefined;
257
257
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
258
258
  orientation?: ("horizontal" | "vertical") | undefined;
259
+ onClick?: ((tick: any) => any) | undefined;
259
260
  variant?: ("ramp" | "swatches") | undefined;
260
261
  classes?: {
261
262
  root?: string;
@@ -256,6 +256,7 @@ declare class __sveltets_Render<TData> {
256
256
  tickLength?: number | undefined;
257
257
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
258
258
  orientation?: ("horizontal" | "vertical") | undefined;
259
+ onClick?: ((tick: any) => any) | undefined;
259
260
  variant?: ("ramp" | "swatches") | undefined;
260
261
  classes?: {
261
262
  root?: string;
@@ -255,6 +255,7 @@ declare class __sveltets_Render<TData> {
255
255
  tickLength?: number | undefined;
256
256
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
257
257
  orientation?: ("horizontal" | "vertical") | undefined;
258
+ onClick?: ((tick: any) => any) | undefined;
258
259
  variant?: ("ramp" | "swatches") | undefined;
259
260
  classes?: {
260
261
  root?: string;
@@ -25,6 +25,7 @@
25
25
  outerRadius?: typeof outerRadius;
26
26
  padAngle?: typeof padAngle;
27
27
  center?: typeof center;
28
+ placement?: typeof placement;
28
29
  props?: typeof props;
29
30
  range?: typeof range;
30
31
  series?: typeof series;
@@ -84,8 +85,11 @@
84
85
  export let cornerRadius = 0;
85
86
  export let padAngle = 0;
86
87
 
88
+ /** Placement of PieChart (default: 'center') */
89
+ export let placement: 'left' | 'center' | 'right' = 'center';
90
+
87
91
  /** Center chart. Override and use `props.group` for more control */
88
- export let center = true;
92
+ export let center = placement === 'center';
89
93
 
90
94
  export let props: {
91
95
  pie?: Partial<ComponentProps<Pie>>;
@@ -151,7 +155,15 @@
151
155
  <slot name="belowMarks" {...slotProps} />
152
156
 
153
157
  <slot name="marks" {...slotProps}>
154
- <Group {...props.group}>
158
+ <Group
159
+ x={placement === 'left'
160
+ ? height / 2
161
+ : placement === 'right'
162
+ ? width - height / 2
163
+ : undefined}
164
+ center={['left', 'right'].includes(placement) ? 'y' : undefined}
165
+ {...props.group}
166
+ >
155
167
  {#each series as s, i}
156
168
  {@const singleArc = s.data?.length === 1 || chartData.length === 1}
157
169
  {#if singleArc}
@@ -209,6 +209,7 @@ declare class __sveltets_Render<TData> {
209
209
  tickLength?: number | undefined;
210
210
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
211
211
  orientation?: ("horizontal" | "vertical") | undefined;
212
+ onClick?: ((tick: any) => any) | undefined;
212
213
  variant?: ("ramp" | "swatches") | undefined;
213
214
  classes?: {
214
215
  root?: string;
@@ -223,6 +224,7 @@ declare class __sveltets_Render<TData> {
223
224
  outerRadius?: number | undefined;
224
225
  padAngle?: number;
225
226
  center?: boolean;
227
+ placement?: "center" | "left" | "right";
226
228
  props?: {
227
229
  pie?: Partial<ComponentProps<Pie>>;
228
230
  group?: Partial<ComponentProps<Group>>;
@@ -58,7 +58,7 @@
58
58
  // Default xScale based on first data's `x` value
59
59
  $: xScale = accessor(x)(chartDataArray(data)[0]) instanceof Date ? scaleTime() : scaleLinear();
60
60
 
61
- let chartData = series
61
+ $: chartData = series
62
62
  .flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
63
63
  .filter((d) => d) as Array<TData>;
64
64
 
@@ -254,6 +254,7 @@ declare class __sveltets_Render<TData> {
254
254
  tickLength?: number | undefined;
255
255
  placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
256
256
  orientation?: ("horizontal" | "vertical") | undefined;
257
+ onClick?: ((tick: any) => any) | undefined;
257
258
  variant?: ("ramp" | "swatches") | undefined;
258
259
  classes?: {
259
260
  root?: string;
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.56.0",
7
+ "version": "0.58.0",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.9",
10
10
  "@mdi/js": "^7.4.47",