@d3plus/core 4.11.0 → 4.12.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/es/internal.js +15 -5
- package/es/src/charts/Alluvial/emit.js +2 -2
- package/es/src/charts/Alluvial/index.js +7 -1
- package/es/src/charts/Alluvial/titles.js +24 -4
- package/es/src/charts/ArcDiagram/emit.js +27 -13
- package/es/src/charts/ArcDiagram/events.js +6 -2
- package/es/src/charts/ArcDiagram/index.js +2 -0
- package/es/src/charts/BarChart/index.js +3 -10
- package/es/src/charts/Calendar/index.js +2 -0
- package/es/src/charts/Candlestick/index.js +4 -10
- package/es/src/charts/Gantt/applyLayout.js +2 -4
- package/es/src/charts/Geomap/flowEmit.js +11 -6
- package/es/src/charts/Hexbin/index.js +2 -0
- package/es/src/charts/Icicle/index.js +3 -1
- package/es/src/charts/Matrix/applyLayout.js +20 -9
- package/es/src/charts/Matrix/index.js +19 -1
- package/es/src/charts/Network/applyLayout.js +36 -5
- package/es/src/charts/Network/bundle.js +5 -4
- package/es/src/charts/Network/emit.js +39 -40
- package/es/src/charts/Network/graph.js +34 -5
- package/es/src/charts/Network/graphFluent.js +5 -3
- package/es/src/charts/Network/index.js +6 -1
- package/es/src/charts/Pack/applyLayout.js +16 -5
- package/es/src/charts/Pack/emit.js +15 -8
- package/es/src/charts/Pack/groupRows.js +61 -0
- package/es/src/charts/Pack/index.js +3 -0
- package/es/src/charts/Pack/neutralPaint.js +20 -0
- package/es/src/charts/Pack/nodeNames.js +35 -0
- package/es/src/charts/ParallelCoordinates/axes.js +22 -22
- package/es/src/charts/ParallelCoordinates/chrome.js +18 -0
- package/es/src/charts/ParallelCoordinates/index.js +3 -1
- package/es/src/charts/ParallelCoordinates/titles.js +17 -9
- package/es/src/charts/Pie/emit.js +9 -1
- package/es/src/charts/Pie/index.js +10 -0
- package/es/src/charts/Plot/areaEnter.js +68 -0
- package/es/src/charts/Plot/draw.js +26 -12
- package/es/src/charts/Plot/index.js +4 -10
- package/es/src/charts/Plot/lineMarkerKeys.js +19 -0
- package/es/src/charts/Plot/plotInit.js +6 -0
- package/es/src/charts/Plot/shapeLabelLegend.js +67 -0
- package/es/src/charts/Plot/sharedHover.js +2 -1
- package/es/src/charts/Plot/sharedTooltip.js +13 -3
- package/es/src/charts/PolarArea/index.js +2 -1
- package/es/src/charts/Priestley/applyLayout.js +11 -7
- package/es/src/charts/Priestley/index.js +0 -2
- package/es/src/charts/Priestley/timeAxis.js +11 -8
- package/es/src/charts/Pyramid/gutter.js +52 -16
- package/es/src/charts/Pyramid/index.js +55 -7
- package/es/src/charts/Pyramid/scene.js +4 -4
- package/es/src/charts/Radar/applyLayout.js +31 -33
- package/es/src/charts/Radar/axisDecorations.js +29 -17
- package/es/src/charts/Radar/curvedLabels.js +43 -2
- package/es/src/charts/Radar/emit.js +30 -15
- package/es/src/charts/Radar/index.js +41 -2
- package/es/src/charts/Radar/points.js +85 -0
- package/es/src/charts/RadialBar/emit.js +6 -1
- package/es/src/charts/RadialBar/index.js +10 -0
- package/es/src/charts/RadialMatrix/applyLayout.js +115 -31
- package/es/src/charts/RadialMatrix/index.js +15 -2
- package/es/src/charts/Rings/applyLayout.js +11 -150
- package/es/src/charts/Rings/emit.js +80 -40
- package/es/src/charts/Rings/index.js +27 -4
- package/es/src/charts/Rings/ringsCurves.js +156 -0
- package/es/src/charts/Rings/ringsParallel.js +20 -3
- package/es/src/charts/Rings/ringsPlacement.js +152 -0
- package/es/src/charts/Rings/ringsSizing.js +61 -38
- package/es/src/charts/Sankey/applyLayout.js +18 -4
- package/es/src/charts/Sankey/index.js +7 -1
- package/es/src/charts/Sunburst/emit.js +9 -1
- package/es/src/charts/Sunburst/index.js +13 -1
- package/es/src/charts/Tree/applyLayout.js +44 -14
- package/es/src/charts/Tree/emit.js +5 -5
- package/es/src/charts/Tree/index.js +10 -12
- package/es/src/charts/Tree/keys.js +33 -0
- package/es/src/charts/Tree/nodeLabel.js +15 -0
- package/es/src/charts/Treemap/emitGroupHeaders.js +3 -5
- package/es/src/charts/definition/makeChart.js +6 -2
- package/es/src/charts/drawSteps/minimap.js +4 -20
- package/es/src/charts/drawSteps/zoomActions.js +36 -0
- package/es/src/charts/drawSteps/zoomControls.js +31 -18
- package/es/src/charts/drawSteps/zoomControlsMarkup.js +23 -4
- package/es/src/charts/drawSteps/zoomDrag.js +188 -0
- package/es/src/charts/drawSteps/zoomFit.js +69 -0
- package/es/src/charts/events/click.legend.js +4 -2
- package/es/src/charts/events/click.shape.js +5 -3
- package/es/src/charts/events/mouseenter.js +6 -16
- package/es/src/charts/events/mouseleave.js +9 -2
- package/es/src/charts/events/mousemove.legend.js +28 -32
- package/es/src/charts/events/mousemove.shape.js +44 -44
- package/es/src/charts/features/axes.js +15 -4
- package/es/src/charts/features/axesFinal.js +7 -2
- package/es/src/charts/features/axesMeasure.js +26 -8
- package/es/src/charts/features/axisTooltip.js +138 -0
- package/es/src/charts/features/centerLabel.js +177 -0
- package/es/src/charts/features/colorScaleBivariate.js +83 -0
- package/es/src/charts/features/colorScaleBucket.js +18 -0
- package/es/src/charts/features/colorScaleHover.js +30 -5
- package/es/src/charts/features/colorScaleLimit.js +73 -0
- package/es/src/charts/features/colorScaleTooltip.js +77 -0
- package/es/src/charts/features/colorScaleTop.js +61 -0
- package/es/src/charts/features/curvedArrows.js +33 -0
- package/es/src/charts/features/depthKey.js +26 -0
- package/es/src/charts/features/edgeArrows.js +61 -2
- package/es/src/charts/features/featuresColorScale.js +57 -16
- package/es/src/charts/features/hoverTicks.js +41 -0
- package/es/src/charts/features/idleQueue.js +72 -0
- package/es/src/charts/features/linkInteraction.js +59 -7
- package/es/src/charts/features/networkMeasures.js +241 -0
- package/es/src/charts/features/nodeStats.js +309 -0
- package/es/src/charts/features/plotEndLabels.js +28 -7
- package/es/src/charts/features/plotPaint.js +9 -2
- package/es/src/charts/features/shapeEmit.js +7 -1
- package/es/src/charts/features/textHalo.js +3 -2
- package/es/src/charts/partition/chartFields.js +12 -3
- package/es/src/charts/partition/interaction.js +10 -5
- package/es/src/charts/pipeline/insetPlacement.js +8 -3
- package/es/src/charts/polar/chrome.js +81 -9
- package/es/src/charts/polar/config.js +4 -0
- package/es/src/charts/polar/wedgeLayout.js +2 -1
- package/es/src/charts/viz/Viz.js +24 -15
- package/es/src/charts/viz/VizBase.js +39 -4
- package/es/src/charts/viz/backgroundInk.js +10 -0
- package/es/src/charts/viz/emphasis.js +14 -0
- package/es/src/charts/viz/fillStroke.js +10 -0
- package/es/src/charts/viz/interactionOpacity.js +115 -32
- package/es/src/charts/viz/reportDrawError.js +15 -0
- package/es/src/charts/viz/setCursor.js +29 -0
- package/es/src/charts/viz/tooltipEnabled.js +38 -0
- package/es/src/charts/viz/userClick.js +34 -0
- package/es/src/charts/viz/vizDataPolling.js +0 -1
- package/es/src/charts/viz/vizDefaults.js +13 -34
- package/es/src/charts/viz/vizFields.js +6 -1
- package/es/src/charts/viz/vizRender.js +35 -5
- package/es/src/charts/viz/vizVisibility.js +12 -2
- package/es/src/components/Axis/Axis.js +29 -2
- package/es/src/components/Axis/axisBreak.js +29 -7
- package/es/src/components/Axis/axisDefaults.js +11 -0
- package/es/src/components/Axis/axisLabelKinds.js +36 -0
- package/es/src/components/Axis/axisLabelLineHeight.js +19 -0
- package/es/src/components/Axis/axisLabelRoom.js +37 -0
- package/es/src/components/Axis/axisLabelSize.js +171 -0
- package/es/src/components/Axis/axisLabelThinning.js +98 -4
- package/es/src/components/Axis/axisLayout.js +71 -46
- package/es/src/components/Axis/axisLayoutLabels.js +82 -140
- package/es/src/components/Axis/axisLayoutScale.js +9 -10
- package/es/src/components/Axis/axisLimit.js +27 -0
- package/es/src/components/Axis/axisMaxSize.js +39 -0
- package/es/src/components/Axis/axisRender.js +20 -8
- package/es/src/components/Axis/axisRounding.js +16 -1
- package/es/src/components/Axis/axisScene.js +11 -2
- package/es/src/components/Axis/axisTitle.js +53 -0
- package/es/src/components/Axis/axisTooltipTargets.js +128 -0
- package/es/src/components/ColorScale/ColorScale.js +62 -18
- package/es/src/components/ColorScale/bivariateRender.js +353 -0
- package/es/src/components/ColorScale/bivariateScale.js +150 -0
- package/es/src/components/ColorScale/colorScaleRender.js +32 -2
- package/es/src/components/ColorScale/colorScaleSwatchTooltips.js +77 -0
- package/es/src/components/Legend/Legend.js +10 -2
- package/es/src/components/Legend/legendCut.js +108 -0
- package/es/src/components/Legend/legendRender.js +38 -13
- package/es/src/components/TextBox.js +5 -2
- package/es/src/components/Timeline/timelineRender.js +2 -1
- package/es/src/components/textBoxScene.js +3 -0
- package/es/src/components/textEllipsis.js +7 -0
- package/es/src/components/tooltipDom.js +8 -5
- package/es/src/fluent.js +48 -0
- package/es/src/utils/BaseClass.js +7 -2
- package/es/src/utils/configValue.js +9 -0
- package/package.json +10 -10
- package/types/index.d.ts +1 -1
- package/types/internal.d.ts +22 -5
- package/types/src/charts/Alluvial/titles.d.ts +16 -3
- package/types/src/charts/ArcDiagram/emit.d.ts +3 -2
- package/types/src/charts/ArcDiagram/events.d.ts +2 -1
- package/types/src/charts/Geomap/flowEmit.d.ts +3 -2
- package/types/src/charts/Matrix/applyLayout.d.ts +4 -2
- package/types/src/charts/Network/applyLayout.d.ts +11 -0
- package/types/src/charts/Network/bundle.d.ts +3 -1
- package/types/src/charts/Network/graph.d.ts +12 -4
- package/types/src/charts/Pack/applyLayout.d.ts +2 -0
- package/types/src/charts/Pack/groupRows.d.ts +46 -0
- package/types/src/charts/Pack/index.d.ts +3 -0
- package/types/src/charts/Pack/neutralPaint.d.ts +14 -0
- package/types/src/charts/Pack/nodeNames.d.ts +23 -0
- package/types/src/charts/ParallelCoordinates/chrome.d.ts +12 -0
- package/types/src/charts/ParallelCoordinates/index.d.ts +1 -0
- package/types/src/charts/ParallelCoordinates/titles.d.ts +7 -2
- package/types/src/charts/Plot/areaEnter.d.ts +34 -0
- package/types/src/charts/Plot/index.d.ts +4 -10
- package/types/src/charts/Plot/lineMarkerKeys.d.ts +11 -0
- package/types/src/charts/Plot/shapeLabelLegend.d.ts +19 -0
- package/types/src/charts/Plot/sharedTooltip.d.ts +7 -1
- package/types/src/charts/Priestley/timeAxis.d.ts +7 -4
- package/types/src/charts/Pyramid/gutter.d.ts +28 -6
- package/types/src/charts/Pyramid/scene.d.ts +1 -1
- package/types/src/charts/Radar/applyLayout.d.ts +2 -3
- package/types/src/charts/Radar/axisDecorations.d.ts +5 -2
- package/types/src/charts/Radar/curvedLabels.d.ts +35 -0
- package/types/src/charts/Radar/emit.d.ts +5 -2
- package/types/src/charts/Radar/index.d.ts +7 -2
- package/types/src/charts/Radar/points.d.ts +50 -0
- package/types/src/charts/RadialMatrix/applyLayout.d.ts +6 -4
- package/types/src/charts/Rings/emit.d.ts +24 -2
- package/types/src/charts/Rings/index.d.ts +4 -2
- package/types/src/charts/Rings/ringsCurves.d.ts +50 -0
- package/types/src/charts/Rings/ringsGraph.d.ts +29 -5
- package/types/src/charts/Rings/ringsParallel.d.ts +4 -2
- package/types/src/charts/Rings/ringsPlacement.d.ts +47 -0
- package/types/src/charts/Rings/ringsSizing.d.ts +36 -9
- package/types/src/charts/Tree/applyLayout.d.ts +20 -0
- package/types/src/charts/Tree/keys.d.ts +25 -0
- package/types/src/charts/Tree/nodeLabel.d.ts +11 -0
- package/types/src/charts/definition/ChartDefinition.d.ts +13 -0
- package/types/src/charts/definition/makeChart.d.ts +2 -2
- package/types/src/charts/drawSteps/zoomActions.d.ts +30 -0
- package/types/src/charts/drawSteps/zoomControls.d.ts +15 -0
- package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +16 -1
- package/types/src/charts/drawSteps/zoomDrag.d.ts +71 -0
- package/types/src/charts/drawSteps/zoomFit.d.ts +30 -0
- package/types/src/charts/features/axisTooltip.d.ts +49 -0
- package/types/src/charts/features/centerLabel.d.ts +75 -0
- package/types/src/charts/features/colorScaleBivariate.d.ts +50 -0
- package/types/src/charts/features/colorScaleBucket.d.ts +10 -0
- package/types/src/charts/features/colorScaleHover.d.ts +13 -3
- package/types/src/charts/features/colorScaleLimit.d.ts +60 -0
- package/types/src/charts/features/colorScaleTooltip.d.ts +43 -0
- package/types/src/charts/features/colorScaleTop.d.ts +30 -0
- package/types/src/charts/features/curvedArrows.d.ts +14 -0
- package/types/src/charts/features/depthKey.d.ts +19 -0
- package/types/src/charts/features/edgeArrows.d.ts +29 -2
- package/types/src/charts/features/hoverTicks.d.ts +30 -0
- package/types/src/charts/features/idleQueue.d.ts +46 -0
- package/types/src/charts/features/linkInteraction.d.ts +13 -4
- package/types/src/charts/features/networkMeasures.d.ts +53 -0
- package/types/src/charts/features/nodeStats.d.ts +93 -0
- package/types/src/charts/features/plotEndLabels.d.ts +14 -1
- package/types/src/charts/features/textHalo.d.ts +4 -3
- package/types/src/charts/partition/chartFields.d.ts +6 -1
- package/types/src/charts/pipeline/insetPlacement.d.ts +6 -0
- package/types/src/charts/polar/chrome.d.ts +19 -6
- package/types/src/charts/viz/Viz.d.ts +10 -3
- package/types/src/charts/viz/VizBase.d.ts +31 -2
- package/types/src/charts/viz/backgroundInk.d.ts +8 -0
- package/types/src/charts/viz/emphasis.d.ts +17 -0
- package/types/src/charts/viz/fillStroke.d.ts +7 -0
- package/types/src/charts/viz/reportDrawError.d.ts +12 -0
- package/types/src/charts/viz/setCursor.d.ts +26 -0
- package/types/src/charts/viz/tooltipEnabled.d.ts +31 -0
- package/types/src/charts/viz/userClick.d.ts +35 -0
- package/types/src/charts/viz/vizFields.d.ts +5 -0
- package/types/src/charts/viz/vizTypes.d.ts +16 -0
- package/types/src/charts/viz/vizVisibility.d.ts +7 -0
- package/types/src/components/Axis/Axis.d.ts +33 -3
- package/types/src/components/Axis/axisBreak.d.ts +19 -3
- package/types/src/components/Axis/axisDefaults.d.ts +12 -0
- package/types/src/components/Axis/axisLabelKinds.d.ts +22 -0
- package/types/src/components/Axis/axisLabelLineHeight.d.ts +27 -0
- package/types/src/components/Axis/axisLabelRoom.d.ts +17 -0
- package/types/src/components/Axis/axisLabelSize.d.ts +82 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +38 -2
- package/types/src/components/Axis/axisLayout.d.ts +9 -2
- package/types/src/components/Axis/axisLayoutLabels.d.ts +28 -33
- package/types/src/components/Axis/axisLayoutScale.d.ts +3 -1
- package/types/src/components/Axis/axisLimit.d.ts +18 -0
- package/types/src/components/Axis/axisMaxSize.d.ts +48 -0
- package/types/src/components/Axis/axisRounding.d.ts +8 -0
- package/types/src/components/Axis/axisTitle.d.ts +30 -0
- package/types/src/components/Axis/axisTooltipTargets.d.ts +82 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +21 -11
- package/types/src/components/ColorScale/bivariateRender.d.ts +53 -0
- package/types/src/components/ColorScale/bivariateScale.d.ts +92 -0
- package/types/src/components/ColorScale/colorScaleSwatchTooltips.d.ts +48 -0
- package/types/src/components/Legend/Legend.d.ts +5 -0
- package/types/src/components/Legend/legendCut.d.ts +31 -0
- package/types/src/components/Legend/legendRender.d.ts +6 -1
- package/types/src/components/TextBox.d.ts +4 -0
- package/types/src/components/textEllipsis.d.ts +6 -0
- package/types/src/fluent.d.ts +18 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/utils/D3plusConfig.d.ts +485 -609
- package/types/src/utils/configValue.d.ts +8 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/umd-entry.d.ts +4 -0
- package/umd/d3plus-core.full.js +22930 -17936
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +21240 -16404
- package/umd/d3plus-core.min.js +2 -2
|
@@ -52,11 +52,23 @@ const num = (v, fallback)=>typeof v === "number" && Number.isFinite(v) ? v : fal
|
|
|
52
52
|
edgePosition
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
The pixels each of `count` explicit breaks takes on an axis `length`
|
|
57
|
+
pixels long: `space`, or less when the axis can't hold that and still
|
|
58
|
+
leave twice a break's room for the data, down to `spaceMin`. `null` when
|
|
59
|
+
even `spaceMin` doesn't fit, and the breaks are dropped.
|
|
60
|
+
*/ export function fitBreakSpace(length, count, space, spaceMin = space) {
|
|
61
|
+
if (!count) return space;
|
|
62
|
+
const room = length / (count + 2);
|
|
63
|
+
if (room >= space) return space;
|
|
64
|
+
return room >= Math.min(spaceMin, space) ? room : null;
|
|
65
|
+
}
|
|
55
66
|
/**
|
|
56
67
|
Replaces a linear axis's scale with a broken one when it has a baseline
|
|
57
68
|
break or any `break` ranges inside its domain, and records the resolved
|
|
58
|
-
breaks on `axis._breaks`. Explicit breaks
|
|
59
|
-
|
|
69
|
+
breaks on `axis._breaks`. Explicit breaks shrink when the range can't
|
|
70
|
+
hold them and still leave twice a break's space for the data (down to
|
|
71
|
+
`breakConfig.spaceMin`), and are dropped below that.
|
|
60
72
|
*/ export function applyAxisBreaks(axis, range) {
|
|
61
73
|
axis._baselineBreak = resolveBaselineBreak(axis, range);
|
|
62
74
|
axis._breaks = [];
|
|
@@ -64,9 +76,12 @@ const num = (v, fallback)=>typeof v === "number" && Number.isFinite(v) ? v : fal
|
|
|
64
76
|
const edge = axis._baselineBreak;
|
|
65
77
|
const domain = axis._d3Scale.domain().map(Number);
|
|
66
78
|
const inner = range.slice(0, 2).map((r)=>edge && r === edge.position ? edge.edgePosition : r);
|
|
67
|
-
const
|
|
79
|
+
const style = breakStyle(axis);
|
|
68
80
|
let breaks = normalizeBreaks(axis.schema.break, Math.min(...domain), Math.max(...domain));
|
|
69
|
-
|
|
81
|
+
const config = axis.schema.breakConfig || {};
|
|
82
|
+
const fitted = fitBreakSpace(Math.abs(inner[1] - inner[0]), breaks.length, style.space, Math.max(0, num(config.spaceMin, style.space)));
|
|
83
|
+
if (fitted === null) breaks = [];
|
|
84
|
+
const space = fitted ?? style.space;
|
|
70
85
|
if (!edge && !breaks.length) return;
|
|
71
86
|
const scale = brokenScale({
|
|
72
87
|
domain,
|
|
@@ -99,7 +114,10 @@ const num = (v, fallback)=>typeof v === "number" && Number.isFinite(v) ? v : fal
|
|
|
99
114
|
startPosition: scale(start),
|
|
100
115
|
endPosition: scale(end),
|
|
101
116
|
baseline: false,
|
|
102
|
-
mask
|
|
117
|
+
mask: style.mask,
|
|
118
|
+
...space < style.space ? {
|
|
119
|
+
fit: space / style.space
|
|
120
|
+
} : {}
|
|
103
121
|
});
|
|
104
122
|
});
|
|
105
123
|
}
|
|
@@ -119,8 +137,12 @@ const num = (v, fallback)=>typeof v === "number" && Number.isFinite(v) ? v : fal
|
|
|
119
137
|
}
|
|
120
138
|
return kept;
|
|
121
139
|
}
|
|
122
|
-
/**
|
|
123
|
-
|
|
140
|
+
/**
|
|
141
|
+
The pixel gap (`[from, to]`, ascending) a break leaves in the axis line,
|
|
142
|
+
shrunk with a break shrunk to fit the axis.
|
|
143
|
+
*/ export function breakGap(axis, brk) {
|
|
144
|
+
const { gap: full } = breakStyle(axis, brk.baseline ? "baselineBreakConfig" : "breakConfig");
|
|
145
|
+
const gap = full * (brk.fit ?? 1);
|
|
124
146
|
const center = (brk.startPosition + brk.endPosition) / 2;
|
|
125
147
|
return [
|
|
126
148
|
center - gap / 2,
|
|
@@ -2,6 +2,7 @@ import { rtl as detectRTL } from "@d3plus/dom";
|
|
|
2
2
|
import { constant } from "../../utils/index.js";
|
|
3
3
|
import { inkAxis, inkGrid } from "../../utils/themeInk.js";
|
|
4
4
|
import { rotatedTextAnchor } from "./axisLabelAngle.js";
|
|
5
|
+
import { textEllipsis } from "../textEllipsis.js";
|
|
5
6
|
/** The axis color of the axis's chart theme, or one that contrasts with the background behind it. */ function contrastInk(axis) {
|
|
6
7
|
return ()=>inkAxis(axis);
|
|
7
8
|
}
|
|
@@ -30,6 +31,16 @@ import { rotatedTextAnchor } from "./axisLabelAngle.js";
|
|
|
30
31
|
"stroke-width": 1
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
/** How a cut tick label ends: as a TextBox line does, or nothing when no text fits. */ export const axisLabelEllipsis = (d)=>d && d.length ? textEllipsis(`${d}`) : "";
|
|
35
|
+
/**
|
|
36
|
+
The ellipsis a cut tick label is measured and painted with: the label
|
|
37
|
+
config's `ellipsis` (a string standing in for the cut line, as TextBox
|
|
38
|
+
reads one), else `axisLabelEllipsis`.
|
|
39
|
+
*/ export function labelEllipsis(shapeConfig) {
|
|
40
|
+
const ellipsis = shapeConfig?.labelConfig?.ellipsis;
|
|
41
|
+
if (typeof ellipsis === "function") return ellipsis;
|
|
42
|
+
return typeof ellipsis === "string" ? ()=>ellipsis : axisLabelEllipsis;
|
|
43
|
+
}
|
|
33
44
|
/** The default `shapeConfig` (tick marks and their labels). */ export function axisShapeConfig(axis) {
|
|
34
45
|
return {
|
|
35
46
|
fill: contrastInk(axis),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Which kind of labels an axis draws: one per category or value read in
|
|
3
|
+
sequence, and how much room each label of an uneven axis has.
|
|
4
|
+
*/ /**
|
|
5
|
+
Each label's own share of an axis whose labels sit unevenly, such as one
|
|
6
|
+
label per variable-width bar (see `Plot/barWidth.ts`): reaching halfway to
|
|
7
|
+
the nearer of its neighbors on either side, so labels wrapped within their
|
|
8
|
+
shares never meet, while one between far-off neighbors keeps the room
|
|
9
|
+
they leave it. A lone label spans the whole range.
|
|
10
|
+
*/ export function ownLabelSpaces(positions, rangeOuter) {
|
|
11
|
+
if (positions.length < 2) return positions.map(()=>Math.abs(rangeOuter[rangeOuter.length - 1] - rangeOuter[0]));
|
|
12
|
+
return positions.map((position, i)=>{
|
|
13
|
+
const gaps = [
|
|
14
|
+
positions[i - 1],
|
|
15
|
+
positions[i + 1]
|
|
16
|
+
].filter((n)=>n !== undefined).map((n)=>Math.abs(position - n));
|
|
17
|
+
return Math.min(...gaps);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
Whether a horizontal axis's labels are values read in sequence (dates, or
|
|
22
|
+
numbers on a category axis) that are drawn whole on one line: thinned
|
|
23
|
+
rather than wrapped or cut short, since any one of them reads alone.
|
|
24
|
+
Labels naming categories wrap or rotate instead (see `rotatesLabels`).
|
|
25
|
+
*/ export function wholeLineLabels(axis, labels) {
|
|
26
|
+
const { scale } = axis.schema;
|
|
27
|
+
if (scale === "time") return true;
|
|
28
|
+
return isDiscreteScale(scale) && labels.length > 0 && labels.every((d)=>d instanceof Date || !isNaN(d));
|
|
29
|
+
}
|
|
30
|
+
/** Whether a scale places one tick per category (every value labeled in turn). */ export function isDiscreteScale(scale) {
|
|
31
|
+
return [
|
|
32
|
+
"band",
|
|
33
|
+
"ordinal",
|
|
34
|
+
"point"
|
|
35
|
+
].includes(scale);
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The line height axis labels are measured and painted with, so a label
|
|
3
|
+
measured as N lines paints as N lines in the room measured for it.
|
|
4
|
+
*/ import configValue from "../../utils/configValue.js";
|
|
5
|
+
/** How many times its font size a label's line height is by default (TextBox's default). */ export const LABEL_LINE_HEIGHT = 1.2;
|
|
6
|
+
/**
|
|
7
|
+
The line height of the axis label for tick `d`: the label config's
|
|
8
|
+
`lineHeight` when set, else the shape config's, else 1.2 times the
|
|
9
|
+
label's `fontSize`, as the label's TextBox draws it by default.
|
|
10
|
+
@param shapeConfig The axis's `shapeConfig`.
|
|
11
|
+
@param d The tick value.
|
|
12
|
+
@param i The tick's index.
|
|
13
|
+
@param fontSize The label's font size, read from the label config when
|
|
14
|
+
not given.
|
|
15
|
+
*/ export function labelLineHeight(shapeConfig, d, i, fontSize = configValue(shapeConfig?.labelConfig?.fontSize ?? 12, d, i)) {
|
|
16
|
+
const value = shapeConfig?.labelConfig?.lineHeight ?? shapeConfig?.lineHeight;
|
|
17
|
+
const lineHeight = value === undefined ? undefined : configValue(value, d, i);
|
|
18
|
+
return typeof lineHeight === "number" && lineHeight > 0 ? lineHeight : fontSize * LABEL_LINE_HEIGHT;
|
|
19
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The box a vertical axis's flat labels wrap in, so each label is cut
|
|
3
|
+
where it is painted.
|
|
4
|
+
*/ import { max } from "d3-array";
|
|
5
|
+
/**
|
|
6
|
+
A vertical axis paints its flat labels in a box as wide as the widest
|
|
7
|
+
one (see `buildTickData`), narrower than the room they were measured
|
|
8
|
+
in. Where a cut label's line breaks decides where it is cut, so each
|
|
9
|
+
label that doesn't fit is wrapped again in that box (by `measure`, which
|
|
10
|
+
wraps a label within its `room`) until the widest label holds; a label
|
|
11
|
+
that fits wraps the same in any box as wide as it, and a label whose
|
|
12
|
+
first word no longer fits is cut short in it (see `cutLabel`). Records
|
|
13
|
+
the box on each label as its `room`.
|
|
14
|
+
@param textData The axis's measured labels.
|
|
15
|
+
@param measure Wraps a label within its `room`.
|
|
16
|
+
*/ export function fitLabelRoom(textData, measure) {
|
|
17
|
+
const widest = ()=>max(textData, (t)=>t.width) || 0;
|
|
18
|
+
let room = widest();
|
|
19
|
+
// A label wrapped in the box is no wider than it, so the box only
|
|
20
|
+
// narrows, and settles.
|
|
21
|
+
for(;;){
|
|
22
|
+
textData.forEach((t)=>t.room = room);
|
|
23
|
+
textData.filter((t)=>!t.fits).forEach((t)=>{
|
|
24
|
+
const { lines, widths, width, height, cut } = measure(t);
|
|
25
|
+
Object.assign(t, {
|
|
26
|
+
lines,
|
|
27
|
+
widths,
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
cut
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
const next = widest();
|
|
34
|
+
if (next >= room) return;
|
|
35
|
+
room = next;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Measures a single axis label for `createTextData` (see
|
|
3
|
+
`axisLayoutLabels.ts`): wrapped with `textWrap` within the room its axis
|
|
4
|
+
gives it. Pure compute, no DOM.
|
|
5
|
+
*/ import { max, min } from "d3-array";
|
|
6
|
+
import { textWrap } from "@d3plus/text";
|
|
7
|
+
import { wholeWordFit, wholeWordSplit } from "../../utils/wholeWords.js";
|
|
8
|
+
import { axisLabelEllipsis, labelEllipsis } from "./axisDefaults.js";
|
|
9
|
+
import { axisCrossing, slantedWrapSize } from "./axisLabelAngle.js";
|
|
10
|
+
import { axisMaxSize } from "./axisMaxSize.js";
|
|
11
|
+
/**
|
|
12
|
+
Cuts a label short to fit `width`: for a label whose first word is wider
|
|
13
|
+
than its room, which wraps to nothing. The word is cut to as many
|
|
14
|
+
characters as fit with the ellipsis after them (the wrap's own, else
|
|
15
|
+
`axisLabelEllipsis`), on one line; with no room for even one, the label
|
|
16
|
+
has no lines.
|
|
17
|
+
*/ export function cutLabel(wrap, text, width) {
|
|
18
|
+
return wrap.width(width).truncateWord(true).ellipsis(wrap.ellipsis() ?? axisLabelEllipsis)(text);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
Measures a flat label whose first word is wider than its room (`space`),
|
|
22
|
+
which wraps to nothing there. On a horizontal axis, where `space` is the
|
|
23
|
+
label's share of the axis: across the whole axis (`across` wide) instead,
|
|
24
|
+
so the overlap pass thins the labels out, or when it is too wide for that
|
|
25
|
+
as well, cut short within its share (see `cutLabel`). Labels in their own
|
|
26
|
+
shares are cut only when none fits whole (`keepShare`, see
|
|
27
|
+
`fitOwnSpaces`). On a vertical axis, where `space` is how far labels
|
|
28
|
+
reach out from the axis, the label is cut short within it (`keepShare`).
|
|
29
|
+
*/ export function longWordLabel(wrap, text, space, across, ctx) {
|
|
30
|
+
if (!ctx.keepShare) {
|
|
31
|
+
const wide = wrap.width(across)(text);
|
|
32
|
+
if (ctx.ownSpace || wide.lines.some((l)=>l !== "")) return {
|
|
33
|
+
res: wide,
|
|
34
|
+
cut: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const res = cutLabel(wrap, text, space);
|
|
38
|
+
return {
|
|
39
|
+
res,
|
|
40
|
+
cut: res.lines.length > 0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
Wraps a slanted label onto fewer lines, each as long as the lines left
|
|
45
|
+
leave room for, until it reaches no further out from the axis than
|
|
46
|
+
`depth`. A label's every line adds its height to how far it reaches,
|
|
47
|
+
across the slant, so giving one up lets the others run further out. A
|
|
48
|
+
wrap that leaves no lines (a word too long for the line) doesn't count:
|
|
49
|
+
the next, longer line is tried, and a label cut short is measured with
|
|
50
|
+
the ellipsis its TextBox ends it with (the wrap's own, else
|
|
51
|
+
`axisLabelEllipsis`). `width` caps how long a line may be; `res` is the
|
|
52
|
+
label as first wrapped.
|
|
53
|
+
*/ export function slantWithin(wrap, text, res, slant) {
|
|
54
|
+
const phi = axisCrossing(slant.angle, slant.horizontal);
|
|
55
|
+
const sin = Math.sin(phi), cos = Math.cos(phi);
|
|
56
|
+
const lineHeight = wrap.lineHeight();
|
|
57
|
+
const count = (r)=>r.lines.filter((l)=>l !== "").length;
|
|
58
|
+
const fits = (r)=>{
|
|
59
|
+
const lines = count(r);
|
|
60
|
+
const width = Math.ceil(Math.max(0, ...r.widths.slice(0, lines)));
|
|
61
|
+
return width * sin + Math.ceil(lines * lineHeight) * cos <= slant.depth;
|
|
62
|
+
};
|
|
63
|
+
if (!count(res) || fits(res)) return res;
|
|
64
|
+
// Measured as drawn: a label cut short ends in an ellipsis.
|
|
65
|
+
wrap.ellipsis(wrap.ellipsis() ?? axisLabelEllipsis);
|
|
66
|
+
for(let n = count(res) - 1; n >= 1; n--){
|
|
67
|
+
const room = (slant.depth - Math.ceil(n * lineHeight) * cos) / sin;
|
|
68
|
+
wrap.height(n * lineHeight).width(Math.max(0, Math.min(slant.width, room)));
|
|
69
|
+
res = wrap(text);
|
|
70
|
+
if (count(res) && fits(res)) return res;
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
/** How far labels may reach out from the axis, past its ticks and margins. */ export function labelRoom(axis, horizontal, hBuff, p) {
|
|
75
|
+
const maxSize = axisMaxSize(axis.schema, horizontal);
|
|
76
|
+
return horizontal ? min([
|
|
77
|
+
maxSize,
|
|
78
|
+
axis.schema.height
|
|
79
|
+
]) - hBuff - p - axis._margin.top - axis._margin.bottom : min([
|
|
80
|
+
maxSize,
|
|
81
|
+
axis.schema.width
|
|
82
|
+
]) - hBuff - p - axis._margin.left - axis._margin.right;
|
|
83
|
+
}
|
|
84
|
+
/** What a label's measurement depends on, to tell two labels measure alike. */ function labelSizeKey(text, datum, ctx) {
|
|
85
|
+
const { fF, fP, fS, lineHeight, rotate, space, angle, slant, room } = datum;
|
|
86
|
+
return JSON.stringify([
|
|
87
|
+
text,
|
|
88
|
+
fF,
|
|
89
|
+
fP,
|
|
90
|
+
fS,
|
|
91
|
+
lineHeight,
|
|
92
|
+
rotate,
|
|
93
|
+
slant && angle,
|
|
94
|
+
slant && ctx.slantWidth,
|
|
95
|
+
space,
|
|
96
|
+
room,
|
|
97
|
+
ctx.keepShare
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
Wraps + measures a single label, returning its sized text result. Given a
|
|
102
|
+
`cache`, a label whose text, font, and space match one measured before
|
|
103
|
+
reuses that measurement.
|
|
104
|
+
*/ export function calculateLabelSize(axis, datum, ctx, cache) {
|
|
105
|
+
const { horizontal, hBuff, p, tickFormat } = ctx;
|
|
106
|
+
const { d, fF, fP, fS, lineHeight, rotate, space, angle, slant } = datum;
|
|
107
|
+
const h = rotate ? "width" : "height", w = rotate ? "height" : "width";
|
|
108
|
+
const text = tickFormat(d);
|
|
109
|
+
const wSize = min([
|
|
110
|
+
axisMaxSize(axis.schema, horizontal),
|
|
111
|
+
axis.schema.width
|
|
112
|
+
]);
|
|
113
|
+
const depth = datum.room ?? labelRoom(axis, horizontal, hBuff, p);
|
|
114
|
+
const slanted = slant ? slantedWrapSize(angle, horizontal, depth, space, lineHeight) : undefined;
|
|
115
|
+
const key = cache && labelSizeKey(text, datum, ctx);
|
|
116
|
+
const cached = key ? cache.get(key) : undefined;
|
|
117
|
+
if (cached) return {
|
|
118
|
+
...cached,
|
|
119
|
+
lines: cached.lines.slice(),
|
|
120
|
+
widths: cached.widths.slice()
|
|
121
|
+
};
|
|
122
|
+
// A cut label ends with the ellipsis it is painted with.
|
|
123
|
+
const wrap = textWrap().fontFamily(fF).fontSize(fS).lineHeight(lineHeight).ellipsis(labelEllipsis(axis.schema.shapeConfig));
|
|
124
|
+
if (slanted) {
|
|
125
|
+
// Slanted labels wrap between words, never mid-word.
|
|
126
|
+
wrap.split(wholeWordSplit).width(Math.min(slanted.width, ctx.slantWidth ?? Infinity)).height(slanted.height);
|
|
127
|
+
} else {
|
|
128
|
+
wrap[w](horizontal ? space : depth);
|
|
129
|
+
// A flat label's lines share its room with its padding (see `res.height`).
|
|
130
|
+
wrap[h](horizontal ? depth - (rotate ? 0 : fP) : space);
|
|
131
|
+
}
|
|
132
|
+
let res, fits;
|
|
133
|
+
let cut = false;
|
|
134
|
+
if (ctx.wholeLine) {
|
|
135
|
+
// Measured across the whole axis (`maxSize` caps its depth, not its
|
|
136
|
+
// length), a label that still breaks onto a second line can't be drawn
|
|
137
|
+
// whole on one.
|
|
138
|
+
wrap.width(axis.schema.width - p * 2);
|
|
139
|
+
res = wrap(text);
|
|
140
|
+
fits = !res.truncated && res.lines.filter((l)=>l !== "").length <= 1;
|
|
141
|
+
} else {
|
|
142
|
+
res = wrap(text);
|
|
143
|
+
// Within a strict `maxSize`, a slanted label reaches out no further
|
|
144
|
+
// than the room it has, its padding with it.
|
|
145
|
+
if (slanted && ctx.strict) res = slantWithin(wrap, text, res, {
|
|
146
|
+
angle: angle,
|
|
147
|
+
horizontal,
|
|
148
|
+
depth: Math.floor(depth - (horizontal ? fP : 0)),
|
|
149
|
+
width: Math.min(slanted.width, ctx.slantWidth ?? Infinity)
|
|
150
|
+
});
|
|
151
|
+
// A label that only fits by breaking a word mid-word doesn't fit.
|
|
152
|
+
fits = wholeWordFit(res, ()=>wrap.split(wholeWordSplit)(text)).fits;
|
|
153
|
+
if (!rotate && `${text}`.trim() && !res.lines.some((l)=>l !== "")) ({ res, cut } = horizontal ? longWordLabel(wrap, text, space, wSize - p * 2, ctx) : longWordLabel(wrap, text, depth, depth, {
|
|
154
|
+
keepShare: true
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
res.fits = fits;
|
|
158
|
+
res.cut = cut;
|
|
159
|
+
res.lines = res.lines.filter((d)=>d !== "");
|
|
160
|
+
res.width = res.lines.length ? Math.ceil(max(res.widths)) : 0;
|
|
161
|
+
res.height = res.lines.length ? Math.ceil(res.lines.length * wrap.lineHeight()) + fP : 0;
|
|
162
|
+
if (key) cache.set(key, {
|
|
163
|
+
lines: res.lines.slice(),
|
|
164
|
+
widths: res.widths.slice(),
|
|
165
|
+
width: res.width,
|
|
166
|
+
height: res.height,
|
|
167
|
+
fits,
|
|
168
|
+
cut
|
|
169
|
+
});
|
|
170
|
+
return res;
|
|
171
|
+
}
|
|
@@ -34,9 +34,14 @@
|
|
|
34
34
|
scale's `range`, each tick at its slot's center: one bar each, for one
|
|
35
35
|
label per bar), so where two narrow neighbors can't both fit, the
|
|
36
36
|
narrower bar's label is the one hidden; every other label stays as it
|
|
37
|
-
is.
|
|
38
|
-
|
|
37
|
+
is. A label with none shown beside it widens no further than the ends
|
|
38
|
+
of the axis (`bounds`, the scale's `range` by default) allow, centered
|
|
39
|
+
on its tick. When no label fits whole, each is drawn in its own share
|
|
40
|
+
instead, cut short if need be. `resize` measures a label again at a
|
|
41
|
+
given width, within that width when `keepShare`.
|
|
42
|
+
*/ export function fitOwnSpaces(textData, spaces, range, resize, bounds = range) {
|
|
39
43
|
const share = (t)=>spaces[t.i] - t.fP * 2;
|
|
44
|
+
const around = (t)=>roomAround(t.position, bounds);
|
|
40
45
|
const pending = new Set(textData.filter((t)=>!t.fits));
|
|
41
46
|
// A label still waiting to widen keeps to its own share for now.
|
|
42
47
|
const extent = (t)=>pending.has(t) ? Math.min(t.width, share(t)) : t.width;
|
|
@@ -51,8 +56,8 @@
|
|
|
51
56
|
shown(datum.i, -1, skip),
|
|
52
57
|
shown(datum.i, 1, skip)
|
|
53
58
|
].filter((t)=>t !== undefined).map((t)=>2 * (Math.abs(t.position - datum.position) - extent(t) / 2 - datum.fP));
|
|
54
|
-
// With no label shown beside it, a label may
|
|
55
|
-
const space = Math.floor(widths.length ? Math.min(...widths) :
|
|
59
|
+
// With no label shown beside it, a label may reach the nearer end of the axis.
|
|
60
|
+
const space = Math.floor(widths.length ? Math.min(...widths) : around(datum));
|
|
56
61
|
if (space > share(datum)) resize(datum, space);
|
|
57
62
|
return datum.fits;
|
|
58
63
|
};
|
|
@@ -73,6 +78,95 @@
|
|
|
73
78
|
if (!widen(datum, false)) widen(datum, true);
|
|
74
79
|
datum.truncated = !datum.fits;
|
|
75
80
|
});
|
|
81
|
+
if (textData.every((t)=>t.truncated)) textData.forEach((datum)=>{
|
|
82
|
+
const space = Math.floor(Math.min(share(datum), around(datum)));
|
|
83
|
+
if (space <= 0) return;
|
|
84
|
+
resize(datum, space, true);
|
|
85
|
+
datum.truncated = !datum.lines.length;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
The widest a label centered on its tick at `position` can be without
|
|
90
|
+
reaching past either end of `bounds` (0 for a tick outside them).
|
|
91
|
+
*/ export function roomAround(position, bounds) {
|
|
92
|
+
const lo = Math.min(...bounds);
|
|
93
|
+
const hi = Math.max(...bounds);
|
|
94
|
+
return Math.max(0, 2 * Math.min(position - lo, hi - position));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
Measures each label left shown along a vertical axis again in the room
|
|
98
|
+
the hidden labels beside it leave: up to its padding short of the
|
|
99
|
+
nearest label shown on either side, and of the ends of the axis
|
|
100
|
+
(`bounds`), centered on its tick. Labels are first measured in room for
|
|
101
|
+
one at every tick, so the ones left shown after thinning could take more
|
|
102
|
+
lines. Only labels that don't fit whole are measured again, and only in
|
|
103
|
+
more room than they had; that room keeps them clear of their neighbors
|
|
104
|
+
and within the axis, so no two shown labels crowd and none reaches
|
|
105
|
+
further past an end than before.
|
|
106
|
+
*/ export function regrowShown(textData, resize, bounds) {
|
|
107
|
+
const shown = textData.filter((t)=>!t.truncated);
|
|
108
|
+
if (shown.length === textData.length) return;
|
|
109
|
+
const rooms = shown.map((datum, i)=>{
|
|
110
|
+
const gaps = [
|
|
111
|
+
shown[i - 1],
|
|
112
|
+
shown[i + 1]
|
|
113
|
+
].filter((t)=>t !== undefined).map((t)=>Math.abs(t.position - datum.position));
|
|
114
|
+
const room = Math.min(roomAround(datum.position, bounds), ...gaps);
|
|
115
|
+
return Math.floor(room - datum.fP);
|
|
116
|
+
});
|
|
117
|
+
shown.forEach((datum, i)=>{
|
|
118
|
+
if (!datum.fits && rooms[i] > datum.space) resize(datum, rooms[i]);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
Picks which labels a vertical axis shows so that each takes as many
|
|
123
|
+
lines as it can, as a gradient color scale's few labels do: for a
|
|
124
|
+
bucketed color scale, whose every bucket has a label. While some label
|
|
125
|
+
shown is cut short, labels are hidden at an even interval, the first
|
|
126
|
+
and last always kept, until every label shown fits whole, or else as far
|
|
127
|
+
as gives the labels shown the most lines (the fewest any of them has),
|
|
128
|
+
hiding no more labels than that takes. Each label shown is measured in
|
|
129
|
+
the room between the nearest labels shown on either side, up to its
|
|
130
|
+
padding short of them (a label at an end, twice its distance to the one
|
|
131
|
+
beside it), and never less than every label had at first (`floor`):
|
|
132
|
+
one at an end reaching past the end of the axis narrows the axis's
|
|
133
|
+
range, as a gradient's do. `resize` measures a label again in a room.
|
|
134
|
+
*/ export function thinForLines(textData, resize, floor) {
|
|
135
|
+
const n = textData.length;
|
|
136
|
+
const shown = textData.filter((t)=>!t.truncated);
|
|
137
|
+
if (n < 3 || shown.every((t)=>t.fits)) return;
|
|
138
|
+
const rooms = (set)=>set.map((datum, i)=>{
|
|
139
|
+
const gaps = [
|
|
140
|
+
set[i - 1],
|
|
141
|
+
set[i + 1]
|
|
142
|
+
].filter((t)=>t !== undefined).map((t)=>Math.abs(t.position - datum.position));
|
|
143
|
+
const gap = gaps.length ? Math.min(...gaps) : 0;
|
|
144
|
+
return Math.max(floor, Math.floor(gap - datum.fP));
|
|
145
|
+
});
|
|
146
|
+
// How a set of labels shown measures: the fewest lines any has, and
|
|
147
|
+
// whether every one fits whole.
|
|
148
|
+
const score = (set)=>{
|
|
149
|
+
const sized = rooms(set).map((room, i)=>resize(set[i], room));
|
|
150
|
+
return {
|
|
151
|
+
set,
|
|
152
|
+
lines: Math.min(...sized.map((t)=>t.lines.length)),
|
|
153
|
+
whole: sized.every((t)=>t.fits)
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const even = (m)=>Array.from({
|
|
157
|
+
length: m
|
|
158
|
+
}, (_, j)=>textData[Math.round(j * (n - 1) / (m - 1))]);
|
|
159
|
+
let best = score(shown);
|
|
160
|
+
for(let m = shown.length - 1; m >= 2 && !best.whole; m--){
|
|
161
|
+
const next = score(even(m));
|
|
162
|
+
if (next.whole || next.lines > best.lines) best = next;
|
|
163
|
+
}
|
|
164
|
+
const keep = new Set(best.set);
|
|
165
|
+
const chosen = rooms(best.set);
|
|
166
|
+
textData.forEach((datum)=>{
|
|
167
|
+
datum.truncated = !keep.has(datum);
|
|
168
|
+
});
|
|
169
|
+
best.set.forEach((datum, i)=>resize(datum, chosen[i]));
|
|
76
170
|
}
|
|
77
171
|
/**
|
|
78
172
|
Whether label `b` sits too close to label `a` before it, leaving less
|