svelteplot 0.0.1-alpha.1 → 0.0.1-alpha.2
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 +171 -0
- package/dist/Plot.svelte.d.ts +15 -0
- package/dist/classes/Channel.svelte.js +72 -0
- package/dist/classes/Mark.svelte.js +17 -0
- package/dist/classes/Plot.svelte.js +99 -0
- package/dist/contants.d.ts +3 -0
- package/dist/contants.js +40 -0
- package/dist/helpers/GroupMultiple.svelte +8 -0
- package/dist/helpers/GroupMultiple.svelte.d.ts +19 -0
- package/dist/helpers/autoTimeFormat.d.ts +2 -0
- package/dist/helpers/autoTimeFormat.js +10 -0
- package/dist/helpers/colors.d.ts +13 -0
- package/dist/helpers/colors.js +200 -0
- package/dist/helpers/createScale.d.ts +4 -0
- package/dist/helpers/createScale.js +47 -0
- package/dist/helpers/getBaseStyles.d.ts +2 -0
- package/dist/helpers/getBaseStyles.js +18 -0
- package/dist/helpers/getLogTicks.d.ts +1 -0
- package/dist/helpers/getLogTicks.js +57 -0
- package/dist/helpers/isDataRecord.d.ts +2 -0
- package/dist/helpers/isDataRecord.js +13 -0
- package/dist/helpers/mergeDeep.d.ts +5 -0
- package/dist/helpers/mergeDeep.js +26 -0
- package/dist/helpers/removeIdenticalLines.d.ts +1 -0
- package/dist/helpers/removeIdenticalLines.js +16 -0
- package/dist/helpers/resolveChannel.d.ts +2 -0
- package/dist/helpers/resolveChannel.js +28 -0
- package/dist/helpers/symbols.d.ts +5 -0
- package/dist/helpers/symbols.js +51 -0
- package/dist/helpers/typeChecks.d.ts +7 -0
- package/dist/helpers/typeChecks.js +21 -0
- package/dist/helpers/wrapArray.d.ts +2 -0
- package/dist/helpers/wrapArray.js +4 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/marks/AxisX.svelte +101 -0
- package/dist/marks/AxisX.svelte.d.ts +17 -0
- package/dist/marks/AxisY.svelte +69 -0
- package/dist/marks/AxisY.svelte.d.ts +15 -0
- package/dist/marks/BaseMark.svelte +22 -0
- package/dist/marks/BaseMark.svelte.d.ts +19 -0
- package/dist/marks/ColorLegend.svelte +52 -0
- package/dist/marks/ColorLegend.svelte.d.ts +14 -0
- package/dist/marks/Dot.svelte +83 -0
- package/dist/marks/Dot.svelte.d.ts +15 -0
- package/dist/marks/DotX.svelte +5 -0
- package/dist/marks/DotX.svelte.d.ts +17 -0
- package/dist/marks/DotY.svelte +5 -0
- package/dist/marks/DotY.svelte.d.ts +17 -0
- package/dist/marks/Frame.svelte +37 -0
- package/dist/marks/Frame.svelte.d.ts +15 -0
- package/dist/marks/GridX.svelte +42 -0
- package/dist/marks/GridX.svelte.d.ts +19 -0
- package/dist/marks/GridY.svelte +31 -0
- package/dist/marks/GridY.svelte.d.ts +15 -0
- package/dist/marks/Line.svelte +49 -0
- package/dist/marks/Line.svelte.d.ts +15 -0
- package/dist/marks/LineX.svelte +10 -0
- package/dist/marks/LineX.svelte.d.ts +17 -0
- package/dist/marks/LineY.svelte +10 -0
- package/dist/marks/LineY.svelte.d.ts +17 -0
- package/dist/marks/RuleX.svelte +30 -0
- package/dist/marks/RuleX.svelte.d.ts +15 -0
- package/dist/marks/RuleY.svelte +31 -0
- package/dist/marks/RuleY.svelte.d.ts +15 -0
- package/dist/marks/SymbolLegend.svelte +50 -0
- package/dist/marks/SymbolLegend.svelte.d.ts +14 -0
- package/dist/types.d.ts +188 -0
- package/dist/types.js +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import { symbol as d3Symbol } from "d3-shape";
|
|
3
|
+
import { maybeSymbol } from "../helpers/symbols";
|
|
4
|
+
const plot = getContext("svelteplot");
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#if plot.color.manualActiveMarks.length > 0}
|
|
8
|
+
<div class="color-legend">
|
|
9
|
+
{#each plot.colorScale.domain() as value}
|
|
10
|
+
{@const symbolV = plot.symbolScale(value)}
|
|
11
|
+
{@const symbolType = maybeSymbol(symbolV)}
|
|
12
|
+
<div class="item">
|
|
13
|
+
<div class="swatch">
|
|
14
|
+
<svg width="15" height="15"
|
|
15
|
+
>{#if plot.colorSymbolRedundant}
|
|
16
|
+
<path
|
|
17
|
+
transform="translate(7.5,7.5)"
|
|
18
|
+
fill={plot.hasFilledDotMarks ? plot.colorScale(value) : 'none'}
|
|
19
|
+
stroke={plot.hasFilledDotMarks ? null : plot.colorScale(value)}
|
|
20
|
+
d={d3Symbol(symbolType, 40)()}
|
|
21
|
+
/>
|
|
22
|
+
{:else}
|
|
23
|
+
<rect fill={plot.colorScale(value)} width="15" height="15" />
|
|
24
|
+
{/if}</svg
|
|
25
|
+
>
|
|
26
|
+
</div>
|
|
27
|
+
<span class="item-label">{value}</span>
|
|
28
|
+
</div>
|
|
29
|
+
{/each}
|
|
30
|
+
</div>
|
|
31
|
+
{/if}
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
|
+
.color-legend {
|
|
35
|
+
text-align: left;
|
|
36
|
+
font-size: 12px;
|
|
37
|
+
display: inline-block;
|
|
38
|
+
margin-right: 2em;
|
|
39
|
+
}
|
|
40
|
+
.item {
|
|
41
|
+
margin: 0 1em 0.5ex 0;
|
|
42
|
+
}
|
|
43
|
+
path { stroke-width: 1.5;}
|
|
44
|
+
.item,
|
|
45
|
+
.item-label,
|
|
46
|
+
.swatch {
|
|
47
|
+
display: inline-block;
|
|
48
|
+
}
|
|
49
|
+
.item-label {
|
|
50
|
+
vertical-align: text-bottom;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
};
|
|
9
|
+
export type ColorLegendProps = typeof __propDef.props;
|
|
10
|
+
export type ColorLegendEvents = typeof __propDef.events;
|
|
11
|
+
export type ColorLegendSlots = typeof __propDef.slots;
|
|
12
|
+
export default class ColorLegend extends SvelteComponent<ColorLegendProps, ColorLegendEvents, ColorLegendSlots> {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<script>import resolveChannel from "../helpers/resolveChannel";
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import BaseMark from "./BaseMark.svelte";
|
|
4
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
5
|
+
import { symbol as d3Symbol } from "d3-shape";
|
|
6
|
+
import { isSymbol, maybeSymbol } from "../helpers/symbols";
|
|
7
|
+
import chroma from "chroma-js";
|
|
8
|
+
const BaseMark_Dot = BaseMark;
|
|
9
|
+
const plot = getContext("svelteplot");
|
|
10
|
+
let {
|
|
11
|
+
data,
|
|
12
|
+
x = null,
|
|
13
|
+
y = null,
|
|
14
|
+
r = 3,
|
|
15
|
+
symbol = "circle",
|
|
16
|
+
stroke = null,
|
|
17
|
+
fill = null,
|
|
18
|
+
...styleProps
|
|
19
|
+
} = $props();
|
|
20
|
+
let styleProps2 = $derived({
|
|
21
|
+
...styleProps,
|
|
22
|
+
...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
|
|
23
|
+
});
|
|
24
|
+
function isValid(value) {
|
|
25
|
+
return value !== null && !Number.isNaN(value);
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<BaseMark_Dot
|
|
30
|
+
type="dot"
|
|
31
|
+
{data}
|
|
32
|
+
channels={[
|
|
33
|
+
...(x ? ['x' as 'x'] : []),
|
|
34
|
+
...(y ? ['y' as 'y'] : []),
|
|
35
|
+
...(r ? ['radius'] : []),
|
|
36
|
+
...(symbol ? ['symbol'] : []),
|
|
37
|
+
...(fill || stroke ? ['color']: [])
|
|
38
|
+
]}
|
|
39
|
+
{x}
|
|
40
|
+
{y}
|
|
41
|
+
{r}
|
|
42
|
+
{fill}
|
|
43
|
+
{stroke}
|
|
44
|
+
{symbol}
|
|
45
|
+
{...styleProps}
|
|
46
|
+
>
|
|
47
|
+
<g class="dots">
|
|
48
|
+
{#each data as datum, i}
|
|
49
|
+
{@const cx = resolveChannel('x', datum, x)}
|
|
50
|
+
{@const cy = resolveChannel('y', datum, y)}
|
|
51
|
+
{@const symbolT = resolveChannel('symbol', datum, symbol) as string|SymbolType}
|
|
52
|
+
{@const symbolType = isSymbol(symbolT)
|
|
53
|
+
? maybeSymbol(symbolT)
|
|
54
|
+
: maybeSymbol(plot.symbolScale(symbolT))}
|
|
55
|
+
{@const radius =
|
|
56
|
+
typeof r === 'number' ? r : plot.radiusScale(resolveChannel('radius', datum, r))}
|
|
57
|
+
{@const size = radius * radius * Math.PI}
|
|
58
|
+
{@const maybeFillColor = resolveChannel('color', datum, fill)}
|
|
59
|
+
{@const maybeStrokeColor = resolveChannel('color', datum, stroke)}
|
|
60
|
+
{#if isValid(cx) && isValid(cy)}
|
|
61
|
+
<path
|
|
62
|
+
d={d3Symbol(symbolType, size)()}
|
|
63
|
+
style={getBaseStyles(datum, styleProps)}
|
|
64
|
+
style:fill={maybeFillColor ? plot.colorScale(maybeFillColor) : null}
|
|
65
|
+
style:stroke={maybeStrokeColor
|
|
66
|
+
? plot.colorScale(maybeStrokeColor)
|
|
67
|
+
: maybeFillColor
|
|
68
|
+
? null
|
|
69
|
+
: 'currentColor'}
|
|
70
|
+
transform="translate({[plot.xScale(cx), plot.yScale(cy)]})"
|
|
71
|
+
/>
|
|
72
|
+
{/if}
|
|
73
|
+
{/each}
|
|
74
|
+
</g>
|
|
75
|
+
</BaseMark_Dot>
|
|
76
|
+
|
|
77
|
+
<style>
|
|
78
|
+
path {
|
|
79
|
+
fill: none;
|
|
80
|
+
stroke: none;
|
|
81
|
+
stroke-width: 1.6px;
|
|
82
|
+
}
|
|
83
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { DotMarkProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: DotMarkProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
export type DotProps = typeof __propDef.props;
|
|
11
|
+
export type DotEvents = typeof __propDef.events;
|
|
12
|
+
export type DotSlots = typeof __propDef.slots;
|
|
13
|
+
export default class Dot extends SvelteComponent<DotProps, DotEvents, DotSlots> {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RawValue } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
data: RawValue[];
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type DotXProps = typeof __propDef.props;
|
|
13
|
+
export type DotXEvents = typeof __propDef.events;
|
|
14
|
+
export type DotXSlots = typeof __propDef.slots;
|
|
15
|
+
export default class DotX extends SvelteComponent<DotXProps, DotXEvents, DotXSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RawValue } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
data: RawValue[];
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type DotYProps = typeof __propDef.props;
|
|
13
|
+
export type DotYEvents = typeof __propDef.events;
|
|
14
|
+
export type DotYSlots = typeof __propDef.slots;
|
|
15
|
+
export default class DotY extends SvelteComponent<DotYProps, DotYEvents, DotYSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import BaseMark from "./BaseMark.svelte";
|
|
3
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
4
|
+
const plot = getContext("svelteplot");
|
|
5
|
+
let { ...styleProps } = $props();
|
|
6
|
+
let styleProps2 = $derived({
|
|
7
|
+
...styleProps,
|
|
8
|
+
...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
|
|
9
|
+
});
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<BaseMark type="frame" data={[]} channels={[]}>
|
|
13
|
+
<rect
|
|
14
|
+
class="frame"
|
|
15
|
+
style={getBaseStyles(null, styleProps2)}
|
|
16
|
+
x={plot.margins.left}
|
|
17
|
+
y={plot.margins.top}
|
|
18
|
+
width={plot.plotWidth}
|
|
19
|
+
height={plot.plotHeight}
|
|
20
|
+
/>
|
|
21
|
+
</BaseMark>
|
|
22
|
+
|
|
23
|
+
<!--
|
|
24
|
+
<text
|
|
25
|
+
style="font-size: 40px;text-anchor:middle"
|
|
26
|
+
dominant-baseline="central"
|
|
27
|
+
opacity={0.1}
|
|
28
|
+
transform="translate({plot.margins.left + plot.plotWidth * 0.5}, {plot.margins.top +
|
|
29
|
+
plot.plotHeight * 0.5})">{plot.plotWidth} x {plot.plotHeight}</text
|
|
30
|
+
> -->
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.frame {
|
|
34
|
+
stroke: none;
|
|
35
|
+
fill: none;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { FrameProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: import("../types").BaseMarkStyleProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
type FrameProps_ = typeof __propDef.props;
|
|
11
|
+
export { FrameProps_ as FrameProps };
|
|
12
|
+
export type FrameEvents = typeof __propDef.events;
|
|
13
|
+
export type FrameSlots = typeof __propDef.slots;
|
|
14
|
+
export default class Frame extends SvelteComponent<FrameProps, FrameEvents, FrameSlots> {
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import BaseMark from "./BaseMark.svelte";
|
|
3
|
+
import resolveChannel from "../helpers/resolveChannel";
|
|
4
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
5
|
+
import { get } from "underscore";
|
|
6
|
+
const BaseMark_GridX = BaseMark;
|
|
7
|
+
const plot = getContext("svelteplot");
|
|
8
|
+
let {
|
|
9
|
+
ticks = [],
|
|
10
|
+
y1 = null,
|
|
11
|
+
y2 = null,
|
|
12
|
+
automatic = false,
|
|
13
|
+
...styleProps
|
|
14
|
+
} = $props();
|
|
15
|
+
let autoTickCount = $derived(plot.plotWidth / get(plot, "options.x.tickSpacing", 80));
|
|
16
|
+
let autoTicks = $derived(
|
|
17
|
+
ticks.length > 0 ? ticks : get(plot, "options.x.ticks", plot.xScale.ticks(autoTickCount))
|
|
18
|
+
);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<BaseMark_GridX type="grid-x" data={ticks} channels={['x']} {y1} {y2} {automatic}>
|
|
22
|
+
<g class="grid-x">
|
|
23
|
+
{#each autoTicks as tick, t}
|
|
24
|
+
<g class="x-tick" transform="translate({plot.xScale(tick)},{plot.margins.top})">
|
|
25
|
+
<line
|
|
26
|
+
class="grid"
|
|
27
|
+
style={getBaseStyles(tick, styleProps)}
|
|
28
|
+
y1={y1 ? plot.yScale(resolveChannel('y', tick, y1)) : 0}
|
|
29
|
+
y2={y2
|
|
30
|
+
? plot.yScale(resolveChannel('y', tick, y2))
|
|
31
|
+
: plot.height - plot.margins.top - plot.margins.bottom}
|
|
32
|
+
/>
|
|
33
|
+
</g>
|
|
34
|
+
{/each}
|
|
35
|
+
</g>
|
|
36
|
+
</BaseMark_GridX>
|
|
37
|
+
|
|
38
|
+
<style>
|
|
39
|
+
.x-tick line.grid {
|
|
40
|
+
stroke: #d9d9d9;
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { GridOptions } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: Partial<import("../types").MarkProps> & GridOptions & {
|
|
5
|
+
y1?: import("../types").ChannelAccessor | undefined;
|
|
6
|
+
y2?: import("../types").ChannelAccessor | undefined;
|
|
7
|
+
automatic?: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
};
|
|
14
|
+
export type GridXProps = typeof __propDef.props;
|
|
15
|
+
export type GridXEvents = typeof __propDef.events;
|
|
16
|
+
export type GridXSlots = typeof __propDef.slots;
|
|
17
|
+
export default class GridX extends SvelteComponent<GridXProps, GridXEvents, GridXSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import BaseMark from "./BaseMark.svelte";
|
|
3
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
4
|
+
import { get } from "underscore";
|
|
5
|
+
const plot = getContext("svelteplot");
|
|
6
|
+
let { ticks = [], automatic = false, ...styleProps } = $props();
|
|
7
|
+
let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
|
|
8
|
+
let autoTicks = $derived(
|
|
9
|
+
ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
|
|
10
|
+
);
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<BaseMark type="grid-y" data={ticks} channels={['y']} {automatic}>
|
|
14
|
+
<g class="grid-y">
|
|
15
|
+
{#each autoTicks as tick}
|
|
16
|
+
<g class="y-tick" transform="translate({plot.margins.left},{plot.yScale(tick)})">
|
|
17
|
+
<line
|
|
18
|
+
style={getBaseStyles(tick, styleProps)}
|
|
19
|
+
class="grid"
|
|
20
|
+
x2={plot.width - plot.margins.right - plot.margins.left}
|
|
21
|
+
/>
|
|
22
|
+
</g>
|
|
23
|
+
{/each}
|
|
24
|
+
</g>
|
|
25
|
+
</BaseMark>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.y-tick line.grid {
|
|
29
|
+
stroke: #d9d9d9;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { GridYMarkProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: GridYMarkProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
export type GridYProps = typeof __propDef.props;
|
|
11
|
+
export type GridYEvents = typeof __propDef.events;
|
|
12
|
+
export type GridYSlots = typeof __propDef.slots;
|
|
13
|
+
export default class GridY extends SvelteComponent<GridYProps, GridYEvents, GridYSlots> {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script>import resolveChannel from "../helpers/resolveChannel";
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import BaseMark from "./BaseMark.svelte";
|
|
4
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
5
|
+
import { line } from "d3-shape";
|
|
6
|
+
import { groupBy } from "underscore";
|
|
7
|
+
const BaseMark_Line = BaseMark;
|
|
8
|
+
const plot = getContext("svelteplot");
|
|
9
|
+
let {
|
|
10
|
+
data,
|
|
11
|
+
x = null,
|
|
12
|
+
y = null,
|
|
13
|
+
z = null,
|
|
14
|
+
fill,
|
|
15
|
+
stroke,
|
|
16
|
+
r = 5,
|
|
17
|
+
...styleProps
|
|
18
|
+
} = $props();
|
|
19
|
+
let groups = $derived(
|
|
20
|
+
z ? Object.values(groupBy(data, (d) => resolveChannel("z", d, z))) : [data]
|
|
21
|
+
);
|
|
22
|
+
let linePath = line().x((d) => plot.xScale(resolveChannel("x", d, x))).y((d) => plot.yScale(resolveChannel("y", d, y)));
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<BaseMark_Line
|
|
26
|
+
type="dot"
|
|
27
|
+
{data}
|
|
28
|
+
channels={['x', 'y', 'radius', 'color']}
|
|
29
|
+
{x}
|
|
30
|
+
{y}
|
|
31
|
+
{r}
|
|
32
|
+
{fill}
|
|
33
|
+
{stroke}
|
|
34
|
+
{...styleProps}
|
|
35
|
+
>
|
|
36
|
+
<g class="lines">
|
|
37
|
+
{#each groups as lineData}
|
|
38
|
+
<path d={linePath(lineData)} style={getBaseStyles(lineData[0], styleProps)} />
|
|
39
|
+
{/each}
|
|
40
|
+
</g>
|
|
41
|
+
</BaseMark_Line>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.lines path {
|
|
45
|
+
stroke: currentColor;
|
|
46
|
+
fill: none;
|
|
47
|
+
stroke-width: 1.4px;
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { LineMarkProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: LineMarkProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
export type LineProps = typeof __propDef.props;
|
|
11
|
+
export type LineEvents = typeof __propDef.events;
|
|
12
|
+
export type LineSlots = typeof __propDef.slots;
|
|
13
|
+
export default class Line extends SvelteComponent<LineProps, LineEvents, LineSlots> {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RawValue } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
data: RawValue[];
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type LineXProps = typeof __propDef.props;
|
|
13
|
+
export type LineXEvents = typeof __propDef.events;
|
|
14
|
+
export type LineXSlots = typeof __propDef.slots;
|
|
15
|
+
export default class LineX extends SvelteComponent<LineXProps, LineXEvents, LineXSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RawValue } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
data: RawValue[];
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type LineYProps = typeof __propDef.props;
|
|
13
|
+
export type LineYEvents = typeof __propDef.events;
|
|
14
|
+
export type LineYSlots = typeof __propDef.slots;
|
|
15
|
+
export default class LineY extends SvelteComponent<LineYProps, LineYEvents, LineYSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import BaseMark from "./BaseMark.svelte";
|
|
3
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
4
|
+
import resolveChannel from "../helpers/resolveChannel";
|
|
5
|
+
const BaseMark_RuleX = BaseMark;
|
|
6
|
+
const plot = getContext("svelteplot");
|
|
7
|
+
let { data = [], x, y1, y2, ...styleProps } = $props();
|
|
8
|
+
let dataWrapped = $derived(x ? data : data.map((d) => ({ x: d, ___orig___: d })));
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<BaseMark_RuleX type="rule-x" data={dataWrapped} channels={['x', 'y']} {x} {y1} {y2}>
|
|
12
|
+
<g class="rule-x">
|
|
13
|
+
{#each data as datum}
|
|
14
|
+
<line
|
|
15
|
+
transform="translate({plot.xScale(resolveChannel('x', datum, x))}, {0})"
|
|
16
|
+
style={getBaseStyles(datum, styleProps)}
|
|
17
|
+
y1={y1 != null ? plot.yScale(resolveChannel('y', datum, y1)) : plot.margins.top}
|
|
18
|
+
y2={y2 != null
|
|
19
|
+
? plot.yScale(resolveChannel('y', datum, y2))
|
|
20
|
+
: plot.plotHeight + plot.margins.top}
|
|
21
|
+
/>
|
|
22
|
+
{/each}
|
|
23
|
+
</g>
|
|
24
|
+
</BaseMark_RuleX>
|
|
25
|
+
|
|
26
|
+
<style>
|
|
27
|
+
.rule-x line {
|
|
28
|
+
stroke: currentColor;
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RuleXMarkProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: RuleXMarkProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
export type RuleXProps = typeof __propDef.props;
|
|
11
|
+
export type RuleXEvents = typeof __propDef.events;
|
|
12
|
+
export type RuleXSlots = typeof __propDef.slots;
|
|
13
|
+
export default class RuleX extends SvelteComponent<RuleXProps, RuleXEvents, RuleXSlots> {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import BaseMark from "./BaseMark.svelte";
|
|
3
|
+
import getBaseStyles from "../helpers/getBaseStyles";
|
|
4
|
+
import resolveChannel from "../helpers/resolveChannel";
|
|
5
|
+
import wrapArray from "../helpers/wrapArray";
|
|
6
|
+
const BaseMark_RuleY = BaseMark;
|
|
7
|
+
const plot = getContext("svelteplot");
|
|
8
|
+
let { data = [], y, x1, x2, ...styleProps } = $props();
|
|
9
|
+
let dataWrapped = $derived(y ? data : data.map((d) => ({ y: d, ___orig___: d })));
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<BaseMark_RuleY type="rule-y" data={dataWrapped} channels={['y', 'x']} {y} {x1} {x2}>
|
|
13
|
+
<g class="rule-y">
|
|
14
|
+
{#each data as datum}
|
|
15
|
+
<line
|
|
16
|
+
transform="translate(0,{plot.yScale(resolveChannel('y', datum, y))})"
|
|
17
|
+
style={getBaseStyles(datum, styleProps)}
|
|
18
|
+
x1={x1 != null ? plot.xScale(resolveChannel('x', datum, x1)) : plot.margins.left}
|
|
19
|
+
x2={x2 != null
|
|
20
|
+
? plot.xScale(resolveChannel('x', datum, x2))
|
|
21
|
+
: plot.plotWidth + plot.margins.left}
|
|
22
|
+
/>
|
|
23
|
+
{/each}
|
|
24
|
+
</g>
|
|
25
|
+
</BaseMark_RuleY>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.rule-y line {
|
|
29
|
+
stroke: currentColor;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { RuleYMarkProps } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: RuleYMarkProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
export type RuleYProps = typeof __propDef.props;
|
|
11
|
+
export type RuleYEvents = typeof __propDef.events;
|
|
12
|
+
export type RuleYSlots = typeof __propDef.slots;
|
|
13
|
+
export default class RuleY extends SvelteComponent<RuleYProps, RuleYEvents, RuleYSlots> {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import { symbol as d3Symbol } from "d3-shape";
|
|
3
|
+
import { maybeSymbol } from "../helpers/symbols";
|
|
4
|
+
const plot = getContext("svelteplot");
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#if plot.color.manualActiveMarks.length > 0 && !(plot.options.color?.legend && plot.colorSymbolRedundant)}
|
|
8
|
+
<div class="symbol-legend">
|
|
9
|
+
{#each plot.symbolScale.domain() as value}
|
|
10
|
+
{@const symbolV = plot.symbolScale(value)}
|
|
11
|
+
{@const symbolType = maybeSymbol(symbolV)}
|
|
12
|
+
{@const color = plot.colorSymbolRedundant ? plot.colorScale(value) : 'currentColor'}
|
|
13
|
+
<div class="item">
|
|
14
|
+
<div class="swatch">
|
|
15
|
+
<svg width="15" height="15"
|
|
16
|
+
>
|
|
17
|
+
<path
|
|
18
|
+
transform="translate(7.5,7.5)"
|
|
19
|
+
fill={plot.hasFilledDotMarks ? color : 'none'}
|
|
20
|
+
stroke={plot.hasFilledDotMarks ? null : color}
|
|
21
|
+
d={d3Symbol(symbolType, 40)()}
|
|
22
|
+
/>
|
|
23
|
+
</svg
|
|
24
|
+
>
|
|
25
|
+
</div>
|
|
26
|
+
<span class="item-label">{value}</span>
|
|
27
|
+
</div>
|
|
28
|
+
{/each}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.symbol-legend {
|
|
34
|
+
text-align: left;
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
display: inline-block;
|
|
37
|
+
}
|
|
38
|
+
.item {
|
|
39
|
+
margin: 0 1em 0.5ex 0;
|
|
40
|
+
}
|
|
41
|
+
path { stroke-width: 1.5;}
|
|
42
|
+
.item,
|
|
43
|
+
.item-label,
|
|
44
|
+
.swatch {
|
|
45
|
+
display: inline-block;
|
|
46
|
+
}
|
|
47
|
+
.item-label {
|
|
48
|
+
vertical-align: text-bottom;
|
|
49
|
+
}
|
|
50
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
};
|
|
9
|
+
export type SymbolLegendProps = typeof __propDef.props;
|
|
10
|
+
export type SymbolLegendEvents = typeof __propDef.events;
|
|
11
|
+
export type SymbolLegendSlots = typeof __propDef.slots;
|
|
12
|
+
export default class SymbolLegend extends SvelteComponent<SymbolLegendProps, SymbolLegendEvents, SymbolLegendSlots> {
|
|
13
|
+
}
|
|
14
|
+
export {};
|