@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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Precomputed boxes: when a Box is given its statistics (`boxMin`,
|
|
3
|
+
`boxQ1`, `boxMedian`, `boxQ3`, `boxMax`, and optionally `boxOutliers`),
|
|
4
|
+
each data row draws one box from them and nothing is computed.
|
|
5
|
+
*/ import { fieldAccessor } from "../utils/fieldAccessor.js";
|
|
6
|
+
import constant from "../utils/constant.js";
|
|
7
|
+
import { warnConfig } from "../utils/configWarnings.js";
|
|
8
|
+
import { drawsOutlier } from "./boxOutlierShape.js";
|
|
9
|
+
import { uniqueIds } from "./uniqueIds.js";
|
|
10
|
+
/** The config keys that give a box its five statistics, lowest first. */ export const boxStatKeys = [
|
|
11
|
+
"boxMin",
|
|
12
|
+
"boxQ1",
|
|
13
|
+
"boxMedian",
|
|
14
|
+
"boxQ3",
|
|
15
|
+
"boxMax"
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
A statistic setting as a row accessor: unset for `undefined`, `null`, or
|
|
19
|
+
`false`, a data key for a string, a function as given, and any other
|
|
20
|
+
value as a constant.
|
|
21
|
+
*/ export function toStatAccessor(value) {
|
|
22
|
+
if (value === undefined || value === null || value === false) return undefined;
|
|
23
|
+
if (typeof value === "function") return value;
|
|
24
|
+
if (typeof value === "string") return fieldAccessor(value);
|
|
25
|
+
return constant(value);
|
|
26
|
+
}
|
|
27
|
+
/** Whether `config` sets any of the five statistics, which draws precomputed boxes. */ export function hasBoxStats(config) {
|
|
28
|
+
return boxStatKeys.some((key)=>typeof config[key] === "function");
|
|
29
|
+
}
|
|
30
|
+
/** The statistics `config` leaves unset, when it sets at least one. */ export function missingBoxStats(config) {
|
|
31
|
+
if (!hasBoxStats(config)) return [];
|
|
32
|
+
return boxStatKeys.filter((key)=>typeof config[key] !== "function");
|
|
33
|
+
}
|
|
34
|
+
/** Warns, once, that a precomputed box config leaves some statistics unset. */ export function warnMissingBoxStats(owner, config) {
|
|
35
|
+
const missing = missingBoxStats(config);
|
|
36
|
+
if (missing.length) warnConfig(`${owner} draws precomputed boxes only when ${boxStatKeys.join(", ")} are all set; missing ${missing.join(", ")}.`);
|
|
37
|
+
}
|
|
38
|
+
const finite = (v)=>typeof v === "number" ? Number.isFinite(v) : false;
|
|
39
|
+
/** `v` as a number: numbers and Dates convert, anything else is NaN. */ const toNumber = (v)=>typeof v === "number" || v instanceof Date ? +v : NaN;
|
|
40
|
+
/**
|
|
41
|
+
A row's outliers: `boxOutliers` as an array or a single value (what
|
|
42
|
+
aggregating one row's array yields), in order, without any value that
|
|
43
|
+
isn't a finite number.
|
|
44
|
+
*/ function readOutliers(config, d, i) {
|
|
45
|
+
const listed = typeof config.boxOutliers === "function" ? config.boxOutliers(d, i) : undefined;
|
|
46
|
+
return (Array.isArray(listed) ? listed : [
|
|
47
|
+
listed
|
|
48
|
+
]).map(toNumber).filter(finite);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
Reads one row's statistics from `config`'s accessors. The five values are
|
|
52
|
+
sorted, so `min` is the smallest and `max` the largest even when they
|
|
53
|
+
arrive in reverse (as pixels on a top-down axis do). Null when a
|
|
54
|
+
statistic is unset or isn't a finite number.
|
|
55
|
+
*/ export function readBoxSummary(config, d, i) {
|
|
56
|
+
const values = [];
|
|
57
|
+
for (const key of boxStatKeys){
|
|
58
|
+
const fn = config[key];
|
|
59
|
+
if (typeof fn !== "function") return null;
|
|
60
|
+
const v = toNumber(fn(d, i));
|
|
61
|
+
if (!finite(v)) return null;
|
|
62
|
+
values.push(v);
|
|
63
|
+
}
|
|
64
|
+
values.sort((a, b)=>a - b);
|
|
65
|
+
const outliers = readOutliers(config, d, i);
|
|
66
|
+
const [min, q1, median, q3, max] = values;
|
|
67
|
+
return {
|
|
68
|
+
min,
|
|
69
|
+
q1,
|
|
70
|
+
median,
|
|
71
|
+
q3,
|
|
72
|
+
max,
|
|
73
|
+
outliers
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
Every value a row's statistics place on the value axis, for widening its
|
|
78
|
+
domain: each set statistic that is a finite number, then the outliers
|
|
79
|
+
unless `outliers` is false (the row draws none). An incomplete set still
|
|
80
|
+
contributes, so the axis holds its values even though the row draws no
|
|
81
|
+
box.
|
|
82
|
+
*/ export function boxSummaryValues(config, d, i, outliers = true) {
|
|
83
|
+
const values = [];
|
|
84
|
+
for (const key of boxStatKeys){
|
|
85
|
+
const fn = config[key];
|
|
86
|
+
const v = typeof fn === "function" ? toNumber(fn(d, i)) : NaN;
|
|
87
|
+
if (finite(v)) values.push(v);
|
|
88
|
+
}
|
|
89
|
+
return outliers ? values.concat(readOutliers(config, d, i)) : values;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
Stamps a box datum's rect geometry from its quartiles (`first` and
|
|
93
|
+
`third`): centered between them along the value axis, `rectWidth` across
|
|
94
|
+
it, at `key` on the category axis.
|
|
95
|
+
*/ export function placeBox(d, key, rectWidth) {
|
|
96
|
+
const box = d;
|
|
97
|
+
const first = d.first;
|
|
98
|
+
const rectLength = d.third - first;
|
|
99
|
+
if (d.orient === "vertical") {
|
|
100
|
+
box.height = rectLength;
|
|
101
|
+
box.width = rectWidth;
|
|
102
|
+
box.x = key;
|
|
103
|
+
box.y = first + rectLength / 2;
|
|
104
|
+
} else if (d.orient === "horizontal") {
|
|
105
|
+
box.height = rectWidth;
|
|
106
|
+
box.width = rectLength;
|
|
107
|
+
box.x = first + rectLength / 2;
|
|
108
|
+
box.y = key;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** An outlier record drawn with `shape` at `value` beside the box datum `d`. */ function outlierRecord(d, shape, value, k) {
|
|
112
|
+
const vertical = d.orient === "vertical";
|
|
113
|
+
return {
|
|
114
|
+
__d3plus__: true,
|
|
115
|
+
data: d.data,
|
|
116
|
+
i: d.i,
|
|
117
|
+
id: `${d.id}-outlier-${k}`,
|
|
118
|
+
outlier: shape,
|
|
119
|
+
x: vertical ? d.x : value,
|
|
120
|
+
y: vertical ? value : d.y
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
Builds one box per row from its statistics, appending its outliers to
|
|
125
|
+
`outlierData` (none when its `outlier` setting draws no point) and recording which box owns each record in `host._owned`.
|
|
126
|
+
Rows without a complete set of statistics draw nothing.
|
|
127
|
+
*/ export function computeSummaryBoxes(host, outlierData) {
|
|
128
|
+
const { schema } = host;
|
|
129
|
+
warnMissingBoxStats("Box", schema);
|
|
130
|
+
const rows = host._data.map((row, i)=>({
|
|
131
|
+
row,
|
|
132
|
+
i,
|
|
133
|
+
stats: readBoxSummary(schema, row, i)
|
|
134
|
+
})).filter((r)=>r.stats);
|
|
135
|
+
const orient = schema.orient;
|
|
136
|
+
const keys = rows.map(({ row, i })=>orient(row, i) === "vertical" ? schema.x(row, i) : schema.y(row, i));
|
|
137
|
+
const ids = uniqueIds(rows.map(({ row, i }, n)=>{
|
|
138
|
+
const id = schema.id ? schema.id(row, i) : undefined;
|
|
139
|
+
return `${id ?? keys[n]}`;
|
|
140
|
+
}));
|
|
141
|
+
host._owned = new Map();
|
|
142
|
+
return rows.map(({ row, i, stats }, n)=>{
|
|
143
|
+
const s = stats;
|
|
144
|
+
const d = {
|
|
145
|
+
__d3plus__: true,
|
|
146
|
+
key: keys[n],
|
|
147
|
+
values: [
|
|
148
|
+
row
|
|
149
|
+
],
|
|
150
|
+
data: row,
|
|
151
|
+
i,
|
|
152
|
+
id: ids[n],
|
|
153
|
+
orient: orient(row, i),
|
|
154
|
+
first: s.q1,
|
|
155
|
+
median: s.median,
|
|
156
|
+
third: s.q3,
|
|
157
|
+
lowerLimit: s.min,
|
|
158
|
+
upperLimit: s.max
|
|
159
|
+
};
|
|
160
|
+
placeBox(d, keys[n], schema.rectWidth(row, i));
|
|
161
|
+
const start = outlierData.length;
|
|
162
|
+
const shape = schema.outlier(row, i);
|
|
163
|
+
if (drawsOutlier(shape)) s.outliers.forEach((v, k)=>outlierData.push(outlierRecord(d, shape, v, k)));
|
|
164
|
+
const owned = {
|
|
165
|
+
datum: d,
|
|
166
|
+
index: n
|
|
167
|
+
};
|
|
168
|
+
for (const record of [
|
|
169
|
+
d,
|
|
170
|
+
...outlierData.slice(start)
|
|
171
|
+
])host._owned.set(record, owned);
|
|
172
|
+
return d;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
into a caller's element through its own SvgRenderer, outside any Viz.
|
|
4
4
|
*/ import { getSize } from "@d3plus/dom";
|
|
5
5
|
import { SvgRenderer } from "@d3plus/render";
|
|
6
|
+
import { applyClassName } from "../utils/className.js";
|
|
6
7
|
/**
|
|
7
8
|
Paints `shape`'s scene and label text into `node`, sized to the node (or
|
|
8
9
|
its first measurable ancestor), reusing and replacing the shape's previous
|
|
@@ -68,4 +69,5 @@ import { SvgRenderer } from "@d3plus/render";
|
|
|
68
69
|
});
|
|
69
70
|
renderer.drawScene(scene);
|
|
70
71
|
shape._sceneRenderer = renderer;
|
|
72
|
+
applyClassName(shape);
|
|
71
73
|
}
|
|
@@ -5,6 +5,7 @@ import { findLocale, translateLocale as dictionaries } from "@d3plus/locales";
|
|
|
5
5
|
import RESET from "./RESET.js";
|
|
6
6
|
import { containsReset, isPlainObject, mergeConfigBag, resolvesReset, RESOLVES_RESET } from "../fluent.js";
|
|
7
7
|
import { isSharedConfig, warnUnknownConfig } from "./configWarnings.js";
|
|
8
|
+
import { applyClassName, RENDERER_CLASSES, rendererSurfaces } from "./className.js";
|
|
8
9
|
/**
|
|
9
10
|
Swaps every nested `RESET` in a config value for the matching entry of
|
|
10
11
|
`defaults`, dropping the key when that default is `undefined`. Objects
|
|
@@ -148,6 +149,24 @@ import { isSharedConfig, warnUnknownConfig } from "./configWarnings.js";
|
|
|
148
149
|
locale(_) {
|
|
149
150
|
return arguments.length ? (this.schema.locale = findLocale(_), this) : this.schema.locale;
|
|
150
151
|
}
|
|
152
|
+
className(_) {
|
|
153
|
+
if (!arguments.length) return this.schema.className;
|
|
154
|
+
this.schema.className = _;
|
|
155
|
+
applyClassName(this);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
The elements `className` adds its classes to, with the fixed classes
|
|
160
|
+
each one keeps: the drawing surface of the instance's scene renderer,
|
|
161
|
+
once it has rendered.
|
|
162
|
+
@private
|
|
163
|
+
*/ _classNameTargets() {
|
|
164
|
+
const renderer = this._sceneRenderer;
|
|
165
|
+
return rendererSurfaces(renderer).map((el)=>({
|
|
166
|
+
el,
|
|
167
|
+
keep: RENDERER_CLASSES
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
151
170
|
colorDefaults(_) {
|
|
152
171
|
if (!arguments.length) return this.schema.colorDefaults;
|
|
153
172
|
const { scale, ...rest } = _ ?? {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The user's `className` config: CSS classes added to the outermost element
|
|
3
|
+
a chart or component draws into, next to its fixed d3plus classes, so page
|
|
4
|
+
CSS can target one chart.
|
|
5
|
+
*/ /** The fixed classes of a scene renderer's drawing surfaces. */ export const RENDERER_CLASSES = [
|
|
6
|
+
"d3plus-render-svg",
|
|
7
|
+
"d3plus-render-canvas"
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
A scene renderer's drawing surface (its `<svg>` or `<canvas>`), leaving out
|
|
11
|
+
the HTML overlay layer it stacks over the drawing, where page CSS such as
|
|
12
|
+
a background would hide the chart.
|
|
13
|
+
@param renderer The scene renderer, once mounted.
|
|
14
|
+
@private
|
|
15
|
+
*/ export function rendererSurfaces(renderer) {
|
|
16
|
+
return (renderer?.elements?.() ?? []).filter((el)=>el.localName === "svg" || el.localName === "canvas");
|
|
17
|
+
}
|
|
18
|
+
/** The user classes last added to each element, so a new value can replace them. */ const applied = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
The distinct class names in a `className` value. A string is split on
|
|
21
|
+
whitespace, an array's entries are split the same way, and anything else
|
|
22
|
+
gives none.
|
|
23
|
+
@param value The config value.
|
|
24
|
+
@private
|
|
25
|
+
*/ export function classNames(value) {
|
|
26
|
+
const list = Array.isArray(value) ? value : [
|
|
27
|
+
value
|
|
28
|
+
];
|
|
29
|
+
const names = list.flatMap((v)=>typeof v === "string" ? v.split(/\s+/).filter(Boolean) : []);
|
|
30
|
+
return Array.from(new Set(names));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
Adds `value`'s classes to `el`, first removing the classes an earlier call
|
|
34
|
+
added that `value` no longer has. Classes the element has for any other
|
|
35
|
+
reason (its fixed d3plus classes) are left alone, unless an earlier call
|
|
36
|
+
added them.
|
|
37
|
+
@param el The element.
|
|
38
|
+
@param value The `className` config value.
|
|
39
|
+
@param keep Classes never to remove (the element's fixed classes).
|
|
40
|
+
@private
|
|
41
|
+
*/ export function setUserClasses(el, value, keep = []) {
|
|
42
|
+
const next = classNames(value);
|
|
43
|
+
for (const name of applied.get(el) ?? [])if (!next.includes(name) && !keep.includes(name)) el.classList.remove(name);
|
|
44
|
+
for (const name of next)el.classList.add(name);
|
|
45
|
+
applied.set(el, next);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
Applies an instance's `className` to every element it currently draws
|
|
49
|
+
into. Before the first render there are none, and the classes are added
|
|
50
|
+
when it renders.
|
|
51
|
+
@param host The chart or component.
|
|
52
|
+
@private
|
|
53
|
+
*/ export function applyClassName(host) {
|
|
54
|
+
for (const { el, keep } of host._classNameTargets())setUserClasses(el, host.schema.className, keep);
|
|
55
|
+
}
|
|
56
|
+
const escapeAttr = (v)=>v.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
57
|
+
/**
|
|
58
|
+
SVG markup with `value`'s classes added to its root element, so a saved or
|
|
59
|
+
server-rendered chart keeps the classes its page element has.
|
|
60
|
+
@param markup Markup whose first tag is the root element.
|
|
61
|
+
@param value The `className` config value.
|
|
62
|
+
@private
|
|
63
|
+
*/ export function withRootClasses(markup, value) {
|
|
64
|
+
const names = classNames(value);
|
|
65
|
+
const open = /^\s*<[a-zA-Z][^\s>/]*/.exec(markup);
|
|
66
|
+
if (!names.length || !open) return markup;
|
|
67
|
+
const end = markup.indexOf(">", open[0].length);
|
|
68
|
+
const tag = markup.slice(0, end < 0 ? markup.length : end);
|
|
69
|
+
const existing = /\sclass="([^"]*)"/.exec(tag);
|
|
70
|
+
if (!existing) return `${open[0]} class="${escapeAttr(names.join(" "))}"${markup.slice(open[0].length)}`;
|
|
71
|
+
const current = existing[1].split(/\s+/).filter(Boolean);
|
|
72
|
+
const merged = [
|
|
73
|
+
...current,
|
|
74
|
+
...names.filter((n)=>!current.includes(n))
|
|
75
|
+
];
|
|
76
|
+
const at = existing.index;
|
|
77
|
+
return `${markup.slice(0, at)} class="${escapeAttr(merged.join(" "))}"${markup.slice(at + existing[0].length)}`;
|
|
78
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const shared = new WeakSet();
|
|
2
2
|
const warned = new Set();
|
|
3
|
+
const warnedBy = new WeakMap();
|
|
3
4
|
let enabled = true;
|
|
4
5
|
export function configWarnings(_) {
|
|
5
6
|
if (!arguments.length) return enabled;
|
|
@@ -33,3 +34,27 @@ export function configWarnings(_) {
|
|
|
33
34
|
warned.add(message);
|
|
34
35
|
console.warn(message);
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
Logs a config warning once per `owner` and `id`, unless
|
|
39
|
+
`configWarnings(false)` turned them off. Use it for warnings about one
|
|
40
|
+
chart's own config and data, so each chart warns for itself however many
|
|
41
|
+
times it redraws.
|
|
42
|
+
@param owner The instance the warning is about.
|
|
43
|
+
@param id What the warning is about, so a changed message (like a longer
|
|
44
|
+
field list) doesn't log again.
|
|
45
|
+
@param message The warning.
|
|
46
|
+
@private
|
|
47
|
+
*/ export function warnConfigOnce(owner, id, message) {
|
|
48
|
+
if (!enabled) return;
|
|
49
|
+
let ids = warnedBy.get(owner);
|
|
50
|
+
if (!ids) warnedBy.set(owner, ids = new Set());
|
|
51
|
+
if (ids.has(id)) return;
|
|
52
|
+
ids.add(id);
|
|
53
|
+
console.warn(message);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
Whether `warnConfigOnce` would log for `owner` and `id`.
|
|
57
|
+
@private
|
|
58
|
+
*/ export function canWarnOnce(owner, id) {
|
|
59
|
+
return enabled && !warnedBy.get(owner)?.has(id);
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import accessor from "./accessor.js";
|
|
2
|
+
/** The data field each user-named accessor reads. */ const fieldNames = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
`accessor(key)` for a field name the user gave a config key, remembered so
|
|
5
|
+
the chart can warn when no row of its data has that field (see
|
|
6
|
+
`fieldNameOf`). A non-string key gives a plain `accessor`.
|
|
7
|
+
@param key The data field to read.
|
|
8
|
+
@private
|
|
9
|
+
*/ export function fieldAccessor(key) {
|
|
10
|
+
const fn = accessor(key);
|
|
11
|
+
if (typeof key === "string") fieldNames.set(fn, key);
|
|
12
|
+
return fn;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
Remembers that `fn`, a function built from a user's field name (such as a
|
|
16
|
+
comparator ranking rows by it), reads the data field `key`.
|
|
17
|
+
@param fn The function.
|
|
18
|
+
@param key The data field it reads.
|
|
19
|
+
@private
|
|
20
|
+
*/ export function markField(fn, key) {
|
|
21
|
+
fieldNames.set(fn, key);
|
|
22
|
+
return fn;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
The data field behind a function built by `fieldAccessor` or `markField`,
|
|
26
|
+
if any.
|
|
27
|
+
@param fn The value to look up.
|
|
28
|
+
@private
|
|
29
|
+
*/ export function fieldNameOf(fn) {
|
|
30
|
+
return typeof fn === "function" ? fieldNames.get(fn) : undefined;
|
|
31
|
+
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
component's `_select` and draws its scene, reusing the renderer instance
|
|
12
12
|
across re-renders.
|
|
13
13
|
*/ import { SvgRenderer } from "@d3plus/render";
|
|
14
|
+
import { applyClassName } from "./className.js";
|
|
14
15
|
export function paintComponentScene(instance) {
|
|
15
16
|
const sel = instance._select;
|
|
16
17
|
const node = sel && typeof sel.node === "function" ? sel.node() : null;
|
|
@@ -45,4 +46,5 @@ export function paintComponentScene(instance) {
|
|
|
45
46
|
instance._sceneRenderer.drawScene(scene, {
|
|
46
47
|
duration: 0
|
|
47
48
|
});
|
|
49
|
+
applyClassName(instance);
|
|
48
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3plus/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -58,14 +58,15 @@
|
|
|
58
58
|
"d3-transition": "^3.0.1",
|
|
59
59
|
"d3-zoom": "^3.0.0",
|
|
60
60
|
"topojson-client": "^3.1.0",
|
|
61
|
-
"@d3plus/color": "4.
|
|
62
|
-
"@d3plus/data": "4.
|
|
63
|
-
"@d3plus/dom": "4.
|
|
64
|
-
"@d3plus/
|
|
65
|
-
"@d3plus/
|
|
66
|
-
"@d3plus/
|
|
67
|
-
"@d3plus/
|
|
68
|
-
"@d3plus/
|
|
61
|
+
"@d3plus/color": "4.10.0",
|
|
62
|
+
"@d3plus/data": "4.10.0",
|
|
63
|
+
"@d3plus/dom": "4.10.0",
|
|
64
|
+
"@d3plus/export": "4.10.0",
|
|
65
|
+
"@d3plus/format": "4.10.0",
|
|
66
|
+
"@d3plus/locales": "4.10.0",
|
|
67
|
+
"@d3plus/math": "4.10.0",
|
|
68
|
+
"@d3plus/render": "4.10.0",
|
|
69
|
+
"@d3plus/text": "4.10.0"
|
|
69
70
|
},
|
|
70
71
|
"scripts": {
|
|
71
72
|
"build:esm": "node ../../scripts/build-esm.js",
|
package/types/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export { AreaPlot, BarChart, Beeswarm, BoxWhisker, Bullet, BumpChart, Calendar,
|
|
|
2
2
|
export { Axis, AxisBottom, AxisLeft, AxisRight, AxisTop, ColorScale, Legend, Message, SizeLegend, TextBox, Timeline, Tooltip, } from "./src/components/index.js";
|
|
3
3
|
export { Area, Bar, Box, Circle, Image, Line, Path, Rect, Shape, Whisker, } from "./src/shapes/index.js";
|
|
4
4
|
export { accessor, BaseClass, configPrep, configWarnings, constant, RESET, } from "./src/utils/index.js";
|
|
5
|
-
export type { D3plusConfig, AxisConfig, ColorDefaultsConfig, ColorScaleConfig, ConfidenceBandSetting, ConfidenceBound, LegendConfig, SizeLegendConfig, TextBoxConfig, TimelineConfig, TooltipConfig, TrendLineConfig, } from "./src/utils/index.js";
|
|
5
|
+
export type { D3plusConfig, AxisConfig, ColorDefaultsConfig, ColorScaleConfig, ConfidenceBandSetting, ConfidenceBound, LegendConfig, SaveControlConfig, SaveFormat, SizeLegendConfig, TextBoxConfig, TimelineConfig, TooltipConfig, TrendLineConfig, } from "./src/utils/index.js";
|
|
6
6
|
export type { LinkConfig, LinkOption } from "./src/charts/viz/linkGroup.js";
|
|
7
|
+
export type { ColorScaleType, ColorScaleTypeSetting, } from "./src/components/ColorScale/colorScaleType.js";
|
|
8
|
+
export type { ColorScaleHoverMarkConfig } from "./src/components/ColorScale/colorScaleHoverMark.js";
|
|
7
9
|
export type { BulletBandInput } from "./src/charts/Bullet/bulletGeometry.js";
|
|
8
10
|
export type { FunnelConversion, FunnelConversionOption, } from "./src/charts/Funnel/funnelLabels.js";
|
|
9
11
|
export type { FunnelCurve } from "./src/charts/Funnel/funnelGeometry.js";
|
package/types/internal.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ export { xAxisRounding } from "./src/charts/features/xAxisConfig.js";
|
|
|
226
226
|
export { roundedDomain } from "./src/components/Axis/axisRounding.js";
|
|
227
227
|
export { clipToPlotArea, DOMAIN_CLIP_KEY, isDomainClip, unwrapDomainClips, } from "./src/charts/Plot/domainClip.js";
|
|
228
228
|
export type { ClipFrame } from "./src/charts/Plot/domainClip.js";
|
|
229
|
-
export { colorScaleFeature, cornerControlsHeight, cornerPlacements, legendFeature, runLayout, subtitleFeature, timelineFeature, titleFeature, totalFeature, } from "./src/charts/features/features.js";
|
|
229
|
+
export { colorScaleFeature, cornerControlsHeight, cornerPlacements, legendFeature, runLayout, sideControlsDrop, subtitleFeature, timelineFeature, titleFeature, totalFeature, } from "./src/charts/features/features.js";
|
|
230
230
|
export { legendLabelsWhole } from "./src/charts/features/featuresLegend.js";
|
|
231
231
|
export { getTopLeftContributions, topLeftControlsFeature, TOP_LEFT_CONTRIBUTORS, } from "./src/charts/drawSteps/topLeftControls.js";
|
|
232
232
|
export { backContribution } from "./src/charts/drawSteps/backControl.js";
|
|
@@ -242,6 +242,8 @@ export { INSET_PRIORITY, insetBackground, insetComponentOffset, insetFrame, inse
|
|
|
242
242
|
export type { InsetKey, InsetOrient, InsetPlacement, InsetRegion, InsetStyle, } from "./src/charts/features/insetState.js";
|
|
243
243
|
export { tableViewContribution } from "./src/charts/drawSteps/tableViewControl.js";
|
|
244
244
|
export { searchContribution } from "./src/charts/drawSteps/searchControls.js";
|
|
245
|
+
export { saveContribution } from "./src/charts/drawSteps/saveControl.js";
|
|
246
|
+
export { canvasTooCoarse, resolveSaveConfig, saveChart, saveFilename, saveFormats, savePixelRatio, svgForSave, } from "./src/charts/drawSteps/saveChart.js";
|
|
245
247
|
export { broadcastLegend, broadcastLink, linkAs, linkKeys, linkedColorDefaults, linkMembers, linkPredicate, linkValues, registerLink, resolveLink, unregisterLink, } from "./src/charts/viz/linkGroup.js";
|
|
246
248
|
export type { LinkKind, ResolvedLink } from "./src/charts/viz/linkGroup.js";
|
|
247
249
|
export { forEachSceneRow, MARK_TYPES } from "./src/charts/viz/sceneRows.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
BoxWhisker — Plot with `discrete: "x"`, `shape: "Box"`, plus a
|
|
3
|
-
tooltip-title accessor that walks through `__d3plus__` wrappers.
|
|
3
|
+
tooltip-title accessor that walks through `__d3plus__` wrappers. Boxes
|
|
4
|
+
summarize each category's rows, or come from each row's own statistics
|
|
5
|
+
(see `summary.ts`).
|
|
4
6
|
*/
|
|
5
7
|
import type { ChartDefinition } from "../definition/ChartDefinition.js";
|
|
6
8
|
export declare const boxWhiskerDef: ChartDefinition;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
BoxWhisker's hidden outliers: a Box whose `outlier` setting is `false`
|
|
3
|
+
draws no point past its whiskers, so the value axis leaves those values
|
|
4
|
+
out and reaches only as far as the whisker ends.
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPoint } from "@d3plus/data";
|
|
7
|
+
import type { VizInstance } from "../viz/vizTypes.js";
|
|
8
|
+
type Row = Record<string, unknown>;
|
|
9
|
+
type RowFn = (d: DataPoint, i: number) => unknown;
|
|
10
|
+
/** The axis a box's statistics run along: the one that isn't discrete. */
|
|
11
|
+
export declare const boxValueAxis: (viz: VizInstance) => "x" | "y";
|
|
12
|
+
/**
|
|
13
|
+
The `outlier` setting of BoxWhisker's boxes (`shapeConfig.Box.outlier`),
|
|
14
|
+
as an accessor of a plotted row; null when every outlier draws a point.
|
|
15
|
+
*/
|
|
16
|
+
export declare function chartOutlierShape(viz: VizInstance): RowFn | null;
|
|
17
|
+
/** Whether each plotted row's box draws its outliers. */
|
|
18
|
+
export declare function drawsRowOutliers(viz: VizInstance): (row: Row) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
The rows that place `axis` (see `_plotAxisRows`): on the value axis of
|
|
21
|
+
boxes computed from observations, each box's rows without the outliers
|
|
22
|
+
its `outlier` setting hides, plus its whisker ends; otherwise `rows`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function boxAxisRows(viz: VizInstance, rows: Row[], axis: string): Row[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
BoxWhisker's precomputed boxes: with `boxMin`, `boxQ1`, `boxMedian`,
|
|
3
|
+
`boxQ3`, and `boxMax` set, each row is one box drawn from its own
|
|
4
|
+
statistics. These hooks place those statistics on the value axis, pad
|
|
5
|
+
the axis around them, and hand them to the Box shape in pixels.
|
|
6
|
+
*/
|
|
7
|
+
import type { D3Scale } from "../../utils/index.js";
|
|
8
|
+
import type { ShapeEmitter } from "../features/shapeEmit.js";
|
|
9
|
+
import type { VizInstance } from "../viz/vizTypes.js";
|
|
10
|
+
type Row = Record<string, unknown>;
|
|
11
|
+
/** Whether the chart draws its boxes from precomputed statistics. */
|
|
12
|
+
export declare const precomputedBoxes: (viz: VizInstance) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
The values precomputed boxes add to `axis` (see `_plotAxisValues`): each
|
|
15
|
+
row's statistics and drawn outliers, on the value axis only.
|
|
16
|
+
*/
|
|
17
|
+
export declare function boxAxisValues(viz: VizInstance, rows: Row[], axis: string): number[];
|
|
18
|
+
/** The arguments Plot hands a shape's axis buffer. */
|
|
19
|
+
interface BufferArgs {
|
|
20
|
+
data: Row[];
|
|
21
|
+
x: D3Scale;
|
|
22
|
+
y: D3Scale;
|
|
23
|
+
x2?: unknown;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
BoxWhisker's axis buffer: Box's own, which pads the value axis past each
|
|
28
|
+
row's value. A precomputed box spans its statistics, so each row is
|
|
29
|
+
buffered at every one of them; a computed box, at the rows that place
|
|
30
|
+
the axis (see `boxAxisRows`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function boxWhiskerBuffer(this: VizInstance, args: BufferArgs): [unknown, unknown];
|
|
33
|
+
/**
|
|
34
|
+
Draws Box rows: precomputed boxes take their statistics in pixels on the
|
|
35
|
+
value axis; otherwise Plot's own Box path, noting each box it draws for
|
|
36
|
+
the tooltip.
|
|
37
|
+
*/
|
|
38
|
+
export declare const boxWhiskerEmit: ShapeEmitter;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
BoxWhisker's tooltip rows: a box lists its whisker ends, quartiles, and
|
|
3
|
+
median, largest first. A precomputed box reads them from its summary row;
|
|
4
|
+
a box computed from observations recomputes them in data units from the
|
|
5
|
+
observations it drew.
|
|
6
|
+
*/
|
|
7
|
+
import type { DataPoint } from "@d3plus/data";
|
|
8
|
+
import type { SceneNode } from "@d3plus/render";
|
|
9
|
+
import type { WhiskerMode } from "../../shapes/boxStats.js";
|
|
10
|
+
import type { VizInstance } from "../viz/vizTypes.js";
|
|
11
|
+
/** A datum's source row and its index, through Plot's and Box's wrappers. */
|
|
12
|
+
export declare function sourceRow(d: DataPoint, i: number): [DataPoint, number];
|
|
13
|
+
/**
|
|
14
|
+
Notes the box record behind each Box part in `nodes`, keyed by the source
|
|
15
|
+
row a tooltip on that box receives, and returns `nodes`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function noteDrawnBoxes(nodes: SceneNode[]): SceneNode[];
|
|
18
|
+
/** The `whiskerMode` BoxWhisker's boxes draw with. */
|
|
19
|
+
export declare function chartWhiskerMode(viz: VizInstance): WhiskerMode;
|
|
20
|
+
/** One table row per statistic, largest first. */
|
|
21
|
+
type Rows = [string, string][];
|
|
22
|
+
/**
|
|
23
|
+
A drawn box's statistics in data units, from the observations it
|
|
24
|
+
summarizes; null when `row` isn't a drawn box.
|
|
25
|
+
*/
|
|
26
|
+
export declare function drawnBoxStats(viz: VizInstance, row: DataPoint): import("../../shapes/boxStats.js").BoxStats | null;
|
|
27
|
+
/**
|
|
28
|
+
The tooltip rows of a box. A precomputed box lists its given statistics.
|
|
29
|
+
A computed box lists its whisker ends as Maximum and Minimum when its
|
|
30
|
+
`whiskerMode` reaches the extreme values (`"extent"`), and as Upper and
|
|
31
|
+
Lower Whisker otherwise, since a Tukey or quantile whisker can stop short
|
|
32
|
+
of (or past) the data's extremes. Anything else, such as an outlier,
|
|
33
|
+
lists nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function boxTooltipRows(viz: VizInstance, d: DataPoint, i: number): Rows;
|
|
36
|
+
export {};
|
|
@@ -31,6 +31,12 @@ export type ValueField = (typeof VALUE_FIELDS)[number];
|
|
|
31
31
|
@param value The setter's argument.
|
|
32
32
|
*/
|
|
33
33
|
export declare function keyedAccessor(value: unknown): unknown;
|
|
34
|
+
/**
|
|
35
|
+
A value field's default accessor: reads `key` and remembers it as
|
|
36
|
+
`keyedAccessor` does, without naming a field of the user's.
|
|
37
|
+
@param key The data key to read.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defaultKeyedAccessor(key: string): RowAccessor;
|
|
34
40
|
/**
|
|
35
41
|
Remembers that `fn` reads the data key `key`.
|
|
36
42
|
@param fn The accessor.
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
*/
|
|
9
|
+
import type { DataPoint } from "@d3plus/data";
|
|
10
|
+
import type { SceneEvent } from "@d3plus/render";
|
|
11
|
+
import type { VizInstance } from "../viz/vizTypes.js";
|
|
12
|
+
import { type AxisName } from "./axisHoverAnchors.js";
|
|
13
|
+
/** One axis's badge: where it sits along the axis, and its text. */
|
|
14
|
+
export interface AxisHoverBadge {
|
|
15
|
+
axis: AxisName;
|
|
16
|
+
/** The badge's center along the axis, in chart content space. */
|
|
17
|
+
at: number;
|
|
18
|
+
text: string;
|
|
19
|
+
/** Whether a guide runs from the point to this axis (the crosshair is the discrete axis's guide). */
|
|
20
|
+
guide: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** The active axis hover: the hovered point, its color and row, and its badges. */
|
|
23
|
+
export interface AxisHoverState {
|
|
24
|
+
point: {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
};
|
|
28
|
+
color?: string;
|
|
29
|
+
datum: DataPoint;
|
|
30
|
+
index: number;
|
|
31
|
+
badges: AxisHoverBadge[];
|
|
32
|
+
/** The small-multiples panel the hover is in, by key. */
|
|
33
|
+
panel?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
The value an axis reads at `pixel`: the record's own value when it is
|
|
37
|
+
drawn there, else the scale inverted at the pixel (a stacked mark's top
|
|
38
|
+
sits at the stack's running total, not its own value).
|
|
39
|
+
@param value The record's value on the axis.
|
|
40
|
+
@param position Where `value` lands on the axis.
|
|
41
|
+
@param pixel Where the anchor sits on the axis.
|
|
42
|
+
@param invert The axis's pixel → value mapping, when it has one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function axisValueAt(value: unknown, position: number, pixel: number, invert?: (px: number) => unknown): unknown;
|
|
45
|
+
/**
|
|
46
|
+
A badge's text for `value`, as plain text: `value` run through `format`,
|
|
47
|
+
with any markup removed. Empty for a missing value.
|
|
48
|
+
@param format The axis's value formatter.
|
|
49
|
+
@param value The value to label.
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatAxisValue(format: ((d: unknown) => string) | undefined, value: unknown): string;
|
|
52
|
+
/**
|
|
53
|
+
Resolves the axis hover for a pointer event (see the module notes), or
|
|
54
|
+
null when nothing is hovered, the point is outside the plot area, or no
|
|
55
|
+
axis has a value to show.
|
|
56
|
+
@param viz The Plot.
|
|
57
|
+
@param event The pointer event.
|
|
58
|
+
@param cursor The pointer in chart content space.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveAxisHover(viz: VizInstance, event: SceneEvent, cursor: [number, number]): AxisHoverState | null;
|
|
61
|
+
/**
|
|
62
|
+
Plot's axis hover handler, run after the snapped hover resolves: tracks
|
|
63
|
+
the hovered point across moves and clears when the pointer leaves it,
|
|
64
|
+
repainting only when what it draws changes. Off with `axisHover(false)`.
|
|
65
|
+
@param viz The Plot.
|
|
66
|
+
@param event The pointer event.
|
|
67
|
+
*/
|
|
68
|
+
export declare function handleAxisHover(viz: VizInstance, event: SceneEvent): void;
|