svelteplot 0.0.1-alpha.22 → 0.0.1-alpha.23

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.
@@ -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
  }
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.23",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",