svelteplot 0.0.1-alpha.24 → 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/Plot.svelte +7 -1
- package/dist/classes/Scale.svelte.js +0 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/marks/Text.svelte +57 -0
- package/dist/marks/Text.svelte.d.ts +21 -0
- package/package.json +2 -1
package/dist/Plot.svelte
CHANGED
|
@@ -74,7 +74,13 @@ const onMouseMove = (evt) => {
|
|
|
74
74
|
let hasLegend = $derived(color?.legend || symbol?.legend);
|
|
75
75
|
</script>
|
|
76
76
|
|
|
77
|
-
<figure
|
|
77
|
+
<figure
|
|
78
|
+
data-testid={testid} class="svelteplot"
|
|
79
|
+
data-reactive-hack-x={plot.x.dataValues.length}
|
|
80
|
+
data-reactive-hack-y={plot.y.dataValues.length}
|
|
81
|
+
data-reactive-hack-color={plot.color.dataValues.length}
|
|
82
|
+
data-reactive-hack-symbol={plot.symbol.dataValues.length}
|
|
83
|
+
bind:clientWidth={width} style:max-width={maxWidth}>
|
|
78
84
|
<div
|
|
79
85
|
role="document"
|
|
80
86
|
class="plot-body"
|
|
@@ -50,21 +50,6 @@ export class Scale {
|
|
|
50
50
|
isColor = $derived(this.name === 'color');
|
|
51
51
|
scaleType = $derived(this.scaleOptions.type ||
|
|
52
52
|
inferScaleType(this.dataValues, { isPosition: this.isPosition, isColor: this.isColor }));
|
|
53
|
-
// readonly valueType = $derived(
|
|
54
|
-
// this.dataValues.every((v) => v == null)
|
|
55
|
-
// ? 'null'
|
|
56
|
-
// : this.dataValues.every(isColorOrNull)
|
|
57
|
-
// ? 'color'
|
|
58
|
-
// : this.dataValues.every(isBooleanOrNull)
|
|
59
|
-
// ? 'boolean'
|
|
60
|
-
// : this.dataValues.every(isStringOrNull)
|
|
61
|
-
// ? 'text'
|
|
62
|
-
// : this.dataValues.every(isNumberOrNull)
|
|
63
|
-
// ? 'number'
|
|
64
|
-
// : this.dataValues.every(isDateOrNull)
|
|
65
|
-
// ? 'date'
|
|
66
|
-
// : 'mixed'
|
|
67
|
-
// );
|
|
68
53
|
domain = $derived(this.scaleOptions.domain || inferScaleDomain(this.dataValues, this.scaleType));
|
|
69
54
|
}
|
|
70
55
|
// opacity: typeof === 'number' && between [0,1]
|
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.
|
|
3
|
+
"version": "0.0.1-alpha.26",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@playwright/test": "^1.40.1",
|
|
31
31
|
"@sveltejs/adapter-auto": "^3.1.0",
|
|
32
|
+
"@sveltejs/adapter-static": "^3.0.1",
|
|
32
33
|
"@sveltejs/kit": "^2.3.2",
|
|
33
34
|
"@sveltejs/package": "^2.2.5",
|
|
34
35
|
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|