@d3plus/core 4.9.0 → 4.10.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 +3 -1
- package/es/src/charts/BoxWhisker/index.js +73 -4
- package/es/src/charts/BoxWhisker/outliers.js +68 -0
- package/es/src/charts/BoxWhisker/summary.js +83 -0
- package/es/src/charts/BoxWhisker/tooltip.js +122 -0
- package/es/src/charts/Bullet/index.js +2 -1
- package/es/src/charts/BumpChart/index.js +5 -0
- package/es/src/charts/Calendar/index.js +2 -1
- package/es/src/charts/Candlestick/aggregate.js +11 -1
- package/es/src/charts/Candlestick/index.js +5 -5
- package/es/src/charts/Chord/index.js +3 -2
- package/es/src/charts/Funnel/index.js +2 -1
- package/es/src/charts/Gauge/index.js +2 -1
- package/es/src/charts/Geomap/index.js +9 -3
- package/es/src/charts/Histogram/index.js +5 -1
- package/es/src/charts/Matrix/index.js +3 -2
- package/es/src/charts/Network/index.js +9 -4
- package/es/src/charts/Pack/index.js +2 -1
- package/es/src/charts/Pie/index.js +2 -1
- package/es/src/charts/Plot/axisHover.js +180 -0
- package/es/src/charts/Plot/axisHoverAnchors.js +174 -0
- package/es/src/charts/Plot/axisHoverScene.js +202 -0
- package/es/src/charts/Plot/barHitArea.js +81 -0
- package/es/src/charts/Plot/barLabelFit.js +123 -0
- package/es/src/charts/Plot/barWidth.js +2 -2
- package/es/src/charts/Plot/confidenceConfig.js +2 -2
- package/es/src/charts/Plot/draw.js +6 -2
- package/es/src/charts/Plot/index.js +25 -6
- package/es/src/charts/Plot/labelPlacement.js +9 -1
- package/es/src/charts/Plot/openDomainEnds.js +2 -5
- package/es/src/charts/Plot/pipeline.js +5 -3
- package/es/src/charts/Plot/pipelineAxisLayout.js +38 -8
- package/es/src/charts/Plot/pipelineDomains.js +7 -3
- package/es/src/charts/Plot/pipelineLineLabels.js +1 -1
- package/es/src/charts/Plot/plotInit.js +15 -0
- package/es/src/charts/Plot/plotZoom.js +15 -6
- package/es/src/charts/Plot/shapeDefaults.js +4 -4
- package/es/src/charts/Plot/sharedHoverScene.js +50 -31
- package/es/src/charts/Plot/sharedTooltip.js +19 -7
- package/es/src/charts/Plot/stackHelpers.js +13 -1
- package/es/src/charts/Plot/stackShareTooltip.js +9 -4
- package/es/src/charts/Plot/stackThreshold.js +154 -0
- package/es/src/charts/PolarArea/index.js +3 -2
- package/es/src/charts/Priestley/index.js +3 -2
- package/es/src/charts/Pyramid/index.js +4 -2
- package/es/src/charts/Radar/index.js +3 -2
- package/es/src/charts/RadialBar/index.js +2 -1
- package/es/src/charts/RadialMatrix/index.js +3 -2
- package/es/src/charts/Rings/index.js +5 -3
- package/es/src/charts/Sankey/index.js +3 -2
- package/es/src/charts/Treemap/applyLayout.js +14 -1
- package/es/src/charts/Treemap/emit.js +8 -2
- package/es/src/charts/Treemap/emitGroupHeaders.js +104 -0
- package/es/src/charts/Treemap/groupHeaders.js +95 -0
- package/es/src/charts/Treemap/index.js +15 -2
- package/es/src/charts/Treemap/thresholdFunction.js +11 -9
- package/es/src/charts/Waffle/index.js +4 -2
- package/es/src/charts/Waffle/tooltip.js +6 -2
- package/es/src/charts/Waterfall/index.js +4 -2
- package/es/src/charts/definition/makeChart.js +12 -5
- package/es/src/charts/drawSteps/saveChart.js +176 -0
- package/es/src/charts/drawSteps/saveControl.js +148 -0
- package/es/src/charts/drawSteps/saveControlMarkup.js +104 -0
- package/es/src/charts/drawSteps/tableViewMarkup.js +1 -1
- package/es/src/charts/drawSteps/topLeftControls.js +3 -1
- package/es/src/charts/drawSteps/topLeftControlsMarkup.js +1 -1
- package/es/src/charts/events/click.shape.js +30 -1
- package/es/src/charts/events/mouseenter.js +9 -0
- package/es/src/charts/events/mousemove.legend.js +3 -0
- package/es/src/charts/events/mousemove.shape.js +7 -2
- package/es/src/charts/facet/facetConfig.js +2 -2
- package/es/src/charts/facet/facetData.js +2 -2
- package/es/src/charts/features/axes.js +7 -6
- package/es/src/charts/features/axesFinal.js +23 -3
- package/es/src/charts/features/axesMeasure.js +54 -2
- package/es/src/charts/features/colorScaleBucket.js +17 -0
- package/es/src/charts/features/colorScaleHover.js +69 -0
- package/es/src/charts/features/features.js +13 -1
- package/es/src/charts/features/featuresColorScale.js +44 -4
- package/es/src/charts/features/featuresLegend.js +6 -8
- package/es/src/charts/features/plotPaint.js +4 -4
- package/es/src/charts/features/shapeEmit.js +23 -2
- package/es/src/charts/features/shareKey.js +15 -0
- package/es/src/charts/features/thresholdMembers.js +71 -0
- package/es/src/charts/helpers/densityChart.js +3 -1
- package/es/src/charts/helpers/valueTitle.js +6 -3
- package/es/src/charts/partition/chartFields.js +4 -3
- package/es/src/charts/partition/hierarchy.js +2 -0
- package/es/src/charts/pipeline/preDrawData.js +31 -10
- package/es/src/charts/pipeline/vizDraw.js +40 -29
- package/es/src/charts/pipeline/vizPreDraw.js +24 -15
- package/es/src/charts/viz/Viz.js +43 -8
- package/es/src/charts/viz/VizBase.js +32 -12
- package/es/src/charts/viz/dataPoller.js +52 -0
- package/es/src/charts/viz/groupRow.js +35 -0
- package/es/src/charts/viz/interactionOpacity.js +19 -5
- package/es/src/charts/viz/missingFields.js +122 -0
- package/es/src/charts/viz/reportHandlerError.js +10 -0
- package/es/src/charts/viz/shapeClassTargets.js +18 -2
- package/es/src/charts/viz/simpleHover.js +2 -0
- package/es/src/charts/viz/vizClassName.js +31 -0
- package/es/src/charts/viz/vizDataPolling.js +167 -0
- package/es/src/charts/viz/vizDefaults.js +66 -0
- package/es/src/charts/viz/vizFields.js +18 -2
- package/es/src/charts/viz/vizRender.js +8 -2
- package/es/src/components/Axis/Axis.js +28 -0
- package/es/src/components/Axis/axisDefaults.js +3 -1
- package/es/src/components/Axis/axisLabelAngle.js +175 -0
- package/es/src/components/Axis/axisLabelThinning.js +13 -4
- package/es/src/components/Axis/axisLayout.js +86 -19
- package/es/src/components/Axis/axisLayoutLabels.js +66 -13
- package/es/src/components/Axis/axisLayoutScale.js +3 -0
- package/es/src/components/Axis/axisRender.js +38 -9
- package/es/src/components/Axis/axisRounding.js +15 -4
- package/es/src/components/Axis/axisSlantWrap.js +39 -0
- package/es/src/components/Axis/powTicks.js +73 -0
- package/es/src/components/ColorScale/ColorScale.js +28 -28
- package/es/src/components/ColorScale/bucketBounds.js +35 -0
- package/es/src/components/ColorScale/colorScaleHoverMark.js +327 -0
- package/es/src/components/ColorScale/colorScaleRender.js +25 -1
- package/es/src/components/ColorScale/colorScaleScale.js +15 -9
- package/es/src/components/ColorScale/colorScaleType.js +26 -0
- package/es/src/components/TextBox.js +2 -0
- package/es/src/components/Timeline/Timeline.js +43 -52
- package/es/src/components/Timeline/brushSpan.js +78 -0
- package/es/src/components/Timeline/timelineConfig.js +7 -0
- package/es/src/components/Timeline/timelineRender.js +44 -6
- package/es/src/components/Tooltip.js +13 -8
- package/es/src/shapes/Box.js +66 -79
- package/es/src/shapes/boxOutlierShape.js +19 -0
- package/es/src/shapes/boxStats.js +35 -0
- package/es/src/shapes/boxStyle.js +78 -0
- package/es/src/shapes/boxSummary.js +174 -0
- package/es/src/shapes/shapeStandalone.js +2 -0
- package/es/src/utils/BaseClass.js +19 -0
- package/es/src/utils/className.js +78 -0
- package/es/src/utils/configWarnings.js +25 -0
- package/es/src/utils/fieldAccessor.js +31 -0
- package/es/src/utils/paintComponentScene.js +2 -0
- package/package.json +10 -9
- package/types/index.d.ts +3 -1
- package/types/internal.d.ts +3 -1
- package/types/src/charts/BoxWhisker/index.d.ts +3 -1
- package/types/src/charts/BoxWhisker/outliers.d.ts +25 -0
- package/types/src/charts/BoxWhisker/summary.d.ts +39 -0
- package/types/src/charts/BoxWhisker/tooltip.d.ts +36 -0
- package/types/src/charts/Candlestick/aggregate.d.ts +6 -0
- package/types/src/charts/Plot/axisHover.d.ts +68 -0
- package/types/src/charts/Plot/axisHoverAnchors.d.ts +88 -0
- package/types/src/charts/Plot/axisHoverScene.d.ts +88 -0
- package/types/src/charts/Plot/barHitArea.d.ts +59 -0
- package/types/src/charts/Plot/barLabelFit.d.ts +81 -0
- package/types/src/charts/Plot/index.d.ts +13 -0
- package/types/src/charts/Plot/labelPlacement.d.ts +5 -0
- package/types/src/charts/Plot/plotInit.d.ts +9 -2
- package/types/src/charts/Plot/plotZoom.d.ts +2 -0
- package/types/src/charts/Plot/sharedHoverScene.d.ts +3 -3
- package/types/src/charts/Plot/sharedTooltip.d.ts +11 -4
- package/types/src/charts/Plot/stackHelpers.d.ts +5 -0
- package/types/src/charts/Plot/stackThreshold.d.ts +75 -0
- package/types/src/charts/Treemap/emit.d.ts +2 -1
- package/types/src/charts/Treemap/emitGroupHeaders.d.ts +16 -0
- package/types/src/charts/Treemap/groupHeaders.d.ts +91 -0
- package/types/src/charts/Treemap/index.d.ts +2 -0
- package/types/src/charts/Treemap/thresholdFunction.d.ts +5 -2
- package/types/src/charts/definition/ChartDefinition.d.ts +14 -2
- package/types/src/charts/definition/makeChart.d.ts +4 -3
- package/types/src/charts/drawSteps/saveChart.d.ts +47 -0
- package/types/src/charts/drawSteps/saveControl.d.ts +9 -0
- package/types/src/charts/drawSteps/saveControlMarkup.d.ts +44 -0
- package/types/src/charts/drawSteps/tableViewMarkup.d.ts +1 -0
- package/types/src/charts/drawSteps/topLeftControls.d.ts +1 -1
- package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +1 -1
- package/types/src/charts/facet/facetData.d.ts +1 -1
- package/types/src/charts/features/axesMeasure.d.ts +9 -1
- package/types/src/charts/features/colorScaleBucket.d.ts +9 -0
- package/types/src/charts/features/colorScaleHover.d.ts +32 -0
- package/types/src/charts/features/features.d.ts +8 -0
- package/types/src/charts/features/plotPaint.d.ts +2 -0
- package/types/src/charts/features/shapeEmit.d.ts +2 -0
- package/types/src/charts/features/shareKey.d.ts +9 -0
- package/types/src/charts/features/thresholdMembers.d.ts +38 -0
- package/types/src/charts/helpers/valueTitle.d.ts +4 -2
- package/types/src/charts/pipeline/stages.d.ts +2 -0
- package/types/src/charts/pipeline/vizDraw.d.ts +8 -3
- package/types/src/charts/pipeline/vizPreDraw.d.ts +3 -2
- package/types/src/charts/viz/Viz.d.ts +28 -4
- package/types/src/charts/viz/VizBase.d.ts +12 -3
- package/types/src/charts/viz/dataPoller.d.ts +28 -0
- package/types/src/charts/viz/groupRow.d.ts +24 -0
- package/types/src/charts/viz/interactionOpacity.d.ts +3 -1
- package/types/src/charts/viz/missingFields.d.ts +57 -0
- package/types/src/charts/viz/reportHandlerError.d.ts +7 -0
- package/types/src/charts/viz/shapeClassTargets.d.ts +6 -0
- package/types/src/charts/viz/simpleHover.d.ts +2 -1
- package/types/src/charts/viz/vizClassName.d.ts +23 -0
- package/types/src/charts/viz/vizDataPolling.d.ts +48 -0
- package/types/src/charts/viz/vizDefaults.d.ts +49 -0
- package/types/src/charts/viz/vizFields.d.ts +15 -0
- package/types/src/charts/viz/vizTypes.d.ts +33 -1
- package/types/src/components/Axis/Axis.d.ts +36 -8
- package/types/src/components/Axis/axisLabelAngle.d.ts +110 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +3 -7
- package/types/src/components/Axis/axisLayout.d.ts +5 -0
- package/types/src/components/Axis/axisLayoutLabels.d.ts +13 -0
- package/types/src/components/Axis/axisRounding.d.ts +6 -3
- package/types/src/components/Axis/axisSlantWrap.d.ts +22 -0
- package/types/src/components/Axis/powTicks.d.ts +29 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +13 -0
- package/types/src/components/ColorScale/bucketBounds.d.ts +14 -0
- package/types/src/components/ColorScale/colorScaleHoverMark.d.ts +86 -0
- package/types/src/components/ColorScale/colorScaleScale.d.ts +3 -0
- package/types/src/components/ColorScale/colorScaleType.d.ts +17 -0
- package/types/src/components/Timeline/brushSpan.d.ts +41 -0
- package/types/src/components/Timeline/timelineConfig.d.ts +6 -0
- package/types/src/components/Timeline/timelineRender.d.ts +8 -0
- package/types/src/components/Tooltip.d.ts +8 -0
- package/types/src/shapes/Box.d.ts +1 -8
- package/types/src/shapes/boxOutlierShape.d.ts +9 -0
- package/types/src/shapes/boxStats.d.ts +19 -0
- package/types/src/shapes/boxStyle.d.ts +25 -0
- package/types/src/shapes/boxSummary.d.ts +66 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/shapes/shapeConfig.d.ts +42 -4
- package/types/src/utils/BaseClass.d.ts +23 -0
- package/types/src/utils/D3Scale.d.ts +3 -0
- package/types/src/utils/D3plusConfig.d.ts +261 -5
- package/types/src/utils/className.d.ts +64 -0
- package/types/src/utils/configWarnings.d.ts +21 -2
- package/types/src/utils/fieldAccessor.d.ts +24 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/src/utils/paintComponentScene.d.ts +3 -1
- package/umd/d3plus-core.full.js +6405 -1068
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +5328 -1002
- package/umd/d3plus-core.min.js +2 -2
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { zoomTransform } from "d3-zoom";
|
|
10
10
|
import { addToQueue } from "@d3plus/data";
|
|
11
11
|
import accessor from "../../utils/accessor.js";
|
|
12
|
+
import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
12
13
|
import constant from "../../utils/constant.js";
|
|
13
14
|
import { chartBounds } from "../features/chartGeometry.js";
|
|
14
15
|
import { ensureZoomDom } from "../features/ensureZoomDom.js";
|
|
@@ -55,6 +56,8 @@ function getNodeId(viz, d, i) {
|
|
|
55
56
|
v.hover(false);
|
|
56
57
|
const links = viz.ctx.linkLookup[id] ?? [];
|
|
57
58
|
const node = viz.ctx.nodeLookup[id];
|
|
59
|
+
// An edge has no node to focus.
|
|
60
|
+
if (!node) return;
|
|
58
61
|
const filterIds = [
|
|
59
62
|
id
|
|
60
63
|
];
|
|
@@ -141,6 +144,8 @@ function getNodeId(viz, d, i) {
|
|
|
141
144
|
const id = getNodeId(viz, d, i);
|
|
142
145
|
const links = viz.ctx.linkLookup[id] ?? [];
|
|
143
146
|
const node = viz.ctx.nodeLookup[id];
|
|
147
|
+
// An edge has no node to focus.
|
|
148
|
+
if (!node) return;
|
|
144
149
|
const filterIds = [
|
|
145
150
|
id
|
|
146
151
|
];
|
|
@@ -222,7 +227,7 @@ function getNodeId(viz, d, i) {
|
|
|
222
227
|
return vv.length === 1 ? vv[0] : vv;
|
|
223
228
|
};
|
|
224
229
|
}
|
|
225
|
-
return
|
|
230
|
+
return fieldAccessor(key);
|
|
226
231
|
});
|
|
227
232
|
return this;
|
|
228
233
|
};
|
|
@@ -233,7 +238,7 @@ function getNodeId(viz, d, i) {
|
|
|
233
238
|
@type {string | function}
|
|
234
239
|
*/ v.size = function(_) {
|
|
235
240
|
if (!arguments.length) return this._size;
|
|
236
|
-
this._size = typeof _ === "function" || !_ ? _ :
|
|
241
|
+
this._size = typeof _ === "function" || !_ ? _ : fieldAccessor(_);
|
|
237
242
|
this._sizeKey = typeof _ === "string" ? _ : undefined;
|
|
238
243
|
return this;
|
|
239
244
|
};
|
|
@@ -248,7 +253,7 @@ function getNodeId(viz, d, i) {
|
|
|
248
253
|
this._x = _;
|
|
249
254
|
} else {
|
|
250
255
|
const key = _;
|
|
251
|
-
this._x =
|
|
256
|
+
this._x = fieldAccessor(key);
|
|
252
257
|
if (!this.schema.aggs[key]) this.schema.aggs[key] = mean;
|
|
253
258
|
}
|
|
254
259
|
return this;
|
|
@@ -264,7 +269,7 @@ function getNodeId(viz, d, i) {
|
|
|
264
269
|
this._y = _;
|
|
265
270
|
} else {
|
|
266
271
|
const key = _;
|
|
267
|
-
this._y =
|
|
272
|
+
this._y = fieldAccessor(key);
|
|
268
273
|
if (!this.schema.aggs[key]) this.schema.aggs[key] = mean;
|
|
269
274
|
}
|
|
270
275
|
return this;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- `recursionCircles.ts` — descendant-walk helper used by hover handlers.
|
|
8
8
|
*/ import { pack } from "d3-hierarchy";
|
|
9
9
|
import accessor from "../../utils/accessor.js";
|
|
10
|
+
import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
10
11
|
import constant from "../../utils/constant.js";
|
|
11
12
|
import { rowLegend } from "../features/sharedFields.js";
|
|
12
13
|
import { makeChart } from "../definition/makeChart.js";
|
|
@@ -81,7 +82,7 @@ export const packDef = {
|
|
|
81
82
|
*/ {
|
|
82
83
|
key: "sum",
|
|
83
84
|
default: accessor("value"),
|
|
84
|
-
coerce: (v)=>typeof v === "function" ? v :
|
|
85
|
+
coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v)
|
|
85
86
|
},
|
|
86
87
|
/**
|
|
87
88
|
The opacity of the parent circles that enclose nested circles: a number or
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/ import { pie as d3Pie } from "d3-shape";
|
|
8
8
|
import { backgroundColor } from "@d3plus/dom";
|
|
9
9
|
import accessor from "../../utils/accessor.js";
|
|
10
|
+
import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
10
11
|
import { centerChartTransform } from "../features/chartGeometry.js";
|
|
11
12
|
import { rowLegend, shareRow } from "../features/sharedFields.js";
|
|
12
13
|
import { makeChart } from "../definition/makeChart.js";
|
|
@@ -86,7 +87,7 @@ export const pieDef = {
|
|
|
86
87
|
*/ {
|
|
87
88
|
key: "value",
|
|
88
89
|
default: accessor("value"),
|
|
89
|
-
coerce: (v)=>typeof v === "function" ? v :
|
|
90
|
+
coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v)
|
|
90
91
|
},
|
|
91
92
|
/**
|
|
92
93
|
A comparator function that sorts the Pie slices. Defaults to descending
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Axis hover for Plot charts (#782): hovering a mark draws a dashed guide
|
|
3
|
+
from its point to each axis and a badge on the axis with the point's
|
|
4
|
+
value there, formatted as the tooltip formats that axis. With a discrete
|
|
5
|
+
axis it follows the snapped hover (see `sharedHover.ts`): the crosshair is
|
|
6
|
+
the discrete axis's guide, and the value axis gets the hovered (or
|
|
7
|
+
nearest) series' point.
|
|
8
|
+
*/ import { nodeColor, ownerNode } from "../features/tooltipSwatch.js";
|
|
9
|
+
import { facetPanelAt } from "../facet/facetPanel.js";
|
|
10
|
+
import { anchorAxes, closestAnchor, collectAnchors, isAnchorMark, liftAnchor, markAnchors, nearestAnchor } from "./axisHoverAnchors.js";
|
|
11
|
+
import { contentPoint, labeledMark } from "./sharedHover.js";
|
|
12
|
+
import { axisValue } from "./sharedTooltip.js";
|
|
13
|
+
/** Pixels a point may sit outside the plot area and still count as shown. */ const SLACK = 1;
|
|
14
|
+
/** Where a value lands on a Plot axis (its position functions take raw values). */ const place = (position, value, axis)=>position(value, axis);
|
|
15
|
+
/**
|
|
16
|
+
The value an axis reads at `pixel`: the record's own value when it is
|
|
17
|
+
drawn there, else the scale inverted at the pixel (a stacked mark's top
|
|
18
|
+
sits at the stack's running total, not its own value).
|
|
19
|
+
@param value The record's value on the axis.
|
|
20
|
+
@param position Where `value` lands on the axis.
|
|
21
|
+
@param pixel Where the anchor sits on the axis.
|
|
22
|
+
@param invert The axis's pixel → value mapping, when it has one.
|
|
23
|
+
*/ export function axisValueAt(value, position, pixel, invert) {
|
|
24
|
+
if (Number.isFinite(position) && Math.abs(position - pixel) <= SLACK) return value;
|
|
25
|
+
return invert ? invert(pixel) : value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
A badge's text for `value`, as plain text: `value` run through `format`,
|
|
29
|
+
with any markup removed. Empty for a missing value.
|
|
30
|
+
@param format The axis's value formatter.
|
|
31
|
+
@param value The value to label.
|
|
32
|
+
*/ export function formatAxisValue(format, value) {
|
|
33
|
+
if (value === undefined || value === null) return "";
|
|
34
|
+
if (typeof value === "number" && !Number.isFinite(value)) return "";
|
|
35
|
+
const text = format ? format(value) : `${value}`;
|
|
36
|
+
return `${text ?? ""}`.replace(/<[^>]*>/g, "").trim();
|
|
37
|
+
}
|
|
38
|
+
/** The pixel → value mapping of a Plot axis, offset the way its position function is. */ function axisInvert(viz, name, position, sample) {
|
|
39
|
+
const scale = viz[`_${name}Axis`]?._d3Scale;
|
|
40
|
+
if (!scale || typeof scale.invert !== "function") return undefined;
|
|
41
|
+
const offset = place(position, sample, name) - scale(sample);
|
|
42
|
+
if (!Number.isFinite(offset)) return undefined;
|
|
43
|
+
return (px)=>scale.invert(px - offset);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
An Area's anchor moved from its baseline to its top edge: its value's
|
|
47
|
+
position, or on a stacked chart the stack's running total there.
|
|
48
|
+
*/ function areaAnchor(viz, anchor, valueAxis) {
|
|
49
|
+
if (anchor.shape !== "Area") return anchor;
|
|
50
|
+
const name = anchor.datum[`${valueAxis}2`] !== undefined ? `${valueAxis}2` : valueAxis;
|
|
51
|
+
const position = valueAxis === "x" ? viz._xFunc : viz._yFunc;
|
|
52
|
+
const value = Number(anchor.datum[name]);
|
|
53
|
+
if (!position || !Number.isFinite(value)) return anchor;
|
|
54
|
+
if (!viz.schema.stacked) return liftAnchor(anchor, place(position, value, name), valueAxis);
|
|
55
|
+
const invert = axisInvert(viz, name, position, value);
|
|
56
|
+
const low = invert ? Number(invert(anchor[valueAxis])) : NaN;
|
|
57
|
+
if (!Number.isFinite(low)) return anchor;
|
|
58
|
+
return liftAnchor(anchor, place(position, low + value, name), valueAxis);
|
|
59
|
+
}
|
|
60
|
+
/** The chart's discrete axis, when it has one. */ function discreteAxis(viz) {
|
|
61
|
+
const discrete = viz.schema.discrete;
|
|
62
|
+
return discrete === "x" || discrete === "y" ? discrete : undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Whether a point sits in the plot area (within a pixel). */ function shown(viz, point) {
|
|
65
|
+
const a = viz._plotArea;
|
|
66
|
+
if (!a) return false;
|
|
67
|
+
return point.x >= a.x - SLACK && point.x <= a.x + a.width + SLACK && point.y >= a.y - SLACK && point.y <= a.y + a.height + SLACK;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
The hovered point of a mark plotted against a secondary value axis, which
|
|
71
|
+
the snapped hover doesn't read: the mark's point nearest the cursor along
|
|
72
|
+
the discrete axis.
|
|
73
|
+
*/ function secondaryAnchor(viz, mark, discrete, cursor) {
|
|
74
|
+
const valueAxis = discrete === "x" ? "y" : "x";
|
|
75
|
+
const anchors = markAnchors(mark, valueAxis, nodeColor(viz, mark));
|
|
76
|
+
if (!anchors.length || anchors[0].datum[`${valueAxis}2`] === undefined) return null;
|
|
77
|
+
return nearestAnchor(anchors.map((a)=>areaAnchor(viz, a, valueAxis)), discrete, cursor[discrete === "x" ? 0 : 1]);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
The anchor a hover resolves to. With a discrete axis it follows the
|
|
81
|
+
snapped hover: among the marks at its position, the hovered mark's (when
|
|
82
|
+
a single mark is hovered), else the one nearest the cursor; a mark the
|
|
83
|
+
snapped hover skips (see `secondaryAnchor`) reads its own point. Without
|
|
84
|
+
a discrete axis it's the hovered mark's point nearest the cursor.
|
|
85
|
+
*/ function hoveredAnchor(viz, event, cursor) {
|
|
86
|
+
const discrete = discreteAxis(viz);
|
|
87
|
+
const picked = event.pick ? event.pick.node : undefined;
|
|
88
|
+
const mark = ownerNode(viz, labeledMark(viz, picked) ?? picked);
|
|
89
|
+
const onMark = isAnchorMark(mark);
|
|
90
|
+
if (discrete) {
|
|
91
|
+
const state = viz._sharedHoverState;
|
|
92
|
+
if (!state) return onMark ? secondaryAnchor(viz, mark, discrete, cursor) : null;
|
|
93
|
+
const id = state.mode === "single" && onMark ? String(mark.datum.id) : undefined;
|
|
94
|
+
const valueAxis = discrete === "x" ? "y" : "x";
|
|
95
|
+
const column = collectAnchors(viz).map((a)=>areaAnchor(viz, a, valueAxis)).filter((a)=>Math.abs(a[discrete] - state.px) <= SLACK && (id === undefined || String(a.datum.id) === id));
|
|
96
|
+
const cross = discrete === "x" ? "y" : "x";
|
|
97
|
+
return nearestAnchor(column, cross, cursor[cross === "x" ? 0 : 1]);
|
|
98
|
+
}
|
|
99
|
+
if (!onMark) return null;
|
|
100
|
+
const anchors = markAnchors(mark, "y", nodeColor(viz, mark));
|
|
101
|
+
return closestAnchor(anchors.map((a)=>areaAnchor(viz, a, "y")), cursor);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
Resolves the axis hover for a pointer event (see the module notes), or
|
|
105
|
+
null when nothing is hovered, the point is outside the plot area, or no
|
|
106
|
+
axis has a value to show.
|
|
107
|
+
@param viz The Plot.
|
|
108
|
+
@param event The pointer event.
|
|
109
|
+
@param cursor The pointer in chart content space.
|
|
110
|
+
*/ export function resolveAxisHover(viz, event, cursor) {
|
|
111
|
+
const anchor = hoveredAnchor(viz, event, cursor);
|
|
112
|
+
if (!anchor || !shown(viz, anchor)) return null;
|
|
113
|
+
const discrete = discreteAxis(viz);
|
|
114
|
+
const state = discrete ? viz._sharedHoverState : null;
|
|
115
|
+
const setting = viz.schema.axisHover;
|
|
116
|
+
const axes = anchorAxes(anchor.datum, {
|
|
117
|
+
discrete,
|
|
118
|
+
bar: anchor.shape === "Bar",
|
|
119
|
+
cross: viz._swarm?.cross,
|
|
120
|
+
only: setting === "x" || setting === "y" ? setting : undefined
|
|
121
|
+
});
|
|
122
|
+
const badges = [];
|
|
123
|
+
for (const axis of axes){
|
|
124
|
+
const dim = axis.charAt(0);
|
|
125
|
+
const snapped = !!state && dim === discrete;
|
|
126
|
+
const at = snapped ? state.px : anchor[dim];
|
|
127
|
+
const position = dim === "x" ? viz._xFunc : viz._yFunc;
|
|
128
|
+
const raw = snapped ? state.value : anchor.datum[axis];
|
|
129
|
+
const value = snapped || !position ? raw : axisValueAt(raw, place(position, raw, axis), at, axisInvert(viz, axis, position, raw));
|
|
130
|
+
const text = formatAxisValue((v)=>axisValue(viz, axis, v), value);
|
|
131
|
+
if (text) badges.push({
|
|
132
|
+
axis,
|
|
133
|
+
at,
|
|
134
|
+
text,
|
|
135
|
+
guide: !snapped
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (!badges.length) return null;
|
|
139
|
+
const row = anchor.datum.data || anchor.datum;
|
|
140
|
+
return {
|
|
141
|
+
point: {
|
|
142
|
+
x: anchor.x,
|
|
143
|
+
y: anchor.y
|
|
144
|
+
},
|
|
145
|
+
color: anchor.color,
|
|
146
|
+
datum: row,
|
|
147
|
+
index: typeof anchor.datum.i === "number" ? anchor.datum.i : 0,
|
|
148
|
+
badges
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** A string that changes whenever the drawn hover would. */ const signature = (s)=>s ? JSON.stringify([
|
|
152
|
+
s.point,
|
|
153
|
+
s.color,
|
|
154
|
+
s.panel,
|
|
155
|
+
s.badges
|
|
156
|
+
]) : "";
|
|
157
|
+
/**
|
|
158
|
+
Plot's axis hover handler, run after the snapped hover resolves: tracks
|
|
159
|
+
the hovered point across moves and clears when the pointer leaves it,
|
|
160
|
+
repainting only when what it draws changes. Off with `axisHover(false)`.
|
|
161
|
+
@param viz The Plot.
|
|
162
|
+
@param event The pointer event.
|
|
163
|
+
*/ export function handleAxisHover(viz, event) {
|
|
164
|
+
let next = null;
|
|
165
|
+
if (event.type === "mousemove" || event.type === "mouseenter") {
|
|
166
|
+
if (viz._transitionEndsAt && Date.now() < viz._transitionEndsAt) return;
|
|
167
|
+
const pick = event.pick?.node;
|
|
168
|
+
if (viz.schema.axisHover !== false && viz._plotArea && Array.isArray(event.point) && !(pick && pick.interactionGroup === "legend")) {
|
|
169
|
+
next = resolveAxisHover(viz, event, contentPoint(viz, event.point));
|
|
170
|
+
if (next) {
|
|
171
|
+
const panel = facetPanelAt(viz, event.point)?.key;
|
|
172
|
+
if (panel !== undefined) next.panel = panel;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else if (event.type !== "mouseleave") return;
|
|
176
|
+
const prev = viz._axisHoverState;
|
|
177
|
+
if (signature(prev) === signature(next)) return;
|
|
178
|
+
viz._axisHoverState = next;
|
|
179
|
+
viz._scheduleSceneRepaint();
|
|
180
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The points a Plot's axis hover (#782) can snap to: a Line/Area's points, a
|
|
3
|
+
Circle's center, and a Bar's end, read from the painted chart scene.
|
|
4
|
+
*/ import { nodeColor } from "../features/tooltipSwatch.js";
|
|
5
|
+
/** Nodes drawn on behalf of another mark (hit targets, stems, error bars). */ const OWNED = /::(hit|stem|confidence)$/;
|
|
6
|
+
/**
|
|
7
|
+
Which edge of a bar's rect is its end: the edge farther from the bar's
|
|
8
|
+
base, which its transform sits on (a negative bar runs the other way).
|
|
9
|
+
@param offset The rect's start along the value axis, relative to the base.
|
|
10
|
+
@param length The rect's size along the value axis.
|
|
11
|
+
*/ export function barEndOffset(offset, length) {
|
|
12
|
+
return Math.abs(offset) >= Math.abs(offset + length) ? offset : offset + length;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
Moves an anchor along its value axis to `end`, spanning from where it was
|
|
16
|
+
(an Area's points sit on its baseline; its value is drawn at its top edge).
|
|
17
|
+
@param anchor The anchor.
|
|
18
|
+
@param end Its end along the value axis.
|
|
19
|
+
@param valueAxis The axis the mark's values run along.
|
|
20
|
+
*/ export function liftAnchor(anchor, end, valueAxis) {
|
|
21
|
+
if (!Number.isFinite(end)) return anchor;
|
|
22
|
+
return {
|
|
23
|
+
...anchor,
|
|
24
|
+
[valueAxis]: end,
|
|
25
|
+
span: [
|
|
26
|
+
anchor[valueAxis],
|
|
27
|
+
end
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
The anchors one mark node draws: each of a Line/Area's interaction points
|
|
33
|
+
(an Area's sit on its baseline, see `liftAnchor`), a circle's center, a Bar's end (along `valueAxis`), or another rect's
|
|
34
|
+
center. Nodes without a source datum, and those drawn for another mark,
|
|
35
|
+
have none.
|
|
36
|
+
@param node The mark's scene node.
|
|
37
|
+
@param valueAxis The axis a Bar's length runs along.
|
|
38
|
+
@param color The mark's color.
|
|
39
|
+
*/ export function markAnchors(node, valueAxis, color) {
|
|
40
|
+
const n = node;
|
|
41
|
+
const datum = n.datum;
|
|
42
|
+
if (!datum || typeof n.key === "string" && OWNED.test(n.key)) return [];
|
|
43
|
+
const shape = n.shapeType;
|
|
44
|
+
if (n.interactionPoints) return n.interactionPoints.map((p)=>({
|
|
45
|
+
x: p.x,
|
|
46
|
+
y: p.y,
|
|
47
|
+
datum: p.datum,
|
|
48
|
+
color,
|
|
49
|
+
shape
|
|
50
|
+
}));
|
|
51
|
+
const tx = n.transform?.x ?? 0, ty = n.transform?.y ?? 0;
|
|
52
|
+
if (n.type === "circle") return [
|
|
53
|
+
{
|
|
54
|
+
x: tx + (n.cx ?? 0),
|
|
55
|
+
y: ty + (n.cy ?? 0),
|
|
56
|
+
datum,
|
|
57
|
+
color,
|
|
58
|
+
shape
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
if (n.type !== "rect") return [];
|
|
62
|
+
const x = n.x ?? 0, y = n.y ?? 0, w = n.width ?? 0, h = n.height ?? 0;
|
|
63
|
+
if (shape !== "Bar") return [
|
|
64
|
+
{
|
|
65
|
+
x: tx + x + w / 2,
|
|
66
|
+
y: ty + y + h / 2,
|
|
67
|
+
datum,
|
|
68
|
+
color,
|
|
69
|
+
shape
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
if (valueAxis === "x") {
|
|
73
|
+
const end = tx + barEndOffset(x, w);
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
x: end,
|
|
77
|
+
y: ty + y + h / 2,
|
|
78
|
+
datum,
|
|
79
|
+
color,
|
|
80
|
+
shape,
|
|
81
|
+
span: [
|
|
82
|
+
tx,
|
|
83
|
+
end
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
const end = ty + barEndOffset(y, h);
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
x: tx + x + w / 2,
|
|
92
|
+
y: end,
|
|
93
|
+
datum,
|
|
94
|
+
color,
|
|
95
|
+
shape,
|
|
96
|
+
span: [
|
|
97
|
+
ty,
|
|
98
|
+
end
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
/** Whether a scene node is a data mark the axis hover reads. */ export function isAnchorMark(node) {
|
|
104
|
+
return !!node && !!node.shapeType && !!node.datum && node.shapeType !== "Box" && !node.interactionGroup && node.interactive !== false && !node.datum.__d3plusShape__;
|
|
105
|
+
}
|
|
106
|
+
/** Every anchor the chart's marks draw (see `markAnchors`). */ export function collectAnchors(viz) {
|
|
107
|
+
const valueAxis = viz.schema.discrete === "y" ? "x" : "y";
|
|
108
|
+
const out = [];
|
|
109
|
+
const walk = (node)=>{
|
|
110
|
+
if (node.interactionGroup || node.interactive === false) return;
|
|
111
|
+
if (node.children) node.children.forEach((c)=>walk(c));
|
|
112
|
+
if (isAnchorMark(node)) out.push(...markAnchors(node, valueAxis, nodeColor(viz, node)));
|
|
113
|
+
};
|
|
114
|
+
(viz._chartScene || []).forEach((node)=>walk(node));
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
The anchor nearest `target` along one axis. A bar holding the target
|
|
119
|
+
within its span counts as no distance away.
|
|
120
|
+
@param anchors The candidates.
|
|
121
|
+
@param axis The axis the distance is measured along.
|
|
122
|
+
@param target The position, in chart content space.
|
|
123
|
+
*/ export function nearestAnchor(anchors, axis, target) {
|
|
124
|
+
let best = null;
|
|
125
|
+
let bestDist = Infinity;
|
|
126
|
+
for (const a of anchors){
|
|
127
|
+
const span = a.span;
|
|
128
|
+
const inside = span && target >= Math.min(span[0], span[1]) && target <= Math.max(span[0], span[1]);
|
|
129
|
+
const dist = inside ? 0 : Math.abs(a[axis] - target);
|
|
130
|
+
if (dist < bestDist) {
|
|
131
|
+
bestDist = dist;
|
|
132
|
+
best = a;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return best;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
The anchor nearest a point in both directions.
|
|
139
|
+
@param anchors The candidates.
|
|
140
|
+
@param point The position, in chart content space.
|
|
141
|
+
*/ export function closestAnchor(anchors, point) {
|
|
142
|
+
let best = null;
|
|
143
|
+
let bestDist = Infinity;
|
|
144
|
+
for (const a of anchors){
|
|
145
|
+
const dist = Math.hypot(a.x - point[0], a.y - point[1]);
|
|
146
|
+
if (dist < bestDist) {
|
|
147
|
+
bestDist = dist;
|
|
148
|
+
best = a;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return best;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
The axes a hovered anchor gets a guide and badge on: x and y, each the
|
|
155
|
+
secondary axis when the record is plotted against it. A bar leaves out its
|
|
156
|
+
discrete axis (its band is labeled already), a swarm leaves out the axis
|
|
157
|
+
its circles are packed along, and `only` keeps just one direction.
|
|
158
|
+
@param datum The anchor's record.
|
|
159
|
+
@param options `discrete`: the chart's discrete axis; `bar`: whether the
|
|
160
|
+
anchor is a Bar's end; `cross`: a swarm's packing axis; `only`: the one
|
|
161
|
+
direction to keep (`axisHover: "x"` or `"y"`).
|
|
162
|
+
*/ export function anchorAxes(datum, options) {
|
|
163
|
+
const out = [];
|
|
164
|
+
for (const dim of [
|
|
165
|
+
"x",
|
|
166
|
+
"y"
|
|
167
|
+
]){
|
|
168
|
+
if (options.bar && dim === (options.discrete ?? "x")) continue;
|
|
169
|
+
if (options.cross === dim) continue;
|
|
170
|
+
if (options.only && options.only !== dim) continue;
|
|
171
|
+
out.push(datum[`${dim}2`] !== undefined ? `${dim}2` : dim);
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Scene nodes for Plot's axis hover (#782): a dashed guide from the hovered
|
|
3
|
+
point to each axis, and a badge on each axis holding the point's value
|
|
4
|
+
there.
|
|
5
|
+
*/ import { colorContrast, colorGray } from "@d3plus/color";
|
|
6
|
+
import { textWidth } from "@d3plus/dom";
|
|
7
|
+
import { parseDash } from "../../shapes/Shape.js";
|
|
8
|
+
/** `axisHoverConfig`'s defaults. */ export function axisHoverDefaults() {
|
|
9
|
+
return {
|
|
10
|
+
guideConfig: {
|
|
11
|
+
strokeDasharray: "4 3",
|
|
12
|
+
strokeWidth: 1
|
|
13
|
+
},
|
|
14
|
+
badgeConfig: {
|
|
15
|
+
fontSize: 12,
|
|
16
|
+
fontWeight: 400,
|
|
17
|
+
padding: 4,
|
|
18
|
+
rx: 2
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
The plot area's edges: the x axis along the bottom, x2 along the top, y
|
|
24
|
+
on the left, and y2 on the right.
|
|
25
|
+
@param area The plot area.
|
|
26
|
+
*/ export function plotEdges(area) {
|
|
27
|
+
return {
|
|
28
|
+
left: area.x,
|
|
29
|
+
right: area.x + area.width,
|
|
30
|
+
top: area.y,
|
|
31
|
+
bottom: area.y + area.height
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
The guide from a point straight across to an axis line.
|
|
36
|
+
@param axis The axis the guide runs to.
|
|
37
|
+
@param point The hovered point.
|
|
38
|
+
@param edges The plot area's edges.
|
|
39
|
+
*/ export function guidePoints(axis, point, edges) {
|
|
40
|
+
const to = axis === "x" ? [
|
|
41
|
+
point.x,
|
|
42
|
+
edges.bottom
|
|
43
|
+
] : axis === "x2" ? [
|
|
44
|
+
point.x,
|
|
45
|
+
edges.top
|
|
46
|
+
] : axis === "y" ? [
|
|
47
|
+
edges.left,
|
|
48
|
+
point.y
|
|
49
|
+
] : [
|
|
50
|
+
edges.right,
|
|
51
|
+
point.y
|
|
52
|
+
];
|
|
53
|
+
return [
|
|
54
|
+
[
|
|
55
|
+
point.x,
|
|
56
|
+
point.y
|
|
57
|
+
],
|
|
58
|
+
to
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
A badge's box: centered on `at` along its axis, and set just outside the
|
|
63
|
+
axis line, over the tick labels.
|
|
64
|
+
@param axis The axis the badge labels.
|
|
65
|
+
@param at The badge's center along the axis.
|
|
66
|
+
@param size The badge's width and height.
|
|
67
|
+
@param edges The plot area's edges.
|
|
68
|
+
*/ export function badgeBox(axis, at, size, edges) {
|
|
69
|
+
const { width, height } = size;
|
|
70
|
+
if (axis === "x") return {
|
|
71
|
+
x: at - width / 2,
|
|
72
|
+
y: edges.bottom,
|
|
73
|
+
width,
|
|
74
|
+
height
|
|
75
|
+
};
|
|
76
|
+
if (axis === "x2") return {
|
|
77
|
+
x: at - width / 2,
|
|
78
|
+
y: edges.top - height,
|
|
79
|
+
width,
|
|
80
|
+
height
|
|
81
|
+
};
|
|
82
|
+
if (axis === "y") return {
|
|
83
|
+
x: edges.left - width,
|
|
84
|
+
y: at - height / 2,
|
|
85
|
+
width,
|
|
86
|
+
height
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
x: edges.right,
|
|
90
|
+
y: at - height / 2,
|
|
91
|
+
width,
|
|
92
|
+
height
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Resolves a style value against the hovered row. */ function style(value, state) {
|
|
96
|
+
return typeof value === "function" ? value(state.datum, state.index) : value;
|
|
97
|
+
}
|
|
98
|
+
/** Stamps a node inert chrome: no hit-testing, never dimmed by hover. */ function inert(node) {
|
|
99
|
+
const n = node;
|
|
100
|
+
n.interactive = false;
|
|
101
|
+
n.interactionGroup = "axis";
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
/** The guide lines from the hovered point to each badged axis. */ function guideNodes(viz, state, edges, color) {
|
|
105
|
+
const config = viz.schema.axisHoverConfig.guideConfig;
|
|
106
|
+
const c = config || {};
|
|
107
|
+
const dash = style(c.strokeDasharray, state);
|
|
108
|
+
return state.badges.filter((b)=>b.guide).map((b)=>inert({
|
|
109
|
+
type: "line",
|
|
110
|
+
key: `plot-axis-hover-guide-${b.axis}`,
|
|
111
|
+
points: guidePoints(b.axis, state.point, edges),
|
|
112
|
+
paint: {
|
|
113
|
+
fill: "none",
|
|
114
|
+
stroke: style(c.stroke, state) ?? color,
|
|
115
|
+
strokeWidth: style(c.strokeWidth, state) ?? 1,
|
|
116
|
+
strokeOpacity: style(c.strokeOpacity, state) ?? 1,
|
|
117
|
+
strokeDasharray: Array.isArray(dash) ? dash : parseDash(dash)
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
/** One axis's badge: a filled box with the value centered in it. */ function badgeNode(viz, state, badge, edges, color) {
|
|
122
|
+
const config = viz.schema.axisHoverConfig.badgeConfig;
|
|
123
|
+
const c = config || {};
|
|
124
|
+
const size = style(c.fontSize, state) ?? 12;
|
|
125
|
+
const family = style(c.fontFamily, state) || `${viz.schema.fontFamily}`;
|
|
126
|
+
const weight = style(c.fontWeight, state) ?? 400;
|
|
127
|
+
const pad = style(c.padding, state) ?? 4;
|
|
128
|
+
const fill = style(c.fill, state) ?? color;
|
|
129
|
+
const ink = style(c.fontColor, state) ?? colorContrast(fill, viz.schema.colorDefaults);
|
|
130
|
+
const width = textWidth(badge.text, {
|
|
131
|
+
"font-family": family,
|
|
132
|
+
"font-size": size,
|
|
133
|
+
"font-weight": weight
|
|
134
|
+
});
|
|
135
|
+
const box = badgeBox(badge.axis, badge.at, {
|
|
136
|
+
width: width + pad * 2,
|
|
137
|
+
height: size + pad * 2
|
|
138
|
+
}, edges);
|
|
139
|
+
const key = `plot-axis-hover-badge-${badge.axis}`;
|
|
140
|
+
return inert({
|
|
141
|
+
type: "group",
|
|
142
|
+
key,
|
|
143
|
+
children: [
|
|
144
|
+
inert({
|
|
145
|
+
type: "rect",
|
|
146
|
+
key: `${key}-box`,
|
|
147
|
+
...box,
|
|
148
|
+
rx: style(c.rx, state) ?? 0,
|
|
149
|
+
paint: {
|
|
150
|
+
fill
|
|
151
|
+
}
|
|
152
|
+
}),
|
|
153
|
+
inert({
|
|
154
|
+
type: "text",
|
|
155
|
+
key: `${key}-text`,
|
|
156
|
+
x: 0,
|
|
157
|
+
y: 0,
|
|
158
|
+
transform: {
|
|
159
|
+
x: box.x + box.width / 2,
|
|
160
|
+
y: box.y + box.height / 2
|
|
161
|
+
},
|
|
162
|
+
lines: [
|
|
163
|
+
{
|
|
164
|
+
text: badge.text,
|
|
165
|
+
x: 0,
|
|
166
|
+
y: 0,
|
|
167
|
+
width
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
font: {
|
|
171
|
+
family,
|
|
172
|
+
size,
|
|
173
|
+
weight,
|
|
174
|
+
anchor: "middle",
|
|
175
|
+
baseline: "middle"
|
|
176
|
+
},
|
|
177
|
+
paint: {
|
|
178
|
+
fill: ink
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
The axis hover's scene nodes, in chart content space: `guides` to draw
|
|
186
|
+
with the plot's marks (inside its zoom clip), and `badges` to draw over
|
|
187
|
+
the axes.
|
|
188
|
+
@param viz The Plot, with the hovered panel's state in place.
|
|
189
|
+
@param state The active axis hover.
|
|
190
|
+
*/ export function axisHoverNodes(viz, state) {
|
|
191
|
+
const area = viz._plotArea;
|
|
192
|
+
if (!area) return {
|
|
193
|
+
guides: [],
|
|
194
|
+
badges: []
|
|
195
|
+
};
|
|
196
|
+
const edges = plotEdges(area);
|
|
197
|
+
const color = state.color || colorGray[500];
|
|
198
|
+
return {
|
|
199
|
+
guides: guideNodes(viz, state, edges, color),
|
|
200
|
+
badges: state.badges.map((b)=>badgeNode(viz, state, b, edges, color))
|
|
201
|
+
};
|
|
202
|
+
}
|