@fundar/data-chart-telling 1.18.0 → 1.20.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/CHANGELOG.md +53 -0
- package/README.md +2 -1
- package/dist/configuration/config.svelte.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/layout/coordinates/CoordinatesLayout.svelte +3 -1
- package/dist/layout/facet/FacetLayout.svelte +54 -41
- package/dist/layout/geometry/GeometryLayout.svelte +57 -22
- package/dist/layout/geometry/ScaleFreeContext.d.ts +31 -0
- package/dist/layout/geometry/ScaleFreeContext.js +65 -0
- package/dist/layout/geometry/ScaleFreeMarks.svelte +14 -0
- package/dist/layout/geometry/ScaleFreeMarks.svelte.d.ts +7 -0
- package/dist/layout/geometry/ScaleGate.svelte.d.ts +8 -0
- package/dist/layout/geometry/ScaleGate.svelte.js +95 -0
- package/dist/layout/geometry/ScaleGateMarks.svelte +15 -0
- package/dist/layout/geometry/ScaleGateMarks.svelte.d.ts +7 -0
- package/dist/layout/hover/HoverShapes.d.ts +20 -8
- package/dist/layout/hover/HoverShapes.js +119 -59
- package/dist/layout/legend/ContinuousSection.svelte +10 -0
- package/dist/layout/legend/LegendState.svelte.d.ts +13 -1
- package/dist/layout/legend/LegendState.svelte.js +32 -0
- package/dist/layout/margins/Box.d.ts +4 -0
- package/dist/layout/margins/Box.js +14 -0
- package/dist/layout/margins/PlotMargins.svelte.js +26 -1
- package/dist/layout/plot/{Plot.svelte → AbstractPlot.svelte} +83 -6
- package/dist/layout/plot/{Plot.svelte.d.ts → AbstractPlot.svelte.d.ts} +4 -4
- package/dist/layout/plot/PublicPlotContext.d.ts +5 -0
- package/dist/layout/plot/PublicPlotContext.js +7 -0
- package/dist/layout/styles/ValueLabels.d.ts +109 -58
- package/dist/layout/styles/ValueLabels.js +299 -141
- package/dist/markers/MarkerKinds.d.ts +79 -1
- package/dist/markers/MarkerKinds.js +149 -23
- package/dist/markers/area/AreaMarker.svelte +1 -1
- package/dist/markers/band/BandMarker.svelte +2 -1
- package/dist/markers/bar/BarMarker.svelte +8 -6
- package/dist/markers/bollinger/BollingerMarker.svelte +1 -1
- package/dist/markers/box/BoxMarker.svelte +1 -1
- package/dist/markers/dot/DotRadius.d.ts +11 -0
- package/dist/markers/dot/DotRadius.js +21 -0
- package/dist/markers/geo/GeoHoverMarker.svelte +14 -11
- package/dist/markers/labels/CurveLabel.svelte +56 -0
- package/dist/markers/labels/CurveLabel.svelte.d.ts +9 -0
- package/dist/markers/labels/LabelMerge.d.ts +11 -0
- package/dist/markers/labels/LabelMerge.js +87 -0
- package/dist/markers/labels/MarkerLabel.svelte +36 -0
- package/dist/markers/labels/MarkerLabel.svelte.d.ts +10 -0
- package/dist/markers/labels/MarkerLabels.d.ts +52 -0
- package/dist/markers/labels/MarkerLabels.js +97 -0
- package/dist/markers/labels/geometry/BoxGeometry.d.ts +8 -0
- package/dist/markers/labels/geometry/BoxGeometry.js +101 -0
- package/dist/markers/labels/geometry/CurveGeometry.d.ts +34 -0
- package/dist/markers/labels/geometry/CurveGeometry.js +193 -0
- package/dist/markers/labels/geometry/PointGeometry.d.ts +9 -0
- package/dist/markers/labels/geometry/PointGeometry.js +22 -0
- package/dist/markers/labels/layouts/BoxLayout.d.ts +10 -0
- package/dist/markers/labels/layouts/BoxLayout.js +49 -0
- package/dist/markers/labels/layouts/PathLayout.d.ts +11 -0
- package/dist/markers/labels/layouts/PathLayout.js +91 -0
- package/dist/markers/labels/layouts/PointLayout.d.ts +19 -0
- package/dist/markers/labels/layouts/PointLayout.js +94 -0
- package/dist/markers/regression/RegressionMarker.svelte +1 -1
- package/dist/markers/text/Covering.d.ts +13 -0
- package/dist/markers/text/Covering.js +29 -0
- package/dist/markers/text/Declutter.d.ts +24 -3
- package/dist/markers/text/Declutter.js +46 -3
- package/dist/markers/text/TextMarker.svelte +90 -17
- package/dist/markers/text/TextMarker.svelte.d.ts +1 -1
- package/dist/markers/tick/TickMarker.svelte +1 -1
- package/dist/markers/utils/MarkerChannels.d.ts +1 -1
- package/dist/markers/utils/MarkerChannels.js +3 -2
- package/dist/markers/violin/ViolinMarker.svelte +1 -1
- package/dist/markers/waffle/WaffleMarker.svelte +1 -1
- package/dist/phases/context/RowContext.d.ts +2 -0
- package/dist/phases/context/RowContext.js +4 -2
- package/dist/phases/context/rowContextKey.d.ts +2 -0
- package/dist/phases/context/rowContextKey.js +2 -0
- package/dist/phases/markers/MarkerStyles.js +14 -11
- package/dist/phases/markers/MarkersPhase.d.ts +2 -3
- package/dist/phases/markers/MarkersPhase.js +17 -11
- package/dist/phases/sharedScales/SharedStepScales.d.ts +10 -0
- package/dist/phases/sharedScales/SharedStepScales.js +43 -0
- package/dist/phases/statistics/MarkerGrouping.js +5 -32
- package/dist/phases/statistics/MarkerInheritance.d.ts +11 -0
- package/dist/phases/statistics/MarkerInheritance.js +25 -0
- package/dist/phases/statistics/MarkerOrientation.d.ts +26 -0
- package/dist/phases/statistics/MarkerOrientation.js +29 -0
- package/dist/phases/statistics/StatisticsPhase.js +15 -15
- package/dist/phases/transforms/TransformsPhase.js +5 -3
- package/dist/plots/correlation/heatmap/Plot.svelte +2 -2
- package/dist/plots/correlation/heatmap/Plot.svelte.d.ts +0 -1
- package/dist/plots/correlation/heatmap/defaults.js +14 -1
- package/dist/plots/correlation/heatmap/markers.d.ts +0 -6
- package/dist/plots/correlation/heatmap/markers.js +5 -9
- package/dist/plots/correlation/scatter/Plot.svelte +2 -2
- package/dist/plots/correlation/scatter/Plot.svelte.d.ts +0 -1
- package/dist/plots/correlation/scatter/defaults.js +9 -3
- package/dist/plots/correlation/scatter/markers.d.ts +0 -9
- package/dist/plots/correlation/scatter/markers.js +21 -28
- package/dist/plots/distribution/box/BoxSummaries.d.ts +5 -0
- package/dist/plots/distribution/box/BoxSummaries.js +9 -0
- package/dist/plots/distribution/box/Plot.svelte +2 -2
- package/dist/plots/distribution/box/Plot.svelte.d.ts +0 -1
- package/dist/plots/distribution/box/defaults.js +11 -0
- package/dist/plots/distribution/box/markers.js +10 -1
- package/dist/plots/distribution/density/Plot.svelte +2 -2
- package/dist/plots/distribution/density/Plot.svelte.d.ts +0 -1
- package/dist/plots/distribution/density/defaults.js +16 -0
- package/dist/plots/distribution/density/markers.js +5 -1
- package/dist/plots/distribution/histogram/Plot.svelte +2 -2
- package/dist/plots/distribution/histogram/Plot.svelte.d.ts +0 -1
- package/dist/plots/distribution/histogram/defaults.js +16 -11
- package/dist/plots/distribution/histogram/markers.js +3 -3
- package/dist/plots/distribution/pyramid/Plot.svelte +2 -2
- package/dist/plots/distribution/pyramid/Plot.svelte.d.ts +0 -1
- package/dist/plots/distribution/pyramid/defaults.js +9 -2
- package/dist/plots/distribution/pyramid/markers.d.ts +0 -8
- package/dist/plots/distribution/pyramid/markers.js +6 -16
- package/dist/plots/distribution/violin/Plot.svelte +2 -2
- package/dist/plots/distribution/violin/Plot.svelte.d.ts +0 -1
- package/dist/plots/distribution/violin/defaults.js +11 -0
- package/dist/plots/distribution/violin/markers.js +27 -3
- package/dist/plots/evolution/area/Plot.svelte +2 -2
- package/dist/plots/evolution/area/Plot.svelte.d.ts +0 -1
- package/dist/plots/evolution/area/defaults.js +4 -7
- package/dist/plots/evolution/area/markers.js +3 -1
- package/dist/plots/evolution/line/Plot.svelte +2 -2
- package/dist/plots/evolution/line/Plot.svelte.d.ts +0 -1
- package/dist/plots/evolution/line/defaults.js +4 -6
- package/dist/plots/evolution/line/markers.js +3 -1
- package/dist/plots/evolution/slope/Plot.svelte +2 -2
- package/dist/plots/evolution/slope/Plot.svelte.d.ts +0 -1
- package/dist/plots/evolution/slope/defaults.js +4 -3
- package/dist/plots/evolution/slope/markers.d.ts +4 -3
- package/dist/plots/evolution/slope/markers.js +16 -9
- package/dist/plots/evolution/sparkline/Plot.svelte +2 -2
- package/dist/plots/evolution/sparkline/Plot.svelte.d.ts +0 -1
- package/dist/plots/evolution/sparkline/defaults.js +1 -1
- package/dist/plots/evolution/sparkline/markers.js +3 -1
- package/dist/plots/generic/Plot.svelte +42 -0
- package/dist/plots/generic/Plot.svelte.d.ts +25 -0
- package/dist/plots/generic/defaults.d.ts +4 -0
- package/dist/plots/generic/defaults.js +7 -0
- package/dist/plots/map/geo/Core.svelte +29 -6
- package/dist/plots/map/geo/Plot.svelte +40 -12
- package/dist/plots/map/geo/Plot.svelte.d.ts +0 -1
- package/dist/plots/map/geo/phases/data.d.ts +2 -1
- package/dist/plots/map/geo/phases/data.js +8 -2
- package/dist/plots/map/geo/phases/scales.js +6 -2
- package/dist/plots/map/geo/slices.d.ts +27 -3
- package/dist/plots/map/geo/slices.js +58 -5
- package/dist/plots/part-of-a-whole/treemap/Plot.svelte +2 -2
- package/dist/plots/part-of-a-whole/treemap/Plot.svelte.d.ts +0 -1
- package/dist/plots/part-of-a-whole/treemap/defaults.js +2 -2
- package/dist/plots/ranking/bar/Plot.svelte +2 -2
- package/dist/plots/ranking/bar/Plot.svelte.d.ts +0 -1
- package/dist/plots/ranking/bar/defaults.js +13 -3
- package/dist/plots/ranking/bar/markers.js +12 -29
- package/dist/plots/ranking/bullet/Plot.svelte +2 -2
- package/dist/plots/ranking/bullet/Plot.svelte.d.ts +0 -1
- package/dist/plots/ranking/bullet/defaults.js +20 -0
- package/dist/plots/ranking/bullet/markers.js +7 -1
- package/dist/plots/ranking/cleveland/ClevelandMarkers.d.ts +2 -9
- package/dist/plots/ranking/cleveland/ClevelandMarkers.js +65 -47
- package/dist/plots/ranking/cleveland/Plot.svelte +2 -2
- package/dist/plots/ranking/cleveland/Plot.svelte.d.ts +0 -1
- package/dist/plots/ranking/cleveland/defaults.js +33 -2
- package/dist/plots/ranking/dumbbell/Plot.svelte +2 -2
- package/dist/plots/ranking/dumbbell/Plot.svelte.d.ts +0 -1
- package/dist/plots/ranking/forest/Plot.svelte +2 -2
- package/dist/plots/ranking/forest/Plot.svelte.d.ts +0 -1
- package/dist/plots/ranking/lollipop/Plot.svelte +2 -2
- package/dist/plots/ranking/lollipop/Plot.svelte.d.ts +0 -1
- package/dist/types/layout/context.d.ts +2 -0
- package/dist/types/layout/plot.d.ts +2 -0
- package/dist/types/layout/styles/bullet.d.ts +4 -1
- package/dist/types/layout/styles/geo.d.ts +3 -3
- package/dist/types/layout/styles/values.d.ts +51 -11
- package/dist/types/markers/axis/area.d.ts +5 -1
- package/dist/types/markers/axis/bar.d.ts +5 -2
- package/dist/types/markers/axis/bollinger.d.ts +2 -1
- package/dist/types/markers/axis/box.d.ts +2 -1
- package/dist/types/markers/axis/cell.d.ts +4 -1
- package/dist/types/markers/axis/line.d.ts +4 -1
- package/dist/types/markers/axis/rect.d.ts +4 -1
- package/dist/types/markers/axis/regression.d.ts +2 -1
- package/dist/types/markers/axis/tick.d.ts +2 -1
- package/dist/types/markers/axis/trail.d.ts +4 -1
- package/dist/types/markers/axis/violin.d.ts +2 -1
- package/dist/types/markers/axis/waffle.d.ts +5 -1
- package/dist/types/markers/basic/dot.d.ts +4 -1
- package/dist/types/markers/basic/text.d.ts +25 -21
- package/dist/types/markers/channels/commonMarkerConfigWithLabel.d.ts +5 -9
- package/dist/types/markers/channels/commonMarkerConfigWithOrientation.d.ts +5 -0
- package/dist/types/markers/channels/commonMarkerConfigWithOrientation.js +1 -0
- package/dist/types/markers/labels/box.d.ts +57 -0
- package/dist/types/markers/labels/box.js +1 -0
- package/dist/types/markers/labels/common.d.ts +15 -0
- package/dist/types/markers/labels/common.js +1 -0
- package/dist/types/markers/labels/path.d.ts +52 -0
- package/dist/types/markers/labels/path.js +1 -0
- package/dist/types/markers/labels/point.d.ts +40 -0
- package/dist/types/markers/labels/point.js +1 -0
- package/dist/types/markers/traits.d.ts +10 -0
- package/dist/types/phases/markers/phase.d.ts +1 -8
- package/dist/types/phases/statistics/phase.d.ts +8 -3
- package/dist/types/phases/styles/phase.d.ts +15 -3
- package/dist/types/phases/transforms/phase.d.ts +2 -0
- package/dist/types/plots/constants.d.ts +0 -12
- package/dist/types/plots/correlation/heatmap/props.d.ts +3 -2
- package/dist/types/plots/correlation/scatter/props.d.ts +3 -2
- package/dist/types/plots/data/geo.d.ts +19 -5
- package/dist/types/plots/distribution/box/props.d.ts +6 -2
- package/dist/types/plots/distribution/density/props.d.ts +2 -1
- package/dist/types/plots/distribution/histogram/props.d.ts +3 -2
- package/dist/types/plots/distribution/pyramid/props.d.ts +3 -2
- package/dist/types/plots/distribution/violin/props.d.ts +4 -1
- package/dist/types/plots/evolution/area/props.d.ts +3 -2
- package/dist/types/plots/evolution/line/props.d.ts +3 -2
- package/dist/types/plots/generic/props.d.ts +16 -0
- package/dist/types/plots/generic/props.js +1 -0
- package/dist/types/plots/generic/state.d.ts +4 -0
- package/dist/types/plots/generic/state.js +1 -0
- package/dist/types/plots/map/geo/props.d.ts +9 -3
- package/dist/types/plots/map/geo/state.d.ts +3 -1
- package/dist/types/plots/part-of-a-whole/treemap/props.d.ts +4 -2
- package/dist/types/plots/ranking/bar/props.d.ts +3 -2
- package/dist/types/plots/ranking/cleveland/props.d.ts +3 -2
- package/dist/types/plots/ranking/dumbbell/props.d.ts +3 -2
- package/dist/types/plots/ranking/forest/props.d.ts +5 -2
- package/dist/types/plots/ranking/lollipop/props.d.ts +3 -2
- package/dist/utils/ConfigEquality.d.ts +11 -0
- package/dist/utils/ConfigEquality.js +37 -0
- package/docs/architecture.md +9 -9
- package/docs/facets.md +12 -0
- package/docs/geo.md +35 -7
- package/docs/legend.md +6 -0
- package/docs/markers.md +2 -4
- package/docs/plots/ranking/bar.md +1 -1
- package/docs/plots/ranking/cleveland.md +1 -1
- package/docs/state.md +1 -1
- package/docs/styles-and-segments.md +1 -14
- package/docs/timeline.md +1 -1
- package/docs/transforms-and-statistics.md +1 -1
- package/docs/value-labels.md +159 -0
- package/examples/BarValues.svelte +1 -1
- package/llms-full.txt +5 -5
- package/llms.txt +1 -0
- package/package.json +3 -1
- package/dist/markers/utils/BoxLabel.d.ts +0 -58
- package/dist/markers/utils/BoxLabel.js +0 -175
- package/dist/markers/utils/MarkerLabel.svelte +0 -33
- package/dist/markers/utils/MarkerLabel.svelte.d.ts +0 -10
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { TextMarkerConfig } from '../../types/markers/common';
|
|
2
|
-
import type { TextLabelConfig } from '../../types/markers/basic/text';
|
|
3
|
-
/** Where a row's edge along an axis is: a field of the rows, the symbol a transform keyed it by, a function of the row, or a literal. */
|
|
4
|
-
type Edge = unknown;
|
|
5
|
-
/** The edges of the box each row spans, in the data's own terms. */
|
|
6
|
-
export type BoxChannels = {
|
|
7
|
-
x1: Edge;
|
|
8
|
-
x2: Edge;
|
|
9
|
-
y1: Edge;
|
|
10
|
-
y2: Edge;
|
|
11
|
-
};
|
|
12
|
-
/** The scales a box is measured on. */
|
|
13
|
-
export type BoxScales = Record<string, {
|
|
14
|
-
type?: string;
|
|
15
|
-
fn: any;
|
|
16
|
-
} | undefined>;
|
|
17
|
-
/** The pixel size of the box of a row, for the markers whose boxes are bands of a category axis rather than edges. */
|
|
18
|
-
export type BoxSizer = (row: unknown, scales: BoxScales) => {
|
|
19
|
-
width: number;
|
|
20
|
-
height: number;
|
|
21
|
-
} | undefined;
|
|
22
|
-
/** The `text` marker that labels the boxes a marker draws, and where each label's box is. */
|
|
23
|
-
export type BoxLabelMarker = {
|
|
24
|
-
marker: TextMarkerConfig;
|
|
25
|
-
box: BoxChannels | BoxSizer;
|
|
26
|
-
};
|
|
27
|
-
/** What a marker has to say for its boxes to be labelled. */
|
|
28
|
-
export type Labelled = {
|
|
29
|
-
type?: string;
|
|
30
|
-
data?: unknown[];
|
|
31
|
-
label?: TextLabelConfig;
|
|
32
|
-
x?: Edge;
|
|
33
|
-
y?: Edge;
|
|
34
|
-
x1?: Edge;
|
|
35
|
-
x2?: Edge;
|
|
36
|
-
y1?: Edge;
|
|
37
|
-
y2?: Edge;
|
|
38
|
-
isHorizontal?: boolean;
|
|
39
|
-
role?: string;
|
|
40
|
-
thickness?: number;
|
|
41
|
-
/** The marker's styles: the insets of a cell or a bar are read off them. */
|
|
42
|
-
styles?: object;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* How a marker that draws a box per row writes a label in each: the `text` marker for them, centred on the box,
|
|
46
|
-
* and where the box is for it to fit to. A `rect` says it with its edges, a `cell` is a band of each axis, and a bar
|
|
47
|
-
* or a waffle is a band of its category axis and the stretch of its value.
|
|
48
|
-
*/
|
|
49
|
-
export declare class BoxLabel {
|
|
50
|
-
#private;
|
|
51
|
-
/** `undefined` when the marker has no label, or does not say where its boxes are. */
|
|
52
|
-
static of(marker: Labelled, plot?: {
|
|
53
|
-
isHorizontal?: boolean;
|
|
54
|
-
scales?: () => BoxScales | undefined;
|
|
55
|
-
gap?: number;
|
|
56
|
-
}): BoxLabelMarker | undefined;
|
|
57
|
-
}
|
|
58
|
-
export {};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
const read = (edge) => (row) => typeof edge === 'function'
|
|
2
|
-
? edge(row)
|
|
3
|
-
: typeof edge === 'string' || typeof edge === 'symbol'
|
|
4
|
-
? row?.[edge]
|
|
5
|
-
: edge;
|
|
6
|
-
/** The middle of two positions along an axis, whether numbers or dates. */
|
|
7
|
-
const middle = (from, to) => from instanceof Date || to instanceof Date
|
|
8
|
-
? new Date((Number(from) + Number(to)) / 2)
|
|
9
|
-
: (Number(from) + Number(to)) / 2;
|
|
10
|
-
const bandwidth = (scale) => scale?.type === 'band' ? Number(scale.fn.bandwidth()) : undefined;
|
|
11
|
-
const distance = (scale, from, to) => scale ? Math.abs(Number(scale.fn(to)) - Number(scale.fn(from))) : undefined;
|
|
12
|
-
/**
|
|
13
|
-
* How a marker that draws a box per row writes a label in each: the `text` marker for them, centred on the box,
|
|
14
|
-
* and where the box is for it to fit to. A `rect` says it with its edges, a `cell` is a band of each axis, and a bar
|
|
15
|
-
* or a waffle is a band of its category axis and the stretch of its value.
|
|
16
|
-
*/
|
|
17
|
-
export class BoxLabel {
|
|
18
|
-
/** `undefined` when the marker has no label, or does not say where its boxes are. */
|
|
19
|
-
static of(marker, plot = {}) {
|
|
20
|
-
if (!marker.label)
|
|
21
|
-
return undefined;
|
|
22
|
-
const own = BoxLabel.#shape(marker, plot.isHorizontal ?? marker.isHorizontal ?? false);
|
|
23
|
-
if (!own)
|
|
24
|
-
return undefined;
|
|
25
|
-
const { anchor, outside, gap, ...label } = marker.label;
|
|
26
|
-
const size = typeof own.box === 'function' ? own.box : own.size;
|
|
27
|
-
const placed = BoxLabel.#anchored({
|
|
28
|
-
anchor,
|
|
29
|
-
outside,
|
|
30
|
-
gap: gap ?? plot.gap
|
|
31
|
-
}, label, size, plot.scales);
|
|
32
|
-
return {
|
|
33
|
-
box: own.box,
|
|
34
|
-
marker: {
|
|
35
|
-
// A label outside its shape has nothing to fit to.
|
|
36
|
-
fit: !outside,
|
|
37
|
-
...label,
|
|
38
|
-
...placed,
|
|
39
|
-
type: 'text',
|
|
40
|
-
data: marker.data,
|
|
41
|
-
x: own.x,
|
|
42
|
-
y: own.y
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* What puts a label at `anchor` of its shape: the pixels it is moved from the middle - a function of the row, for
|
|
48
|
-
* the size of its shape is the row's own - and the sides of its point it is written on. `{}` for the middle.
|
|
49
|
-
*/
|
|
50
|
-
static #anchored(where, label, size, scales) {
|
|
51
|
-
const { anchor = 'middle', outside = false } = where;
|
|
52
|
-
if (anchor === 'middle' || !size)
|
|
53
|
-
return {};
|
|
54
|
-
const gap = where.gap ?? 4;
|
|
55
|
-
const horizontal = anchor.endsWith('left') ? -1 : anchor.endsWith('right') ? 1 : 0;
|
|
56
|
-
const vertical = anchor.startsWith('top') ? -1 : anchor.startsWith('bottom') ? 1 : 0;
|
|
57
|
-
// Beyond an edge only means something for an edge: a corner is inside its shape.
|
|
58
|
-
const beyond = outside && horizontal * vertical === 0;
|
|
59
|
-
const away = beyond ? 1 : -1;
|
|
60
|
-
const move = (axis, side, row) => {
|
|
61
|
-
// Read when a label is drawn, not when its marker is made: the scales move as the labels register.
|
|
62
|
-
const current = scales?.();
|
|
63
|
-
const box = current ? size(row, current) : undefined;
|
|
64
|
-
return box ? side * (box[axis] / 2 + away * gap) : 0;
|
|
65
|
-
};
|
|
66
|
-
// A number of the label's own (or its styles') is added to the move: it is the push from the anchor.
|
|
67
|
-
const own = (value, fallback) => Number(typeof value === 'number' ? value : (fallback ?? 0));
|
|
68
|
-
const baseX = own(label.dx, label.styles?.dx);
|
|
69
|
-
const baseY = own(label.dy, label.styles?.dy);
|
|
70
|
-
return {
|
|
71
|
-
dx: horizontal === 0 ? label.dx : (row) => baseX + move('width', horizontal, row),
|
|
72
|
-
dy: vertical === 0 ? label.dy : (row) => baseY + move('height', vertical, row),
|
|
73
|
-
styles: {
|
|
74
|
-
...label.styles,
|
|
75
|
-
textAnchor: label.styles?.textAnchor ??
|
|
76
|
-
(horizontal === 0 ? 'middle' : (horizontal === 1) === beyond ? 'start' : 'end'),
|
|
77
|
-
lineAnchor: label.styles?.lineAnchor ??
|
|
78
|
-
(vertical === 0 ? 'middle' : (vertical === 1) === beyond ? 'top' : 'bottom')
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** A style of the marker, when it is a number: a function of the row says nothing of a box in general. */
|
|
83
|
-
static #style(marker, name) {
|
|
84
|
-
const value = marker.styles?.[name];
|
|
85
|
-
return typeof value === 'number' ? value : undefined;
|
|
86
|
-
}
|
|
87
|
-
static #shape(marker, isHorizontal) {
|
|
88
|
-
if (marker.type === 'cell')
|
|
89
|
-
return BoxLabel.#cell(marker);
|
|
90
|
-
if (marker.type === 'bar') {
|
|
91
|
-
return marker.role === 'segment'
|
|
92
|
-
? BoxLabel.#bar(marker, marker.isHorizontal ?? false)
|
|
93
|
-
: undefined;
|
|
94
|
-
}
|
|
95
|
-
if (marker.type === 'waffle')
|
|
96
|
-
return BoxLabel.#bar(marker, isHorizontal);
|
|
97
|
-
return BoxLabel.#edges(marker);
|
|
98
|
-
}
|
|
99
|
-
/** A rectangle: the box is between its edges. */
|
|
100
|
-
static #edges({ x, y, x1, x2, y1, y2 }) {
|
|
101
|
-
// A side with a value and no start, next to one with both its edges, runs from zero to it, as a bar does.
|
|
102
|
-
if (y1 === undefined &&
|
|
103
|
-
y2 === undefined &&
|
|
104
|
-
y !== undefined &&
|
|
105
|
-
x1 !== undefined &&
|
|
106
|
-
x2 !== undefined) {
|
|
107
|
-
[y1, y2] = [0, y];
|
|
108
|
-
}
|
|
109
|
-
if (x1 === undefined &&
|
|
110
|
-
x2 === undefined &&
|
|
111
|
-
x !== undefined &&
|
|
112
|
-
y1 !== undefined &&
|
|
113
|
-
y2 !== undefined) {
|
|
114
|
-
[x1, x2] = [0, x];
|
|
115
|
-
}
|
|
116
|
-
if ([x1, x2, y1, y2].some((edge) => edge === undefined))
|
|
117
|
-
return undefined;
|
|
118
|
-
const [left, right, top, bottom] = [x1, x2, y1, y2].map(read);
|
|
119
|
-
const size = (row, scales) => {
|
|
120
|
-
const [width, height] = [
|
|
121
|
-
distance(scales.x, left(row), right(row)),
|
|
122
|
-
distance(scales.y, top(row), bottom(row))
|
|
123
|
-
];
|
|
124
|
-
return width === undefined || height === undefined ? undefined : { width, height };
|
|
125
|
-
};
|
|
126
|
-
return {
|
|
127
|
-
box: { x1, x2, y1, y2 },
|
|
128
|
-
size,
|
|
129
|
-
x: (row) => middle(left(row), right(row)),
|
|
130
|
-
y: (row) => middle(top(row), bottom(row))
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/** A cell: a band of each axis, less its inset. */
|
|
134
|
-
static #cell(marker) {
|
|
135
|
-
if (marker.x === undefined || marker.y === undefined)
|
|
136
|
-
return undefined;
|
|
137
|
-
const inset = Number(BoxLabel.#style(marker, 'inset') ?? 0.5);
|
|
138
|
-
const box = (_, scales) => {
|
|
139
|
-
const [width, height] = [bandwidth(scales.x), bandwidth(scales.y)];
|
|
140
|
-
return width === undefined || height === undefined
|
|
141
|
-
? undefined
|
|
142
|
-
: { width: width - 2 * inset, height: height - 2 * inset };
|
|
143
|
-
};
|
|
144
|
-
return { box: box, x: marker.x, y: marker.y };
|
|
145
|
-
}
|
|
146
|
-
/** A bar or a waffle: a band of the category axis, as wide as its insets leave it, and as long as its value. */
|
|
147
|
-
static #bar(marker, isHorizontal) {
|
|
148
|
-
const [category, from, to] = isHorizontal
|
|
149
|
-
? [marker.y, marker.x1, marker.x2]
|
|
150
|
-
: [marker.x, marker.y1, marker.y2];
|
|
151
|
-
const value = isHorizontal ? marker.x : marker.y;
|
|
152
|
-
// Without both ends, the bar runs from zero to its value.
|
|
153
|
-
const [start, end] = from !== undefined && to !== undefined ? [from, to] : [0, value];
|
|
154
|
-
if (category === undefined || end === undefined)
|
|
155
|
-
return undefined;
|
|
156
|
-
const [first, last] = [start, end].map(read);
|
|
157
|
-
const [before, after] = isHorizontal
|
|
158
|
-
? [BoxLabel.#style(marker, 'insetTop'), BoxLabel.#style(marker, 'insetBottom')]
|
|
159
|
-
: [BoxLabel.#style(marker, 'insetLeft'), BoxLabel.#style(marker, 'insetRight')];
|
|
160
|
-
const middleOf = (row) => middle(first(row), last(row));
|
|
161
|
-
const box = (row, scales) => {
|
|
162
|
-
const band = bandwidth(isHorizontal ? scales.y : scales.x);
|
|
163
|
-
const length = distance(isHorizontal ? scales.x : scales.y, first(row), last(row));
|
|
164
|
-
if (band === undefined || length === undefined)
|
|
165
|
-
return undefined;
|
|
166
|
-
const thickness = marker.thickness ?? band * (1 - Number(before ?? 0) - Number(after ?? 0));
|
|
167
|
-
return isHorizontal
|
|
168
|
-
? { width: length, height: thickness }
|
|
169
|
-
: { width: thickness, height: length };
|
|
170
|
-
};
|
|
171
|
-
return isHorizontal
|
|
172
|
-
? { box: box, x: middleOf, y: category }
|
|
173
|
-
: { box: box, x: category, y: middleOf };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import TextMarker from '../text/TextMarker.svelte';
|
|
3
|
-
import { getConfiguration } from '../../configuration/config.svelte';
|
|
4
|
-
import { usePlot } from '../../layout/plot/usePlot';
|
|
5
|
-
import { BoxLabel, type Labelled } from './BoxLabel';
|
|
6
|
-
import { MARK_EVENTS } from '../../types/markers/channels/commonMarkerEvents';
|
|
7
|
-
import type { TextLabelConfig } from '../../types/markers/basic/text';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The `label` of a marker that draws a box per row: a `text` marker anchored in each box and fitted to it. A marker
|
|
11
|
-
* with a label only has to render `<MarkerLabel {marker} />` after its own shapes. Nothing is drawn without a
|
|
12
|
-
* `label`, or when the marker does not say where its boxes are.
|
|
13
|
-
*/
|
|
14
|
-
const { marker }: { marker: Labelled & { label?: TextLabelConfig } } = $props();
|
|
15
|
-
const plot = usePlot();
|
|
16
|
-
const cfg = $derived(getConfiguration());
|
|
17
|
-
|
|
18
|
-
const labelled = $derived(
|
|
19
|
-
BoxLabel.of(marker, {
|
|
20
|
-
isHorizontal: plot.axes?.isHorizontal,
|
|
21
|
-
gap: cfg.text.label.gap,
|
|
22
|
-
scales: () => plot.svelteplot.scales as never
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
/** A label with a handler of its own listens for the pointer; one without leaves it to the shape under it. */
|
|
26
|
-
const listens = $derived(MARK_EVENTS.some((name) => !!marker.label?.[name]));
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
{#if labelled}
|
|
30
|
-
<g pointer-events={listens ? undefined : 'none'}>
|
|
31
|
-
<TextMarker marker={labelled.marker} box={labelled.box} />
|
|
32
|
-
</g>
|
|
33
|
-
{/if}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Labelled } from './BoxLabel';
|
|
2
|
-
import type { TextLabelConfig } from '../../types/markers/basic/text';
|
|
3
|
-
type $$ComponentProps = {
|
|
4
|
-
marker: Labelled & {
|
|
5
|
-
label?: TextLabelConfig;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
declare const MarkerLabel: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
-
type MarkerLabel = ReturnType<typeof MarkerLabel>;
|
|
10
|
-
export default MarkerLabel;
|