@fundar/data-chart-telling 0.0.1
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/README.md +250 -0
- package/dist/charts/Chart.svelte +125 -0
- package/dist/charts/Chart.svelte.d.ts +42 -0
- package/dist/charts/bar/Chart.svelte +104 -0
- package/dist/charts/bar/Chart.svelte.d.ts +27 -0
- package/dist/charts/container/ChartContainer.svelte +127 -0
- package/dist/charts/container/ChartContainer.svelte.d.ts +14 -0
- package/dist/charts/heatmap/Chart.svelte +107 -0
- package/dist/charts/heatmap/Chart.svelte.d.ts +30 -0
- package/dist/charts/line/Chart.svelte +106 -0
- package/dist/charts/line/Chart.svelte.d.ts +27 -0
- package/dist/charts/pyramid/Chart.svelte +127 -0
- package/dist/charts/pyramid/Chart.svelte.d.ts +31 -0
- package/dist/configuration/config.svelte.d.ts +12 -0
- package/dist/configuration/config.svelte.js +159 -0
- package/dist/configuration/themes/compact.d.ts +2 -0
- package/dist/configuration/themes/compact.js +9 -0
- package/dist/configuration/themes/dark.d.ts +2 -0
- package/dist/configuration/themes/dark.js +17 -0
- package/dist/configuration/themes/default.d.ts +3 -0
- package/dist/configuration/themes/default.js +2 -0
- package/dist/configuration/themes/editorial.d.ts +2 -0
- package/dist/configuration/themes/editorial.js +14 -0
- package/dist/configuration/themes/index.d.ts +481 -0
- package/dist/configuration/themes/index.js +16 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +27 -0
- package/dist/layout/facet/FacetLayout.svelte +97 -0
- package/dist/layout/facet/FacetLayout.svelte.d.ts +35 -0
- package/dist/layout/legend/ContinuousSection.svelte +95 -0
- package/dist/layout/legend/ContinuousSection.svelte.d.ts +7 -0
- package/dist/layout/legend/DiscreteSection.svelte +87 -0
- package/dist/layout/legend/DiscreteSection.svelte.d.ts +7 -0
- package/dist/layout/legend/LegendLayout.svelte +47 -0
- package/dist/layout/legend/LegendLayout.svelte.d.ts +7 -0
- package/dist/layout/plot/PlotLayout.svelte +236 -0
- package/dist/layout/plot/PlotLayout.svelte.d.ts +70 -0
- package/dist/layout/timeline/Timeline.svelte +86 -0
- package/dist/layout/timeline/Timeline.svelte.d.ts +11 -0
- package/dist/layout/timeline/TimelineLayout.svelte +181 -0
- package/dist/layout/timeline/TimelineLayout.svelte.d.ts +38 -0
- package/dist/layout/tooltip/Tooltip.svelte +55 -0
- package/dist/layout/tooltip/Tooltip.svelte.d.ts +12 -0
- package/dist/layout/tooltip/controller.svelte.d.ts +52 -0
- package/dist/layout/tooltip/controller.svelte.js +128 -0
- package/dist/layout/tooltip/hover.svelte.d.ts +7 -0
- package/dist/layout/tooltip/hover.svelte.js +28 -0
- package/dist/layout/tooltip/utils.d.ts +41 -0
- package/dist/layout/tooltip/utils.js +78 -0
- package/dist/plots/bar/Plot.svelte +176 -0
- package/dist/plots/bar/Plot.svelte.d.ts +26 -0
- package/dist/plots/heatmap/Plot.svelte +175 -0
- package/dist/plots/heatmap/Plot.svelte.d.ts +26 -0
- package/dist/plots/line/Plot.svelte +232 -0
- package/dist/plots/line/Plot.svelte.d.ts +26 -0
- package/dist/plots/markers/DeltaMarker.svelte +104 -0
- package/dist/plots/markers/DeltaMarker.svelte.d.ts +30 -0
- package/dist/plots/markers/DotMarker.svelte +41 -0
- package/dist/plots/markers/DotMarker.svelte.d.ts +31 -0
- package/dist/plots/markers/HoverMarker.svelte +78 -0
- package/dist/plots/markers/HoverMarker.svelte.d.ts +22 -0
- package/dist/plots/markers/PeakMarker.svelte +80 -0
- package/dist/plots/markers/PeakMarker.svelte.d.ts +13 -0
- package/dist/plots/markers/TextMarker.svelte +55 -0
- package/dist/plots/markers/TextMarker.svelte.d.ts +32 -0
- package/dist/plots/pyramid/Plot.svelte +282 -0
- package/dist/plots/pyramid/Plot.svelte.d.ts +26 -0
- package/dist/plots/utils/accessors.d.ts +6 -0
- package/dist/plots/utils/accessors.js +10 -0
- package/dist/plots/utils/delta.d.ts +12 -0
- package/dist/plots/utils/delta.js +69 -0
- package/dist/plots/utils/segments.d.ts +33 -0
- package/dist/plots/utils/segments.js +153 -0
- package/dist/stores/device.d.ts +7 -0
- package/dist/stores/device.js +39 -0
- package/dist/types/charts/common.d.ts +64 -0
- package/dist/types/charts/common.js +1 -0
- package/dist/types/charts/interpolate.d.ts +2 -0
- package/dist/types/charts/interpolate.js +1 -0
- package/dist/types/charts/legend.d.ts +29 -0
- package/dist/types/charts/legend.js +1 -0
- package/dist/types/charts/props.d.ts +35 -0
- package/dist/types/charts/props.js +1 -0
- package/dist/types/configuration/styling.d.ts +97 -0
- package/dist/types/configuration/styling.js +1 -0
- package/dist/types/layout/tooltip.d.ts +88 -0
- package/dist/types/layout/tooltip.js +1 -0
- package/dist/types/plots/common.d.ts +100 -0
- package/dist/types/plots/common.js +1 -0
- package/dist/types/plots/delta.d.ts +19 -0
- package/dist/types/plots/delta.js +1 -0
- package/dist/types/plots/markers.d.ts +56 -0
- package/dist/types/plots/markers.js +1 -0
- package/dist/types/plots/props.d.ts +23 -0
- package/dist/types/plots/props.js +1 -0
- package/dist/types/plots/styles.d.ts +176 -0
- package/dist/types/plots/styles.js +1 -0
- package/dist/types/viewport.d.ts +4 -0
- package/dist/types/viewport.js +1 -0
- package/dist/utils/color.d.ts +5 -0
- package/dist/utils/color.js +42 -0
- package/dist/utils/grouping.d.ts +14 -0
- package/dist/utils/grouping.js +36 -0
- package/dist/utils/interpolate.d.ts +30 -0
- package/dist/utils/interpolate.js +71 -0
- package/package.json +76 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="TData extends Record<string, unknown>"
|
|
4
|
+
>
|
|
5
|
+
import { Line } from 'svelteplot';
|
|
6
|
+
import DotMarker from './DotMarker.svelte';
|
|
7
|
+
import TextMarker from './TextMarker.svelte';
|
|
8
|
+
import { resolveXDeltas, resolveYDeltas } from '../utils/delta';
|
|
9
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
10
|
+
import type { Series } from '../../types/plots/common';
|
|
11
|
+
import type { DeltaConfig } from '../../types/plots/delta';
|
|
12
|
+
|
|
13
|
+
interface Props extends MarkerProps<Series<TData>>, DeltaConfig {
|
|
14
|
+
xDomain?: (number | string | Date)[];
|
|
15
|
+
yDomain?: (number | string | Date)[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
data = [],
|
|
20
|
+
axis,
|
|
21
|
+
at,
|
|
22
|
+
from,
|
|
23
|
+
to,
|
|
24
|
+
formatDiff,
|
|
25
|
+
strokeStyle,
|
|
26
|
+
fontStyle,
|
|
27
|
+
dotStyle,
|
|
28
|
+
xDomain,
|
|
29
|
+
yDomain,
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
|
|
32
|
+
const resolved = $derived.by(() => {
|
|
33
|
+
const cfg: DeltaConfig = { axis, at, from, to, formatDiff, strokeStyle, fontStyle, dotStyle };
|
|
34
|
+
const [d] = axis === 'x' ? resolveXDeltas(data, [cfg]) : resolveYDeltas(data, [cfg]);
|
|
35
|
+
return d;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const clampRange = $derived.by((): [number, number] | undefined => {
|
|
39
|
+
const domain = axis === 'x' ? yDomain : xDomain;
|
|
40
|
+
if (!domain || domain.length < 2) return undefined;
|
|
41
|
+
const lo = Number(domain[0]);
|
|
42
|
+
const hi = Number(domain[domain.length - 1]);
|
|
43
|
+
return isNaN(lo) || isNaN(hi) ? undefined : [Math.min(lo, hi), Math.max(lo, hi)];
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function clamp(v: number): number {
|
|
47
|
+
return clampRange ? Math.max(clampRange[0], Math.min(clampRange[1], v)) : v;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function pt(fixed: number, varying: number) {
|
|
51
|
+
return axis === 'x' ? { x: fixed, y: varying } : { x: varying, y: fixed };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function textVaryCoord(fromVis: number, toVis: number) {
|
|
55
|
+
const anchor = fontStyle?.lineAnchor ?? 'middle';
|
|
56
|
+
return anchor === 'top'
|
|
57
|
+
? Math.max(fromVis, toVis)
|
|
58
|
+
: anchor === 'bottom'
|
|
59
|
+
? Math.min(fromVis, toVis)
|
|
60
|
+
: (fromVis + toVis) / 2;
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
{#if resolved}
|
|
65
|
+
{@const fromVis = clamp(resolved.from)}
|
|
66
|
+
{@const toVis = clamp(resolved.to)}
|
|
67
|
+
{@const textPt = pt(resolved.at, textVaryCoord(fromVis, toVis))}
|
|
68
|
+
|
|
69
|
+
<Line
|
|
70
|
+
data={[pt(resolved.at, fromVis), pt(resolved.at, toVis)]}
|
|
71
|
+
x={(p) => p.x}
|
|
72
|
+
y={(p) => p.y}
|
|
73
|
+
stroke={strokeStyle?.stroke ?? 'currentColor'}
|
|
74
|
+
strokeWidth={strokeStyle?.strokeWidth ?? 2}
|
|
75
|
+
strokeOpacity={strokeStyle?.strokeOpacity ?? 0.8}
|
|
76
|
+
strokeDasharray={strokeStyle?.strokeDasharray ?? '6 6'}
|
|
77
|
+
strokeLinecap={strokeStyle?.strokeLinecap ?? 'round'}
|
|
78
|
+
/>
|
|
79
|
+
<DotMarker
|
|
80
|
+
x={pt(resolved.at, fromVis).x}
|
|
81
|
+
y={pt(resolved.at, fromVis).y}
|
|
82
|
+
style={{ dotRadius: 4, dotFill: strokeStyle?.stroke, dotStroke: strokeStyle?.stroke, dotStrokeWidth: 2, ...dotStyle }}
|
|
83
|
+
/>
|
|
84
|
+
<DotMarker
|
|
85
|
+
x={pt(resolved.at, toVis).x}
|
|
86
|
+
y={pt(resolved.at, toVis).y}
|
|
87
|
+
style={{ dotRadius: 4, dotFill: strokeStyle?.stroke, dotStroke: strokeStyle?.stroke, dotStrokeWidth: 2, ...dotStyle }}
|
|
88
|
+
/>
|
|
89
|
+
<TextMarker
|
|
90
|
+
x={textPt.x}
|
|
91
|
+
y={textPt.y}
|
|
92
|
+
text={(formatDiff ?? ((v: number) => v.toFixed(1)))(resolved.diff)}
|
|
93
|
+
style={{
|
|
94
|
+
fontWeight: 'bold',
|
|
95
|
+
fontSize: 14,
|
|
96
|
+
textAnchor: 'middle',
|
|
97
|
+
fill: strokeStyle?.stroke ?? 'currentColor',
|
|
98
|
+
...fontStyle,
|
|
99
|
+
dx: fontStyle?.dx ?? (axis === 'x' ? 12 : 0),
|
|
100
|
+
dy: fontStyle?.dy ?? (axis === 'x' ? 0 : -10),
|
|
101
|
+
lineAnchor: axis === 'x' ? (fontStyle?.lineAnchor ?? 'middle') : 'bottom',
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
{/if}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
2
|
+
import type { Series } from '../../types/plots/common';
|
|
3
|
+
import type { DeltaConfig } from '../../types/plots/delta';
|
|
4
|
+
declare function $$render<TData extends Record<string, unknown>>(): {
|
|
5
|
+
props: MarkerProps<Series<TData>> & DeltaConfig & {
|
|
6
|
+
xDomain?: (number | string | Date)[];
|
|
7
|
+
yDomain?: (number | string | Date)[];
|
|
8
|
+
};
|
|
9
|
+
exports: {};
|
|
10
|
+
bindings: "";
|
|
11
|
+
slots: {};
|
|
12
|
+
events: {};
|
|
13
|
+
};
|
|
14
|
+
declare class __sveltets_Render<TData extends Record<string, unknown>> {
|
|
15
|
+
props(): ReturnType<typeof $$render<TData>>['props'];
|
|
16
|
+
events(): ReturnType<typeof $$render<TData>>['events'];
|
|
17
|
+
slots(): ReturnType<typeof $$render<TData>>['slots'];
|
|
18
|
+
bindings(): "";
|
|
19
|
+
exports(): {};
|
|
20
|
+
}
|
|
21
|
+
interface $$IsomorphicComponent {
|
|
22
|
+
new <TData extends Record<string, unknown>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
|
|
23
|
+
$$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
|
|
24
|
+
} & ReturnType<__sveltets_Render<TData>['exports']>;
|
|
25
|
+
<TData extends Record<string, unknown>>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
|
|
26
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
27
|
+
}
|
|
28
|
+
declare const DeltaMarker: $$IsomorphicComponent;
|
|
29
|
+
type DeltaMarker<TData extends Record<string, unknown>> = InstanceType<typeof DeltaMarker<TData>>;
|
|
30
|
+
export default DeltaMarker;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts" generics="TData = Record<string, unknown>">
|
|
2
|
+
import { Dot } from 'svelteplot';
|
|
3
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
4
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
5
|
+
import type { DotStyle } from '../../types/plots/styles';
|
|
6
|
+
|
|
7
|
+
interface Props extends MarkerProps<TData> {
|
|
8
|
+
x?: AxisValue | ((d: TData) => AxisValue);
|
|
9
|
+
y?: AxisValue | ((d: TData) => AxisValue);
|
|
10
|
+
style?: DotStyle;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { data = [], x, y, style }: Props = $props();
|
|
14
|
+
|
|
15
|
+
const xAccessor = $derived(typeof x === 'function' ? x : () => x ?? 0);
|
|
16
|
+
const yAccessor = $derived(typeof y === 'function' ? y : () => y ?? 0);
|
|
17
|
+
const displayData = $derived(data.length > 0 ? data : [{} as TData]);
|
|
18
|
+
|
|
19
|
+
const r = $derived(style?.dotRadius ?? 5);
|
|
20
|
+
const fill = $derived(style?.dotFill ?? 'currentColor');
|
|
21
|
+
const fillOpacity = $derived(style?.dotFillOpacity ?? 1);
|
|
22
|
+
const symbol = $derived(style?.dotSymbol ?? 'circle');
|
|
23
|
+
const stroke = $derived(style?.dotStroke ?? 'currentColor');
|
|
24
|
+
const strokeWidth = $derived(style?.dotStrokeWidth ?? 1);
|
|
25
|
+
const strokeOpacity = $derived(style?.dotStrokeOpacity ?? 1);
|
|
26
|
+
const strokeDasharray = $derived(style?.dotStrokeDasharray);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<Dot
|
|
30
|
+
data={displayData}
|
|
31
|
+
x={xAccessor}
|
|
32
|
+
y={yAccessor}
|
|
33
|
+
{r}
|
|
34
|
+
{fill}
|
|
35
|
+
{fillOpacity}
|
|
36
|
+
{stroke}
|
|
37
|
+
{strokeWidth}
|
|
38
|
+
{strokeOpacity}
|
|
39
|
+
{strokeDasharray}
|
|
40
|
+
{symbol}
|
|
41
|
+
/>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
2
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
3
|
+
import type { DotStyle } from '../../types/plots/styles';
|
|
4
|
+
declare function $$render<TData = Record<string, unknown>>(): {
|
|
5
|
+
props: MarkerProps<TData> & {
|
|
6
|
+
x?: AxisValue | ((d: TData) => AxisValue);
|
|
7
|
+
y?: AxisValue | ((d: TData) => AxisValue);
|
|
8
|
+
style?: DotStyle;
|
|
9
|
+
};
|
|
10
|
+
exports: {};
|
|
11
|
+
bindings: "";
|
|
12
|
+
slots: {};
|
|
13
|
+
events: {};
|
|
14
|
+
};
|
|
15
|
+
declare class __sveltets_Render<TData = Record<string, unknown>> {
|
|
16
|
+
props(): ReturnType<typeof $$render<TData>>['props'];
|
|
17
|
+
events(): ReturnType<typeof $$render<TData>>['events'];
|
|
18
|
+
slots(): ReturnType<typeof $$render<TData>>['slots'];
|
|
19
|
+
bindings(): "";
|
|
20
|
+
exports(): {};
|
|
21
|
+
}
|
|
22
|
+
interface $$IsomorphicComponent {
|
|
23
|
+
new <TData = Record<string, unknown>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
|
|
24
|
+
$$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
|
|
25
|
+
} & ReturnType<__sveltets_Render<TData>['exports']>;
|
|
26
|
+
<TData = Record<string, unknown>>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
|
|
27
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
28
|
+
}
|
|
29
|
+
declare const DotMarker: $$IsomorphicComponent;
|
|
30
|
+
type DotMarker<TData = Record<string, unknown>> = InstanceType<typeof DotMarker<TData>>;
|
|
31
|
+
export default DotMarker;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { RuleX, RuleY } from 'svelteplot';
|
|
3
|
+
import DotMarker from './DotMarker.svelte';
|
|
4
|
+
import TextMarker from './TextMarker.svelte';
|
|
5
|
+
import { getConfiguration } from '../../configuration/config.svelte';
|
|
6
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
7
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
8
|
+
import type { DotStyle, FontStyle, StrokeStyle } from '../../types/plots/styles';
|
|
9
|
+
import type { HoverDisplayPoint } from '../../types/layout/tooltip';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* In-SVG hover highlight, rendered *inside* a `<Plot>`. Because it positions
|
|
13
|
+
* itself through the host plot's scales, it places the same coordinate
|
|
14
|
+
* correctly in every facet — that is what makes cross-facet sync work without
|
|
15
|
+
* any pixel math. Draws optional x/y crosshair rules plus a dot + value label
|
|
16
|
+
* for each matched point.
|
|
17
|
+
*/
|
|
18
|
+
interface Props extends MarkerProps<HoverDisplayPoint> {
|
|
19
|
+
ruleX?: AxisValue | null;
|
|
20
|
+
ruleY?: AxisValue | null;
|
|
21
|
+
showLabels?: boolean;
|
|
22
|
+
ruleStyle?: StrokeStyle;
|
|
23
|
+
dotStyle?: DotStyle;
|
|
24
|
+
fontStyle?: FontStyle;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
data = [],
|
|
29
|
+
ruleX = null,
|
|
30
|
+
ruleY = null,
|
|
31
|
+
showLabels = true,
|
|
32
|
+
ruleStyle,
|
|
33
|
+
dotStyle,
|
|
34
|
+
fontStyle,
|
|
35
|
+
}: Props = $props();
|
|
36
|
+
|
|
37
|
+
const cfg = $derived(getConfiguration());
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
{#if ruleX != null}
|
|
41
|
+
<RuleX
|
|
42
|
+
data={[{ v: ruleX }]}
|
|
43
|
+
x={(d) => d.v}
|
|
44
|
+
stroke={ruleStyle?.stroke ?? cfg.hover.rule.stroke}
|
|
45
|
+
strokeOpacity={ruleStyle?.strokeOpacity ?? cfg.hover.rule.strokeOpacity}
|
|
46
|
+
strokeWidth={ruleStyle?.strokeWidth ?? cfg.hover.rule.strokeWidth}
|
|
47
|
+
strokeDasharray={ruleStyle?.strokeDasharray ?? cfg.hover.rule.strokeDasharray}
|
|
48
|
+
/>
|
|
49
|
+
{/if}
|
|
50
|
+
|
|
51
|
+
{#if ruleY != null}
|
|
52
|
+
<RuleY
|
|
53
|
+
data={[{ v: ruleY }]}
|
|
54
|
+
y={(d) => d.v}
|
|
55
|
+
stroke={ruleStyle?.stroke ?? cfg.hover.rule.stroke}
|
|
56
|
+
strokeOpacity={ruleStyle?.strokeOpacity ?? cfg.hover.rule.strokeOpacity}
|
|
57
|
+
strokeWidth={ruleStyle?.strokeWidth ?? cfg.hover.rule.strokeWidth}
|
|
58
|
+
strokeDasharray={ruleStyle?.strokeDasharray ?? cfg.hover.rule.strokeDasharray}
|
|
59
|
+
/>
|
|
60
|
+
{/if}
|
|
61
|
+
|
|
62
|
+
{#if data.length > 0}
|
|
63
|
+
<DotMarker
|
|
64
|
+
{data}
|
|
65
|
+
x={(d) => d.x}
|
|
66
|
+
y={(d) => d.y}
|
|
67
|
+
style={{ ...cfg.hover.dot, ...dotStyle }}
|
|
68
|
+
/>
|
|
69
|
+
{#if showLabels}
|
|
70
|
+
<TextMarker
|
|
71
|
+
{data}
|
|
72
|
+
x={(d) => d.x}
|
|
73
|
+
y={(d) => d.y}
|
|
74
|
+
text={(d) => d.label ?? ''}
|
|
75
|
+
style={{ ...cfg.hover.font, ...fontStyle }}
|
|
76
|
+
/>
|
|
77
|
+
{/if}
|
|
78
|
+
{/if}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
2
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
3
|
+
import type { DotStyle, FontStyle, StrokeStyle } from '../../types/plots/styles';
|
|
4
|
+
import type { HoverDisplayPoint } from '../../types/layout/tooltip';
|
|
5
|
+
/**
|
|
6
|
+
* In-SVG hover highlight, rendered *inside* a `<Plot>`. Because it positions
|
|
7
|
+
* itself through the host plot's scales, it places the same coordinate
|
|
8
|
+
* correctly in every facet — that is what makes cross-facet sync work without
|
|
9
|
+
* any pixel math. Draws optional x/y crosshair rules plus a dot + value label
|
|
10
|
+
* for each matched point.
|
|
11
|
+
*/
|
|
12
|
+
interface Props extends MarkerProps<HoverDisplayPoint> {
|
|
13
|
+
ruleX?: AxisValue | null;
|
|
14
|
+
ruleY?: AxisValue | null;
|
|
15
|
+
showLabels?: boolean;
|
|
16
|
+
ruleStyle?: StrokeStyle;
|
|
17
|
+
dotStyle?: DotStyle;
|
|
18
|
+
fontStyle?: FontStyle;
|
|
19
|
+
}
|
|
20
|
+
declare const HoverMarker: import("svelte").Component<Props, {}, "">;
|
|
21
|
+
type HoverMarker = ReturnType<typeof HoverMarker>;
|
|
22
|
+
export default HoverMarker;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import DotMarker from './DotMarker.svelte';
|
|
3
|
+
import TextMarker from './TextMarker.svelte';
|
|
4
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
5
|
+
import type { DotStyle, FontStyle } from '../../types/plots/styles';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
interface Props extends MarkerProps<Record<string, any>> {
|
|
9
|
+
yProp?: string;
|
|
10
|
+
xProp?: string;
|
|
11
|
+
mode?: 'max' | 'min';
|
|
12
|
+
label?: string;
|
|
13
|
+
dotStyle?: DotStyle;
|
|
14
|
+
textStyle?: FontStyle;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
data = [],
|
|
19
|
+
yProp = 'value',
|
|
20
|
+
xProp = 'x',
|
|
21
|
+
mode = 'max',
|
|
22
|
+
label,
|
|
23
|
+
dotStyle,
|
|
24
|
+
textStyle,
|
|
25
|
+
seriesColor,
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
|
|
28
|
+
const resolvedDotFill = $derived(dotStyle?.dotFill ?? seriesColor ?? 'currentColor');
|
|
29
|
+
const resolvedDotStroke = $derived(dotStyle?.dotStroke ?? seriesColor ?? 'currentColor');
|
|
30
|
+
const resolvedTextFill = $derived(textStyle?.fill ?? seriesColor ?? 'currentColor');
|
|
31
|
+
|
|
32
|
+
const peakPoint = $derived.by(() => {
|
|
33
|
+
if (data.length === 0) return null;
|
|
34
|
+
|
|
35
|
+
return data.reduce((peak, current) => {
|
|
36
|
+
const currentY = current[yProp];
|
|
37
|
+
const peakY = peak[yProp];
|
|
38
|
+
|
|
39
|
+
if (mode === 'max') {
|
|
40
|
+
return currentY > peakY ? current : peak;
|
|
41
|
+
} else {
|
|
42
|
+
return currentY < peakY ? current : peak;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const peakX = $derived(peakPoint ? peakPoint[xProp] : null);
|
|
48
|
+
const peakY = $derived(peakPoint ? peakPoint[yProp] : null);
|
|
49
|
+
|
|
50
|
+
const resolvedDotStyle = $derived<DotStyle>({
|
|
51
|
+
...dotStyle,
|
|
52
|
+
dotFill: resolvedDotFill,
|
|
53
|
+
dotStroke: resolvedDotStroke,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const resolvedTextStyle = $derived<FontStyle>({
|
|
57
|
+
...textStyle,
|
|
58
|
+
fill: resolvedTextFill,
|
|
59
|
+
fontWeight: textStyle?.fontWeight ?? 'bold',
|
|
60
|
+
dy: textStyle?.dy ?? -15,
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
{#if peakPoint}
|
|
65
|
+
<DotMarker
|
|
66
|
+
data={[peakPoint]}
|
|
67
|
+
x={() => peakX}
|
|
68
|
+
y={() => peakY}
|
|
69
|
+
style={resolvedDotStyle}
|
|
70
|
+
/>
|
|
71
|
+
{#if label}
|
|
72
|
+
<TextMarker
|
|
73
|
+
data={[peakPoint]}
|
|
74
|
+
x={() => peakX}
|
|
75
|
+
y={() => peakY}
|
|
76
|
+
text={label}
|
|
77
|
+
style={resolvedTextStyle}
|
|
78
|
+
/>
|
|
79
|
+
{/if}
|
|
80
|
+
{/if}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
2
|
+
import type { DotStyle, FontStyle } from '../../types/plots/styles';
|
|
3
|
+
interface Props extends MarkerProps<Record<string, any>> {
|
|
4
|
+
yProp?: string;
|
|
5
|
+
xProp?: string;
|
|
6
|
+
mode?: 'max' | 'min';
|
|
7
|
+
label?: string;
|
|
8
|
+
dotStyle?: DotStyle;
|
|
9
|
+
textStyle?: FontStyle;
|
|
10
|
+
}
|
|
11
|
+
declare const PeakMarker: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type PeakMarker = ReturnType<typeof PeakMarker>;
|
|
13
|
+
export default PeakMarker;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script lang="ts" generics="TData = Record<string, unknown>">
|
|
2
|
+
import { Text } from 'svelteplot';
|
|
3
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
4
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
5
|
+
import type { FontStyle } from '../../types/plots/styles';
|
|
6
|
+
|
|
7
|
+
interface Props extends MarkerProps<TData> {
|
|
8
|
+
x?: AxisValue | ((d: TData) => AxisValue);
|
|
9
|
+
y?: AxisValue | ((d: TData) => AxisValue);
|
|
10
|
+
text?: string | ((d: TData) => string);
|
|
11
|
+
style?: FontStyle;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
data = [],
|
|
16
|
+
x,
|
|
17
|
+
y,
|
|
18
|
+
text = '',
|
|
19
|
+
style,
|
|
20
|
+
}: Props = $props();
|
|
21
|
+
|
|
22
|
+
const xAccessor = $derived(typeof x === 'function' ? x : () => x ?? 0);
|
|
23
|
+
const yAccessor = $derived(typeof y === 'function' ? y : () => y ?? 0);
|
|
24
|
+
const textAccessor = $derived(typeof text === 'function' ? text : () => text ?? '');
|
|
25
|
+
const displayData = $derived(data.length > 0 ? data : [{} as TData]);
|
|
26
|
+
|
|
27
|
+
const fill = $derived(style?.fill ?? 'currentColor');
|
|
28
|
+
const fontSize = $derived(style?.fontSize ?? 12);
|
|
29
|
+
const fontWeight = $derived(style?.fontWeight ?? 'normal');
|
|
30
|
+
const fontStyleProp = $derived(style?.fontStyle ?? 'normal');
|
|
31
|
+
const textAnchor = $derived(style?.textAnchor ?? 'middle');
|
|
32
|
+
const lineAnchor = $derived(style?.lineAnchor ?? 'middle');
|
|
33
|
+
const dx = $derived(style?.dx ?? 0);
|
|
34
|
+
const dy = $derived(style?.dy ?? 0);
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
{#if text}
|
|
38
|
+
<Text
|
|
39
|
+
data={displayData}
|
|
40
|
+
x={xAccessor}
|
|
41
|
+
y={yAccessor}
|
|
42
|
+
text={textAccessor}
|
|
43
|
+
{fill}
|
|
44
|
+
{fontSize}
|
|
45
|
+
{fontWeight}
|
|
46
|
+
fontStyle={fontStyleProp}
|
|
47
|
+
{textAnchor}
|
|
48
|
+
{lineAnchor}
|
|
49
|
+
stroke={style?.stroke}
|
|
50
|
+
strokeWidth={style?.strokeWidth}
|
|
51
|
+
paintOrder={style?.paintOrder}
|
|
52
|
+
{dx}
|
|
53
|
+
{dy}
|
|
54
|
+
/>
|
|
55
|
+
{/if}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MarkerProps } from '../../types/plots/markers';
|
|
2
|
+
import type { AxisValue } from '../../types/plots/common';
|
|
3
|
+
import type { FontStyle } from '../../types/plots/styles';
|
|
4
|
+
declare function $$render<TData = Record<string, unknown>>(): {
|
|
5
|
+
props: MarkerProps<TData> & {
|
|
6
|
+
x?: AxisValue | ((d: TData) => AxisValue);
|
|
7
|
+
y?: AxisValue | ((d: TData) => AxisValue);
|
|
8
|
+
text?: string | ((d: TData) => string);
|
|
9
|
+
style?: FontStyle;
|
|
10
|
+
};
|
|
11
|
+
exports: {};
|
|
12
|
+
bindings: "";
|
|
13
|
+
slots: {};
|
|
14
|
+
events: {};
|
|
15
|
+
};
|
|
16
|
+
declare class __sveltets_Render<TData = Record<string, unknown>> {
|
|
17
|
+
props(): ReturnType<typeof $$render<TData>>['props'];
|
|
18
|
+
events(): ReturnType<typeof $$render<TData>>['events'];
|
|
19
|
+
slots(): ReturnType<typeof $$render<TData>>['slots'];
|
|
20
|
+
bindings(): "";
|
|
21
|
+
exports(): {};
|
|
22
|
+
}
|
|
23
|
+
interface $$IsomorphicComponent {
|
|
24
|
+
new <TData = Record<string, unknown>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
|
|
25
|
+
$$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
|
|
26
|
+
} & ReturnType<__sveltets_Render<TData>['exports']>;
|
|
27
|
+
<TData = Record<string, unknown>>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
|
|
28
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
29
|
+
}
|
|
30
|
+
declare const TextMarker: $$IsomorphicComponent;
|
|
31
|
+
type TextMarker<TData = Record<string, unknown>> = InstanceType<typeof TextMarker<TData>>;
|
|
32
|
+
export default TextMarker;
|