@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,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The ColorScale's hover mark (#770): while a value is hovered (see
|
|
3
|
+
`ColorScale.hover`), an extra axis tick marks where the value falls on
|
|
4
|
+
the color bar and a badge, where that tick's label would sit, reads it.
|
|
5
|
+
A bucketed bar
|
|
6
|
+
(`bucketAxis`) also outlines the value's bucket. Discrete swatches
|
|
7
|
+
(jenks, buckets, quantile without `bucketAxis`) get no mark: the value's
|
|
8
|
+
swatch stays lit and the rest dim instead (see `hoveredSwatch`).
|
|
9
|
+
*/ import { colorContrast } from "@d3plus/color";
|
|
10
|
+
import { backgroundColor, textWidth } from "@d3plus/dom";
|
|
11
|
+
/** `hoverMarkConfig`'s defaults. */ export function hoverMarkDefaults() {
|
|
12
|
+
return {
|
|
13
|
+
tickConfig: {},
|
|
14
|
+
badgeConfig: {
|
|
15
|
+
fontSize: 11,
|
|
16
|
+
fontWeight: 400,
|
|
17
|
+
padding: 3,
|
|
18
|
+
rx: 2
|
|
19
|
+
},
|
|
20
|
+
outlineConfig: {
|
|
21
|
+
strokeWidth: 2
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Whether a bar orient runs along x. */ const horizontal = (orient)=>orient === "bottom" || orient === "top";
|
|
26
|
+
/** `value` held within `[min, max]` (in either order). */ export function clampTo(value, [a, b]) {
|
|
27
|
+
const lo = Math.min(a, b);
|
|
28
|
+
const hi = Math.max(a, b);
|
|
29
|
+
return Math.min(hi, Math.max(lo, value));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
The hovered value's pixel along the bar: a value outside the bar's domain
|
|
33
|
+
clamps to its nearer end. Null for a value that isn't a finite number.
|
|
34
|
+
*/ export function barPosition(geometry, value) {
|
|
35
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
36
|
+
const px = geometry.position(clampTo(value, geometry.domain));
|
|
37
|
+
return Number.isFinite(px) ? clampTo(px, geometry.range) : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
The tick at `at` along a bar whose labels face `orient`: from the bar's
|
|
41
|
+
edge on the labels' side, `length` out toward them.
|
|
42
|
+
@returns The tick's two ends, on the bar first.
|
|
43
|
+
*/ export function tickPoints(orient, at, cross, length) {
|
|
44
|
+
if (orient === "bottom") return [
|
|
45
|
+
[
|
|
46
|
+
at,
|
|
47
|
+
cross[1]
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
at,
|
|
51
|
+
cross[1] + length
|
|
52
|
+
]
|
|
53
|
+
];
|
|
54
|
+
if (orient === "top") return [
|
|
55
|
+
[
|
|
56
|
+
at,
|
|
57
|
+
cross[0]
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
at,
|
|
61
|
+
cross[0] - length
|
|
62
|
+
]
|
|
63
|
+
];
|
|
64
|
+
if (orient === "right") return [
|
|
65
|
+
[
|
|
66
|
+
cross[1],
|
|
67
|
+
at
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
cross[1] + length,
|
|
71
|
+
at
|
|
72
|
+
]
|
|
73
|
+
];
|
|
74
|
+
return [
|
|
75
|
+
[
|
|
76
|
+
cross[0],
|
|
77
|
+
at
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
cross[0] - length,
|
|
81
|
+
at
|
|
82
|
+
]
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
The value badge's box: centered on `at` along the bar (held within
|
|
87
|
+
`[0, limit]`), its near edge `offset` past the bar's edge on the labels'
|
|
88
|
+
side, where the tick ends.
|
|
89
|
+
*/ export function badgeBox(orient, at, cross, size, limit, offset) {
|
|
90
|
+
const { width, height } = size;
|
|
91
|
+
if (horizontal(orient)) {
|
|
92
|
+
const x = clampTo(at - width / 2, [
|
|
93
|
+
0,
|
|
94
|
+
Math.max(0, limit - width)
|
|
95
|
+
]);
|
|
96
|
+
const y = orient === "bottom" ? cross[1] + offset : cross[0] - offset - height;
|
|
97
|
+
return {
|
|
98
|
+
x,
|
|
99
|
+
y,
|
|
100
|
+
width,
|
|
101
|
+
height
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const y = clampTo(at - height / 2, [
|
|
105
|
+
0,
|
|
106
|
+
Math.max(0, limit - height)
|
|
107
|
+
]);
|
|
108
|
+
const x = orient === "right" ? cross[1] + offset : cross[0] - offset - width;
|
|
109
|
+
return {
|
|
110
|
+
x,
|
|
111
|
+
y,
|
|
112
|
+
width,
|
|
113
|
+
height
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
The span `[start, end]` of the bucket holding `value` on a bucketed bar
|
|
118
|
+
whose buckets start at `ticks`, the last running to `domainEnd`; null
|
|
119
|
+
when the value is below the first bucket.
|
|
120
|
+
*/ export function bucketSpan(ticks, value, domainEnd) {
|
|
121
|
+
let index = -1;
|
|
122
|
+
ticks.forEach((tick, i)=>{
|
|
123
|
+
if (value >= tick) index = i;
|
|
124
|
+
});
|
|
125
|
+
if (index < 0) return ticks.length ? [
|
|
126
|
+
ticks[0],
|
|
127
|
+
ticks[1] ?? domainEnd
|
|
128
|
+
] : null;
|
|
129
|
+
return [
|
|
130
|
+
ticks[index],
|
|
131
|
+
ticks[index + 1] ?? domainEnd
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
/** Resolves a style value against the hovered value. */ function style(value, hovered) {
|
|
135
|
+
return typeof value === "function" ? value(hovered) : value;
|
|
136
|
+
}
|
|
137
|
+
/** Stamps a node inert chrome: no hit-testing, never dimmed by hover. */ function inert(node) {
|
|
138
|
+
const n = node;
|
|
139
|
+
n.interactive = false;
|
|
140
|
+
n.interactionGroup = "axis";
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
/** The tick's length: `tickConfig.length`, else the axis's `tickSize`. */ function tickLength(mark) {
|
|
144
|
+
const length = style(mark.config.tickConfig?.length, mark.value);
|
|
145
|
+
const size = mark.cs._axisClass.schema.tickSize;
|
|
146
|
+
return typeof length === "number" ? length : typeof size === "number" ? size : 8;
|
|
147
|
+
}
|
|
148
|
+
/** The tick at `at`, from the bar to the badge. */ function tickNode(mark, orient, at, cross) {
|
|
149
|
+
const c = mark.config.tickConfig || {};
|
|
150
|
+
return inert({
|
|
151
|
+
type: "line",
|
|
152
|
+
key: `${mark.key}-tick`,
|
|
153
|
+
points: tickPoints(orient, at, cross, tickLength(mark)),
|
|
154
|
+
paint: {
|
|
155
|
+
fill: "none",
|
|
156
|
+
stroke: style(c.stroke, mark.value) ?? mark.tickPaint.stroke ?? mark.ink,
|
|
157
|
+
strokeWidth: style(c.strokeWidth, mark.value) ?? mark.tickPaint.strokeWidth ?? 1
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
The badge reading the value, over the axis labels: it starts where the
|
|
163
|
+
tick ends, and its text sits as far from the bar as the tick labels' text
|
|
164
|
+
(the axis's `tickSize` plus its `padding`), so the badge is padded across
|
|
165
|
+
the bar by that gap, or by `padding` when the gap is smaller.
|
|
166
|
+
*/ function badgeNode(mark, geometry, at, text) {
|
|
167
|
+
const { cs, value } = mark;
|
|
168
|
+
const c = mark.config.badgeConfig || {};
|
|
169
|
+
const size = style(c.fontSize, value) ?? 11;
|
|
170
|
+
const family = style(c.fontFamily, value) || `${cs._labelClass.fontFamily()(text)}`;
|
|
171
|
+
const weight = style(c.fontWeight, value) ?? 400;
|
|
172
|
+
const pad = style(c.padding, value) ?? 3;
|
|
173
|
+
const fill = style(c.fill, value) ?? mark.color;
|
|
174
|
+
const ink = style(c.fontColor, value) ?? colorContrast(fill, cs.schema.colorDefaults);
|
|
175
|
+
const width = textWidth(text, {
|
|
176
|
+
"font-family": family,
|
|
177
|
+
"font-size": size,
|
|
178
|
+
"font-weight": weight
|
|
179
|
+
});
|
|
180
|
+
const limit = horizontal(geometry.orient) ? cs.schema.width : cs.schema.height;
|
|
181
|
+
const length = tickLength(mark);
|
|
182
|
+
const axis = cs._axisClass.schema;
|
|
183
|
+
const labelGap = (typeof axis.tickSize === "number" ? axis.tickSize : 8) + (typeof axis.padding === "number" ? axis.padding : 0);
|
|
184
|
+
const across = Math.max(pad, labelGap - length);
|
|
185
|
+
const box = badgeBox(geometry.orient, at, geometry.cross, horizontal(geometry.orient) ? {
|
|
186
|
+
width: width + pad * 2,
|
|
187
|
+
height: size + across * 2
|
|
188
|
+
} : {
|
|
189
|
+
width: width + across * 2,
|
|
190
|
+
height: size + pad * 2
|
|
191
|
+
}, limit, length);
|
|
192
|
+
const key = `${mark.key}-badge`;
|
|
193
|
+
return inert({
|
|
194
|
+
type: "group",
|
|
195
|
+
key,
|
|
196
|
+
children: [
|
|
197
|
+
inert({
|
|
198
|
+
type: "rect",
|
|
199
|
+
key: `${key}-box`,
|
|
200
|
+
...box,
|
|
201
|
+
rx: style(c.rx, value) ?? 0,
|
|
202
|
+
paint: {
|
|
203
|
+
fill,
|
|
204
|
+
stroke: style(c.stroke, value) ?? mark.ink,
|
|
205
|
+
strokeWidth: style(c.strokeWidth, value) ?? 1
|
|
206
|
+
}
|
|
207
|
+
}),
|
|
208
|
+
inert({
|
|
209
|
+
type: "text",
|
|
210
|
+
key: `${key}-text`,
|
|
211
|
+
x: 0,
|
|
212
|
+
y: 0,
|
|
213
|
+
transform: {
|
|
214
|
+
x: box.x + box.width / 2,
|
|
215
|
+
y: box.y + box.height / 2
|
|
216
|
+
},
|
|
217
|
+
lines: [
|
|
218
|
+
{
|
|
219
|
+
text,
|
|
220
|
+
x: 0,
|
|
221
|
+
y: 0,
|
|
222
|
+
width
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
font: {
|
|
226
|
+
family,
|
|
227
|
+
size,
|
|
228
|
+
weight,
|
|
229
|
+
anchor: "middle",
|
|
230
|
+
baseline: "middle"
|
|
231
|
+
},
|
|
232
|
+
paint: {
|
|
233
|
+
fill: ink
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
]
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/** The outline around the bucket holding the value on a bucketed bar. */ function bucketOutline(mark, geometry) {
|
|
240
|
+
if (!geometry.ticks) return [];
|
|
241
|
+
const span = bucketSpan(geometry.ticks, mark.value, geometry.domain[1]);
|
|
242
|
+
if (!span) return [];
|
|
243
|
+
const [a, b] = span.map((v)=>barPosition(geometry, v));
|
|
244
|
+
if (a === null || b === null) return [];
|
|
245
|
+
const c = mark.config.outlineConfig || {};
|
|
246
|
+
const lo = Math.min(a, b);
|
|
247
|
+
const length = Math.abs(b - a);
|
|
248
|
+
const [c0, c1] = geometry.cross;
|
|
249
|
+
const box = horizontal(geometry.orient) ? {
|
|
250
|
+
x: lo,
|
|
251
|
+
y: c0,
|
|
252
|
+
width: length,
|
|
253
|
+
height: c1 - c0
|
|
254
|
+
} : {
|
|
255
|
+
x: c0,
|
|
256
|
+
y: lo,
|
|
257
|
+
width: c1 - c0,
|
|
258
|
+
height: length
|
|
259
|
+
};
|
|
260
|
+
return [
|
|
261
|
+
inert({
|
|
262
|
+
type: "rect",
|
|
263
|
+
key: `${mark.key}-outline`,
|
|
264
|
+
...box,
|
|
265
|
+
paint: {
|
|
266
|
+
fill: "none",
|
|
267
|
+
stroke: style(c.stroke, mark.value) ?? mark.ink,
|
|
268
|
+
strokeWidth: style(c.strokeWidth, mark.value) ?? 2
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
/** The badge text for a value: the axis's own tick format, without markup. */ function formatValue(cs, value) {
|
|
274
|
+
const format = cs._axisClass._labelFormat ?? cs.schema.axisConfig.tickFormat;
|
|
275
|
+
const text = format ? format(value) : `${value}`;
|
|
276
|
+
return `${text ?? ""}`.replace(/<[^>]*>/g, "").trim();
|
|
277
|
+
}
|
|
278
|
+
/** The bar variant's mark: tick, badge, and a bucketed bar's outline. */ function barMark(mark, geometry) {
|
|
279
|
+
const at = barPosition(geometry, mark.value);
|
|
280
|
+
if (at === null) return [];
|
|
281
|
+
const text = formatValue(mark.cs, mark.value);
|
|
282
|
+
return [
|
|
283
|
+
...bucketOutline(mark, geometry),
|
|
284
|
+
tickNode(mark, geometry.orient, at, geometry.cross),
|
|
285
|
+
...text ? [
|
|
286
|
+
badgeNode(mark, geometry, at, text)
|
|
287
|
+
] : []
|
|
288
|
+
];
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
The stroke and width of the ColorScale axis's ticks, read off its scene
|
|
292
|
+
in `group` (the first visible tick path of the `Axis-` group).
|
|
293
|
+
*/ function axisTickPaint(group) {
|
|
294
|
+
let paint;
|
|
295
|
+
const walk = (node, inAxis)=>{
|
|
296
|
+
if (paint) return;
|
|
297
|
+
const axis = inAxis || String(node.key).startsWith("Axis-");
|
|
298
|
+
if (node.type === "group") node.children.forEach((child)=>walk(child, axis));
|
|
299
|
+
else if (axis && node.type === "path" && !String(node.key).endsWith("::hit")) paint = {
|
|
300
|
+
stroke: node.paint?.stroke,
|
|
301
|
+
strokeWidth: node.paint?.strokeWidth
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
group.children.forEach((child)=>walk(child, false));
|
|
305
|
+
return paint ?? {};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
Adds the hover mark for the ColorScale's hovered value to its scene
|
|
309
|
+
`group` (changed in place): nothing when no finite value is hovered,
|
|
310
|
+
`hoverMark` is off, or the scale draws discrete swatches.
|
|
311
|
+
*/ export function addHoverMark(cs, group) {
|
|
312
|
+
const value = cs._hoverValue;
|
|
313
|
+
const geometry = cs._barGeometry;
|
|
314
|
+
if (cs.schema.hoverMark === false || typeof value !== "number" || !Number.isFinite(value) || !cs._colorScale || !geometry) return;
|
|
315
|
+
const node = cs._select && typeof cs._select.node === "function" ? cs._select.node() : null;
|
|
316
|
+
const ink = colorContrast(node ? backgroundColor(node) : "rgb(255, 255, 255)", cs.schema.colorDefaults);
|
|
317
|
+
const mark = {
|
|
318
|
+
cs,
|
|
319
|
+
key: `${group.key}-hover`,
|
|
320
|
+
value,
|
|
321
|
+
color: String(cs._colorScale(value)),
|
|
322
|
+
ink,
|
|
323
|
+
config: cs.schema.hoverMarkConfig || {},
|
|
324
|
+
tickPaint: axisTickPaint(group)
|
|
325
|
+
};
|
|
326
|
+
group.children.push(...barMark(mark, geometry));
|
|
327
|
+
}
|
|
@@ -19,7 +19,7 @@ import { gradientToken } from "@d3plus/render";
|
|
|
19
19
|
labels: labels || ticks,
|
|
20
20
|
orient: cs.schema.orient,
|
|
21
21
|
padding: cs.schema.padding,
|
|
22
|
-
scale:
|
|
22
|
+
scale: compute.scale === "log" ? "log" : "linear",
|
|
23
23
|
ticks,
|
|
24
24
|
width: cs.schema.width
|
|
25
25
|
}, cs.schema.axisConfig);
|
|
@@ -167,6 +167,29 @@ import { gradientToken } from "@d3plus/render";
|
|
|
167
167
|
// Force internal shapes into compute mode so they populate label/scene data
|
|
168
168
|
// without spinning up their own SvgRenderer (which would nest a second <svg>
|
|
169
169
|
// into the page). Legend/Axis do the same.
|
|
170
|
+
const cross = cs._outerBounds[y] + ([
|
|
171
|
+
"top",
|
|
172
|
+
"left"
|
|
173
|
+
].includes(cs.schema.orient) ? axisBounds[height] : 0) + offsets[y];
|
|
174
|
+
cs._barGeometry = {
|
|
175
|
+
orient: cs.schema.orient,
|
|
176
|
+
position: (v)=>axisScale(v) + offsets[x],
|
|
177
|
+
range: [
|
|
178
|
+
scaleRange[0] + offsets[x],
|
|
179
|
+
scaleRange[1] + offsets[x]
|
|
180
|
+
],
|
|
181
|
+
cross: [
|
|
182
|
+
cross,
|
|
183
|
+
cross + cs.schema.size
|
|
184
|
+
],
|
|
185
|
+
domain: [
|
|
186
|
+
axisDomain[0],
|
|
187
|
+
axisDomain[axisDomain.length - 1]
|
|
188
|
+
],
|
|
189
|
+
...ticks ? {
|
|
190
|
+
ticks
|
|
191
|
+
} : {}
|
|
192
|
+
};
|
|
170
193
|
cs._rectClass.renderMode("compute").data(ticks || [
|
|
171
194
|
0
|
|
172
195
|
]).id((_d, i)=>i).select(groups.rectGroup.node()).config(rectConfig).render();
|
|
@@ -198,6 +221,7 @@ import { gradientToken } from "@d3plus/render";
|
|
|
198
221
|
}
|
|
199
222
|
/** Renders the discrete legend ColorScale variant (jenks/buckets/quantile). */ export function renderLegendVariant(cs, compute, groups) {
|
|
200
223
|
const { horizontal, allValues, ticks, colors } = compute;
|
|
224
|
+
cs._barGeometry = undefined;
|
|
201
225
|
elem("g.d3plus-ColorScale-axis", Object.assign({
|
|
202
226
|
condition: groups.gradient
|
|
203
227
|
}, groups.groupParams));
|
|
@@ -4,6 +4,7 @@ import { scaleLinear, scaleThreshold } from "d3-scale";
|
|
|
4
4
|
import { colorLighter, colorRamp } from "@d3plus/color";
|
|
5
5
|
import { unique } from "@d3plus/data";
|
|
6
6
|
import { ckmeans } from "@d3plus/math";
|
|
7
|
+
import { resolveColorScaleType } from "./colorScaleType.js";
|
|
7
8
|
/** The scale's poles, with unset ones taken from its `colorDefaults`. */ const colorMin = (cs)=>cs.schema.colorMin ?? cs.schema.colorDefaults.off;
|
|
8
9
|
const colorMid = (cs)=>cs.schema.colorMid ?? cs.schema.colorDefaults.light;
|
|
9
10
|
const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
@@ -99,13 +100,13 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
/** Resolves the non-diverging linear-gradient color/bucket arrays. */ function resolveNonDivergingLinear(cs, ctx, buckets) {
|
|
102
|
-
const { allValues, domain, negative, positive, diverging, numBuckets } = ctx;
|
|
103
|
+
const { allValues, domain, negative, positive, diverging, numBuckets, scale } = ctx;
|
|
103
104
|
let { colors } = ctx;
|
|
104
105
|
if (!colors) {
|
|
105
106
|
// Single-hue ramp of the relevant pole, stepped in OKLab (light→dark).
|
|
106
107
|
// Negative-only scales read dark→light, so the ramp is reversed.
|
|
107
108
|
const base = negative ? colorMin(cs) : colorMax(cs);
|
|
108
|
-
if (
|
|
109
|
+
if (scale === "buckets" || scale === "quantile") {
|
|
109
110
|
const ramp = colorRamp(base, numBuckets);
|
|
110
111
|
colors = positive ? ramp : ramp.slice().reverse();
|
|
111
112
|
} else {
|
|
@@ -114,7 +115,7 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
if (!buckets) {
|
|
117
|
-
if (
|
|
118
|
+
if (scale === "quantile") {
|
|
118
119
|
const step = 1 / (colors.length - 1);
|
|
119
120
|
buckets = range(0, 1 + step / 2, step).map((d)=>quantile(allValues, d));
|
|
120
121
|
} else if (diverging && cs.schema.color && cs.schema.centered) {
|
|
@@ -135,17 +136,18 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
135
136
|
};
|
|
136
137
|
}
|
|
137
138
|
/** Builds the linear/log/buckets/quantile scale and assigns it to the instance. */ function computeLinearScale(cs, ctx) {
|
|
139
|
+
const { scale } = ctx;
|
|
138
140
|
let buckets = cs.schema.buckets instanceof Array ? cs.schema.buckets : undefined;
|
|
139
141
|
const resolved = ctx.diverging && !ctx.colors ? resolveDivergingLinear(cs, ctx, buckets) : resolveNonDivergingLinear(cs, ctx, buckets);
|
|
140
142
|
let { colors } = resolved;
|
|
141
143
|
buckets = resolved.buckets;
|
|
142
144
|
let ticks;
|
|
143
|
-
if (
|
|
145
|
+
if (scale === "buckets" || scale === "quantile") {
|
|
144
146
|
ticks = buckets;
|
|
145
147
|
colors = [
|
|
146
148
|
colors[0]
|
|
147
149
|
].concat(colors);
|
|
148
|
-
} else if (
|
|
150
|
+
} else if (scale === "log") {
|
|
149
151
|
const negativeBuckets = buckets.filter((d)=>d < 0);
|
|
150
152
|
if (negativeBuckets.length) {
|
|
151
153
|
const minVal = negativeBuckets[0];
|
|
@@ -164,7 +166,7 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
164
166
|
}
|
|
165
167
|
if (buckets.includes(0)) buckets[buckets.indexOf(0)] = 1;
|
|
166
168
|
}
|
|
167
|
-
const scaleFn =
|
|
169
|
+
const scaleFn = scale === "buckets" || scale === "quantile" ? scaleThreshold : scaleLinear;
|
|
168
170
|
cs._colorScale = scaleFn().domain(buckets).range(colors);
|
|
169
171
|
return {
|
|
170
172
|
colors,
|
|
@@ -181,14 +183,16 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
181
183
|
"top"
|
|
182
184
|
].includes(cs.schema.orient);
|
|
183
185
|
const height = horizontal ? "height" : "width", width = horizontal ? "width" : "height", x = horizontal ? "x" : "y", y = horizontal ? "y" : "x";
|
|
184
|
-
const allValues = cs._data.map(cs.schema.value).filter((d)=>
|
|
186
|
+
const allValues = cs._data.map(cs.schema.value).filter((d)=>typeof d === "number" && !Number.isNaN(d)).sort((a, b)=>a - b);
|
|
187
|
+
const scale = resolveColorScaleType(cs.schema.scale, allValues, cs);
|
|
188
|
+
cs._scaleType = scale;
|
|
185
189
|
const domain = cs.schema.domain || extent(allValues);
|
|
186
190
|
const negative = domain[0] < cs.schema.midpoint;
|
|
187
191
|
const positive = domain[1] > cs.schema.midpoint;
|
|
188
192
|
const diverging = negative && positive;
|
|
189
193
|
const numBuckets = min([
|
|
190
194
|
cs.schema.buckets instanceof Array ? cs.schema.buckets.length : cs.schema.buckets,
|
|
191
|
-
diverging &&
|
|
195
|
+
diverging && scale !== "jenks" ? 2 * Math.floor(unique(allValues).length / 2) - 1 : unique(allValues).length
|
|
192
196
|
]);
|
|
193
197
|
let colors = diverging && (!cs.schema.color || cs.schema.color instanceof Array && !cs.schema.color.includes(colorMid(cs))) ? undefined : cs.schema.color;
|
|
194
198
|
if (colors && !(colors instanceof Array)) {
|
|
@@ -196,6 +200,7 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
196
200
|
colors = colorRamp(colors, numBuckets);
|
|
197
201
|
}
|
|
198
202
|
const ctx = {
|
|
203
|
+
scale,
|
|
199
204
|
allValues,
|
|
200
205
|
domain,
|
|
201
206
|
negative,
|
|
@@ -206,9 +211,10 @@ const colorMax = (cs)=>cs.schema.colorMax ?? cs.schema.colorDefaults.sequential;
|
|
|
206
211
|
// is always an array (or undefined).
|
|
207
212
|
colors: colors
|
|
208
213
|
};
|
|
209
|
-
const result =
|
|
214
|
+
const result = scale === "jenks" ? computeJenksScale(cs, ctx) : computeLinearScale(cs, ctx);
|
|
210
215
|
if (cs._colorScale.clamp) cs._colorScale.clamp(true);
|
|
211
216
|
return {
|
|
217
|
+
scale,
|
|
212
218
|
allValues,
|
|
213
219
|
domain,
|
|
214
220
|
ticks: result.ticks,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { warnConfig } from "../../utils/configWarnings.js";
|
|
2
|
+
export const colorScaleTypes = [
|
|
3
|
+
"buckets",
|
|
4
|
+
"jenks",
|
|
5
|
+
"linear",
|
|
6
|
+
"log",
|
|
7
|
+
"quantile"
|
|
8
|
+
];
|
|
9
|
+
/** Whether a scale draws as discrete swatches (one per bucket) rather than a bar. */ export const isBucketScale = (scale)=>scale === "buckets" || scale === "jenks" || scale === "quantile";
|
|
10
|
+
/**
|
|
11
|
+
Resolves a `scale` setting to a scale name for one render. A function is
|
|
12
|
+
called with the sorted `values` and their extent, with `context` as
|
|
13
|
+
`this`. An unknown name warns and falls back to `"linear"`.
|
|
14
|
+
*/ export function resolveColorScaleType(setting, values, context) {
|
|
15
|
+
const extent = values.length ? [
|
|
16
|
+
values[0],
|
|
17
|
+
values[values.length - 1]
|
|
18
|
+
] : [
|
|
19
|
+
void 0,
|
|
20
|
+
void 0
|
|
21
|
+
];
|
|
22
|
+
const scale = typeof setting === "function" ? setting.call(context, values.slice(), extent) : setting;
|
|
23
|
+
if (colorScaleTypes.includes(scale)) return scale;
|
|
24
|
+
warnConfig(`ColorScale received unknown scale ${JSON.stringify(scale) ?? String(scale)}; using "linear". ` + `Use one of ${colorScaleTypes.map((d)=>`"${d}"`).join(", ")}, or a function returning one.`);
|
|
25
|
+
return "linear";
|
|
26
|
+
}
|
|
@@ -3,6 +3,7 @@ import { rtl as detectRTL } from "@d3plus/dom";
|
|
|
3
3
|
import { fontFamily, strip, textSplit } from "@d3plus/text";
|
|
4
4
|
import { SvgRenderer } from "@d3plus/render";
|
|
5
5
|
import { accessor, BaseClass, constant } from "../utils/index.js";
|
|
6
|
+
import { applyClassName } from "../utils/className.js";
|
|
6
7
|
import { installFluent } from "../fluent.js";
|
|
7
8
|
import { computeTextBoxDatum } from "./textBoxLayout.js";
|
|
8
9
|
const defaultHtmlLookup = {
|
|
@@ -324,6 +325,7 @@ const defaultHtmlLookup = {
|
|
|
324
325
|
});
|
|
325
326
|
renderer.drawScene(scene);
|
|
326
327
|
this._sceneRenderer = renderer;
|
|
328
|
+
applyClassName(this);
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
if (callback) setTimeout(callback, 0);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { max, min } from "d3-array";
|
|
2
1
|
import { pointers } from "d3-selection";
|
|
3
2
|
import { assign, attrize, date } from "@d3plus/dom";
|
|
4
3
|
import { closest } from "@d3plus/math";
|
|
5
4
|
import { Axis } from "../index.js";
|
|
6
5
|
import { constant } from "../../utils/index.js";
|
|
7
6
|
import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
|
|
8
|
-
import {
|
|
7
|
+
import { fitBrush, timelineBrushSpan } from "./brushSpan.js";
|
|
8
|
+
import { byValue, initTimelineDefaults } from "./timelineConfig.js";
|
|
9
9
|
import { configureScale, measureTicksWidth, paintTimelineScene, prepareTicks, renderPlayButton, setupBrush } from "./timelineRender.js";
|
|
10
10
|
/** Timeline's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const timelineSchema = [
|
|
11
11
|
{
|
|
@@ -22,6 +22,10 @@ import { configureScale, measureTicksWidth, paintTimelineScene, prepareTicks, re
|
|
|
22
22
|
key: "brushFilter",
|
|
23
23
|
coerce: "identity"
|
|
24
24
|
},
|
|
25
|
+
{
|
|
26
|
+
key: "brushMax",
|
|
27
|
+
coerce: "const"
|
|
28
|
+
},
|
|
25
29
|
{
|
|
26
30
|
key: "brushMin",
|
|
27
31
|
coerce: "const",
|
|
@@ -226,60 +230,47 @@ import { configureScale, measureTicksWidth, paintTimelineScene, prepareTicks, re
|
|
|
226
230
|
@private
|
|
227
231
|
*/ _updateDomain(event) {
|
|
228
232
|
const x = pointers(event, this._select.node());
|
|
229
|
-
|
|
233
|
+
const pixels = (event.selection && this.schema.brushing || !x.length ? event.selection : [
|
|
230
234
|
x[0][0],
|
|
231
235
|
x[0][0]
|
|
232
|
-
];
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
minIndex = max([
|
|
264
|
-
0,
|
|
265
|
-
minIndex - (minTicksAllowed - ticksApart)
|
|
266
|
-
]);
|
|
267
|
-
minDomain = ticks[minIndex];
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
domain[0] = minDomain;
|
|
271
|
-
domain[1] = maxDomain;
|
|
272
|
-
} else {
|
|
273
|
-
domain[0] = closest(domain[0], ticks);
|
|
274
|
-
domain[1] = closest(domain[1], ticks);
|
|
275
|
-
}
|
|
236
|
+
]).map(Number);
|
|
237
|
+
// Each period's value, earliest first (a reversed timeline lays them out
|
|
238
|
+
// latest first), and in buttons mode each button's position.
|
|
239
|
+
const ticksMode = this._buttonBehaviorCurrent === "ticks";
|
|
240
|
+
const periods = byValue(this._availableTicks).map(Number);
|
|
241
|
+
const positions = this._d3Scale.range();
|
|
242
|
+
const values = this._availableTicks.map(Number);
|
|
243
|
+
const periodAt = (px)=>periods.indexOf(ticksMode ? closest(+this._d3Scale.invert(px), periods) : values[positions.indexOf(closest(px, positions))]);
|
|
244
|
+
const ticks = ticksMode ? periods : positions;
|
|
245
|
+
// The edge being dragged (nearest the pointer) stays put when a
|
|
246
|
+
// selection is pulled in to `brushMax`, or (buttons) pushed out to
|
|
247
|
+
// `brushMin`.
|
|
248
|
+
const brushed = event.selection;
|
|
249
|
+
const px = x.length ? x[0][0] : NaN;
|
|
250
|
+
const anchor = brushed && Math.abs(px - brushed[0]) < Math.abs(px - brushed[1]) ? "lo" : "hi";
|
|
251
|
+
// The periods under each edge, moved so the selection spans `brushMin`
|
|
252
|
+
// to `brushMax` periods. A short ticks-mode selection grows from its
|
|
253
|
+
// first tick; a short buttons selection keeps the button being dragged,
|
|
254
|
+
// or starts at the one clicked.
|
|
255
|
+
const [lo, hi] = fitBrush([
|
|
256
|
+
periodAt(pixels[0]),
|
|
257
|
+
periodAt(pixels[1])
|
|
258
|
+
], periods.length, timelineBrushSpan(this.schema), anchor, !ticksMode);
|
|
259
|
+
const position = (i)=>positions[values.indexOf(periods[i])];
|
|
260
|
+
const domain = ticksMode ? [
|
|
261
|
+
date(periods[lo]),
|
|
262
|
+
date(periods[hi])
|
|
263
|
+
] : byValue([
|
|
264
|
+
position(lo),
|
|
265
|
+
position(hi)
|
|
266
|
+
]);
|
|
276
267
|
// if the brush event has finished, update the current "selection" value
|
|
277
268
|
const single = +domain[0] === +domain[1];
|
|
278
269
|
if (event.type === "brush" || event.type === "end") {
|
|
279
|
-
this.schema.selection = this._buttonBehaviorCurrent === "ticks" ? single ? domain[0] : domain : single ? date(this._availableTicks[ticks.indexOf(domain[0])]) : [
|
|
270
|
+
this.schema.selection = this._buttonBehaviorCurrent === "ticks" ? single ? domain[0] : domain : single ? date(this._availableTicks[ticks.indexOf(domain[0])]) : byValue([
|
|
280
271
|
date(this._availableTicks[ticks.indexOf(domain[0])]),
|
|
281
272
|
date(this._availableTicks[ticks.indexOf(domain[1])])
|
|
282
|
-
];
|
|
273
|
+
]);
|
|
283
274
|
}
|
|
284
275
|
return domain;
|
|
285
276
|
}
|
|
@@ -287,7 +278,7 @@ import { configureScale, measureTicksWidth, paintTimelineScene, prepareTicks, re
|
|
|
287
278
|
Updates limits of the brush.
|
|
288
279
|
@private
|
|
289
280
|
*/ _updateBrushLimit(domain) {
|
|
290
|
-
const selection = this._buttonBehaviorCurrent === "ticks" ? domain.map(date).map((d)=>this._d3Scale(d)) : domain;
|
|
281
|
+
const selection = this._buttonBehaviorCurrent === "ticks" ? byValue(domain.map(date).map((d)=>this._d3Scale(d))) : domain;
|
|
291
282
|
if (selection[0] === selection[1]) {
|
|
292
283
|
selection[0] -= 0.1;
|
|
293
284
|
selection[1] += 0.1;
|
|
@@ -330,8 +321,8 @@ import { configureScale, measureTicksWidth, paintTimelineScene, prepareTicks, re
|
|
|
330
321
|
};
|
|
331
322
|
let firstTime = true;
|
|
332
323
|
const nextYear = ()=>{
|
|
333
|
-
const periods = this._buttonBehaviorCurrent === "ticks" ? this._availableTicks : this.schema.ticks;
|
|
334
|
-
if (!periods
|
|
324
|
+
const periods = byValue((this._buttonBehaviorCurrent === "ticks" ? this._availableTicks : this.schema.ticks) || []);
|
|
325
|
+
if (!periods.length) return;
|
|
335
326
|
let selection = this.schema.selection || [
|
|
336
327
|
this.schema.domain[this.schema.domain.length - 1]
|
|
337
328
|
];
|