svelteplot 0.6.0 → 0.7.0-pr-269.0
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/Mark.svelte +7 -0
- package/dist/Mark.svelte.d.ts +5 -4
- package/dist/Plot.svelte +10 -2
- package/dist/constants.d.ts +1 -1
- package/dist/core/FacetAxes.svelte +2 -2
- package/dist/core/Plot.svelte +7 -11
- package/dist/helpers/colors.d.ts +9 -12
- package/dist/helpers/facets.d.ts +1 -1
- package/dist/helpers/getBaseStyles.d.ts +4 -4
- package/dist/helpers/getBaseStyles.js +8 -0
- package/dist/helpers/index.d.ts +3 -3
- package/dist/helpers/reduce.d.ts +1 -1
- package/dist/helpers/removeIdenticalLines.js +3 -2
- package/dist/helpers/scales.d.ts +7 -7
- package/dist/helpers/scales.js +2 -2
- package/dist/helpers/symbols.d.ts +2 -2
- package/dist/helpers/time.d.ts +3 -3
- package/dist/helpers/typeChecks.d.ts +8 -8
- package/dist/helpers/wordwrap.d.ts +14 -0
- package/dist/helpers/wordwrap.js +129 -0
- package/dist/marks/Area.svelte.d.ts +5 -4
- package/dist/marks/AreaX.svelte.d.ts +6 -5
- package/dist/marks/Arrow.svelte.d.ts +5 -4
- package/dist/marks/AxisX.svelte +2 -1
- package/dist/marks/AxisX.svelte.d.ts +7 -5
- package/dist/marks/AxisY.svelte.d.ts +6 -5
- package/dist/marks/BarX.svelte.d.ts +5 -4
- package/dist/marks/BarY.svelte.d.ts +5 -4
- package/dist/marks/BollingerX.svelte.d.ts +2 -76
- package/dist/marks/BollingerY.svelte.d.ts +2 -76
- package/dist/marks/BoxY.svelte.d.ts +6 -68
- package/dist/marks/Brush.svelte +44 -4
- package/dist/marks/Cell.svelte.d.ts +5 -4
- package/dist/marks/CustomMark.svelte.d.ts +2 -84
- package/dist/marks/CustomMarkHTML.svelte.d.ts +1 -1
- package/dist/marks/DifferenceY.svelte.d.ts +7 -69
- package/dist/marks/Dot.svelte.d.ts +5 -4
- package/dist/marks/DotX.svelte.d.ts +6 -5
- package/dist/marks/DotY.svelte.d.ts +6 -5
- package/dist/marks/Geo.svelte.d.ts +5 -4
- package/dist/marks/GridX.svelte.d.ts +5 -4
- package/dist/marks/GridY.svelte.d.ts +5 -4
- package/dist/marks/Image.svelte.d.ts +2 -75
- package/dist/marks/Line.svelte +1 -1
- package/dist/marks/Line.svelte.d.ts +6 -5
- package/dist/marks/LineX.svelte.d.ts +7 -6
- package/dist/marks/LineY.svelte.d.ts +7 -6
- package/dist/marks/Link.svelte.d.ts +5 -4
- package/dist/marks/Rect.svelte.d.ts +5 -4
- package/dist/marks/RuleX.svelte.d.ts +5 -4
- package/dist/marks/RuleY.svelte.d.ts +5 -4
- package/dist/marks/Spike.svelte.d.ts +6 -5
- package/dist/marks/Text.svelte.d.ts +7 -6
- package/dist/marks/TickX.svelte.d.ts +5 -4
- package/dist/marks/TickY.svelte.d.ts +5 -4
- package/dist/marks/Vector.svelte.d.ts +5 -4
- package/dist/marks/WaffleX.svelte +115 -0
- package/dist/marks/WaffleX.svelte.d.ts +19 -0
- package/dist/marks/WaffleY.svelte +119 -0
- package/dist/marks/WaffleY.svelte.d.ts +19 -0
- package/dist/marks/helpers/Anchor.svelte.d.ts +5 -5
- package/dist/marks/helpers/BaseAxisX.svelte +31 -3
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +2 -0
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +2 -164
- package/dist/marks/helpers/RectPath.svelte.d.ts +3 -65
- package/dist/marks/helpers/waffle.d.ts +58 -0
- package/dist/marks/helpers/waffle.js +194 -0
- package/dist/marks/index.d.ts +3 -1
- package/dist/marks/index.js +3 -1
- package/dist/transforms/bollinger.d.ts +1 -69
- package/dist/transforms/centroid.d.ts +1 -4
- package/dist/transforms/group.d.ts +4 -12
- package/dist/transforms/group.js +11 -5
- package/dist/transforms/interval.d.ts +2 -128
- package/dist/transforms/recordize.d.ts +4 -7
- package/dist/transforms/select.d.ts +7 -448
- package/dist/transforms/sort.d.ts +5 -253
- package/dist/transforms/stack.d.ts +3 -23
- package/dist/transforms/window.d.ts +2 -134
- package/dist/types/data.d.ts +1 -0
- package/dist/types/mark.d.ts +1 -1
- package/dist/types/plot.d.ts +19 -5
- package/dist/types/scale.d.ts +8 -0
- package/package.json +129 -128
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as CSS from 'csstype';
|
|
2
2
|
import { type Snippet } from 'svelte';
|
|
3
3
|
import type { DataRecord, ConstantAccessor, ChannelAccessor, LinkableMarkProps } from '../types/index.js';
|
|
4
|
+
import { sort } from '../index.js';
|
|
4
5
|
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
5
6
|
props(): Partial<{
|
|
6
7
|
filter: ConstantAccessor<boolean, Datum>;
|
|
@@ -9,14 +10,14 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
9
10
|
fy: ChannelAccessor<Datum>;
|
|
10
11
|
dx: ConstantAccessor<number, Datum>;
|
|
11
12
|
dy: ConstantAccessor<number, Datum>;
|
|
12
|
-
dodgeX:
|
|
13
|
-
dodgeY:
|
|
13
|
+
dodgeX: sort;
|
|
14
|
+
dodgeY: sort;
|
|
14
15
|
fill: ChannelAccessor<Datum>;
|
|
15
16
|
fillOpacity: ConstantAccessor<number, Datum>;
|
|
16
|
-
sort:
|
|
17
|
+
sort: {
|
|
17
18
|
channel: string;
|
|
18
19
|
order?: "ascending" | "descending";
|
|
19
|
-
} | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
20
|
+
} | ((a: import("../types/data").RawValue, b: import("../types/data").RawValue) => number) | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
20
21
|
stroke: ChannelAccessor<Datum>;
|
|
21
22
|
strokeWidth: ConstantAccessor<number, Datum>;
|
|
22
23
|
strokeOpacity: ConstantAccessor<number, Datum>;
|
|
@@ -75,7 +76,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
75
76
|
* the font size of the text
|
|
76
77
|
*/
|
|
77
78
|
fontFamily?: ConstantAccessor<CSS.Property.FontFamily, Datum>;
|
|
78
|
-
fontSize?: ConstantAccessor<number | "-moz-initial" | "inherit" | "initial" | "revert" | "revert-layer" | "unset" | (string & {}) | "small" | "large" | "medium" | "x-large" | "x-small" | "xx-large" | "xx-small" | "xxx-large" | "larger" | "smaller", Datum>;
|
|
79
|
+
fontSize?: ConstantAccessor<number | "-moz-initial" | "inherit" | "initial" | "revert" | "revert-layer" | "unset" | (string & {}) | "small" | "math" | "large" | "medium" | "x-large" | "x-small" | "xx-large" | "xx-small" | "xxx-large" | "larger" | "smaller", Datum>;
|
|
79
80
|
fontWeight?: ConstantAccessor<CSS.Property.FontWeight, Datum>;
|
|
80
81
|
fontStyle?: ConstantAccessor<CSS.Property.FontStyle, Datum>;
|
|
81
82
|
fontVariant?: ConstantAccessor<CSS.Property.FontVariant, Datum>;
|
|
@@ -100,7 +101,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
100
101
|
* @default 1.2
|
|
101
102
|
*/
|
|
102
103
|
lineHeight?: ConstantAccessor<number, Datum>;
|
|
103
|
-
frameAnchor?: ConstantAccessor<"
|
|
104
|
+
frameAnchor?: ConstantAccessor<"bottom" | "top" | "left" | "right" | "middle" | "top-left" | "bottom-left" | "top-right" | "bottom-right", Datum>;
|
|
104
105
|
/**
|
|
105
106
|
* rotate text by angle in degrees
|
|
106
107
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChannelAccessor, DataRow, ConstantAccessor } from '../types/index.js';
|
|
2
|
+
import { recordizeX } from '../index.js';
|
|
2
3
|
declare class __sveltets_Render<Datum extends DataRow> {
|
|
3
4
|
props(): Omit<Partial<{
|
|
4
5
|
filter: ConstantAccessor<boolean, Datum>;
|
|
@@ -7,14 +8,14 @@ declare class __sveltets_Render<Datum extends DataRow> {
|
|
|
7
8
|
fy: ChannelAccessor<Datum>;
|
|
8
9
|
dx: ConstantAccessor<number, Datum>;
|
|
9
10
|
dy: ConstantAccessor<number, Datum>;
|
|
10
|
-
dodgeX:
|
|
11
|
-
dodgeY:
|
|
11
|
+
dodgeX: recordizeX;
|
|
12
|
+
dodgeY: recordizeX;
|
|
12
13
|
fill: ChannelAccessor<Datum>;
|
|
13
14
|
fillOpacity: ConstantAccessor<number, Datum>;
|
|
14
|
-
sort:
|
|
15
|
+
sort: {
|
|
15
16
|
channel: string;
|
|
16
17
|
order?: "ascending" | "descending";
|
|
17
|
-
} | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
18
|
+
} | ((a: import("../types/data").RawValue, b: import("../types/data").RawValue) => number) | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
18
19
|
stroke: ChannelAccessor<Datum>;
|
|
19
20
|
strokeWidth: ConstantAccessor<number, Datum>;
|
|
20
21
|
strokeOpacity: ConstantAccessor<number, Datum>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChannelAccessor, DataRow, ConstantAccessor } from '../types/index.js';
|
|
2
|
+
import { recordizeY } from '../index.js';
|
|
2
3
|
declare class __sveltets_Render<Datum extends DataRow> {
|
|
3
4
|
props(): Omit<Partial<{
|
|
4
5
|
filter: ConstantAccessor<boolean, Datum>;
|
|
@@ -7,14 +8,14 @@ declare class __sveltets_Render<Datum extends DataRow> {
|
|
|
7
8
|
fy: ChannelAccessor<Datum>;
|
|
8
9
|
dx: ConstantAccessor<number, Datum>;
|
|
9
10
|
dy: ConstantAccessor<number, Datum>;
|
|
10
|
-
dodgeX:
|
|
11
|
-
dodgeY:
|
|
11
|
+
dodgeX: recordizeY;
|
|
12
|
+
dodgeY: recordizeY;
|
|
12
13
|
fill: ChannelAccessor<Datum>;
|
|
13
14
|
fillOpacity: ConstantAccessor<number, Datum>;
|
|
14
|
-
sort:
|
|
15
|
+
sort: {
|
|
15
16
|
channel: string;
|
|
16
17
|
order?: "ascending" | "descending";
|
|
17
|
-
} | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
18
|
+
} | ((a: import("../types/data").RawValue, b: import("../types/data").RawValue) => number) | ConstantAccessor<import("../types/data").RawValue, Datum>;
|
|
18
19
|
stroke: ChannelAccessor<Datum>;
|
|
19
20
|
strokeWidth: ConstantAccessor<number, Datum>;
|
|
20
21
|
strokeOpacity: ConstantAccessor<number, Datum>;
|
|
@@ -4,6 +4,7 @@ export type ShapeRenderer = {
|
|
|
4
4
|
};
|
|
5
5
|
import type { DataRecord, ChannelAccessor } from '../types/index.js';
|
|
6
6
|
import { type Snippet } from 'svelte';
|
|
7
|
+
import { sort } from '../index.js';
|
|
7
8
|
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
8
9
|
props(): Partial<{
|
|
9
10
|
filter: import("../types/index.js").ConstantAccessor<boolean, Datum>;
|
|
@@ -12,14 +13,14 @@ declare class __sveltets_Render<Datum extends DataRecord> {
|
|
|
12
13
|
fy: ChannelAccessor<Datum>;
|
|
13
14
|
dx: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
14
15
|
dy: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
15
|
-
dodgeX:
|
|
16
|
-
dodgeY:
|
|
16
|
+
dodgeX: sort;
|
|
17
|
+
dodgeY: sort;
|
|
17
18
|
fill: ChannelAccessor<Datum>;
|
|
18
19
|
fillOpacity: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
19
|
-
sort:
|
|
20
|
+
sort: {
|
|
20
21
|
channel: string;
|
|
21
22
|
order?: "ascending" | "descending";
|
|
22
|
-
} | import("../types/index.js").ConstantAccessor<import("../types/data.js").RawValue, Datum>;
|
|
23
|
+
} | ((a: import("../types/data.js").RawValue, b: import("../types/data.js").RawValue) => number) | import("../types/index.js").ConstantAccessor<import("../types/data.js").RawValue, Datum>;
|
|
23
24
|
stroke: ChannelAccessor<Datum>;
|
|
24
25
|
strokeWidth: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
25
26
|
strokeOpacity: import("../types/index.js").ConstantAccessor<number, Datum>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The waffleX mark lets you create waffle charts by filling a rectangular area with small squares representing data values.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" generics="Datum extends DataRecord">
|
|
6
|
+
import type {
|
|
7
|
+
DataRecord,
|
|
8
|
+
BaseMarkProps,
|
|
9
|
+
ChannelAccessor,
|
|
10
|
+
LinkableMarkProps,
|
|
11
|
+
BorderRadius
|
|
12
|
+
} from '../types';
|
|
13
|
+
import { wafflePolygon, type WaffleOptions } from './helpers/waffle';
|
|
14
|
+
import { getPlotDefaults } from '../hooks/plotDefaults';
|
|
15
|
+
import { intervalX, recordizeX, sort, stackX } from '../transforms';
|
|
16
|
+
import type { StackOptions } from '../transforms/stack';
|
|
17
|
+
import Mark from '../Mark.svelte';
|
|
18
|
+
import { getContext } from 'svelte';
|
|
19
|
+
import { resolveProp, resolveStyles } from '../helpers/resolve';
|
|
20
|
+
import { roundedRect } from '../helpers/roundedRect';
|
|
21
|
+
|
|
22
|
+
interface WaffleXMarkProps
|
|
23
|
+
extends BaseMarkProps<Datum>,
|
|
24
|
+
LinkableMarkProps<Datum>,
|
|
25
|
+
WaffleOptions<Datum> {
|
|
26
|
+
data?: Datum[];
|
|
27
|
+
/**
|
|
28
|
+
* bound to a quantitative scale
|
|
29
|
+
*/
|
|
30
|
+
x?: ChannelAccessor<Datum>;
|
|
31
|
+
/**
|
|
32
|
+
* bound to a quantitative scale
|
|
33
|
+
*/
|
|
34
|
+
x1?: ChannelAccessor<Datum>;
|
|
35
|
+
/**
|
|
36
|
+
* bound to a quantitative scale
|
|
37
|
+
*/
|
|
38
|
+
x2?: ChannelAccessor<Datum>;
|
|
39
|
+
/**
|
|
40
|
+
* bound to a band scale
|
|
41
|
+
*/
|
|
42
|
+
y?: ChannelAccessor<Datum>;
|
|
43
|
+
stack?: StackOptions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const DEFAULTS = {
|
|
47
|
+
fill: 'currentColor',
|
|
48
|
+
...getPlotDefaults().waffle,
|
|
49
|
+
...getPlotDefaults().waffleX
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let markProps: WaffleXMarkProps = $props();
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
data = [{} as Datum],
|
|
56
|
+
class: className = null,
|
|
57
|
+
stack,
|
|
58
|
+
symbol = null,
|
|
59
|
+
unit,
|
|
60
|
+
...options
|
|
61
|
+
}: WaffleXMarkProps = $derived({ ...DEFAULTS, ...markProps });
|
|
62
|
+
|
|
63
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
64
|
+
const plot = $derived(getPlotState());
|
|
65
|
+
|
|
66
|
+
const args = $derived(
|
|
67
|
+
stackX(
|
|
68
|
+
intervalX(
|
|
69
|
+
// by default, sort by y channel (the ordinal labels)
|
|
70
|
+
sort(recordizeX({ data, ...options })),
|
|
71
|
+
{ plot }
|
|
72
|
+
),
|
|
73
|
+
stack
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<Mark
|
|
79
|
+
type="waffleX"
|
|
80
|
+
requiredScales={{ y: ['band'] }}
|
|
81
|
+
channels={['x1', 'x2', 'y', 'fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity']}
|
|
82
|
+
{...args}>
|
|
83
|
+
{#snippet children({ mark, usedScales, scaledData })}
|
|
84
|
+
{@const wafflePoly = wafflePolygon('x', args, plot.scales)}
|
|
85
|
+
{#each scaledData as d, i (i)}
|
|
86
|
+
{@const borderRadius = resolveProp(args.borderRadius, d?.datum, 0) as BorderRadius}
|
|
87
|
+
{@const hasBorderRadius =
|
|
88
|
+
(typeof borderRadius === 'number' && borderRadius > 0) ||
|
|
89
|
+
(typeof borderRadius === 'object' &&
|
|
90
|
+
Math.max(
|
|
91
|
+
borderRadius.topRight ?? 0,
|
|
92
|
+
borderRadius.bottomRight ?? 0,
|
|
93
|
+
borderRadius.topLeft ?? 0,
|
|
94
|
+
borderRadius.bottomLeft ?? 0
|
|
95
|
+
) > 0)}
|
|
96
|
+
{@const [style, styleClass] = resolveStyles(plot, d, options, 'fill', usedScales)}
|
|
97
|
+
{@const { pattern, rect, path } = wafflePoly(d)}
|
|
98
|
+
<g class={['waffle-x', className]}>
|
|
99
|
+
<pattern {...pattern}>
|
|
100
|
+
{#if symbol}
|
|
101
|
+
{@render symbol(rect)}
|
|
102
|
+
{:else if hasBorderRadius}
|
|
103
|
+
<path
|
|
104
|
+
d={roundedRect(rect.x, rect.y, rect.width, rect.height, borderRadius)}
|
|
105
|
+
{style}
|
|
106
|
+
class={styleClass} />
|
|
107
|
+
{:else}
|
|
108
|
+
<rect {style} class={styleClass} {...rect} />
|
|
109
|
+
{/if}
|
|
110
|
+
</pattern>
|
|
111
|
+
<path {...path} />
|
|
112
|
+
</g>
|
|
113
|
+
{/each}
|
|
114
|
+
{/snippet}
|
|
115
|
+
</Mark>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DataRecord } from '../types';
|
|
2
|
+
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
3
|
+
props(): any;
|
|
4
|
+
events(): {};
|
|
5
|
+
slots(): {};
|
|
6
|
+
bindings(): "";
|
|
7
|
+
exports(): {};
|
|
8
|
+
}
|
|
9
|
+
interface $$IsomorphicComponent {
|
|
10
|
+
new <Datum extends DataRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Datum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Datum>['props']>, ReturnType<__sveltets_Render<Datum>['events']>, ReturnType<__sveltets_Render<Datum>['slots']>> & {
|
|
11
|
+
$$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
|
|
12
|
+
} & ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
13
|
+
<Datum extends DataRecord>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
14
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
15
|
+
}
|
|
16
|
+
/** The waffleX mark lets you create waffle charts by filling a rectangular area with small squares representing data values. */
|
|
17
|
+
declare const WaffleX: $$IsomorphicComponent;
|
|
18
|
+
type WaffleX<Datum extends DataRecord> = InstanceType<typeof WaffleX<Datum>>;
|
|
19
|
+
export default WaffleX;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The waffleX mark lets you create waffle charts by filling a rectangular area with small squares representing data values.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" generics="Datum extends DataRecord">
|
|
6
|
+
import type {
|
|
7
|
+
DataRecord,
|
|
8
|
+
ChannelAccessor,
|
|
9
|
+
BaseMarkProps,
|
|
10
|
+
LinkableMarkProps,
|
|
11
|
+
PlotContext,
|
|
12
|
+
BorderRadius
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { wafflePolygon, type WaffleOptions } from './helpers/waffle';
|
|
15
|
+
import { getPlotDefaults } from '../hooks/plotDefaults';
|
|
16
|
+
import { getContext } from 'svelte';
|
|
17
|
+
import { intervalY, recordizeY, sort, stackY } from '../transforms';
|
|
18
|
+
import Mark from '../Mark.svelte';
|
|
19
|
+
import { resolveProp, resolveStyles } from '../helpers/resolve';
|
|
20
|
+
import { roundedRect } from '../helpers/roundedRect';
|
|
21
|
+
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
22
|
+
|
|
23
|
+
interface WaffleYMarkProps
|
|
24
|
+
extends BaseMarkProps<Datum>,
|
|
25
|
+
LinkableMarkProps<Datum>,
|
|
26
|
+
WaffleOptions<Datum> {
|
|
27
|
+
data?: Datum[];
|
|
28
|
+
/**
|
|
29
|
+
* bound to a babd scale
|
|
30
|
+
*/
|
|
31
|
+
x?: ChannelAccessor<Datum>;
|
|
32
|
+
/**
|
|
33
|
+
* bound to a quantitative scale
|
|
34
|
+
*/
|
|
35
|
+
y?: ChannelAccessor<Datum>;
|
|
36
|
+
/**
|
|
37
|
+
* bound to a quantitative scale
|
|
38
|
+
*/
|
|
39
|
+
y1?: ChannelAccessor<Datum>;
|
|
40
|
+
/**
|
|
41
|
+
* bound to a quantitative scale
|
|
42
|
+
*/
|
|
43
|
+
y2?: ChannelAccessor<Datum>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const DEFAULTS = {
|
|
47
|
+
...getPlotDefaults().waffle,
|
|
48
|
+
...getPlotDefaults().waffleY
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let markProps: WaffleYMarkProps = $props();
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
data = [{} as Datum],
|
|
55
|
+
class: className = null,
|
|
56
|
+
stack,
|
|
57
|
+
symbol = null,
|
|
58
|
+
...options
|
|
59
|
+
}: WaffleYMarkProps = $derived({ ...DEFAULTS, ...markProps });
|
|
60
|
+
|
|
61
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
62
|
+
const plot = $derived(getPlotState());
|
|
63
|
+
|
|
64
|
+
const args = $derived(
|
|
65
|
+
stackY(
|
|
66
|
+
intervalY(
|
|
67
|
+
// by default, sort by y channel (the ordinal labels)
|
|
68
|
+
sort(recordizeY({ data, ...options })),
|
|
69
|
+
{ plot }
|
|
70
|
+
),
|
|
71
|
+
stack
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<Mark
|
|
77
|
+
type="waffleY"
|
|
78
|
+
requiredScales={{ x: ['band'] }}
|
|
79
|
+
channels={['y1', 'y2', 'x', 'fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity']}
|
|
80
|
+
{...args}>
|
|
81
|
+
{#snippet children({ mark, usedScales, scaledData })}
|
|
82
|
+
{@const wafflePoly = wafflePolygon('y', args, plot.scales)}
|
|
83
|
+
{#each scaledData as d, i (i)}
|
|
84
|
+
{@const [style, styleClass] = resolveStyles(
|
|
85
|
+
plot,
|
|
86
|
+
d,
|
|
87
|
+
args,
|
|
88
|
+
args.stroke && !args.fill ? 'stroke' : 'fill',
|
|
89
|
+
usedScales
|
|
90
|
+
)}
|
|
91
|
+
{@const borderRadius = resolveProp(args.borderRadius, d?.datum, 0) as BorderRadius}
|
|
92
|
+
{@const hasBorderRadius =
|
|
93
|
+
(typeof borderRadius === 'number' && borderRadius > 0) ||
|
|
94
|
+
(typeof borderRadius === 'object' &&
|
|
95
|
+
Math.max(
|
|
96
|
+
borderRadius.topRight ?? 0,
|
|
97
|
+
borderRadius.bottomRight ?? 0,
|
|
98
|
+
borderRadius.topLeft ?? 0,
|
|
99
|
+
borderRadius.bottomLeft ?? 0
|
|
100
|
+
) > 0)}
|
|
101
|
+
{@const { pattern, rect, path } = wafflePoly(d)}
|
|
102
|
+
<g class={['waffle-y', className]}>
|
|
103
|
+
<pattern {...pattern}>
|
|
104
|
+
{#if symbol}
|
|
105
|
+
{@render symbol({ ...rect, style, styleClass, datum: d.datum })}
|
|
106
|
+
{:else if hasBorderRadius}
|
|
107
|
+
<path
|
|
108
|
+
d={roundedRect(rect.x, rect.y, rect.width, rect.height, borderRadius)}
|
|
109
|
+
{style}
|
|
110
|
+
class={styleClass} />
|
|
111
|
+
{:else}
|
|
112
|
+
<rect {style} class={styleClass} {...rect} />
|
|
113
|
+
{/if}
|
|
114
|
+
</pattern>
|
|
115
|
+
<path {...path} />
|
|
116
|
+
</g>
|
|
117
|
+
{/each}
|
|
118
|
+
{/snippet}
|
|
119
|
+
</Mark>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DataRecord } from '../types';
|
|
2
|
+
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
3
|
+
props(): any;
|
|
4
|
+
events(): {};
|
|
5
|
+
slots(): {};
|
|
6
|
+
bindings(): "";
|
|
7
|
+
exports(): {};
|
|
8
|
+
}
|
|
9
|
+
interface $$IsomorphicComponent {
|
|
10
|
+
new <Datum extends DataRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Datum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Datum>['props']>, ReturnType<__sveltets_Render<Datum>['events']>, ReturnType<__sveltets_Render<Datum>['slots']>> & {
|
|
11
|
+
$$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
|
|
12
|
+
} & ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
13
|
+
<Datum extends DataRecord>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
14
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
15
|
+
}
|
|
16
|
+
/** The waffleX mark lets you create waffle charts by filling a rectangular area with small squares representing data values. */
|
|
17
|
+
declare const WaffleY: $$IsomorphicComponent;
|
|
18
|
+
type WaffleY<Datum extends DataRecord> = InstanceType<typeof WaffleY<Datum>>;
|
|
19
|
+
export default WaffleY;
|
|
@@ -4,11 +4,11 @@ declare class __sveltets_Render<Datum extends Record<string, any>> {
|
|
|
4
4
|
datum?: Datum | undefined;
|
|
5
5
|
options?: {
|
|
6
6
|
[key: string]: any;
|
|
7
|
-
href?: ConstantAccessor<string,
|
|
8
|
-
target?: ConstantAccessor<string,
|
|
9
|
-
rel?: ConstantAccessor<string,
|
|
10
|
-
type?: ConstantAccessor<string,
|
|
11
|
-
download?: ConstantAccessor<string,
|
|
7
|
+
href?: ConstantAccessor<string, Datum_1>;
|
|
8
|
+
target?: ConstantAccessor<string, Datum_1>;
|
|
9
|
+
rel?: ConstantAccessor<string, Datum_1>;
|
|
10
|
+
type?: ConstantAccessor<string, Datum_1>;
|
|
11
|
+
download?: ConstantAccessor<string, Datum_1>;
|
|
12
12
|
} | undefined;
|
|
13
13
|
children?: (() => any) | undefined;
|
|
14
14
|
};
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { randomId, testFilter } from '../../helpers/index.js';
|
|
18
18
|
import { INDEX } from '../../constants';
|
|
19
19
|
import { RAW_VALUE } from '../../transforms/recordize';
|
|
20
|
+
import wordwrap from '../../helpers/wordwrap';
|
|
20
21
|
|
|
21
22
|
type BaseAxisXProps = {
|
|
22
23
|
scaleFn: (d: RawValue) => number;
|
|
@@ -35,7 +36,9 @@
|
|
|
35
36
|
dx: ConstantAccessor<number>;
|
|
36
37
|
dy: ConstantAccessor<number>;
|
|
37
38
|
filter: ChannelAccessor;
|
|
39
|
+
wordwrap: boolean;
|
|
38
40
|
textAnchor: ConstantAccessor<'start' | 'middle' | 'end'> | 'auto';
|
|
41
|
+
removeDuplicateTicks: boolean;
|
|
39
42
|
};
|
|
40
43
|
text: boolean;
|
|
41
44
|
plot: PlotState;
|
|
@@ -59,8 +62,21 @@
|
|
|
59
62
|
text = true
|
|
60
63
|
}: BaseAxisXProps = $props();
|
|
61
64
|
|
|
65
|
+
const isBandScale = $derived(scaleType === 'band');
|
|
66
|
+
const bandWidth = $derived(isBandScale ? scaleFn.bandwidth() : 0);
|
|
67
|
+
|
|
62
68
|
function splitTick(tick: string | string[]) {
|
|
63
|
-
return Array.isArray(tick)
|
|
69
|
+
return Array.isArray(tick)
|
|
70
|
+
? tick
|
|
71
|
+
: typeof tick === 'string' && isBandScale && options.wordwrap !== false
|
|
72
|
+
? wordwrap(
|
|
73
|
+
tick,
|
|
74
|
+
{ maxLineWidth: bandWidth * 0.9 },
|
|
75
|
+
{ minCharactersPerLine: 4 },
|
|
76
|
+
+resolveProp(tickFontSize, {}, 11),
|
|
77
|
+
false
|
|
78
|
+
)
|
|
79
|
+
: [tick];
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
let tickRotate = $derived(plot.options.x.tickRotate || 0);
|
|
@@ -72,7 +88,7 @@
|
|
|
72
88
|
// generate id used for registering margins
|
|
73
89
|
const id = randomId();
|
|
74
90
|
|
|
75
|
-
const { autoMarginTop, autoMarginBottom } =
|
|
91
|
+
const { autoMarginTop, autoMarginBottom, autoMarginLeft, autoMarginRight } =
|
|
76
92
|
getContext<AutoMarginStores>('svelteplot/autoMargins');
|
|
77
93
|
|
|
78
94
|
let tickTextElements = $state([] as SVGTextElement[]);
|
|
@@ -109,6 +125,14 @@
|
|
|
109
125
|
return tickObjects as ScaledDataRecord[];
|
|
110
126
|
});
|
|
111
127
|
|
|
128
|
+
$effect(() => {
|
|
129
|
+
// just add some minimal horizontal margins for axis ticks
|
|
130
|
+
untrack(() => $autoMarginLeft);
|
|
131
|
+
untrack(() => $autoMarginRight);
|
|
132
|
+
$autoMarginLeft.set(id, 5);
|
|
133
|
+
$autoMarginRight.set(id, 10);
|
|
134
|
+
});
|
|
135
|
+
|
|
112
136
|
$effect(() => {
|
|
113
137
|
untrack(() => [$autoMarginTop, $autoMarginBottom]);
|
|
114
138
|
if (!text) return;
|
|
@@ -147,6 +171,8 @@
|
|
|
147
171
|
return () => {
|
|
148
172
|
if ($autoMarginBottom.has(id)) $autoMarginBottom.delete(id);
|
|
149
173
|
if ($autoMarginTop.has(id)) $autoMarginTop.delete(id);
|
|
174
|
+
if ($autoMarginLeft.has(id)) $autoMarginLeft.delete(id);
|
|
175
|
+
if ($autoMarginRight.has(id)) $autoMarginRight.delete(id);
|
|
150
176
|
};
|
|
151
177
|
});
|
|
152
178
|
</script>
|
|
@@ -222,7 +248,9 @@
|
|
|
222
248
|
{:else}
|
|
223
249
|
{#each textLines as line, i (i)}
|
|
224
250
|
<tspan x="0" dy={i ? 12 : 0}
|
|
225
|
-
>{!prevTextLines ||
|
|
251
|
+
>{!prevTextLines ||
|
|
252
|
+
prevTextLines[i] !== line ||
|
|
253
|
+
options.removeDuplicateTicks === false
|
|
226
254
|
? line
|
|
227
255
|
: ''}</tspan>
|
|
228
256
|
{/each}
|
|
@@ -16,7 +16,9 @@ type BaseAxisXProps = {
|
|
|
16
16
|
dx: ConstantAccessor<number>;
|
|
17
17
|
dy: ConstantAccessor<number>;
|
|
18
18
|
filter: ChannelAccessor;
|
|
19
|
+
wordwrap: boolean;
|
|
19
20
|
textAnchor: ConstantAccessor<'start' | 'middle' | 'end'> | 'auto';
|
|
21
|
+
removeDuplicateTicks: boolean;
|
|
20
22
|
};
|
|
21
23
|
text: boolean;
|
|
22
24
|
plot: PlotState;
|