svelteplot 0.0.1-alpha.25 → 0.0.1-alpha.26

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/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { default as LineY } from './marks/LineY.svelte';
20
20
  export { default as RuleX } from './marks/RuleX.svelte';
21
21
  export { default as RuleY } from './marks/RuleY.svelte';
22
22
  export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
23
+ export { default as Text } from './marks/Text.svelte';
23
24
  export { default as TickX } from './marks/TickX.svelte';
24
25
  export { default as TickY } from './marks/TickY.svelte';
25
26
  export { stackX, stackY } from './transforms/stack.js';
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ export { default as LineY } from './marks/LineY.svelte';
22
22
  export { default as RuleX } from './marks/RuleX.svelte';
23
23
  export { default as RuleY } from './marks/RuleY.svelte';
24
24
  export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
25
+ export { default as Text } from './marks/Text.svelte';
25
26
  export { default as TickX } from './marks/TickX.svelte';
26
27
  export { default as TickY } from './marks/TickY.svelte';
27
28
  // transforms
@@ -0,0 +1,57 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { getContext } from "svelte";
4
+ import BaseMark from "./BaseMark.svelte";
5
+ import getBaseStyles from "../helpers/getBaseStyles.js";
6
+ import resolveChannel from "../helpers/resolveChannel.js";
7
+ const BaseMark_Text = BaseMark;
8
+ const plot = getContext("svelteplot");
9
+ let { data, ...channels } = $props();
10
+ function isValid(value) {
11
+ return value !== null && !Number.isNaN(value);
12
+ }
13
+ </script>
14
+
15
+ <BaseMark_Text
16
+ type="text"
17
+ {data}
18
+ channels={['x', 'y', 'text', 'fill', 'stroke']}
19
+ {...channels}
20
+ >
21
+ <g class="text">
22
+ {#each data as datum, i}
23
+ {@const cx = resolveChannel('x', datum, channels)}
24
+ {@const cy = resolveChannel('y', datum, channels)}
25
+ {@const maybeFillColor = resolveChannel('fill', datum, channels)}
26
+ {@const maybeStrokeColor = resolveChannel('stroke', datum, channels)}
27
+ <!-- {@const radius =
28
+ typeof r === 'number'
29
+ ? r
30
+ : plot.radiusScale(resolveChannel('r', datum, channels))}
31
+ {@const size = radius * radius * Math.PI} -->
32
+
33
+ {#if isValid(cx) && isValid(cy)}
34
+ <text
35
+ style={getBaseStyles(datum, channels)}
36
+ style:fill={maybeFillColor ? plot.colorScale(maybeFillColor) : maybeStrokeColor ? null : 'currentColor'}
37
+ style:stroke={maybeStrokeColor
38
+ ? plot.colorScale(maybeStrokeColor)
39
+ : null}
40
+ dominant-baseline="central"
41
+ transform="translate({[plot.xScale(cx), plot.yScale(cy)]})"
42
+ >{resolveChannel('text', datum, channels)}</text>
43
+ {/if}
44
+ {/each}
45
+ </g>
46
+ </BaseMark_Text>
47
+
48
+ <style>
49
+ text {
50
+ text-anchor: middle;
51
+ fill: none;
52
+ stroke: none;
53
+ font-size: 13px;
54
+ font-weight: 500;
55
+ stroke-width: 1.6px;
56
+ }
57
+ </style>
@@ -0,0 +1,21 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
3
+ export type TextMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
6
+ y?: ChannelAccessor;
7
+ text?: ChannelAccessor;
8
+ };
9
+ declare const __propDef: {
10
+ props: TextMarkProps;
11
+ events: {
12
+ [evt: string]: CustomEvent<any>;
13
+ };
14
+ slots: {};
15
+ };
16
+ export type TextProps = typeof __propDef.props;
17
+ export type TextEvents = typeof __propDef.events;
18
+ export type TextSlots = typeof __propDef.slots;
19
+ export default class Text extends SvelteComponentTyped<TextProps, TextEvents, TextSlots> {
20
+ }
21
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.0.1-alpha.25",
3
+ "version": "0.0.1-alpha.26",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",