svelteplot 0.0.1-alpha.22 → 0.0.1-alpha.24

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.
@@ -14,8 +14,10 @@ let {
14
14
  data,
15
15
  curve,
16
16
  tension,
17
+ x = null,
17
18
  x1 = null,
18
19
  x2 = null,
20
+ y = null,
19
21
  y1 = null,
20
22
  y2 = null,
21
23
  z = null,
@@ -25,9 +27,9 @@ let {
25
27
  ...styleProps
26
28
  } = $props();
27
29
  let channels = $derived({
28
- x1,
30
+ x1: x1 == null ? x : x1,
29
31
  x2,
30
- y1,
32
+ y1: y1 == null ? y : y1,
31
33
  y2,
32
34
  fill,
33
35
  stroke,
@@ -45,7 +47,7 @@ let sortedGroups = $derived(
45
47
  let areaPath = $derived(
46
48
  callWithProps(area, [], {
47
49
  curve: maybeCurve(curve, tension),
48
- ...x1 != null && x2 != null ? {
50
+ ...channels.x1 != null && channels.x2 != null ? {
49
51
  // "vertical" area
50
52
  x0: (d) => plot.xScale(resolveChannel("x1", d, channels)),
51
53
  x1: (d) => plot.xScale(resolveChannel("x2", d, channels)),
@@ -58,15 +60,16 @@ let areaPath = $derived(
58
60
  }
59
61
  })
60
62
  );
63
+ $inspect({ channels, x });
61
64
  </script>
62
65
 
63
66
  <BaseMark_Area
64
67
  type="area"
65
68
  {data}
66
69
  channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke']}
67
- {x1}
70
+ x1={x1 != null ? x1 : x}
68
71
  {x2}
69
- {y1}
72
+ y1={y1 != null ? y1 : y}
70
73
  {y2}
71
74
  {fill}
72
75
  {stroke}
@@ -1,8 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
3
3
  export type AreaMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ x?: ChannelAccessor;
4
5
  x1?: ChannelAccessor;
5
6
  x2?: ChannelAccessor;
7
+ y?: ChannelAccessor;
6
8
  y1?: ChannelAccessor;
7
9
  y2?: ChannelAccessor;
8
10
  z?: ChannelAccessor;
@@ -1,10 +1,10 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import Area from "./Area.svelte";
4
- import { stackX, recordizeX, renameChannels } from "..";
4
+ import { stackX, recordizeX } from "..";
5
5
  let { data: rawData, stack, ...rawChannels } = $props();
6
6
  let { data, ...channels } = $derived(
7
- renameChannels(stackX(recordizeX({ data: rawData, ...rawChannels }), stack), { y: "y1" })
7
+ stackX(recordizeX({ data: rawData, ...rawChannels }), stack)
8
8
  );
9
9
  </script>
10
10
 
@@ -1,10 +1,10 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import Area from "./Area.svelte";
4
- import { stackY, recordizeY, renameChannels } from "..";
4
+ import { stackY, recordizeY } from "..";
5
5
  let { data: rawData, stack, ...rawChannels } = $props();
6
6
  let { data, ...channels } = $derived(
7
- renameChannels(stackY(recordizeY({ data: rawData, ...rawChannels }), stack), { x: "x1" })
7
+ stackY(recordizeY({ data: rawData, ...rawChannels }), stack)
8
8
  );
9
9
  $inspect({ data, channels });
10
10
  </script>
@@ -8,11 +8,14 @@ import { stackX } from "../transforms/stack.js";
8
8
  import { recordizeX } from "../transforms/recordize.js";
9
9
  const BaseMark_BarX = BaseMark;
10
10
  const plot = getContext("svelteplot");
11
- let { data: rawData, inset = 0, ...rawChannels } = $props();
11
+ let { data: rawData, inset = 0, onclick, onmouseenter, onmouseleave, ...rawChannels } = $props();
12
12
  let { data, ...channels } = $derived(stackX(recordizeX({ data: rawData, ...rawChannels })));
13
13
  function isValid(value) {
14
14
  return value !== null && !Number.isNaN(value);
15
15
  }
16
+ function wrapEvent(handler, d) {
17
+ return handler ? () => handler(d.___orig___ !== void 0 ? d.___orig___ : d) : null;
18
+ }
16
19
  </script>
17
20
 
18
21
  <BaseMark_BarX type="bar-x" {data} channels={['y', 'x1', 'x2', 'fill', 'stroke']} {...channels}>
@@ -37,6 +40,10 @@ function isValid(value) {
37
40
  transform="translate({[minx, plot.yScale(cy) + inset]})"
38
41
  width={maxx - minx}
39
42
  height={plot.yScale.bandwidth() - inset * 2}
43
+ role={onclick ? 'button' : null}
44
+ onclick={wrapEvent(onclick, datum)}
45
+ onmouseenter={wrapEvent(onmouseenter, datum)}
46
+ onmouseleave={wrapEvent(onmouseleave, datum)}
40
47
  />
41
48
  {/if}
42
49
  {/each}
@@ -8,11 +8,22 @@ import { stackY } from "../transforms/stack.js";
8
8
  import { recordizeY } from "../transforms/recordize.js";
9
9
  const BaseMark_BarY = BaseMark;
10
10
  const plot = getContext("svelteplot");
11
- let { data: rawData, insetLeft, insetRight, ...rawChannels } = $props();
11
+ let {
12
+ data: rawData,
13
+ insetLeft,
14
+ insetRight,
15
+ onclick,
16
+ onmouseenter,
17
+ onmouseleave,
18
+ ...rawChannels
19
+ } = $props();
12
20
  let { data, ...channels } = $derived(stackY(recordizeY({ data: rawData, ...rawChannels })));
13
21
  function isValid(value) {
14
22
  return value !== null && !Number.isNaN(value);
15
23
  }
24
+ function wrapEvent(handler, d) {
25
+ return handler ? () => handler(d.___orig___ !== void 0 ? d.___orig___ : d) : null;
26
+ }
16
27
  </script>
17
28
 
18
29
  <BaseMark_BarY type="bar-y" {data} channels={['x', 'y1', 'y2', 'fill', 'stroke']} {...channels}>
@@ -37,6 +48,10 @@ function isValid(value) {
37
48
  transform="translate({[plot.xScale(cx), miny]})"
38
49
  height={maxy - miny}
39
50
  width={plot.xScale.bandwidth()}
51
+ role={onclick ? 'button' : null}
52
+ onclick={wrapEvent(onclick, datum)}
53
+ onmouseenter={wrapEvent(onmouseenter, datum)}
54
+ onmouseleave={wrapEvent(onmouseleave, datum)}
40
55
  />
41
56
  {/if}
42
57
  {/each}
@@ -1,4 +1,5 @@
1
1
  <script context="module"></script>
2
+
2
3
  <script>import { getContext } from "svelte";
3
4
  import resolveChannel from "../helpers/resolveChannel.js";
4
5
  import { quadtree } from "d3-quadtree";
@@ -28,18 +29,18 @@ let tree = $derived(
28
29
  );
29
30
  </script>
30
31
 
31
-
32
- <div class="tooltip" class:hide={!!!datum}
32
+ <div
33
+ class="tooltip"
34
+ class:hide={!!!datum}
33
35
  style:left="{tooltipX ? plot.xScale(tooltipX) : 0}px"
34
36
  style:top="{tooltipY ? plot.yScale(tooltipY) : 0}px"
35
- >
37
+ >
36
38
  <div class="tooltip-body">
37
39
  <slot {datum} />
38
40
  </div>
39
41
  </div>
40
42
 
41
43
  <style>
42
-
43
44
  div.tooltip {
44
45
  background: white;
45
46
  background: var(--svelteplot-tooltip-bg);
@@ -48,7 +49,9 @@ let tree = $derived(
48
49
  font-size: 13px;
49
50
  padding: 1ex 1em;
50
51
  border-radius: 3px;
51
- box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
52
+ box-shadow:
53
+ rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
54
+ rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
52
55
  position: absolute;
53
56
  pointer-events: none;
54
57
  }
@@ -56,7 +56,6 @@ function stackXY(byDim, data, channels, options) {
56
56
  });
57
57
  })
58
58
  .flat(1);
59
- console.log({ newData });
60
59
  return {
61
60
  data: newData,
62
61
  ...channels,
package/dist/types.d.ts CHANGED
@@ -145,6 +145,9 @@ export type ValueOf<T> = T[keyof T];
145
145
  export type ChannelType = ValueOf<typeof SCALE_TYPES>;
146
146
  export interface MarkProps {
147
147
  data: DataRow[];
148
+ onclick?: MouseEventHandler<SVGPathElement>;
149
+ onmouseenter?: MouseEventHandler<SVGPathElement>;
150
+ onmouseleave?: MouseEventHandler<SVGPathElement>;
148
151
  }
149
152
  export type BaseMarkProps = MarkProps & {
150
153
  type: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.0.1-alpha.22",
3
+ "version": "0.0.1-alpha.24",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",