svelteplot 0.5.3-pr-255.0 → 0.5.3-pr-255.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/Mark.svelte +6 -0
- package/dist/Plot.svelte +12 -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 +8 -11
- package/dist/helpers/facets.d.ts +1 -1
- package/dist/helpers/getBaseStyles.d.ts +2 -4
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/reduce.d.ts +1 -1
- package/dist/helpers/removeIdenticalLines.js +3 -2
- package/dist/helpers/scales.d.ts +5 -5
- package/dist/helpers/symbols.d.ts +2 -2
- package/dist/helpers/time.d.ts +3 -3
- package/dist/helpers/typeChecks.d.ts +4 -4
- package/dist/helpers/wordwrap.d.ts +14 -0
- package/dist/helpers/wordwrap.js +129 -0
- package/dist/marks/AxisX.svelte +2 -1
- package/dist/marks/AxisX.svelte.d.ts +1 -0
- package/dist/marks/Brush.svelte +44 -4
- package/dist/marks/CustomMark.svelte +9 -3
- package/dist/marks/Image.svelte +76 -0
- package/dist/marks/Image.svelte.d.ts +19 -0
- package/dist/marks/Text.svelte.d.ts +1 -1
- package/dist/marks/WaffleX.svelte +28 -4
- package/dist/marks/WaffleY.svelte +35 -8
- package/dist/marks/helpers/Anchor.svelte +16 -2
- package/dist/marks/helpers/Anchor.svelte.d.ts +28 -14
- package/dist/marks/helpers/BaseAxisX.svelte +31 -3
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +2 -0
- package/dist/marks/helpers/waffle.d.ts +17 -2
- package/dist/marks/helpers/waffle.js +0 -1
- package/dist/marks/index.d.ts +2 -1
- package/dist/marks/index.js +2 -1
- package/dist/transforms/centroid.d.ts +1 -4
- package/dist/transforms/group.js +11 -5
- package/dist/transforms/recordize.d.ts +3 -3
- package/dist/transforms/sort.d.ts +2 -2
- package/dist/types/plot.d.ts +10 -6
- package/dist/types/scale.d.ts +8 -0
- package/package.json +14 -14
package/dist/Mark.svelte
CHANGED
|
@@ -152,6 +152,12 @@
|
|
|
152
152
|
if (options?.[channel] !== undefined && out[channel] === undefined) {
|
|
153
153
|
// resolve value
|
|
154
154
|
out[channel] = resolveChannel(channel, row, options);
|
|
155
|
+
if (options[channel] === INDEX) {
|
|
156
|
+
const scale = plot.scales[CHANNEL_SCALE[channel]];
|
|
157
|
+
if (scale.type === 'band' || scale.type === 'point') {
|
|
158
|
+
out[channel] = scale.domain[out[channel] % scale.domain.length];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
return [out];
|
package/dist/Plot.svelte
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<script lang="ts">
|
|
13
13
|
import Plot from './core/Plot.svelte';
|
|
14
14
|
|
|
15
|
-
import type { PlotOptions } from './types/index.js';
|
|
15
|
+
import type { PlotOptions, RawValue, ScaleOptions } from './types/index.js';
|
|
16
16
|
|
|
17
17
|
// implicit marks
|
|
18
18
|
import AxisX from './marks/AxisX.svelte';
|
|
@@ -62,12 +62,22 @@
|
|
|
62
62
|
const scales = $derived(
|
|
63
63
|
Object.fromEntries(
|
|
64
64
|
['x', 'y', 'r', 'color', 'opacity', 'symbol', 'length', 'fx', 'fy'].map((scale) => {
|
|
65
|
-
const scaleOpts = restOptions[scale]
|
|
65
|
+
const scaleOpts = maybeScaleOptions(restOptions[scale]);
|
|
66
66
|
const scaleFn = scaleOpts.scale || (scale === 'color' ? autoScaleColor : autoScale);
|
|
67
67
|
return [scale, { ...scaleOpts, scale: scaleFn }];
|
|
68
68
|
})
|
|
69
69
|
)
|
|
70
70
|
);
|
|
71
|
+
|
|
72
|
+
function maybeScaleOptions(
|
|
73
|
+
scaleOptions: undefined | false | RawValue[] | object
|
|
74
|
+
): Partial<ScaleOptions> | undefined {
|
|
75
|
+
if (scaleOptions === false) return { axis: false };
|
|
76
|
+
if (Array.isArray(scaleOptions)) return { domain: scaleOptions };
|
|
77
|
+
return scaleOptions || {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
$inspect({ scales });
|
|
71
81
|
</script>
|
|
72
82
|
|
|
73
83
|
{#snippet header()}
|
package/dist/constants.d.ts
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
scaleFn={facetXScale}
|
|
36
36
|
scaleType="band"
|
|
37
37
|
ticks={fxValues}
|
|
38
|
-
tickFormat={(d) => d}
|
|
38
|
+
tickFormat={plot.options.fx.tickFormat || ((d) => d)}
|
|
39
39
|
tickFontSize={11}
|
|
40
40
|
tickSize={0}
|
|
41
41
|
tickPadding={5}
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
scaleFn={facetYScale}
|
|
54
54
|
scaleType="band"
|
|
55
55
|
ticks={fyValues}
|
|
56
|
-
tickFormat={(d) => d}
|
|
56
|
+
tickFormat={plot.options.fy.tickFormat || ((d) => d)}
|
|
57
57
|
tickFontSize={11}
|
|
58
58
|
tickSize={0}
|
|
59
59
|
tickPadding={5}
|
package/dist/core/Plot.svelte
CHANGED
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
class: className = '',
|
|
115
115
|
css = DEFAULTS.css,
|
|
116
116
|
width: fixedWidth,
|
|
117
|
-
...
|
|
117
|
+
...initialOptions
|
|
118
118
|
}: Partial<PlotOptions> = $props();
|
|
119
119
|
|
|
120
120
|
let width = $state(DEFAULTS.initialWidth);
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
);
|
|
165
165
|
|
|
166
166
|
const explicitDomains = $derived(
|
|
167
|
-
new Set(SCALES.filter((scale) => !!
|
|
167
|
+
new Set(SCALES.filter((scale) => !!initialOptions[scale]?.domain))
|
|
168
168
|
);
|
|
169
169
|
|
|
170
170
|
// one-dimensional plots have different automatic margins and heights
|
|
@@ -173,12 +173,12 @@
|
|
|
173
173
|
// construct the plot options from the user-defined options (top-level props) as well
|
|
174
174
|
// as extending them from smart context-aware defaults
|
|
175
175
|
const plotOptions = $derived(
|
|
176
|
-
extendPlotOptions(
|
|
176
|
+
extendPlotOptions(initialOptions, {
|
|
177
177
|
explicitScales,
|
|
178
178
|
explicitDomains,
|
|
179
|
-
hasProjection: !!
|
|
180
|
-
margin:
|
|
181
|
-
inset:
|
|
179
|
+
hasProjection: !!initialOptions.projection,
|
|
180
|
+
margin: initialOptions.margin,
|
|
181
|
+
inset: initialOptions.inset
|
|
182
182
|
})
|
|
183
183
|
);
|
|
184
184
|
|
|
@@ -369,7 +369,7 @@
|
|
|
369
369
|
{},
|
|
370
370
|
{ sortOrdinalDomains: DEFAULTS.sortOrdinalDomains },
|
|
371
371
|
smartDefaultPlotOptions(opts),
|
|
372
|
-
|
|
372
|
+
initialOptions
|
|
373
373
|
);
|
|
374
374
|
}
|
|
375
375
|
|
|
@@ -614,10 +614,6 @@
|
|
|
614
614
|
border: 0 !important;
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
-
.plot-header :global(h3) {
|
|
618
|
-
font-weight: 500;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
617
|
.plot-footer {
|
|
622
618
|
margin-bottom: 2rem;
|
|
623
619
|
}
|
package/dist/helpers/colors.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { interpolateBrBG } from 'd3-scale-chromatic';
|
|
2
1
|
import type { ColorScheme } from '../types/index.js';
|
|
3
|
-
export declare const categoricalSchemes:
|
|
4
|
-
export declare function isCategoricalScheme(scheme: string):
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function ordinalRange(scheme: string, length: number): readonly string[] | undefined;
|
|
2
|
+
export declare const categoricalSchemes: any;
|
|
3
|
+
export declare function isCategoricalScheme(scheme: string): any;
|
|
4
|
+
export declare function isOrdinalScheme(scheme: ColorScheme): any;
|
|
5
|
+
export declare function ordinalScheme(scheme: string): any;
|
|
6
|
+
export declare function ordinalRange(scheme: string, length: number): any;
|
|
9
7
|
export declare function maybeBooleanRange(domain: boolean[], scheme?: string): any[] | undefined;
|
|
10
|
-
export declare function isQuantitativeScheme(scheme: string):
|
|
11
|
-
export declare function quantitativeScheme(scheme: string):
|
|
12
|
-
export declare function isDivergingScheme(scheme: string):
|
|
13
|
-
export {};
|
|
8
|
+
export declare function isQuantitativeScheme(scheme: string): any;
|
|
9
|
+
export declare function quantitativeScheme(scheme: string): any;
|
|
10
|
+
export declare function isDivergingScheme(scheme: string): any;
|
package/dist/helpers/facets.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ import type { GenericMarkOptions, Mark, RawValue } from '../types/index.js';
|
|
|
9
9
|
* @param fyValues y facet domain
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare function getEmptyFacets(marks: Mark<GenericMarkOptions>[], fxValues: RawValue[], fyValues: RawValue[]):
|
|
12
|
+
export declare function getEmptyFacets(marks: Mark<GenericMarkOptions>[], fxValues: RawValue[], fyValues: RawValue[]): any;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Channels } from '../types/index.js';
|
|
2
2
|
import type { DataRow } from '../types/index.js';
|
|
3
|
-
export declare function getBaseStylesObject(datum: DataRow, props: Partial<Channels>):
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export default function (datum: DataRow, props: Partial<Channels>): string;
|
|
3
|
+
export declare function getBaseStylesObject(datum: DataRow, props: Partial<Channels>): any;
|
|
4
|
+
export default function (datum: DataRow, props: Partial<Channels>): any;
|
|
7
5
|
export declare function maybeToPixel(cssKey: string, value: string | number): string | number;
|
|
8
6
|
export declare function maybeFromPixel(value: string | number): string | number;
|
|
9
7
|
export declare function maybeFromRem(value: string | number, rootFontSize?: number): string | number;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ export declare const POSITION_CHANNELS: Set<ChannelName>;
|
|
|
15
15
|
export declare function parseInset(inset: number | string, width: number): number;
|
|
16
16
|
export declare function omit<T extends {}, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
|
|
17
17
|
export declare function identity<T>(x: T): T;
|
|
18
|
-
export declare const GEOJSON_PREFER_STROKE:
|
|
18
|
+
export declare const GEOJSON_PREFER_STROKE: any;
|
package/dist/helpers/reduce.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type ReducerOption = ReducerName | ReducerFunc;
|
|
|
4
4
|
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
5
5
|
export type ReducerPercentile = (`p${Digit}${Digit}` & Record<never, never>) | 'p25' | 'p50' | 'p75';
|
|
6
6
|
export type ReducerName = 'count' | 'deviation' | 'difference' | 'first' | 'last' | 'max' | 'mean' | 'median' | 'min' | 'mode' | 'ratio' | 'sum' | 'variance' | ReducerPercentile;
|
|
7
|
-
export declare const Reducer:
|
|
7
|
+
export declare const Reducer: any;
|
|
8
8
|
export declare function mayberReducer(r: ReducerOption): ReducerFunc;
|
|
9
9
|
export declare function reduceOutputs(newDatum: DataRecord, data: DataRecord[], options: Record<ChannelName, ReducerOption>, outputs: Iterable<ChannelName>, channels: Channels, newChannels: Channels): void;
|
|
10
10
|
export {};
|
|
@@ -12,10 +12,11 @@ export default function removeIdenticalLines(input) {
|
|
|
12
12
|
text: []
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const maxLines = Math.max(...input.map((t) => t.text.length));
|
|
16
|
+
for (let l = 0; l < maxLines; l++) {
|
|
16
17
|
const isIdentical = input.length > 1 && input.every((tick) => input[0].text[l] === tick.text[l]);
|
|
17
18
|
for (let c = 0; c < input.length; c++) {
|
|
18
|
-
if (!isIdentical && input[c].text[l])
|
|
19
|
+
if (!isIdentical && input[c].text[l] != null)
|
|
19
20
|
uniqueTicks[c].text.push(input[c].text[l]);
|
|
20
21
|
}
|
|
21
22
|
}
|
package/dist/helpers/scales.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenericMarkOptions, Mark, MarkType, PlotDefaults, PlotOptions, PlotScales, PlotState, RawValue, ScaleName, ScaleOptions, ScaleType, UsedScales } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* compute the plot scales
|
|
4
4
|
*/
|
|
@@ -8,7 +8,7 @@ export declare function createScale<T extends ScaleOptions>(name: ScaleName, sca
|
|
|
8
8
|
domain: number[];
|
|
9
9
|
range: number[];
|
|
10
10
|
fn: (() => string) | (() => number);
|
|
11
|
-
skip:
|
|
11
|
+
skip: any;
|
|
12
12
|
isDummy: boolean;
|
|
13
13
|
manualActiveMarks?: undefined;
|
|
14
14
|
uniqueScaleProps?: undefined;
|
|
@@ -18,9 +18,9 @@ export declare function createScale<T extends ScaleOptions>(name: ScaleName, sca
|
|
|
18
18
|
domain: any;
|
|
19
19
|
range: any;
|
|
20
20
|
fn: any;
|
|
21
|
-
skip:
|
|
21
|
+
skip: any;
|
|
22
22
|
manualActiveMarks: number;
|
|
23
|
-
uniqueScaleProps:
|
|
23
|
+
uniqueScaleProps: any;
|
|
24
24
|
autoTitle: string | null;
|
|
25
25
|
isDummy?: undefined;
|
|
26
26
|
};
|
|
@@ -36,7 +36,7 @@ export declare function inferScaleType(name: ScaleName, dataValues: RawValue[],
|
|
|
36
36
|
* not. That's what this function is used for.
|
|
37
37
|
*/
|
|
38
38
|
export declare function getUsedScales(plot: PlotState, options: GenericMarkOptions, mark: Mark<GenericMarkOptions>): UsedScales;
|
|
39
|
-
export declare function looksLikeANumber(input: string | number):
|
|
39
|
+
export declare function looksLikeANumber(input: string | number): any;
|
|
40
40
|
export declare function projectXY(scales: PlotScales, x: RawValue, y: RawValue, useXScale?: boolean, useYScale?: boolean): [number, number];
|
|
41
41
|
export declare function projectX(channel: 'x' | 'x1' | 'x2', scales: PlotScales, value: RawValue): number;
|
|
42
42
|
export declare function projectY(channel: 'y' | 'y1' | 'y2', scales: PlotScales, value: RawValue): number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SymbolType } from 'd3-shape';
|
|
2
2
|
export declare const sqrt3: number;
|
|
3
3
|
export declare const sqrt4_3: number;
|
|
4
|
-
export declare function isSymbol(value: string | SymbolType):
|
|
5
|
-
export declare function maybeSymbol(symbol: SymbolType | string):
|
|
4
|
+
export declare function isSymbol(value: string | SymbolType): any;
|
|
5
|
+
export declare function maybeSymbol(symbol: SymbolType | string): any;
|
package/dist/helpers/time.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const durations:
|
|
2
|
-
export declare const intervalDuration:
|
|
3
|
-
export declare const intervalType:
|
|
1
|
+
export declare const durations: any;
|
|
2
|
+
export declare const intervalDuration: any;
|
|
3
|
+
export declare const intervalType: any;
|
|
4
4
|
export declare function parseTimeInterval(input: string): [string, number];
|
|
5
5
|
export declare function maybeTimeInterval(input: string): any;
|
|
6
6
|
export declare function maybeUtcInterval(input: string): any;
|
|
@@ -2,9 +2,9 @@ import type { RawValue } from '../types/index.js';
|
|
|
2
2
|
export declare function isBooleanOrNull(v: RawValue): boolean;
|
|
3
3
|
export declare function isDate(v: RawValue): v is Date;
|
|
4
4
|
export declare function isDateOrNull(v: RawValue | null | undefined): boolean;
|
|
5
|
-
export declare function isNumberOrNull(v: RawValue | null | undefined):
|
|
6
|
-
export declare function isNumberOrNullOrNaN(v: RawValue | null | undefined):
|
|
5
|
+
export declare function isNumberOrNull(v: RawValue | null | undefined): any;
|
|
6
|
+
export declare function isNumberOrNullOrNaN(v: RawValue | null | undefined): any;
|
|
7
7
|
export declare function isStringOrNull(v: RawValue | null | undefined): boolean;
|
|
8
|
-
export declare function isSymbolOrNull(v: RawValue | null | undefined):
|
|
8
|
+
export declare function isSymbolOrNull(v: RawValue | null | undefined): any;
|
|
9
9
|
export declare function isColorOrNull(v: RawValue | null | undefined): any;
|
|
10
|
-
export declare function isOpacityOrNull(v: RawValue):
|
|
10
|
+
export declare function isOpacityOrNull(v: RawValue): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Greedy word-wrapping that approximates visual width by character widths.
|
|
3
|
+
*
|
|
4
|
+
* - Splits input into words, additionally breaking on `-` to avoid very long segments.
|
|
5
|
+
* - Uses a rough character width table to approximate line widths.
|
|
6
|
+
* - Wraps once the maximum visual width is exceeded, but only after a minimum.
|
|
7
|
+
*/
|
|
8
|
+
export default function wordwrap(line: string, { maxCharactersPerLine, maxLineWidth }: {
|
|
9
|
+
maxCharactersPerLine?: number;
|
|
10
|
+
maxLineWidth?: number;
|
|
11
|
+
}, { minCharactersPerLine, minLineWidth }: {
|
|
12
|
+
minCharactersPerLine?: number;
|
|
13
|
+
minLineWidth?: number;
|
|
14
|
+
}, fontSize?: number, monospace?: boolean): string[];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { sum } from 'd3-array';
|
|
2
|
+
// Per-character width table for a typical proportional font.
|
|
3
|
+
// This is not perfect for all fonts, but is better than treating
|
|
4
|
+
// all characters as equal width. Set `monospace = true` to bypass.
|
|
5
|
+
const CHAR_W = {
|
|
6
|
+
A: 7,
|
|
7
|
+
a: 7,
|
|
8
|
+
B: 8,
|
|
9
|
+
b: 7,
|
|
10
|
+
C: 8,
|
|
11
|
+
c: 6,
|
|
12
|
+
D: 9,
|
|
13
|
+
d: 7,
|
|
14
|
+
E: 7,
|
|
15
|
+
e: 7,
|
|
16
|
+
F: 7,
|
|
17
|
+
f: 4,
|
|
18
|
+
G: 9,
|
|
19
|
+
g: 7,
|
|
20
|
+
H: 9,
|
|
21
|
+
h: 7,
|
|
22
|
+
I: 3,
|
|
23
|
+
i: 3,
|
|
24
|
+
J: 5,
|
|
25
|
+
j: 3,
|
|
26
|
+
K: 8,
|
|
27
|
+
k: 6,
|
|
28
|
+
L: 7,
|
|
29
|
+
l: 3,
|
|
30
|
+
M: 11,
|
|
31
|
+
m: 11,
|
|
32
|
+
N: 9,
|
|
33
|
+
n: 7,
|
|
34
|
+
O: 9,
|
|
35
|
+
o: 7,
|
|
36
|
+
P: 8,
|
|
37
|
+
p: 7,
|
|
38
|
+
Q: 9,
|
|
39
|
+
q: 7,
|
|
40
|
+
R: 8,
|
|
41
|
+
r: 4,
|
|
42
|
+
S: 8,
|
|
43
|
+
s: 6,
|
|
44
|
+
T: 7,
|
|
45
|
+
t: 4,
|
|
46
|
+
U: 9,
|
|
47
|
+
u: 7,
|
|
48
|
+
V: 7,
|
|
49
|
+
v: 6,
|
|
50
|
+
W: 11,
|
|
51
|
+
w: 9,
|
|
52
|
+
X: 7,
|
|
53
|
+
x: 6,
|
|
54
|
+
Y: 7,
|
|
55
|
+
y: 6,
|
|
56
|
+
Z: 7,
|
|
57
|
+
z: 5,
|
|
58
|
+
'.': 2,
|
|
59
|
+
',': 2,
|
|
60
|
+
':': 2,
|
|
61
|
+
';': 2
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Greedy word-wrapping that approximates visual width by character widths.
|
|
65
|
+
*
|
|
66
|
+
* - Splits input into words, additionally breaking on `-` to avoid very long segments.
|
|
67
|
+
* - Uses a rough character width table to approximate line widths.
|
|
68
|
+
* - Wraps once the maximum visual width is exceeded, but only after a minimum.
|
|
69
|
+
*/
|
|
70
|
+
export default function wordwrap(line, { maxCharactersPerLine, maxLineWidth }, { minCharactersPerLine, minLineWidth }, fontSize = 12, monospace = false) {
|
|
71
|
+
// Tokenized words (with hyphen-splitting applied) including trailing spaces/hyphens.
|
|
72
|
+
const tokens = [];
|
|
73
|
+
// First split by spaces, then further split by hyphens so we can
|
|
74
|
+
// wrap inside hyphenated words if necessary.
|
|
75
|
+
const spaceSeparated = line.split(' ');
|
|
76
|
+
spaceSeparated.forEach((word, wordIndex) => {
|
|
77
|
+
const hyphenParts = word.split('-');
|
|
78
|
+
const trailingWhitespace = wordIndex < spaceSeparated.length - 1 ? ' ' : '';
|
|
79
|
+
if (hyphenParts.length > 1) {
|
|
80
|
+
hyphenParts.forEach((part, partIndex) => {
|
|
81
|
+
const suffix = partIndex < hyphenParts.length - 1 ? '-' : trailingWhitespace;
|
|
82
|
+
tokens.push(part + suffix);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
tokens.push(word + trailingWhitespace);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const maxChars = maxCharactersPerLine || 40;
|
|
90
|
+
if (!maxLineWidth) {
|
|
91
|
+
// Fallback for max characters per line if not provided / falsy.
|
|
92
|
+
// Convert character counts into approximate visual widths.
|
|
93
|
+
maxLineWidth = maxChars * CHAR_W.a;
|
|
94
|
+
}
|
|
95
|
+
if (!minLineWidth) {
|
|
96
|
+
// Estimate a good minimum line length:
|
|
97
|
+
// - start from either a provided value or
|
|
98
|
+
// - clamp a scaled median word length between 3 and half of maxChars.
|
|
99
|
+
const sortedWordLengths = tokens.map((t) => t.length).sort((a, b) => a - b);
|
|
100
|
+
const medianIndex = Math.round(tokens.length / 2);
|
|
101
|
+
const medianWordLength = sortedWordLengths[medianIndex] ?? maxChars;
|
|
102
|
+
const minChars = minCharactersPerLine || Math.max(3, Math.min(maxChars * 0.5, 0.75 * medianWordLength));
|
|
103
|
+
minLineWidth = minChars * CHAR_W.a;
|
|
104
|
+
}
|
|
105
|
+
const lines = [];
|
|
106
|
+
const currentWords = [];
|
|
107
|
+
let currentWidth = 0;
|
|
108
|
+
// Helper to look up a character width, falling back to "a" if unknown
|
|
109
|
+
// or when monospace mode is enabled.
|
|
110
|
+
const charWidth = (char) => (fontSize / 12) * (!monospace ? CHAR_W[char] : CHAR_W.a);
|
|
111
|
+
// Greedy line construction: append tokens until the next one would exceed
|
|
112
|
+
// max visual width, but only break if the line has passed the minimum width.
|
|
113
|
+
tokens.forEach((token) => {
|
|
114
|
+
const tokenWidth = sum(token.split('').map(charWidth));
|
|
115
|
+
if (currentWidth + tokenWidth > maxLineWidth && currentWidth > minLineWidth) {
|
|
116
|
+
lines.push(currentWords.join(''));
|
|
117
|
+
currentWords.length = 0;
|
|
118
|
+
currentWidth = 0;
|
|
119
|
+
}
|
|
120
|
+
currentWidth += tokenWidth;
|
|
121
|
+
currentWords.push(token);
|
|
122
|
+
});
|
|
123
|
+
// Flush trailing tokens into the last line.
|
|
124
|
+
if (currentWords.length > 0) {
|
|
125
|
+
lines.push(currentWords.join(''));
|
|
126
|
+
}
|
|
127
|
+
// Filter out any empty lines that may have been created.
|
|
128
|
+
return lines.filter((d) => d !== '');
|
|
129
|
+
}
|
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
tickSpacing?: number;
|
|
52
52
|
/** text anchor for axis labels */
|
|
53
53
|
textAnchor?: ConstantAccessor<CSS.Property.TextAnchor | 'auto', Datum>;
|
|
54
|
+
removeDuplicateTicks: boolean;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
let markProps: AxisXMarkProps = $props();
|
|
@@ -223,7 +224,7 @@
|
|
|
223
224
|
{anchor}
|
|
224
225
|
{className}
|
|
225
226
|
{labelAnchor}
|
|
226
|
-
{options}
|
|
227
|
+
options={{ ...options, ...plot.options.x }}
|
|
227
228
|
{plot}
|
|
228
229
|
{text}
|
|
229
230
|
{tickClass}
|
|
@@ -88,6 +88,7 @@ declare class __sveltets_Render<Datum extends RawValue> {
|
|
|
88
88
|
tickSpacing?: number;
|
|
89
89
|
/** text anchor for axis labels */
|
|
90
90
|
textAnchor?: ConstantAccessor<"auto" | CSS.Property.TextAnchor, Datum>;
|
|
91
|
+
removeDuplicateTicks: boolean;
|
|
91
92
|
};
|
|
92
93
|
events(): {};
|
|
93
94
|
slots(): {};
|
package/dist/marks/Brush.svelte
CHANGED
|
@@ -33,14 +33,17 @@
|
|
|
33
33
|
onbrushend?: (evt: BrushEvent) => void;
|
|
34
34
|
onbrush?: (evt: BrushEvent) => void;
|
|
35
35
|
}
|
|
36
|
-
import { getContext } from 'svelte';
|
|
36
|
+
import { getContext, untrack } from 'svelte';
|
|
37
37
|
import Rect from './Rect.svelte';
|
|
38
38
|
import type { BaseMarkProps, DataRecord, PlotContext } from '../types/index.js';
|
|
39
39
|
import { clientToLayerCoordinates } from './helpers/events.js';
|
|
40
40
|
import Frame from './Frame.svelte';
|
|
41
41
|
import { getPlotDefaults } from '../hooks/plotDefaults.js';
|
|
42
42
|
|
|
43
|
-
let { brush = $bindable({ enabled: false }), ...markProps }: BrushMarkProps =
|
|
43
|
+
let { brush: brushExternal = $bindable({ enabled: false }), ...markProps }: BrushMarkProps =
|
|
44
|
+
$props();
|
|
45
|
+
|
|
46
|
+
let brush = $state<Brush>(brushExternal);
|
|
44
47
|
|
|
45
48
|
const DEFAULTS = {
|
|
46
49
|
stroke: 'currentColor',
|
|
@@ -179,6 +182,7 @@
|
|
|
179
182
|
);
|
|
180
183
|
|
|
181
184
|
$effect(() => {
|
|
185
|
+
// update brush prop when internal state changes
|
|
182
186
|
brush.x1 =
|
|
183
187
|
!brush.enabled || limitDimension === 'y'
|
|
184
188
|
? undefined
|
|
@@ -197,6 +201,38 @@
|
|
|
197
201
|
: constrain(y1 > y2 ? y1 : y2, yDomain);
|
|
198
202
|
});
|
|
199
203
|
|
|
204
|
+
// update internal state when external brush prop changes
|
|
205
|
+
$effect(() => {
|
|
206
|
+
const brushInt = untrack(() => brush);
|
|
207
|
+
if (!brushIdentical(brushInt, brushExternal)) {
|
|
208
|
+
brush = brushExternal;
|
|
209
|
+
// also keep internal x1,x2,y1,y2 in sync
|
|
210
|
+
x1 = brush.x1 as Date | number;
|
|
211
|
+
x2 = brush.x2 as Date | number;
|
|
212
|
+
y1 = brush.y1 as Date | number;
|
|
213
|
+
y2 = brush.y2 as Date | number;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// update external brush when internal state changes
|
|
218
|
+
$effect(() => {
|
|
219
|
+
const brushExt = untrack(() => brushExternal);
|
|
220
|
+
if (!brushIdentical(brush, brushExt)) {
|
|
221
|
+
// avoid cycles
|
|
222
|
+
brushExternal = brush;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
function brushIdentical(b1: Brush, b2: Brush) {
|
|
227
|
+
return (
|
|
228
|
+
b1.enabled === b2.enabled &&
|
|
229
|
+
b1.x1 === b2.x1 &&
|
|
230
|
+
b1.x2 === b2.x2 &&
|
|
231
|
+
b1.y1 === b2.y1 &&
|
|
232
|
+
b1.y2 === b2.y2
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
200
236
|
function constrain<T extends number | Date>(x: T, extent: [typeof x, typeof x]) {
|
|
201
237
|
const minE = extent[0] < extent[1] ? extent[0] : extent[1];
|
|
202
238
|
const maxE = extent[0] > extent[1] ? extent[0] : extent[1];
|
|
@@ -242,8 +278,12 @@
|
|
|
242
278
|
} else {
|
|
243
279
|
// draw new brush selection
|
|
244
280
|
action = 'draw';
|
|
245
|
-
|
|
246
|
-
|
|
281
|
+
if (typeof xScaleFn.invert === 'function' && limitDimension !== 'y') {
|
|
282
|
+
x1 = x2 = xScaleFn.invert(dragStart[0]);
|
|
283
|
+
}
|
|
284
|
+
if (typeof yScaleFn.invert === 'function' && limitDimension !== 'x') {
|
|
285
|
+
y1 = y2 = yScaleFn.invert(dragStart[1]);
|
|
286
|
+
}
|
|
247
287
|
}
|
|
248
288
|
onbrushstart?.({ ...e, brush });
|
|
249
289
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<script lang="ts" generics="Datum extends DataRecord">
|
|
6
6
|
interface CustomMarkProps extends BaseMarkProps<Datum> {
|
|
7
7
|
data?: Datum[];
|
|
8
|
+
type?: string;
|
|
8
9
|
x?: ChannelAccessor<Datum>;
|
|
9
10
|
x1?: ChannelAccessor<Datum>;
|
|
10
11
|
x2?: ChannelAccessor<Datum>;
|
|
@@ -18,7 +19,6 @@
|
|
|
18
19
|
marks?: Snippet<[{ records: ScaledDataRecord<Datum>[]; usedScales: UsedScales }]>;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
import { getContext } from 'svelte';
|
|
22
22
|
import type {
|
|
23
23
|
PlotContext,
|
|
24
24
|
DataRecord,
|
|
@@ -33,7 +33,13 @@
|
|
|
33
33
|
|
|
34
34
|
import Mark from '../Mark.svelte';
|
|
35
35
|
|
|
36
|
-
let {
|
|
36
|
+
let {
|
|
37
|
+
data = [{} as Datum],
|
|
38
|
+
mark,
|
|
39
|
+
type = 'custom',
|
|
40
|
+
marks,
|
|
41
|
+
...options
|
|
42
|
+
}: CustomMarkProps = $props();
|
|
37
43
|
|
|
38
44
|
const args = $derived(sort({ data, ...options })) as CustomMarkProps;
|
|
39
45
|
|
|
@@ -53,7 +59,7 @@
|
|
|
53
59
|
];
|
|
54
60
|
</script>
|
|
55
61
|
|
|
56
|
-
<Mark type
|
|
62
|
+
<Mark {type} required={[]} channels={channels.filter((d) => !!options[d])} {...args}>
|
|
57
63
|
{#snippet children({ scaledData, usedScales })}
|
|
58
64
|
{#if marks}
|
|
59
65
|
{@render marks({ records: scaledData.filter((d) => d.valid), usedScales })}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
For showing images positioned at x/y coordinates
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" generics="Datum extends DataRecord">
|
|
6
|
+
interface ImageMarkProps extends BaseMarkProps<Datum>, LinkableMarkProps<Datum> {
|
|
7
|
+
data: Datum[];
|
|
8
|
+
x: ChannelAccessor<Datum>;
|
|
9
|
+
y: ChannelAccessor<Datum>;
|
|
10
|
+
r?: ChannelAccessor<Datum>;
|
|
11
|
+
width?: ConstantAccessor<number, Datum>;
|
|
12
|
+
height?: ConstantAccessor<number, Datum>;
|
|
13
|
+
src?: ConstantAccessor<string, Datum>;
|
|
14
|
+
title?: ConstantAccessor<string, Datum>;
|
|
15
|
+
preserveAspectRatio?: string;
|
|
16
|
+
// canvas?: boolean;
|
|
17
|
+
imageClass?: ConstantAccessor<string, Datum>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
import type {
|
|
21
|
+
BaseMarkProps,
|
|
22
|
+
ChannelAccessor,
|
|
23
|
+
ConstantAccessor,
|
|
24
|
+
DataRecord,
|
|
25
|
+
LinkableMarkProps
|
|
26
|
+
} from '../types';
|
|
27
|
+
import { resolveProp } from '../helpers/resolve';
|
|
28
|
+
import CustomMark from './CustomMark.svelte';
|
|
29
|
+
import { getPlotDefaults } from '../hooks/plotDefaults';
|
|
30
|
+
import { sort } from '../transforms';
|
|
31
|
+
import Anchor from './helpers/Anchor.svelte';
|
|
32
|
+
|
|
33
|
+
let markProps: ImageMarkProps = $props();
|
|
34
|
+
|
|
35
|
+
const DEFAULTS: Partial<ImageMarkProps> = {
|
|
36
|
+
width: 20,
|
|
37
|
+
preserveAspectRatio: 'xMidYMin slice',
|
|
38
|
+
...getPlotDefaults().image
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
data = [{} as Datum],
|
|
43
|
+
width,
|
|
44
|
+
height,
|
|
45
|
+
src,
|
|
46
|
+
title,
|
|
47
|
+
imageClass,
|
|
48
|
+
preserveAspectRatio,
|
|
49
|
+
...options
|
|
50
|
+
}: ImageMarkProps = $derived({
|
|
51
|
+
...DEFAULTS,
|
|
52
|
+
...markProps
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const args = $derived(sort({ data, ...options }));
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<CustomMark type="image" {...args}>
|
|
59
|
+
{#snippet mark({ record, index, usedScales })}
|
|
60
|
+
{@const w = record.r !== undefined ? record.r * 2 : resolveProp(width, record.datum, 20)}
|
|
61
|
+
{@const h =
|
|
62
|
+
record.r !== undefined ? record.r * 2 : resolveProp(height || width, record.datum, 20)}
|
|
63
|
+
<Anchor {options} datum={record.datum}>
|
|
64
|
+
<image
|
|
65
|
+
class={resolveProp(imageClass, record.datum, null)}
|
|
66
|
+
href={resolveProp(src, record.datum, '')}
|
|
67
|
+
x={record.x - w * 0.5}
|
|
68
|
+
y={record.y - h * 0.5}
|
|
69
|
+
{preserveAspectRatio}
|
|
70
|
+
clip-path={record.r !== undefined ? `circle(${record.r}px)` : null}
|
|
71
|
+
width={w}
|
|
72
|
+
height={h}
|
|
73
|
+
>{#if title}<title>{resolveProp(title, record.datum, '')}</title>{/if}</image>
|
|
74
|
+
</Anchor>
|
|
75
|
+
{/snippet}
|
|
76
|
+
</CustomMark>
|
|
@@ -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
|
+
/** For showing images positioned at x/y coordinates */
|
|
17
|
+
declare const Image: $$IsomorphicComponent;
|
|
18
|
+
type Image<Datum extends DataRecord> = InstanceType<typeof Image<Datum>>;
|
|
19
|
+
export default Image;
|