svelteplot 0.0.1-alpha.21 → 0.0.1-alpha.22

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.
package/dist/Plot.svelte CHANGED
@@ -67,24 +67,24 @@ $effect(() => {
67
67
  caption
68
68
  });
69
69
  });
70
- function onMouseMove(evt) {
70
+ const onMouseMove = (evt) => {
71
71
  if (onmousemove)
72
72
  onmousemove({ ...evt, plot });
73
- }
73
+ };
74
74
  let hasLegend = $derived(color?.legend || symbol?.legend);
75
75
  </script>
76
76
 
77
77
  <figure data-testid={testid} class="svelteplot" bind:clientWidth={width} style:max-width={maxWidth}>
78
- <div class="plot-body">
78
+ <div
79
+ role="document"
80
+ class="plot-body"
81
+ bind:this={plot.body}
82
+ on:mousemove={onmousemove ? onMouseMove : null}
83
+ >
79
84
  <div class="overlay">
80
85
  {#if overlay}{@render overlay(plot)}{/if}
81
86
  </div>
82
- <svg
83
- role="document"
84
- {width}
85
- height={plot.height}
86
- onmousemove={onmousemove ? onMouseMove : null}
87
- >
87
+ <svg {width} height={plot.height}>
88
88
  <!-- automatic grids -->
89
89
  {#if (grid && plot.hasScaleX) || x?.grid}<GridX automatic />{/if}
90
90
  {#if (grid && plot.hasScaleY) || y?.grid}<GridY automatic />{/if}
@@ -111,7 +111,6 @@ let hasLegend = $derived(color?.legend || symbol?.legend);
111
111
  {#if frame}<Frame />{/if}
112
112
  {#if children}{@render children(plot)}{/if}
113
113
  </svg>
114
-
115
114
  </div>
116
115
 
117
116
  {#if plot.options.title || plot.options.subtitle || header || hasLegend}
@@ -165,7 +164,6 @@ let hasLegend = $derived(color?.legend || symbol?.legend);
165
164
  }
166
165
  .plot-body {
167
166
  order: 2;
168
-
169
167
  }
170
168
  svg {
171
169
  overflow: visible;
@@ -72,6 +72,7 @@ export class Plot {
72
72
  radius = new Scale('radius', this);
73
73
  color = new Scale('color', this);
74
74
  symbol = new Scale('symbol', this);
75
+ body = $state();
75
76
  colorSymbolRedundant = $derived(this.color.uniqueMarkProps.length === 1 &&
76
77
  this.symbol.uniqueMarkProps.length === 1 &&
77
78
  this.color.uniqueMarkProps[0] === this.symbol.uniqueMarkProps[0]);
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export { default as DotY } from './marks/DotY.svelte';
13
13
  export { default as Frame } from './marks/Frame.svelte';
14
14
  export { default as GridX } from './marks/GridX.svelte';
15
15
  export { default as GridY } from './marks/GridY.svelte';
16
+ export { default as HTMLTooltip } from './marks/HTMLTooltip.svelte';
16
17
  export { default as Line } from './marks/Line.svelte';
17
18
  export { default as LineX } from './marks/LineX.svelte';
18
19
  export { default as LineY } from './marks/LineY.svelte';
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export { default as DotY } from './marks/DotY.svelte';
15
15
  export { default as Frame } from './marks/Frame.svelte';
16
16
  export { default as GridX } from './marks/GridX.svelte';
17
17
  export { default as GridY } from './marks/GridY.svelte';
18
+ export { default as HTMLTooltip } from './marks/HTMLTooltip.svelte';
18
19
  export { default as Line } from './marks/Line.svelte';
19
20
  export { default as LineX } from './marks/LineX.svelte';
20
21
  export { default as LineY } from './marks/LineY.svelte';
@@ -0,0 +1,58 @@
1
+ <script context="module"></script>
2
+ <script>import { getContext } from "svelte";
3
+ import resolveChannel from "../helpers/resolveChannel.js";
4
+ import { quadtree } from "d3-quadtree";
5
+ const plot = getContext("svelteplot");
6
+ let { data, x, y, r } = $props();
7
+ let datum = $state(false);
8
+ let tooltipX = $state();
9
+ let tooltipY = $state();
10
+ function onMouseMove(evt) {
11
+ const pt = tree.find(evt.layerX, evt.layerY, 15);
12
+ if (pt) {
13
+ tooltipX = resolveChannel("x", pt, { x, y, r });
14
+ tooltipY = resolveChannel("y", pt, { x, y, r });
15
+ datum = pt;
16
+ } else {
17
+ datum = false;
18
+ }
19
+ }
20
+ $effect(() => {
21
+ plot.body?.addEventListener("mousemove", onMouseMove);
22
+ return () => {
23
+ plot.body?.removeEventListener("mousemove", onMouseMove);
24
+ };
25
+ });
26
+ let tree = $derived(
27
+ quadtree().x((d) => plot.xScale(resolveChannel("x", d, { x, y, r }))).y((d) => plot.yScale(resolveChannel("y", d, { x, y, r }))).addAll(data)
28
+ );
29
+ </script>
30
+
31
+
32
+ <div class="tooltip" class:hide={!!!datum}
33
+ style:left="{tooltipX ? plot.xScale(tooltipX) : 0}px"
34
+ style:top="{tooltipY ? plot.yScale(tooltipY) : 0}px"
35
+ >
36
+ <div class="tooltip-body">
37
+ <slot {datum} />
38
+ </div>
39
+ </div>
40
+
41
+ <style>
42
+
43
+ div.tooltip {
44
+ background: white;
45
+ background: var(--svelteplot-tooltip-bg);
46
+ border: 1px solid #ccc;
47
+ border-color: var(--svelteplot-tooltip-border);
48
+ font-size: 13px;
49
+ padding: 1ex 1em;
50
+ 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
+ position: absolute;
53
+ pointer-events: none;
54
+ }
55
+ .tooltip.hide {
56
+ display: none;
57
+ }
58
+ </style>
@@ -0,0 +1,25 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { ChannelAccessor, DataRow } from '../types.js';
3
+ export type HTMLTooltipMarkProps = {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
6
+ y?: ChannelAccessor;
7
+ r?: ChannelAccessor;
8
+ };
9
+ declare const __propDef: {
10
+ props: HTMLTooltipMarkProps;
11
+ events: {
12
+ [evt: string]: CustomEvent<any>;
13
+ };
14
+ slots: {
15
+ default: {
16
+ datum: boolean;
17
+ };
18
+ };
19
+ };
20
+ export type HtmlTooltipProps = typeof __propDef.props;
21
+ export type HtmlTooltipEvents = typeof __propDef.events;
22
+ export type HtmlTooltipSlots = typeof __propDef.slots;
23
+ export default class HtmlTooltip extends SvelteComponentTyped<HtmlTooltipProps, HtmlTooltipEvents, HtmlTooltipSlots> {
24
+ }
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.0.1-alpha.21",
3
+ "version": "0.0.1-alpha.22",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -27,24 +27,24 @@
27
27
  "!dist/**/*.spec.*"
28
28
  ],
29
29
  "devDependencies": {
30
- "@sveltejs/package": "^2.2.5",
31
30
  "@playwright/test": "^1.40.1",
32
31
  "@sveltejs/adapter-auto": "^3.1.0",
33
32
  "@sveltejs/kit": "^2.3.2",
33
+ "@sveltejs/package": "^2.2.5",
34
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
35
+ "@sveltepress/theme-default": "^1.22.3",
36
+ "@sveltepress/vite": "^0.31.3",
34
37
  "@types/chroma-js": "^2.4.3",
38
+ "@types/d3-array": "^3.2.1",
35
39
  "@types/d3-dsv": "^3.0.7",
36
40
  "@types/d3-interpolate": "^3.0.4",
37
41
  "@types/d3-random": "^3.0.3",
42
+ "@types/d3-scale": "^4.0.8",
38
43
  "@types/d3-scale-chromatic": "^3.0.3",
39
44
  "@types/d3-shape": "^3.1.6",
40
- "@types/d3-array": "^3.2.1",
41
- "@types/d3-scale": "^4.0.8",
42
45
  "@types/underscore": "^1.11.15",
43
46
  "@typescript-eslint/eslint-plugin": "^6.19.0",
44
47
  "@typescript-eslint/parser": "^6.19.0",
45
- "@sveltejs/vite-plugin-svelte": "^3.0.1",
46
- "@sveltepress/theme-default": "^1.22.3",
47
- "@sveltepress/vite": "^0.31.3",
48
48
  "bulma": "^0.9.4",
49
49
  "d3-dsv": "^3.0.1",
50
50
  "eslint": "^8.56.0",
@@ -71,6 +71,7 @@
71
71
  "chroma-js": "^2.4.2",
72
72
  "d3-array": "^3.2.4",
73
73
  "d3-interpolate": "^3.0.1",
74
+ "d3-quadtree": "^3.0.1",
74
75
  "d3-random": "^3.0.1",
75
76
  "d3-scale": "^4.0.2",
76
77
  "d3-scale-chromatic": "^3.0.0",