@d3plus/core 4.6.0 → 4.7.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/README.md +728 -1454
- package/es/index.js.map +1 -1
- package/es/internal.js +5 -0
- package/es/internal.js.map +1 -1
- package/es/src/charts/Chord/index.js +2 -0
- package/es/src/charts/Chord/index.js.map +1 -1
- package/es/src/charts/Geomap/applyLayout.js +3 -1
- package/es/src/charts/Geomap/applyLayout.js.map +1 -1
- package/es/src/charts/Geomap/index.js +3 -1
- package/es/src/charts/Geomap/index.js.map +1 -1
- package/es/src/charts/Matrix/emit.js +5 -4
- package/es/src/charts/Matrix/emit.js.map +1 -1
- package/es/src/charts/Network/index.js +4 -0
- package/es/src/charts/Network/index.js.map +1 -1
- package/es/src/charts/Pack/emit.js +6 -6
- package/es/src/charts/Pack/emit.js.map +1 -1
- package/es/src/charts/Pack/index.js +2 -0
- package/es/src/charts/Pack/index.js.map +1 -1
- package/es/src/charts/Pie/emit.js +5 -6
- package/es/src/charts/Pie/emit.js.map +1 -1
- package/es/src/charts/Pie/index.js +2 -0
- package/es/src/charts/Pie/index.js.map +1 -1
- package/es/src/charts/Plot/index.js +15 -1
- package/es/src/charts/Plot/index.js.map +1 -1
- package/es/src/charts/Plot/insetRegion.js +21 -0
- package/es/src/charts/Plot/insetRegion.js.map +1 -0
- package/es/src/charts/Plot/sharedHover.js +117 -16
- package/es/src/charts/Plot/sharedHover.js.map +1 -1
- package/es/src/charts/Plot/sharedTooltip.js +35 -15
- package/es/src/charts/Plot/sharedTooltip.js.map +1 -1
- package/es/src/charts/Plot/trendLines.js +140 -38
- package/es/src/charts/Plot/trendLines.js.map +1 -1
- package/es/src/charts/Plot/trendProjection.js +120 -0
- package/es/src/charts/Plot/trendProjection.js.map +1 -0
- package/es/src/charts/Plot/trendScene.js +33 -19
- package/es/src/charts/Plot/trendScene.js.map +1 -1
- package/es/src/charts/Plot/trendTooltip.js +79 -17
- package/es/src/charts/Plot/trendTooltip.js.map +1 -1
- package/es/src/charts/Priestley/emit.js +3 -4
- package/es/src/charts/Priestley/emit.js.map +1 -1
- package/es/src/charts/RadialMatrix/emit.js +4 -4
- package/es/src/charts/RadialMatrix/emit.js.map +1 -1
- package/es/src/charts/Rings/index.js +5 -1
- package/es/src/charts/Rings/index.js.map +1 -1
- package/es/src/charts/Sankey/index.js +2 -0
- package/es/src/charts/Sankey/index.js.map +1 -1
- package/es/src/charts/Tree/index.js +2 -0
- package/es/src/charts/Tree/index.js.map +1 -1
- package/es/src/charts/Treemap/emit.js +3 -4
- package/es/src/charts/Treemap/emit.js.map +1 -1
- package/es/src/charts/definition/ChartDefinition.js.map +1 -1
- package/es/src/charts/definition/makeChart.js +8 -2
- package/es/src/charts/definition/makeChart.js.map +1 -1
- package/es/src/charts/drawSteps/bottomRightControls.js +3 -0
- package/es/src/charts/drawSteps/bottomRightControls.js.map +1 -1
- package/es/src/charts/drawSteps/bottomRightControlsMarkup.js +135 -4
- package/es/src/charts/drawSteps/bottomRightControlsMarkup.js.map +1 -1
- package/es/src/charts/drawSteps/searchControlsMarkup.js +15 -38
- package/es/src/charts/drawSteps/searchControlsMarkup.js.map +1 -1
- package/es/src/charts/events/click.legend.js +10 -5
- package/es/src/charts/events/click.legend.js.map +1 -1
- package/es/src/charts/events/mousemove.shape.js +8 -1
- package/es/src/charts/events/mousemove.shape.js.map +1 -1
- package/es/src/charts/features/emitHelpers.js +19 -5
- package/es/src/charts/features/emitHelpers.js.map +1 -1
- package/es/src/charts/features/features.js +3 -108
- package/es/src/charts/features/features.js.map +1 -1
- package/es/src/charts/features/featuresColorScale.js +161 -0
- package/es/src/charts/features/featuresColorScale.js.map +1 -0
- package/es/src/charts/features/featuresLegend.js +145 -32
- package/es/src/charts/features/featuresLegend.js.map +1 -1
- package/es/src/charts/features/insetState.js +174 -0
- package/es/src/charts/features/insetState.js.map +1 -0
- package/es/src/charts/features/sceneBounds.js +271 -0
- package/es/src/charts/features/sceneBounds.js.map +1 -0
- package/es/src/charts/features/tooltipSwatch.js +73 -0
- package/es/src/charts/features/tooltipSwatch.js.map +1 -0
- package/es/src/charts/pipeline/insetPlacement.js +406 -0
- package/es/src/charts/pipeline/insetPlacement.js.map +1 -0
- package/es/src/charts/pipeline/runVizPipeline.js +6 -2
- package/es/src/charts/pipeline/runVizPipeline.js.map +1 -1
- package/es/src/charts/viz/Viz.js +18 -3
- package/es/src/charts/viz/Viz.js.map +1 -1
- package/es/src/charts/viz/VizBaseConfig.js +20 -24
- package/es/src/charts/viz/VizBaseConfig.js.map +1 -1
- package/es/src/charts/viz/interactionOpacity.js +21 -13
- package/es/src/charts/viz/interactionOpacity.js.map +1 -1
- package/es/src/charts/viz/linkGroup.js +386 -0
- package/es/src/charts/viz/linkGroup.js.map +1 -0
- package/es/src/charts/viz/sceneRows.js +33 -0
- package/es/src/charts/viz/sceneRows.js.map +1 -0
- package/es/src/charts/viz/vizDefaults.js +13 -8
- package/es/src/charts/viz/vizDefaults.js.map +1 -1
- package/es/src/charts/viz/vizTypes.js.map +1 -1
- package/es/src/components/Axis/AxisBottom.js +1 -1
- package/es/src/components/Axis/AxisBottom.js.map +1 -1
- package/es/src/components/Axis/AxisLeft.js +1 -1
- package/es/src/components/Axis/AxisLeft.js.map +1 -1
- package/es/src/components/Axis/AxisRight.js +1 -1
- package/es/src/components/Axis/AxisRight.js.map +1 -1
- package/es/src/components/Axis/AxisTop.js +1 -1
- package/es/src/components/Axis/AxisTop.js.map +1 -1
- package/es/src/components/Axis/axisLayoutLabels.js +13 -1
- package/es/src/components/Axis/axisLayoutLabels.js.map +1 -1
- package/es/src/components/ColorScale/ColorScale.js.map +1 -1
- package/es/src/components/Legend/legendConfig.js +2 -1
- package/es/src/components/Legend/legendConfig.js.map +1 -1
- package/es/src/components/Legend/legendRender.js +42 -5
- package/es/src/components/Legend/legendRender.js.map +1 -1
- package/es/src/components/TextBox.js +1 -1
- package/es/src/components/TextBox.js.map +1 -1
- package/es/src/shapes/Bar.js +1 -1
- package/es/src/shapes/Bar.js.map +1 -1
- package/es/src/shapes/Box.js +1 -1
- package/es/src/shapes/Box.js.map +1 -1
- package/es/src/shapes/Rect.js +1 -1
- package/es/src/shapes/Rect.js.map +1 -1
- package/es/src/shapes/Shape.js +9 -36
- package/es/src/shapes/Shape.js.map +1 -1
- package/es/src/shapes/Whisker.js +1 -1
- package/es/src/shapes/Whisker.js.map +1 -1
- package/es/src/shapes/textureKey.js +104 -0
- package/es/src/shapes/textureKey.js.map +1 -0
- package/es/src/utils/D3plusConfig.js.map +1 -1
- package/package.json +10 -9
- package/types/index.d.ts +1 -0
- package/types/internal.d.ts +7 -0
- package/types/src/charts/Plot/index.d.ts +8 -0
- package/types/src/charts/Plot/insetRegion.d.ts +4 -0
- package/types/src/charts/Plot/sharedHover.d.ts +5 -0
- package/types/src/charts/Plot/sharedTooltip.d.ts +10 -0
- package/types/src/charts/Plot/trendLines.d.ts +23 -3
- package/types/src/charts/Plot/trendProjection.d.ts +28 -0
- package/types/src/charts/Plot/trendScene.d.ts +2 -1
- package/types/src/charts/Plot/trendTooltip.d.ts +16 -5
- package/types/src/charts/definition/ChartDefinition.d.ts +9 -0
- package/types/src/charts/definition/makeChart.d.ts +2 -2
- package/types/src/charts/drawSteps/bottomRightControlsMarkup.d.ts +2 -0
- package/types/src/charts/drawSteps/searchControlsMarkup.d.ts +7 -5
- package/types/src/charts/features/emitHelpers.d.ts +10 -4
- package/types/src/charts/features/features.d.ts +1 -8
- package/types/src/charts/features/featuresColorScale.d.ts +24 -0
- package/types/src/charts/features/featuresLegend.d.ts +15 -0
- package/types/src/charts/features/insetState.d.ts +95 -0
- package/types/src/charts/features/sceneBounds.d.ts +18 -0
- package/types/src/charts/features/tooltipSwatch.d.ts +31 -0
- package/types/src/charts/pipeline/insetPlacement.d.ts +45 -0
- package/types/src/charts/pipeline/runVizPipeline.d.ts +2 -1
- package/types/src/charts/viz/Viz.d.ts +9 -1
- package/types/src/charts/viz/VizBaseConfig.d.ts +8 -12
- package/types/src/charts/viz/linkGroup.d.ts +96 -0
- package/types/src/charts/viz/sceneRows.d.ts +13 -0
- package/types/src/charts/viz/vizTypes.d.ts +17 -0
- package/types/src/components/Axis/AxisBottom.d.ts +1 -1
- package/types/src/components/Axis/AxisLeft.d.ts +1 -1
- package/types/src/components/Axis/AxisRight.d.ts +1 -1
- package/types/src/components/Axis/AxisTop.d.ts +1 -1
- package/types/src/components/ColorScale/ColorScale.d.ts +4 -4
- package/types/src/components/Legend/legendRender.d.ts +1 -1
- package/types/src/components/TextBox.d.ts +1 -1
- package/types/src/shapes/Bar.d.ts +1 -1
- package/types/src/shapes/Box.d.ts +1 -1
- package/types/src/shapes/Rect.d.ts +1 -1
- package/types/src/shapes/Whisker.d.ts +1 -1
- package/types/src/shapes/textureKey.d.ts +9 -0
- package/types/src/utils/D3plusConfig.d.ts +42 -1
- package/umd/d3plus-core.full.js +2393 -594
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +1945 -1601
- package/umd/d3plus-core.js +1744 -404
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +1401 -1087
package/umd/d3plus-core.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/core v4.
|
|
2
|
+
@d3plus/core v4.7.0
|
|
3
3
|
Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
|
|
4
4
|
Copyright (c) 2026 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
6
6
|
*/
|
|
7
7
|
(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('@d3plus/data'), require('@d3plus/dom'), require('d3-brush'), require('d3-color'), require('d3-scale'), require('d3-zoom'), require('@d3plus/color'), require('@d3plus/format'), require('@d3plus/text'), require('d3-selection'), require('open-color/open-color.js'), require('d3-transition'), require('@d3plus/render'), require('@d3plus/locales'), require('@d3plus/math'), require('d3-shape'), require('d3-interpolate'), require('@floating-ui/dom'), require('d3-time-format'), require('d3-chord'), require('d3-tile'), require('d3-geo'), require('d3-geo-projection'), require('d3-composite-projections'), require('topojson-client'), require('d3-force'), require('d3-polygon'), require('d3-hierarchy'), require('d3-sankey')) :
|
|
9
|
-
typeof define === 'function' && define.amd ? define('@d3plus/core', ['exports', 'd3-array', '@d3plus/data', '@d3plus/dom', 'd3-brush', 'd3-color', 'd3-scale', 'd3-zoom', '@d3plus/color', '@d3plus/format', '@d3plus/text', 'd3-selection', 'open-color/open-color.js', 'd3-transition', '@d3plus/render', '@d3plus/locales', '@d3plus/math', 'd3-shape', 'd3-interpolate', '@floating-ui/dom', 'd3-time-format', 'd3-chord', 'd3-tile', 'd3-geo', 'd3-geo-projection', 'd3-composite-projections', 'topojson-client', 'd3-force', 'd3-polygon', 'd3-hierarchy', 'd3-sankey'], factory) :
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = global.d3plus || {}, global.d3Array, global.data, global.dom, global.d3Brush, global.d3Color, global.scales, global.d3Zoom, global.color, global.format, global.text, global.d3Selection, global.pkg, global.d3Transition, global.render, global.locales, global.math, global.d3Shape, global.d3Interpolate, global.dom$1, global.d3TimeFormat, global.d3Chord, global.d3Tile, global.d3GeoCore, global.d3GeoProjection, global.d3CompositeProjections, global.topojsonClient, global.d3Force, global.d3Polygon, global.d3Hierarchy, global.d3Sankey));
|
|
11
|
-
})(this, (function (exports, d3Array, data, dom, d3Brush, d3Color, scales, d3Zoom, color, format, text, d3Selection, pkg, d3Transition, render, locales, math, d3Shape, d3Interpolate, dom$1, d3TimeFormat, d3Chord, d3Tile, d3GeoCore, d3GeoProjection, d3CompositeProjections, topojsonClient, d3Force, d3Polygon, d3Hierarchy, d3Sankey) { 'use strict';
|
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('@d3plus/data'), require('@d3plus/dom'), require('d3-brush'), require('d3-color'), require('d3-scale'), require('d3-zoom'), require('@d3plus/color'), require('@d3plus/format'), require('@d3plus/text'), require('d3-selection'), require('open-color/open-color.js'), require('d3-transition'), require('@d3plus/render'), require('@d3plus/locales'), require('@d3plus/math'), require('d3-shape'), require('d3-interpolate'), require('@floating-ui/dom'), require('d3-time-format'), require('d3-time'), require('d3-chord'), require('d3-tile'), require('d3-geo'), require('d3-geo-projection'), require('d3-composite-projections'), require('topojson-client'), require('d3-force'), require('d3-polygon'), require('d3-hierarchy'), require('d3-sankey')) :
|
|
9
|
+
typeof define === 'function' && define.amd ? define('@d3plus/core', ['exports', 'd3-array', '@d3plus/data', '@d3plus/dom', 'd3-brush', 'd3-color', 'd3-scale', 'd3-zoom', '@d3plus/color', '@d3plus/format', '@d3plus/text', 'd3-selection', 'open-color/open-color.js', 'd3-transition', '@d3plus/render', '@d3plus/locales', '@d3plus/math', 'd3-shape', 'd3-interpolate', '@floating-ui/dom', 'd3-time-format', 'd3-time', 'd3-chord', 'd3-tile', 'd3-geo', 'd3-geo-projection', 'd3-composite-projections', 'topojson-client', 'd3-force', 'd3-polygon', 'd3-hierarchy', 'd3-sankey'], factory) :
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = global.d3plus || {}, global.d3Array, global.data, global.dom, global.d3Brush, global.d3Color, global.scales, global.d3Zoom, global.color, global.format, global.text, global.d3Selection, global.pkg, global.d3Transition, global.render, global.locales, global.math, global.d3Shape, global.d3Interpolate, global.dom$1, global.d3TimeFormat, global.d3Time, global.d3Chord, global.d3Tile, global.d3GeoCore, global.d3GeoProjection, global.d3CompositeProjections, global.topojsonClient, global.d3Force, global.d3Polygon, global.d3Hierarchy, global.d3Sankey));
|
|
11
|
+
})(this, (function (exports, d3Array, data, dom, d3Brush, d3Color, scales, d3Zoom, color, format, text, d3Selection, pkg, d3Transition, render, locales, math, d3Shape, d3Interpolate, dom$1, d3TimeFormat, d3Time, d3Chord, d3Tile, d3GeoCore, d3GeoProjection, d3CompositeProjections, topojsonClient, d3Force, d3Polygon, d3Hierarchy, d3Sankey) { 'use strict';
|
|
12
12
|
|
|
13
13
|
function _interopNamespaceDefault(e) {
|
|
14
14
|
var n = Object.create(null);
|
|
@@ -48,49 +48,6 @@
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
`ResolvedSpec` + `resolveSpec(viz)` — the boundary between
|
|
53
|
-
"config the user supplied" and "context the pipeline transforms."
|
|
54
|
-
|
|
55
|
-
Today the chart's class instance holds both: every `this._foo` slot is
|
|
56
|
-
either a config the user can set (via accessors) or a derived value the
|
|
57
|
-
pipeline writes back during `_preDraw` / `_draw` / `_paint`. The clean
|
|
58
|
-
split is:
|
|
59
|
-
|
|
60
|
-
ResolvedSpec <- user config (frozen, immutable, serializable)
|
|
61
|
-
↓
|
|
62
|
-
VizContext <- pipeline-derived state (filteredData, drawDepth,
|
|
63
|
-
legendData, _chartScene, etc.)
|
|
64
|
-
|
|
65
|
-
`resolveSpec(viz)` returns a frozen snapshot of every user-settable
|
|
66
|
-
config key for the given viz instance. The free functions
|
|
67
|
-
`vizPreDraw(viz)` / `vizDraw(viz)` / `runVizPipeline(viz)` /
|
|
68
|
-
`plotPaint(viz, ctx)` all take a live viz instance — the
|
|
69
|
-
contract that's currently shipping. `resolveSpec` is provided as a
|
|
70
|
-
public seam so callers (custom drivers, tests, future refactors)
|
|
71
|
-
can pin a config snapshot independently of any draw cycle. The
|
|
72
|
-
spec type is the contract.
|
|
73
|
-
|
|
74
|
-
The spec is a READONLY view: mutating it is a programming error. The
|
|
75
|
-
type uses `Readonly<>` to discourage in-place writes; runtime
|
|
76
|
-
freezing happens in `resolveSpec()`.
|
|
77
|
-
*/ /**
|
|
78
|
-
Snapshot every config key from a viz instance into a frozen spec.
|
|
79
|
-
|
|
80
|
-
Reads the same keys `BaseClass.config()` reflects — strips the `_`
|
|
81
|
-
prefix from every instance field whose name matches a method on the
|
|
82
|
-
prototype (the v3/v4 config-method-is-also-the-storage-slot pattern).
|
|
83
|
-
Returns a frozen object so consumers can't accidentally mutate it
|
|
84
|
-
upstream of the chart.
|
|
85
|
-
*/ function resolveSpec(viz) {
|
|
86
|
-
// BaseClass.config() already does this reflection; reuse it.
|
|
87
|
-
const cfg = typeof viz.config === "function" ? viz.config() : {};
|
|
88
|
-
// Object.freeze for shallow protection. Deep freeze isn't worth the cost
|
|
89
|
-
// (most consumers don't mutate, and accessor functions reading the spec
|
|
90
|
-
// wouldn't trigger surface mutation anyway).
|
|
91
|
-
return Object.freeze(cfg);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
51
|
/** Applies the axis title's wrapped height to the orient-side margin. */ function applyTitleMargin(axis, ctx) {
|
|
95
52
|
if (!axis.schema.title) return;
|
|
96
53
|
const { range, p, height, margin } = ctx;
|
|
@@ -132,7 +89,14 @@
|
|
|
132
89
|
const wrap = text.textWrap().fontFamily(fF).fontSize(fS).lineHeight(axis.schema.shapeConfig.lineHeight ? axis.schema.shapeConfig.lineHeight(d, i) : undefined);
|
|
133
90
|
wrap[w](horizontal ? space : wSize - hBuff - p - axis._margin.left - axis._margin.right);
|
|
134
91
|
wrap[h](horizontal ? hSize - hBuff - p - axis._margin.top - axis._margin.bottom : space);
|
|
135
|
-
const
|
|
92
|
+
const text$1 = tickFormat(d);
|
|
93
|
+
let res = wrap(text$1);
|
|
94
|
+
// A label wider than its share of the axis wraps to nothing; measure it
|
|
95
|
+
// across the whole axis instead, so the overlap pass thins the labels out.
|
|
96
|
+
if (horizontal && !rotate && `${text$1}`.trim() && !res.lines.some((l)=>l !== "")) {
|
|
97
|
+
wrap.width(wSize - p * 2);
|
|
98
|
+
res = wrap(text$1);
|
|
99
|
+
}
|
|
136
100
|
res.lines = res.lines.filter((d)=>d !== "");
|
|
137
101
|
res.width = res.lines.length ? Math.ceil(d3Array.max(res.widths)) : 0;
|
|
138
102
|
res.height = res.lines.length ? Math.ceil(res.lines.length * wrap.lineHeight()) + fP : 0;
|
|
@@ -200,6 +164,9 @@
|
|
|
200
164
|
textData = textData.map((datum)=>{
|
|
201
165
|
datum.space = maxSpace - datum.fP * 2;
|
|
202
166
|
const res = calculateLabelSize(axis, datum, labelCtx);
|
|
167
|
+
// A label measured wider than its share (see `calculateLabelSize`) is
|
|
168
|
+
// painted at that width; the overlap pass below thins its neighbors.
|
|
169
|
+
if (horizontal && !datum.rotate) datum.space = Math.max(datum.space, Math.ceil(res.width));
|
|
203
170
|
return Object.assign(res, datum);
|
|
204
171
|
});
|
|
205
172
|
const reverseTextData = textData.slice().reverse();
|
|
@@ -1216,6 +1183,60 @@
|
|
|
1216
1183
|
} : {};
|
|
1217
1184
|
}
|
|
1218
1185
|
|
|
1186
|
+
/** textures.js path-based texture names, drawn by its `paths()` generator. */ const pathNames = [
|
|
1187
|
+
"squares",
|
|
1188
|
+
"nylon",
|
|
1189
|
+
"waves",
|
|
1190
|
+
"woven",
|
|
1191
|
+
"crosses",
|
|
1192
|
+
"caps",
|
|
1193
|
+
"hexagons"
|
|
1194
|
+
];
|
|
1195
|
+
/** Color-valued texture keys; a d3-color object is reduced to its CSS string. */ const colorKeys = [
|
|
1196
|
+
"background",
|
|
1197
|
+
"fill",
|
|
1198
|
+
"stroke"
|
|
1199
|
+
];
|
|
1200
|
+
/**
|
|
1201
|
+
Builds the JSON key of a textures.js config for one datum, or `false` when
|
|
1202
|
+
the datum has no texture or no fill (`"none"`, e.g. a line or link). The key is what a `pattern:<key>` scene fill
|
|
1203
|
+
carries for the renderer backends to materialize. `fill` and `stroke` are
|
|
1204
|
+
the shape's resolved fill and stroke for the datum, used as the texture's
|
|
1205
|
+
default background and line colors.
|
|
1206
|
+
@private
|
|
1207
|
+
*/ function textureKey(textureVal, fill, stroke, textureDefault = {}) {
|
|
1208
|
+
if (!textureVal) return false;
|
|
1209
|
+
const background = fill();
|
|
1210
|
+
if (background === "none") return false;
|
|
1211
|
+
const texture = dom.isObject(textureVal) ? {
|
|
1212
|
+
...textureVal
|
|
1213
|
+
} : {
|
|
1214
|
+
texture: textureVal
|
|
1215
|
+
};
|
|
1216
|
+
if (!texture.background) texture.background = background;
|
|
1217
|
+
if (!texture.stroke && !textureDefault.stroke) texture.stroke = stroke();
|
|
1218
|
+
if (pathNames.includes(texture.texture) || typeof texture.texture === "function") {
|
|
1219
|
+
texture.d = texture.texture;
|
|
1220
|
+
texture.texture = "paths";
|
|
1221
|
+
} else if (texture.texture === "grid") {
|
|
1222
|
+
if (!texture.orientation && !textureDefault.orientation) texture.orientation = [
|
|
1223
|
+
"vertical",
|
|
1224
|
+
"horizontal"
|
|
1225
|
+
];
|
|
1226
|
+
texture.texture = "lines";
|
|
1227
|
+
}
|
|
1228
|
+
if (!texture.fill && texture.texture !== "paths") texture.fill = texture.stroke;
|
|
1229
|
+
for (const key of colorKeys){
|
|
1230
|
+
const v = texture[key];
|
|
1231
|
+
if (v && typeof v === "object") texture[key] = String(v);
|
|
1232
|
+
}
|
|
1233
|
+
const retObj = dom.assign({}, textureDefault, texture);
|
|
1234
|
+
if (typeof retObj.d === "function") {
|
|
1235
|
+
retObj.d = retObj.d(retObj.size || 20);
|
|
1236
|
+
}
|
|
1237
|
+
return JSON.stringify(retObj);
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1219
1240
|
/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back
|
|
1220
1241
|
to the source datum, so a `sort` comparator sees the same object the other
|
|
1221
1242
|
per-datum accessors receive. */ function unwrap(d) {
|
|
@@ -1656,39 +1677,7 @@
|
|
|
1656
1677
|
*/ const styleLogic = (_)=>{
|
|
1657
1678
|
return typeof _ !== "function" ? _ : d.nested && d.key && d.values ? _(d.values[0], this._data.indexOf(d.values[0])) : _(d, i);
|
|
1658
1679
|
};
|
|
1659
|
-
|
|
1660
|
-
let texture;
|
|
1661
|
-
if (!dom.isObject(textureVal)) texture = {
|
|
1662
|
-
texture: textureVal
|
|
1663
|
-
};
|
|
1664
|
-
else texture = textureVal;
|
|
1665
|
-
if (!texture.background) texture.background = styleLogic(this.schema.fill);
|
|
1666
|
-
if (!texture.stroke && !fallback.stroke) texture.stroke = styleLogic(this.schema.stroke);
|
|
1667
|
-
const pathNames = [
|
|
1668
|
-
"squares",
|
|
1669
|
-
"nylon",
|
|
1670
|
-
"waves",
|
|
1671
|
-
"woven",
|
|
1672
|
-
"crosses",
|
|
1673
|
-
"caps",
|
|
1674
|
-
"hexagons"
|
|
1675
|
-
];
|
|
1676
|
-
if (pathNames.includes(texture.texture) || typeof texture.texture === "function") {
|
|
1677
|
-
texture.d = texture.texture;
|
|
1678
|
-
texture.texture = "paths";
|
|
1679
|
-
} else if (texture.texture === "grid") {
|
|
1680
|
-
if (!texture.orientation && !fallback.orientation) texture.orientation = [
|
|
1681
|
-
"vertical",
|
|
1682
|
-
"horizontal"
|
|
1683
|
-
];
|
|
1684
|
-
texture.texture = "lines";
|
|
1685
|
-
}
|
|
1686
|
-
if (!texture.fill && texture.texture !== "paths") texture.fill = texture.stroke;
|
|
1687
|
-
const retObj = dom.assign({}, fallback, texture);
|
|
1688
|
-
if (typeof retObj.d === "function") {
|
|
1689
|
-
retObj.d = retObj.d(retObj.size || 20);
|
|
1690
|
-
}
|
|
1691
|
-
return JSON.stringify(retObj);
|
|
1680
|
+
return textureKey(textureVal, ()=>styleLogic(this.schema.fill), ()=>styleLogic(this.schema.stroke), this.schema.textureDefault);
|
|
1692
1681
|
}
|
|
1693
1682
|
/**
|
|
1694
1683
|
Checks for nested data and uses the appropriate variables for accessor functions.
|
|
@@ -2063,7 +2052,7 @@
|
|
|
2063
2052
|
"none"
|
|
2064
2053
|
].includes(c)) c = this.schema.stroke(d, i);
|
|
2065
2054
|
const col = d3Color.color(c);
|
|
2066
|
-
return col ? col.darker(1) : c;
|
|
2055
|
+
return col ? col.darker(1).toString() : c;
|
|
2067
2056
|
},
|
|
2068
2057
|
"stroke-width": (d, i)=>{
|
|
2069
2058
|
const s = this.schema.strokeWidth(d, i) || 1;
|
|
@@ -2078,7 +2067,7 @@
|
|
|
2078
2067
|
"none"
|
|
2079
2068
|
].includes(c)) c = this.schema.stroke(d, i);
|
|
2080
2069
|
const col = d3Color.color(c);
|
|
2081
|
-
return col ? col.darker(0.5) : c;
|
|
2070
|
+
return col ? col.darker(0.5).toString() : c;
|
|
2082
2071
|
},
|
|
2083
2072
|
"stroke-width": (d, i)=>{
|
|
2084
2073
|
const s = this.schema.strokeWidth(d, i) || 1;
|
|
@@ -4423,8 +4412,7 @@
|
|
|
4423
4412
|
},
|
|
4424
4413
|
labelBounds: (dd, i)=>{
|
|
4425
4414
|
const d = legend._lineData[i];
|
|
4426
|
-
|
|
4427
|
-
if (d.shape === "Circle") x -= d.shapeR / 2;
|
|
4415
|
+
const x = d.shapeWidth / 2;
|
|
4428
4416
|
const height = d3Array.max([
|
|
4429
4417
|
d.shapeHeight,
|
|
4430
4418
|
d.height
|
|
@@ -4450,6 +4438,8 @@
|
|
|
4450
4438
|
// key than its swatch, so hovering across the swatch→label padding would
|
|
4451
4439
|
// otherwise read as leaving one item and entering another.
|
|
4452
4440
|
pointerEvents: constant("none"),
|
|
4441
|
+
// Every swatch's label starts right after it (a Circle's own labels center).
|
|
4442
|
+
textAnchor: "start",
|
|
4453
4443
|
verticalAlign: "middle"
|
|
4454
4444
|
},
|
|
4455
4445
|
opacity: 1,
|
|
@@ -4478,14 +4468,16 @@
|
|
|
4478
4468
|
const label = legend.schema.label(d, i);
|
|
4479
4469
|
const shape = legend.schema.shape(d, i);
|
|
4480
4470
|
const r = legend._fetchConfig("r", d, i);
|
|
4471
|
+
const height = legend._fetchConfig("height", d, i);
|
|
4481
4472
|
let res = {
|
|
4482
4473
|
data: d,
|
|
4483
4474
|
i,
|
|
4484
4475
|
id: legend.schema.id(d, i),
|
|
4485
4476
|
shape,
|
|
4486
4477
|
shapeR: r,
|
|
4487
|
-
|
|
4488
|
-
|
|
4478
|
+
// A Line swatch fills a square, like a Rect's, so swatches line up.
|
|
4479
|
+
shapeWidth: shape === "Circle" ? r * 2 : shape === "Line" ? height : legend._fetchConfig("width", d, i),
|
|
4480
|
+
shapeHeight: shape === "Circle" ? r * 2 : height,
|
|
4489
4481
|
y: 0
|
|
4490
4482
|
};
|
|
4491
4483
|
if (!label) {
|
|
@@ -4646,7 +4638,26 @@
|
|
|
4646
4638
|
right: "end"
|
|
4647
4639
|
}[legend.schema.align]).width(legend.schema.width - legend.schema.padding * 2).x(legend.schema.padding).y(legend._outerBounds.y).config(legend.schema.titleConfig).render();
|
|
4648
4640
|
}
|
|
4649
|
-
/**
|
|
4641
|
+
/** A Line swatch's dot radius, as a share of its size: its stroke pokes out either side. */ const LINE_DOT = 0.3;
|
|
4642
|
+
/** A Line swatch's stroke thickness, in pixels. */ const LINE_STROKE = 2;
|
|
4643
|
+
/**
|
|
4644
|
+
Per-shape overrides that draw a "Line" legend entry as a line glyph: a
|
|
4645
|
+
short stroke (in the Rect group, which also carries the item's label and
|
|
4646
|
+
hover target) through a small dot (in the Circle group).
|
|
4647
|
+
*/ function lineSwatchConfig(legend, shapeName) {
|
|
4648
|
+
const isLine = (d)=>d.shape === "Line";
|
|
4649
|
+
const fetch = (key, d)=>legend._fetchConfig(key, d.data, d.i);
|
|
4650
|
+
const line = (d)=>legend._lineData[d.i];
|
|
4651
|
+
return shapeName === "Rect" ? {
|
|
4652
|
+
width: (d)=>isLine(d) ? line(d).shapeWidth : fetch("width", d),
|
|
4653
|
+
height: (d)=>isLine(d) ? LINE_STROKE : fetch("height", d)
|
|
4654
|
+
} : {
|
|
4655
|
+
r: (d)=>isLine(d) ? line(d).shapeHeight * LINE_DOT : fetch("r", d),
|
|
4656
|
+
label: (d)=>isLine(d) ? false : d.label,
|
|
4657
|
+
hitArea: (d)=>isLine(d) ? null : fetch("hitArea", d)
|
|
4658
|
+
};
|
|
4659
|
+
}
|
|
4660
|
+
/** Builds the per-shape data and renders the Circle/Rect swatch groups (Line entries draw in both). */ function renderLegendShapes(legend) {
|
|
4650
4661
|
legend._shapes = [];
|
|
4651
4662
|
const baseConfig = configPrep.bind(legend)(legend.schema.shapeConfig, "legend"), config = {
|
|
4652
4663
|
id: (d)=>d.id,
|
|
@@ -4670,9 +4681,9 @@
|
|
|
4670
4681
|
].forEach((shapeName)=>{
|
|
4671
4682
|
legend._shapes.push(// Child shapes are compute-only — Legend composes the swatches into its
|
|
4672
4683
|
// own toScene, so sub-shapes never auto-render their own <svg>.
|
|
4673
|
-
new shapes[shapeName]().renderMode("compute").parent(legend).data(data.filter((d)=>d.shape === shapeName)).duration(legend.schema.duration).labelConfig({
|
|
4684
|
+
new shapes[shapeName]().renderMode("compute").parent(legend).data(data.filter((d)=>d.shape === shapeName || d.shape === "Line")).duration(legend.schema.duration).labelConfig({
|
|
4674
4685
|
padding: 0
|
|
4675
|
-
}).select(legend._shapeGroup.node()).verticalAlign("top").config(baseConfig).config(config).render());
|
|
4686
|
+
}).select(legend._shapeGroup.node()).verticalAlign("top").config(baseConfig).config(config).config(lineSwatchConfig(legend, shapeName)).render());
|
|
4676
4687
|
});
|
|
4677
4688
|
}
|
|
4678
4689
|
|
|
@@ -8062,6 +8073,234 @@
|
|
|
8062
8073
|
}
|
|
8063
8074
|
}
|
|
8064
8075
|
|
|
8076
|
+
/** Scene mark types that carry a datum hover/active/highlight/search apply to. */ const MARK_TYPES = new Set([
|
|
8077
|
+
"rect",
|
|
8078
|
+
"circle",
|
|
8079
|
+
"line",
|
|
8080
|
+
"area",
|
|
8081
|
+
"path"
|
|
8082
|
+
]);
|
|
8083
|
+
/**
|
|
8084
|
+
Calls `fn` once per painted data mark in `nodes`, with the mark's source
|
|
8085
|
+
row and index. The row is unwrapped one level (`datum.data ?? datum`) and
|
|
8086
|
+
the index resolved `node.index` → `row.i` → 0, the same way
|
|
8087
|
+
`applyInteractionOpacity` evaluates its predicates, so a predicate sees the
|
|
8088
|
+
same arguments here as it does when the scene is dimmed. Rows are de-duped
|
|
8089
|
+
by reference, so a mark's separate label node doesn't visit it twice.
|
|
8090
|
+
*/ function forEachSceneRow(nodes, fn) {
|
|
8091
|
+
const seen = new Set();
|
|
8092
|
+
const walk = (node)=>{
|
|
8093
|
+
if (MARK_TYPES.has(node.type) && node.datum !== undefined) {
|
|
8094
|
+
const raw = node.datum;
|
|
8095
|
+
const row = raw && raw.data ? raw.data : raw;
|
|
8096
|
+
if (row !== undefined && !seen.has(row)) {
|
|
8097
|
+
seen.add(row);
|
|
8098
|
+
const i = typeof node.index === "number" ? node.index : typeof row.i === "number" ? row.i : 0;
|
|
8099
|
+
fn(row, i, node);
|
|
8100
|
+
}
|
|
8101
|
+
}
|
|
8102
|
+
const kids = node.children;
|
|
8103
|
+
if (kids) kids.forEach(walk);
|
|
8104
|
+
};
|
|
8105
|
+
nodes.forEach(walk);
|
|
8106
|
+
}
|
|
8107
|
+
|
|
8108
|
+
const groups = new Map();
|
|
8109
|
+
const groupColorScales = new Map();
|
|
8110
|
+
const dispatching = new Set();
|
|
8111
|
+
const linkAsPredicates = new WeakMap();
|
|
8112
|
+
/** Normalizes a chart's `link` config, or returns null when it isn't linked. */ function resolveLink(viz) {
|
|
8113
|
+
const raw = viz.schema.link;
|
|
8114
|
+
if (!raw) return null;
|
|
8115
|
+
const cfg = typeof raw === "string" ? {
|
|
8116
|
+
group: raw
|
|
8117
|
+
} : raw;
|
|
8118
|
+
if (!cfg.group) return null;
|
|
8119
|
+
const by = typeof cfg.by === "function" ? cfg.by : typeof cfg.by === "string" ? accessor(cfg.by) : (d, i)=>viz._id?.(d, i);
|
|
8120
|
+
return {
|
|
8121
|
+
group: cfg.group,
|
|
8122
|
+
by,
|
|
8123
|
+
hover: cfg.hover !== false,
|
|
8124
|
+
active: cfg.active !== false,
|
|
8125
|
+
highlight: cfg.highlight !== false,
|
|
8126
|
+
legend: cfg.legend !== false,
|
|
8127
|
+
color: cfg.color !== false
|
|
8128
|
+
};
|
|
8129
|
+
}
|
|
8130
|
+
/** Adds the chart to its `link` group, leaving any group it was in before. */ function registerLink(viz) {
|
|
8131
|
+
unregisterLink(viz);
|
|
8132
|
+
const link = resolveLink(viz);
|
|
8133
|
+
if (!link) return;
|
|
8134
|
+
let members = groups.get(link.group);
|
|
8135
|
+
if (!members) groups.set(link.group, members = new Set());
|
|
8136
|
+
members.add(viz);
|
|
8137
|
+
viz._linkGroup = link.group;
|
|
8138
|
+
}
|
|
8139
|
+
/** Removes the chart from its `link` group, if any. */ function unregisterLink(viz) {
|
|
8140
|
+
const group = viz._linkGroup;
|
|
8141
|
+
if (group === undefined) return;
|
|
8142
|
+
const members = groups.get(group);
|
|
8143
|
+
if (members) {
|
|
8144
|
+
members.delete(viz);
|
|
8145
|
+
if (!members.size) {
|
|
8146
|
+
groups.delete(group);
|
|
8147
|
+
groupColorScales.delete(group);
|
|
8148
|
+
}
|
|
8149
|
+
}
|
|
8150
|
+
viz._linkGroup = undefined;
|
|
8151
|
+
}
|
|
8152
|
+
/** The charts currently registered under a group name. */ function linkMembers(group) {
|
|
8153
|
+
return Array.from(groups.get(group) ?? []);
|
|
8154
|
+
}
|
|
8155
|
+
/**
|
|
8156
|
+
The color defaults `viz` assigns categorical colors from. A linked chart
|
|
8157
|
+
still on its own default scale (`viz._autoColorScale`) shares one scale
|
|
8158
|
+
with the rest of its group, so each value takes the same color in every
|
|
8159
|
+
chart however the charts order their data; the first chart to join seeds
|
|
8160
|
+
the group's palette. A chart given its own `colorDefaults.scale`, or linked
|
|
8161
|
+
with `color: false`, keeps its own.
|
|
8162
|
+
*/ function linkedColorDefaults(viz) {
|
|
8163
|
+
const defaults = viz.schema.colorDefaults;
|
|
8164
|
+
const group = viz._linkGroup;
|
|
8165
|
+
if (group === undefined || defaults.scale !== viz._autoColorScale) return defaults;
|
|
8166
|
+
if (!resolveLink(viz)?.color) return defaults;
|
|
8167
|
+
let scale = groupColorScales.get(group);
|
|
8168
|
+
if (!scale) {
|
|
8169
|
+
scale = scales.scaleOrdinal().range(defaults.scale.range());
|
|
8170
|
+
groupColorScales.set(group, scale);
|
|
8171
|
+
}
|
|
8172
|
+
return {
|
|
8173
|
+
...defaults,
|
|
8174
|
+
scale
|
|
8175
|
+
};
|
|
8176
|
+
}
|
|
8177
|
+
/**
|
|
8178
|
+
Flattens a `by` value into comparable string keys: arrays (from
|
|
8179
|
+
aggregated rows whose members disagree) contribute every entry, Dates
|
|
8180
|
+
compare by time, and null/undefined contribute nothing.
|
|
8181
|
+
*/ function linkKeys(value) {
|
|
8182
|
+
const values = Array.isArray(value) ? value : [
|
|
8183
|
+
value
|
|
8184
|
+
];
|
|
8185
|
+
const keys = [];
|
|
8186
|
+
for (const v of values){
|
|
8187
|
+
if (v === null || v === undefined) continue;
|
|
8188
|
+
keys.push(v instanceof Date ? `${+v}` : `${v}`);
|
|
8189
|
+
}
|
|
8190
|
+
return keys;
|
|
8191
|
+
}
|
|
8192
|
+
/**
|
|
8193
|
+
The `by` keys of every row in `viz` that `predicate` matches. Evaluates
|
|
8194
|
+
over the painted marks (`_chartScene`), which are the rows the predicate
|
|
8195
|
+
was written against; before a first paint it falls back to the filtered
|
|
8196
|
+
data.
|
|
8197
|
+
*/ function linkValues(viz, by, predicate) {
|
|
8198
|
+
const values = new Set();
|
|
8199
|
+
const visit = (row, i)=>{
|
|
8200
|
+
if (predicate(row, i)) for (const k of linkKeys(by(row, i)))values.add(k);
|
|
8201
|
+
};
|
|
8202
|
+
const scene = viz._chartScene;
|
|
8203
|
+
if (scene && scene.length) forEachSceneRow(scene, visit);
|
|
8204
|
+
else (viz._filteredData ?? []).forEach(visit);
|
|
8205
|
+
return values;
|
|
8206
|
+
}
|
|
8207
|
+
/**
|
|
8208
|
+
A predicate matching the rows whose `by` keys include one of `values`. An
|
|
8209
|
+
empty set matches nothing, so a chart without the linked value dims
|
|
8210
|
+
entirely.
|
|
8211
|
+
*/ function linkPredicate(link, values) {
|
|
8212
|
+
return (d, i)=>linkKeys(link.by(d, i)).some((k)=>values.has(k));
|
|
8213
|
+
}
|
|
8214
|
+
/**
|
|
8215
|
+
Overrides which rows the next broadcast from `viz` treats as matched,
|
|
8216
|
+
for an interaction whose own predicate also matches marks it doesn't
|
|
8217
|
+
mean to emphasize (Plot's stacked column hover keeps non-bar marks
|
|
8218
|
+
bright). Consumed by the next `broadcastLink` call.
|
|
8219
|
+
*/ function linkAs(viz, predicate) {
|
|
8220
|
+
linkAsPredicates.set(viz, predicate);
|
|
8221
|
+
}
|
|
8222
|
+
/** Runs `fn` for each other linked member of `viz`'s group, with echoes suppressed. */ function dispatch(viz, link, fn) {
|
|
8223
|
+
if (dispatching.has(link.group)) return;
|
|
8224
|
+
const members = groups.get(link.group);
|
|
8225
|
+
if (!members || members.size < 2) return;
|
|
8226
|
+
dispatching.add(link.group);
|
|
8227
|
+
try {
|
|
8228
|
+
for (const target of members){
|
|
8229
|
+
if (target === viz) continue;
|
|
8230
|
+
const targetLink = resolveLink(target);
|
|
8231
|
+
if (targetLink) fn(target, targetLink);
|
|
8232
|
+
}
|
|
8233
|
+
} finally{
|
|
8234
|
+
dispatching.delete(link.group);
|
|
8235
|
+
}
|
|
8236
|
+
}
|
|
8237
|
+
/**
|
|
8238
|
+
Mirrors `viz`'s new hover/active/highlight state onto the rest of its link
|
|
8239
|
+
group. A predicate becomes a match on its rows' `by` values; `false`
|
|
8240
|
+
clears the same state everywhere.
|
|
8241
|
+
*/ function broadcastLink(viz, kind, predicate) {
|
|
8242
|
+
const override = linkAsPredicates.get(viz);
|
|
8243
|
+
linkAsPredicates.delete(viz);
|
|
8244
|
+
if (predicate === undefined) return;
|
|
8245
|
+
const link = resolveLink(viz);
|
|
8246
|
+
if (!link || !link[kind]) return;
|
|
8247
|
+
const source = typeof predicate === "function" ? override ?? predicate : null;
|
|
8248
|
+
let values = null;
|
|
8249
|
+
dispatch(viz, link, (target, targetLink)=>{
|
|
8250
|
+
if (!targetLink[kind]) return;
|
|
8251
|
+
const setter = target[kind];
|
|
8252
|
+
if (!setter) return;
|
|
8253
|
+
if (source && !values) values = linkValues(viz, link.by, source);
|
|
8254
|
+
setter.call(target, values ? linkPredicate(targetLink, values) : false);
|
|
8255
|
+
});
|
|
8256
|
+
}
|
|
8257
|
+
/** The raw legend ids of a legend row, as `_hidden`/`_solo` store them. */ function legendIds(viz, d, i) {
|
|
8258
|
+
const id = viz._id(d, i);
|
|
8259
|
+
return Array.isArray(id) ? id : [
|
|
8260
|
+
id
|
|
8261
|
+
];
|
|
8262
|
+
}
|
|
8263
|
+
/** The `by` keys of the legend rows whose ids appear in `ids`. */ function legendKeys(viz, link, ids) {
|
|
8264
|
+
const keys = new Set();
|
|
8265
|
+
if (!ids.length) return keys;
|
|
8266
|
+
(viz._legendData ?? []).forEach((d, i)=>{
|
|
8267
|
+
if (legendIds(viz, d, i).some((id)=>ids.includes(id))) for (const k of linkKeys(link.by(d, i)))keys.add(k);
|
|
8268
|
+
});
|
|
8269
|
+
return keys;
|
|
8270
|
+
}
|
|
8271
|
+
/**
|
|
8272
|
+
Mirrors `viz`'s legend hide/solo state onto the rest of its link group,
|
|
8273
|
+
then re-renders each chart that changed. Matching goes through `by`, so
|
|
8274
|
+
charts with different legend groupings still line up: a target legend item
|
|
8275
|
+
is solo'd when any of its keys is solo'd in the source, and hidden when all
|
|
8276
|
+
of its keys are hidden there. A target that hasn't drawn its legend yet is
|
|
8277
|
+
skipped.
|
|
8278
|
+
*/ function broadcastLegend(viz) {
|
|
8279
|
+
const link = resolveLink(viz);
|
|
8280
|
+
if (!link || !link.legend) return;
|
|
8281
|
+
const hiddenKeys = legendKeys(viz, link, viz._hidden);
|
|
8282
|
+
const soloKeys = legendKeys(viz, link, viz._solo);
|
|
8283
|
+
dispatch(viz, link, (target, targetLink)=>{
|
|
8284
|
+
if (!targetLink.legend || !target._legendData?.length) return;
|
|
8285
|
+
const hidden = [];
|
|
8286
|
+
const solo = [];
|
|
8287
|
+
target._legendData.forEach((d, i)=>{
|
|
8288
|
+
const keys = linkKeys(targetLink.by(d, i));
|
|
8289
|
+
const ids = legendIds(target, d, i);
|
|
8290
|
+
const add = (list)=>{
|
|
8291
|
+
for (const id of ids)if (!list.includes(id)) list.push(id);
|
|
8292
|
+
};
|
|
8293
|
+
if (soloKeys.size && keys.some((k)=>soloKeys.has(k))) add(solo);
|
|
8294
|
+
else if (hiddenKeys.size && keys.length && keys.every((k)=>hiddenKeys.has(k))) add(hidden);
|
|
8295
|
+
});
|
|
8296
|
+
const same = (a, b)=>a.length === b.length && a.every((v)=>b.includes(v));
|
|
8297
|
+
if (same(hidden, target._hidden) && same(solo, target._solo)) return;
|
|
8298
|
+
target._hidden = solo.length ? [] : hidden;
|
|
8299
|
+
target._solo = solo;
|
|
8300
|
+
target.render?.();
|
|
8301
|
+
});
|
|
8302
|
+
}
|
|
8303
|
+
|
|
8065
8304
|
/**
|
|
8066
8305
|
@module clickLegend
|
|
8067
8306
|
On click event for all legend shapes in a Viz.
|
|
@@ -8083,17 +8322,21 @@
|
|
|
8083
8322
|
return id;
|
|
8084
8323
|
})).length;
|
|
8085
8324
|
const inverted = this.schema.legendFilterInvert.bind(this)(this);
|
|
8325
|
+
const rerender = ()=>{
|
|
8326
|
+
broadcastLegend(this);
|
|
8327
|
+
this.render();
|
|
8328
|
+
};
|
|
8086
8329
|
if (inverted) {
|
|
8087
8330
|
if (event.shiftKey) {
|
|
8088
8331
|
if (hiddenIndex < 0 && !this._solo.length) {
|
|
8089
8332
|
this._hidden = this._hidden.concat(id);
|
|
8090
8333
|
if (soloIndex >= 0) this._solo = [];
|
|
8091
8334
|
if (this._hidden.length === dataLength) this._hidden = [];
|
|
8092
|
-
|
|
8335
|
+
rerender();
|
|
8093
8336
|
} else if (soloIndex >= 0) {
|
|
8094
8337
|
this._solo = [];
|
|
8095
8338
|
this._hidden = [];
|
|
8096
|
-
|
|
8339
|
+
rerender();
|
|
8097
8340
|
}
|
|
8098
8341
|
} else {
|
|
8099
8342
|
if (soloIndex < 0 && this._hidden.length < dataLength - 1) {
|
|
@@ -8103,13 +8346,13 @@
|
|
|
8103
8346
|
this._solo = [];
|
|
8104
8347
|
this._hidden = [];
|
|
8105
8348
|
}
|
|
8106
|
-
|
|
8349
|
+
rerender();
|
|
8107
8350
|
}
|
|
8108
8351
|
} else {
|
|
8109
8352
|
if (event.shiftKey && soloIndex < 0) {
|
|
8110
8353
|
this._solo = id;
|
|
8111
8354
|
this._hidden = [];
|
|
8112
|
-
|
|
8355
|
+
rerender();
|
|
8113
8356
|
} else if (!event.shiftKey) {
|
|
8114
8357
|
if (hiddenIndex >= 0) {
|
|
8115
8358
|
this._hidden.splice(hiddenIndex, id.length);
|
|
@@ -8123,7 +8366,7 @@
|
|
|
8123
8366
|
this._hidden = this._hidden.concat(id);
|
|
8124
8367
|
if (this._hidden.length === dataLength) this._hidden = [];
|
|
8125
8368
|
}
|
|
8126
|
-
|
|
8369
|
+
rerender();
|
|
8127
8370
|
}
|
|
8128
8371
|
}
|
|
8129
8372
|
}
|
|
@@ -8343,6 +8586,58 @@
|
|
|
8343
8586
|
}
|
|
8344
8587
|
}
|
|
8345
8588
|
|
|
8589
|
+
/**
|
|
8590
|
+
The small colored glyph that ties a tooltip row or title to the mark it
|
|
8591
|
+
describes, matching the legend's swatches: a dot with a short line through
|
|
8592
|
+
it for a Line, a dot for a Circle, and a square for everything else.
|
|
8593
|
+
*/ /** Every swatch's size in pixels, so swatches line up down a tooltip. */ const SIZE = 10;
|
|
8594
|
+
/** Inline styles shared by every swatch: a fixed box, spaced from its text. */ const BASE = `display: inline-block; flex: none; margin-right: 6px; width: ${SIZE}px; height: ${SIZE}px;`;
|
|
8595
|
+
/**
|
|
8596
|
+
A swatch's HTML for a mark of `shape` in `color`, to lead a tooltip title
|
|
8597
|
+
or row (see `withSwatch`). Empty without a color.
|
|
8598
|
+
@param color The mark's color.
|
|
8599
|
+
@param shape The mark's shape type (e.g. "Line", "Circle", "Bar").
|
|
8600
|
+
*/ function tooltipSwatch(color, shape) {
|
|
8601
|
+
if (!color) return "";
|
|
8602
|
+
if (shape === "Line") {
|
|
8603
|
+
const dot = SIZE * 0.6;
|
|
8604
|
+
return `<span class="d3plus-tooltip-swatch d3plus-tooltip-swatch-line" style="${BASE} position: relative">` + `<span style="position: absolute; left: 0; right: 0; top: ${SIZE / 2 - 1}px; height: 2px; background: ${color}"></span>` + `<span style="position: absolute; left: ${(SIZE - dot) / 2}px; top: ${(SIZE - dot) / 2}px; width: ${dot}px; height: ${dot}px; border-radius: 50%; background: ${color}"></span>` + "</span>";
|
|
8605
|
+
}
|
|
8606
|
+
const radius = shape === "Circle" ? "50%" : "1px";
|
|
8607
|
+
return `<span class="d3plus-tooltip-swatch" style="${BASE} border-radius: ${radius}; background: ${color}"></span>`;
|
|
8608
|
+
}
|
|
8609
|
+
/**
|
|
8610
|
+
Leads `text` with a swatch, centered on the text however large or bold it
|
|
8611
|
+
is (a tooltip title, or a row's name). Just `text` without a swatch.
|
|
8612
|
+
@param swatch The swatch HTML, from `tooltipSwatch`.
|
|
8613
|
+
@param text The title or name it leads.
|
|
8614
|
+
*/ function withSwatch(swatch, text) {
|
|
8615
|
+
if (!swatch) return `${text}`;
|
|
8616
|
+
return `<span style="display: inline-flex; align-items: center">${swatch}<span>${text}</span></span>`;
|
|
8617
|
+
}
|
|
8618
|
+
/** A paint color that actually shows: not unset, "none", or transparent. */ const visibleColor = (s)=>typeof s === "string" && s !== "none" && s !== "transparent" ? s : undefined;
|
|
8619
|
+
/** The scene node with a given key, searching depth-first. */ function findNode(nodes, key) {
|
|
8620
|
+
for (const node of nodes){
|
|
8621
|
+
if (node.key === key) return node;
|
|
8622
|
+
const child = node.children && findNode(node.children, key);
|
|
8623
|
+
if (child) return child;
|
|
8624
|
+
}
|
|
8625
|
+
return undefined;
|
|
8626
|
+
}
|
|
8627
|
+
/**
|
|
8628
|
+
The color a picked scene node draws in: a Line's stroke, otherwise its
|
|
8629
|
+
fill (or stroke, for an unfilled mark). A transparent hover target (a
|
|
8630
|
+
`::hit` node) reads its visible sibling's paint.
|
|
8631
|
+
@param viz The chart, whose scene holds the sibling.
|
|
8632
|
+
@param node The picked scene node.
|
|
8633
|
+
*/ function nodeColor(viz, node) {
|
|
8634
|
+
let n = node;
|
|
8635
|
+
if (n && typeof n.key === "string" && n.key.endsWith("::hit")) n = findNode(viz._chartScene || [], n.key.slice(0, -"::hit".length)) || n;
|
|
8636
|
+
const paint = n && n.paint;
|
|
8637
|
+
if (!paint) return undefined;
|
|
8638
|
+
return n.shapeType === "Line" ? visibleColor(paint.stroke) ?? visibleColor(paint.fill) : visibleColor(paint.fill) ?? visibleColor(paint.stroke);
|
|
8639
|
+
}
|
|
8640
|
+
|
|
8346
8641
|
/**
|
|
8347
8642
|
@module mouseMoveShape
|
|
8348
8643
|
Tooltip logic for a specified data point.
|
|
@@ -8381,9 +8676,12 @@
|
|
|
8381
8676
|
// wrapper whose `.data` chain leads back to the row).
|
|
8382
8677
|
let tooltipDatum = x || d;
|
|
8383
8678
|
while(tooltipDatum && tooltipDatum.__d3plus__ && tooltipDatum.data)tooltipDatum = tooltipDatum.data;
|
|
8679
|
+
// The title leads with a swatch of the hovered mark, as in the legend.
|
|
8680
|
+
const pick = this._lastScenePick;
|
|
8681
|
+
const swatch = pick && !pick.isLegend ? tooltipSwatch(nodeColor(this, pick.node), pick.shapeType ?? undefined) : "";
|
|
8384
8682
|
this._tooltipClass.data([
|
|
8385
8683
|
tooltipDatum
|
|
8386
|
-
]).footer(hasDefaultClick && hasDeeperLevel ? this.schema.translate("Click to Expand") : false).title(this._drawLabel).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig)).render();
|
|
8684
|
+
]).footer(hasDefaultClick && hasDeeperLevel ? this.schema.translate("Click to Expand") : false).title((dd, ii)=>withSwatch(swatch, this._drawLabel(dd, ii))).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig)).render();
|
|
8387
8685
|
}
|
|
8388
8686
|
}
|
|
8389
8687
|
|
|
@@ -8469,6 +8767,11 @@
|
|
|
8469
8767
|
key: "legendSort",
|
|
8470
8768
|
coerce: "identity"
|
|
8471
8769
|
},
|
|
8770
|
+
{
|
|
8771
|
+
key: "link",
|
|
8772
|
+
coerce: "identity",
|
|
8773
|
+
onSet: (viz)=>registerLink(viz)
|
|
8774
|
+
},
|
|
8472
8775
|
{
|
|
8473
8776
|
key: "minimap",
|
|
8474
8777
|
coerce: "identity"
|
|
@@ -8587,10 +8890,12 @@
|
|
|
8587
8890
|
viz.schema.color = (d, i)=>viz.schema.groupBy[0](d, i);
|
|
8588
8891
|
// Each viz gets its own categorical scale so assignments don't leak
|
|
8589
8892
|
// across charts on the same page.
|
|
8893
|
+
const scale = scales.scaleOrdinal().range(color.colorDefaults.scale.range());
|
|
8590
8894
|
viz.schema.colorDefaults = {
|
|
8591
8895
|
...color.colorDefaults,
|
|
8592
|
-
scale
|
|
8896
|
+
scale
|
|
8593
8897
|
};
|
|
8898
|
+
viz._autoColorScale = scale;
|
|
8594
8899
|
viz._colorScaleClass = new ColorScale();
|
|
8595
8900
|
viz.schema.colorScaleConfig = {
|
|
8596
8901
|
axisConfig: {
|
|
@@ -8613,11 +8918,6 @@
|
|
|
8613
8918
|
viz.schema.detectVisible = true;
|
|
8614
8919
|
viz.schema.detectVisibleInterval = 1000;
|
|
8615
8920
|
viz.schema.detectVisibleUnload = true;
|
|
8616
|
-
viz.schema.downloadButton = false;
|
|
8617
|
-
viz.schema.downloadConfig = {
|
|
8618
|
-
type: "png"
|
|
8619
|
-
};
|
|
8620
|
-
viz.schema.downloadPosition = "top";
|
|
8621
8921
|
viz.schema.duration = 600;
|
|
8622
8922
|
viz.schema.fontFamily = text.fontFamily;
|
|
8623
8923
|
viz._hidden = [];
|
|
@@ -8772,7 +9072,7 @@
|
|
|
8772
9072
|
// light→dark ramp (built in vizPreDraw) instead of nominal categorical
|
|
8773
9073
|
// hues, so the color itself carries the ordering.
|
|
8774
9074
|
if (viz.schema.colorOrdinal && viz._ordinalColorScale) return viz._ordinalColorScale(key);
|
|
8775
|
-
return color.colorAssign(key, viz
|
|
9075
|
+
return color.colorAssign(key, linkedColorDefaults(viz));
|
|
8776
9076
|
},
|
|
8777
9077
|
labelConfig: {
|
|
8778
9078
|
// Marked so chart emitters layering user label config keep their own
|
|
@@ -8788,7 +9088,7 @@
|
|
|
8788
9088
|
// A fill that doesn't parse as a color (e.g. "none"/"transparent" on a
|
|
8789
9089
|
// confidence band) has no darker shade — fall back to the fill itself.
|
|
8790
9090
|
const col = d3Color.color(c);
|
|
8791
|
-
return col ? col.darker(0.25) : c;
|
|
9091
|
+
return col ? col.darker(0.25).toString() : c;
|
|
8792
9092
|
},
|
|
8793
9093
|
role: "presentation",
|
|
8794
9094
|
strokeWidth: constant(0)
|
|
@@ -10320,51 +10620,27 @@
|
|
|
10320
10620
|
if (!needle) return viz._searchPrevHighlight ?? false;
|
|
10321
10621
|
return (d, i)=>matchesSearchNeedle(viz, d, i, needle);
|
|
10322
10622
|
}
|
|
10323
|
-
/** Scene mark types a match is searched against — mirrors `interactionOpacity.ts`'s own `MARK_TYPES`. */ const MARK_TYPES$1 = new Set([
|
|
10324
|
-
"rect",
|
|
10325
|
-
"circle",
|
|
10326
|
-
"line",
|
|
10327
|
-
"area",
|
|
10328
|
-
"path"
|
|
10329
|
-
]);
|
|
10330
10623
|
/**
|
|
10331
10624
|
Every currently-rendered mark matching the given term, in scene order.
|
|
10332
10625
|
Walks `viz._chartScene` (the actual painted scene, post-layout) rather
|
|
10333
|
-
than the raw data array,
|
|
10334
|
-
`applyInteractionOpacity`
|
|
10335
|
-
rendered mark, not by raw input row
|
|
10336
|
-
|
|
10337
|
-
|
|
10626
|
+
than the raw data array, via `forEachSceneRow` — the same row/index
|
|
10627
|
+
resolution `applyInteractionOpacity` uses — so a grouped/aggregated chart
|
|
10628
|
+
matches by rendered mark, not by raw input row, and the index a custom
|
|
10629
|
+
searchAccessor sees always matches the one the highlight predicate was
|
|
10630
|
+
evaluated with (Enter/Shift+Enter never jumps to a different mark than the
|
|
10631
|
+
one that's actually highlighted). An empty term matches nothing (there's
|
|
10632
|
+
no "everything" state to jump through).
|
|
10338
10633
|
*/ function searchMatches(viz, term) {
|
|
10339
10634
|
const needle = term.trim().toLowerCase();
|
|
10340
10635
|
if (!needle) return [];
|
|
10341
|
-
const nodes = viz._chartScene || [];
|
|
10342
|
-
const seen = new Set();
|
|
10343
10636
|
const results = [];
|
|
10344
|
-
|
|
10345
|
-
if (
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
// (interactionOpacity.ts) — node.index, then the row's own `.i`,
|
|
10352
|
-
// then 0 — so the index a custom searchAccessor sees here always
|
|
10353
|
-
// matches the index the highlight predicate was evaluated with,
|
|
10354
|
-
// and Enter/Shift+Enter never jumps to a different mark than the
|
|
10355
|
-
// one that's actually highlighted.
|
|
10356
|
-
const i = typeof node.index === "number" ? node.index : typeof row.i === "number" ? row.i : 0;
|
|
10357
|
-
if (matchesSearchNeedle(viz, row, i, needle)) results.push({
|
|
10358
|
-
node,
|
|
10359
|
-
row,
|
|
10360
|
-
index: i
|
|
10361
|
-
});
|
|
10362
|
-
}
|
|
10363
|
-
}
|
|
10364
|
-
const kids = node.children;
|
|
10365
|
-
if (kids) kids.forEach(walk);
|
|
10366
|
-
};
|
|
10367
|
-
nodes.forEach(walk);
|
|
10637
|
+
forEachSceneRow(viz._chartScene || [], (row, i, node)=>{
|
|
10638
|
+
if (matchesSearchNeedle(viz, row, i, needle)) results.push({
|
|
10639
|
+
node,
|
|
10640
|
+
row,
|
|
10641
|
+
index: i
|
|
10642
|
+
});
|
|
10643
|
+
});
|
|
10368
10644
|
return results;
|
|
10369
10645
|
}
|
|
10370
10646
|
/**
|
|
@@ -10822,25 +11098,116 @@
|
|
|
10822
11098
|
}
|
|
10823
11099
|
};
|
|
10824
11100
|
|
|
11101
|
+
const INSET_PRIORITY = [
|
|
11102
|
+
"sizeLegend",
|
|
11103
|
+
"legend",
|
|
11104
|
+
"colorScale"
|
|
11105
|
+
];
|
|
10825
11106
|
/**
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
11107
|
+
Seeds `legendInset`/`legendInsetConfig`, and remembers the default
|
|
11108
|
+
legend/colorScale position accessors so a placement can tell a position
|
|
11109
|
+
the user chose (which it leaves alone) from the default. Runs after the
|
|
11110
|
+
legend and color defaults are seeded.
|
|
11111
|
+
*/ function initInsetDefaults(viz) {
|
|
11112
|
+
viz.schema.legendInset = true;
|
|
11113
|
+
viz.schema.legendInsetConfig = {};
|
|
11114
|
+
viz._insetAutoPositions = {
|
|
11115
|
+
legend: viz.schema.legendPosition,
|
|
11116
|
+
colorScale: viz.schema.colorScalePosition
|
|
11117
|
+
};
|
|
11118
|
+
}
|
|
11119
|
+
/** The resolved background-box style, with the chart's defaults filled in. */ function insetStyle(viz) {
|
|
11120
|
+
const config = viz.schema.legendInsetConfig || {};
|
|
11121
|
+
return {
|
|
11122
|
+
padding: 10,
|
|
11123
|
+
margin: 6,
|
|
11124
|
+
fillOpacity: 0.85,
|
|
11125
|
+
strokeWidth: 1,
|
|
11126
|
+
rx: 4,
|
|
11127
|
+
...config
|
|
11128
|
+
};
|
|
11129
|
+
}
|
|
11130
|
+
/** Whether `key` is being laid out for the chart's interior this pass (so it claims no margin). */ function isInsetPending(viz, key) {
|
|
11131
|
+
return Boolean(viz._insetPending && viz._insetPending.has(key));
|
|
11132
|
+
}
|
|
11133
|
+
/** The final placement of `key`, or null when it isn't drawn inside the chart. */ function insetPlacementFor(viz, key) {
|
|
11134
|
+
const p = viz._insetPlacement;
|
|
11135
|
+
return p && p.key === key ? p : null;
|
|
11136
|
+
}
|
|
11137
|
+
/** The orientation `key` is laid out with when inset (column until placement picks one). */ function insetOrient(viz, key) {
|
|
11138
|
+
return insetPlacementFor(viz, key)?.orient ?? "column";
|
|
11139
|
+
}
|
|
11140
|
+
/**
|
|
11141
|
+
The largest frame a legend or colorScale may lay itself out in when inset,
|
|
11142
|
+
for a chart area of `area`: a column takes up to 40% of the width and 60%
|
|
11143
|
+
of the height, a row the reverse.
|
|
11144
|
+
*/ function insetFrame(orient, area) {
|
|
11145
|
+
return orient === "column" ? {
|
|
11146
|
+
width: area.width * 0.4,
|
|
11147
|
+
height: area.height * 0.6
|
|
11148
|
+
} : {
|
|
11149
|
+
width: area.width * 0.6,
|
|
11150
|
+
height: area.height * 0.4
|
|
11151
|
+
};
|
|
11152
|
+
}
|
|
11153
|
+
/** The chart's background color, as the default fill for the inset box. */ function chartBackground(viz) {
|
|
11154
|
+
const node = viz._select && typeof viz._select.node === "function" ? viz._select.node() : null;
|
|
11155
|
+
return node ? dom.backgroundColor(node) : "rgb(255, 255, 255)";
|
|
11156
|
+
}
|
|
11157
|
+
/** The semi-transparent box drawn behind inset chrome, so it stays legible over marks panned beneath it. */ function insetBackground(viz, placement) {
|
|
11158
|
+
const style = insetStyle(viz);
|
|
11159
|
+
const fill = style.fill ?? chartBackground(viz);
|
|
11160
|
+
return {
|
|
11161
|
+
type: "rect",
|
|
11162
|
+
key: "viz-inset-background",
|
|
11163
|
+
x: placement.x,
|
|
11164
|
+
y: placement.y,
|
|
11165
|
+
width: placement.width,
|
|
11166
|
+
height: placement.height,
|
|
11167
|
+
rx: style.rx,
|
|
11168
|
+
ry: style.rx,
|
|
11169
|
+
paint: {
|
|
11170
|
+
fill,
|
|
11171
|
+
fillOpacity: style.fillOpacity,
|
|
11172
|
+
stroke: style.stroke ?? color.colorContrast(fill, viz.schema.colorDefaults),
|
|
11173
|
+
strokeOpacity: style.stroke ? 1 : 0.15,
|
|
11174
|
+
strokeWidth: style.strokeWidth
|
|
11175
|
+
}
|
|
11176
|
+
};
|
|
11177
|
+
}
|
|
11178
|
+
/**
|
|
11179
|
+
The scene children for a legend or colorScale component: just its own
|
|
11180
|
+
scene normally, or — when it's drawn inside the chart — its background box
|
|
11181
|
+
plus its scene moved into the box. `bounds` is the component's
|
|
11182
|
+
`outerBounds()` (its content box within its own frame).
|
|
11183
|
+
*/ function insetComponentScene(viz, key, scene, bounds) {
|
|
11184
|
+
const transform = insetComponentOffset(viz, key, bounds);
|
|
11185
|
+
if (!transform) return [
|
|
11186
|
+
scene
|
|
11187
|
+
];
|
|
11188
|
+
return [
|
|
11189
|
+
insetBackground(viz, insetPlacementFor(viz, key)),
|
|
11190
|
+
{
|
|
11191
|
+
...scene,
|
|
11192
|
+
transform
|
|
11193
|
+
}
|
|
11194
|
+
];
|
|
11195
|
+
}
|
|
11196
|
+
/**
|
|
11197
|
+
Where a legend or colorScale component's own frame goes so its content
|
|
11198
|
+
(`bounds`, its `outerBounds()`) lands inside its placed box; null when it
|
|
11199
|
+
isn't drawn inside the chart.
|
|
11200
|
+
*/ function insetComponentOffset(viz, key, bounds) {
|
|
11201
|
+
const placed = insetPlacementFor(viz, key);
|
|
11202
|
+
if (!placed) return null;
|
|
11203
|
+
const { margin } = insetStyle(viz);
|
|
11204
|
+
return {
|
|
11205
|
+
x: placed.x + margin - (bounds.x ?? 0),
|
|
11206
|
+
y: placed.y + margin - (bounds.y ?? 0)
|
|
11207
|
+
};
|
|
11208
|
+
}
|
|
10841
11209
|
|
|
10842
|
-
|
|
10843
|
-
*/ /** Horizontal gap between items, and between the panel and content inset around it. */ const BOTTOM_RIGHT_GAP = 6;
|
|
11210
|
+
/** Horizontal gap between items, and between the panel and content inset around it. */ const BOTTOM_RIGHT_GAP = 6;
|
|
10844
11211
|
/** Lays contributions out in a row, right to left: the panel's total width and height. */ function measureBottomRight(items) {
|
|
10845
11212
|
const width = items.reduce((w, item, i)=>w + item.width + (i ? BOTTOM_RIGHT_GAP : 0), 0);
|
|
10846
11213
|
const height = Math.max(0, ...items.map((item)=>item.height));
|
|
@@ -10853,6 +11220,10 @@
|
|
|
10853
11220
|
const box = viz._bottomRightBox;
|
|
10854
11221
|
return box && box.width && box.height ? box : null;
|
|
10855
11222
|
}
|
|
11223
|
+
/** The panel when it occupies the chart's corner, so margins and neighbors make room for it; null when it doesn't. */ function cornerBox(viz) {
|
|
11224
|
+
const box = bottomRightControlsBox(viz);
|
|
11225
|
+
return box && !box.inset ? box : null;
|
|
11226
|
+
}
|
|
10856
11227
|
/**
|
|
10857
11228
|
How far content in the bottom band must pull in its right edge to clear
|
|
10858
11229
|
the panel: content whose bottom edge sits `bottom` px above the chart's
|
|
@@ -10860,7 +11231,7 @@
|
|
|
10860
11231
|
right edge. Zero when nothing is showing or the content starts above the
|
|
10861
11232
|
panel.
|
|
10862
11233
|
*/ function bottomRightControlsInset(viz, bottom, right) {
|
|
10863
|
-
const box =
|
|
11234
|
+
const box = cornerBox(viz);
|
|
10864
11235
|
// A right-side panel already widened the right margin bottom content lays out against.
|
|
10865
11236
|
if (!box || box.side === "right" || bottom >= box.bottom + box.height) return 0;
|
|
10866
11237
|
const inset = box.width - right;
|
|
@@ -10871,7 +11242,7 @@
|
|
|
10871
11242
|
above the chart's bottom edge, must shorten to end above the panel. Zero
|
|
10872
11243
|
when nothing is showing.
|
|
10873
11244
|
*/ function bottomRightControlsDrop(viz, bottom) {
|
|
10874
|
-
const box =
|
|
11245
|
+
const box = cornerBox(viz);
|
|
10875
11246
|
if (!box) return 0;
|
|
10876
11247
|
return Math.max(0, box.bottom + box.height - bottom);
|
|
10877
11248
|
}
|
|
@@ -10890,7 +11261,7 @@
|
|
|
10890
11261
|
`bottom` px above the chart's bottom edge, stays clear of a bottom-side
|
|
10891
11262
|
panel. Zero for a right-side panel.
|
|
10892
11263
|
*/ function bottomRightControlsShortfall(viz, bottom) {
|
|
10893
|
-
const box =
|
|
11264
|
+
const box = cornerBox(viz);
|
|
10894
11265
|
return box && box.side === "bottom" ? Math.max(0, box.bottom + box.height - bottom) : 0;
|
|
10895
11266
|
}
|
|
10896
11267
|
/**
|
|
@@ -10898,14 +11269,63 @@
|
|
|
10898
11269
|
`right` px in from the chart's right edge, stays clear of a right-side
|
|
10899
11270
|
panel. Zero for a bottom-side panel.
|
|
10900
11271
|
*/ function bottomRightControlsRightShortfall(viz, right) {
|
|
10901
|
-
const box =
|
|
11272
|
+
const box = cornerBox(viz);
|
|
10902
11273
|
return box && box.side === "right" ? Math.max(0, box.width + BOTTOM_RIGHT_GAP - right) : 0;
|
|
10903
11274
|
}
|
|
11275
|
+
/**
|
|
11276
|
+
The panel's scene when it's drawn inside the chart: the items painted
|
|
11277
|
+
from their final state, in a row on a background box that hugs them,
|
|
11278
|
+
aligned within the placed box the way the placement anchored it.
|
|
11279
|
+
*/ function buildInsetPanel(viz, box, zoom) {
|
|
11280
|
+
const placed = insetPlacementFor(viz, "sizeLegend");
|
|
11281
|
+
if (!placed) return null;
|
|
11282
|
+
const { margin } = insetStyle(viz);
|
|
11283
|
+
const painted = box.items.map((item)=>({
|
|
11284
|
+
item,
|
|
11285
|
+
paint: item.paint(zoom)
|
|
11286
|
+
})).filter((p)=>Boolean(p.paint));
|
|
11287
|
+
if (!painted.length) return null;
|
|
11288
|
+
const width = painted.reduce((w, p, i)=>w + p.paint.width + (i ? BOTTOM_RIGHT_GAP : 0), 0) + margin * 2;
|
|
11289
|
+
const height = Math.max(...painted.map((p)=>p.paint.height)) + margin * 2;
|
|
11290
|
+
const x = placed.alignX === "left" ? placed.x : placed.alignX === "center" ? placed.x + (placed.width - width) / 2 : placed.x + placed.width - width;
|
|
11291
|
+
const y = placed.alignY === "top" ? placed.y : placed.alignY === "middle" ? placed.y + (placed.height - height) / 2 : placed.y + placed.height - height;
|
|
11292
|
+
const children = [
|
|
11293
|
+
insetBackground(viz, {
|
|
11294
|
+
...placed,
|
|
11295
|
+
x,
|
|
11296
|
+
y,
|
|
11297
|
+
width,
|
|
11298
|
+
height
|
|
11299
|
+
})
|
|
11300
|
+
];
|
|
11301
|
+
let right = x + width - margin;
|
|
11302
|
+
const baseline = y + height - margin;
|
|
11303
|
+
for (const { item, paint } of painted){
|
|
11304
|
+
children.push({
|
|
11305
|
+
type: "group",
|
|
11306
|
+
key: item.key,
|
|
11307
|
+
transform: {
|
|
11308
|
+
x: right - paint.width,
|
|
11309
|
+
y: baseline - paint.height
|
|
11310
|
+
},
|
|
11311
|
+
children: [
|
|
11312
|
+
paint.node
|
|
11313
|
+
]
|
|
11314
|
+
});
|
|
11315
|
+
right -= paint.width + BOTTOM_RIGHT_GAP;
|
|
11316
|
+
}
|
|
11317
|
+
return {
|
|
11318
|
+
type: "group",
|
|
11319
|
+
key: "viz-bottomRight",
|
|
11320
|
+
children
|
|
11321
|
+
};
|
|
11322
|
+
}
|
|
10904
11323
|
/**
|
|
10905
11324
|
The panel's scene: each item painted from its final state, bottom-right
|
|
10906
11325
|
aligned in the slot it reserved. Null when nothing paints.
|
|
10907
11326
|
*/ function buildBottomRightPanel(viz, box) {
|
|
10908
11327
|
const zoom = viz._zoomTransform?.scale ?? 1;
|
|
11328
|
+
if (box.inset) return buildInsetPanel(viz, box, zoom);
|
|
10909
11329
|
const children = [];
|
|
10910
11330
|
let right = viz.schema.width;
|
|
10911
11331
|
const baseline = viz.schema.height - box.bottom;
|
|
@@ -10947,6 +11367,49 @@
|
|
|
10947
11367
|
] : panels;
|
|
10948
11368
|
}
|
|
10949
11369
|
|
|
11370
|
+
/**
|
|
11371
|
+
`ResolvedSpec` + `resolveSpec(viz)` — the boundary between
|
|
11372
|
+
"config the user supplied" and "context the pipeline transforms."
|
|
11373
|
+
|
|
11374
|
+
Today the chart's class instance holds both: every `this._foo` slot is
|
|
11375
|
+
either a config the user can set (via accessors) or a derived value the
|
|
11376
|
+
pipeline writes back during `_preDraw` / `_draw` / `_paint`. The clean
|
|
11377
|
+
split is:
|
|
11378
|
+
|
|
11379
|
+
ResolvedSpec <- user config (frozen, immutable, serializable)
|
|
11380
|
+
↓
|
|
11381
|
+
VizContext <- pipeline-derived state (filteredData, drawDepth,
|
|
11382
|
+
legendData, _chartScene, etc.)
|
|
11383
|
+
|
|
11384
|
+
`resolveSpec(viz)` returns a frozen snapshot of every user-settable
|
|
11385
|
+
config key for the given viz instance. The free functions
|
|
11386
|
+
`vizPreDraw(viz)` / `vizDraw(viz)` / `runVizPipeline(viz)` /
|
|
11387
|
+
`plotPaint(viz, ctx)` all take a live viz instance — the
|
|
11388
|
+
contract that's currently shipping. `resolveSpec` is provided as a
|
|
11389
|
+
public seam so callers (custom drivers, tests, future refactors)
|
|
11390
|
+
can pin a config snapshot independently of any draw cycle. The
|
|
11391
|
+
spec type is the contract.
|
|
11392
|
+
|
|
11393
|
+
The spec is a READONLY view: mutating it is a programming error. The
|
|
11394
|
+
type uses `Readonly<>` to discourage in-place writes; runtime
|
|
11395
|
+
freezing happens in `resolveSpec()`.
|
|
11396
|
+
*/ /**
|
|
11397
|
+
Snapshot every config key from a viz instance into a frozen spec.
|
|
11398
|
+
|
|
11399
|
+
Reads the same keys `BaseClass.config()` reflects — strips the `_`
|
|
11400
|
+
prefix from every instance field whose name matches a method on the
|
|
11401
|
+
prototype (the v3/v4 config-method-is-also-the-storage-slot pattern).
|
|
11402
|
+
Returns a frozen object so consumers can't accidentally mutate it
|
|
11403
|
+
upstream of the chart.
|
|
11404
|
+
*/ function resolveSpec(viz) {
|
|
11405
|
+
// BaseClass.config() already does this reflection; reuse it.
|
|
11406
|
+
const cfg = typeof viz.config === "function" ? viz.config() : {};
|
|
11407
|
+
// Object.freeze for shallow protection. Deep freeze isn't worth the cost
|
|
11408
|
+
// (most consumers don't mutate, and accessor functions reading the spec
|
|
11409
|
+
// wouldn't trigger surface mutation anyway).
|
|
11410
|
+
return Object.freeze(cfg);
|
|
11411
|
+
}
|
|
11412
|
+
|
|
10950
11413
|
/**
|
|
10951
11414
|
Rolls filtered legend data up by paint attributes, sorts it, and computes
|
|
10952
11415
|
`viz._legendDepth` (the lowest groupBy level whose values are unique).
|
|
@@ -11035,59 +11498,118 @@
|
|
|
11035
11498
|
};
|
|
11036
11499
|
}
|
|
11037
11500
|
/**
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
*/ function renderLegendFeature(viz, built, layoutMargin) {
|
|
11501
|
+
Configures and renders the chart's `_legendClass` Legend instance in
|
|
11502
|
+
compute mode (Legend contributes to the scene via its `toScene()`,
|
|
11503
|
+
collected on Viz.toScene) into `frame`.
|
|
11504
|
+
*/ function paintLegend(viz, built, frame) {
|
|
11043
11505
|
const { legendData, legendKey, getAttr } = built;
|
|
11044
11506
|
const hidden = (d, i)=>{
|
|
11045
11507
|
let id = viz._id(d, i);
|
|
11046
11508
|
if (Array.isArray(id)) id = id[0];
|
|
11047
11509
|
return viz._hidden.includes(id) || viz._solo.length > 0 && !viz._solo.includes(id);
|
|
11048
11510
|
};
|
|
11049
|
-
// The margin *claim* uses the previous render's outerBounds; on first
|
|
11050
|
-
// render it's zero and the Legend re-flows on the second render with the
|
|
11051
|
-
// real space.
|
|
11052
|
-
const legendBounds = viz._legendClass.outerBounds();
|
|
11053
|
-
const config = resolveSpec(viz);
|
|
11054
|
-
const position = sanitizePosition(viz.schema.legendPosition.bind(viz)(config));
|
|
11055
|
-
const wide = [
|
|
11056
|
-
"top",
|
|
11057
|
-
"bottom"
|
|
11058
|
-
].includes(position);
|
|
11059
|
-
const padding = viz.schema.legendPadding(viz) ? viz._padding : {
|
|
11060
|
-
top: 0,
|
|
11061
|
-
right: 0,
|
|
11062
|
-
bottom: 0,
|
|
11063
|
-
left: 0
|
|
11064
|
-
};
|
|
11065
|
-
const { inset, drop, insetRight, shorten } = legendCornerClearance(viz, position, layoutMargin, padding);
|
|
11066
11511
|
const transform = {
|
|
11067
|
-
transform: `translate(${
|
|
11512
|
+
transform: `translate(${frame.x}, ${frame.y})`
|
|
11068
11513
|
};
|
|
11069
|
-
// `visible` gates the legend group's DOM presence + data binding.
|
|
11070
|
-
// `position === false` forces it off so `.legendPosition(false)` is
|
|
11071
|
-
// an actual hide signal: the legend's render runs against [] data,
|
|
11072
|
-
// which exits any prior DOM and emits no scene.
|
|
11073
|
-
const visible = position === false ? false : viz.schema.legend.bind(viz)(config, legendData);
|
|
11074
11514
|
// The Legend instance renders into a `g.d3plus-viz-legend` group as a
|
|
11075
11515
|
// child of the chart's svg. This group is created via the `elem` helper
|
|
11076
11516
|
// so the Legend has a DOM `_select` (its `toScene()` walks from there).
|
|
11077
11517
|
// Once Legend is fully compute-only the elem wrapper can go.
|
|
11078
11518
|
const legendGroup = dom.elem("g.d3plus-viz-legend", {
|
|
11079
|
-
condition: visible && !viz.schema.legendConfig.select,
|
|
11519
|
+
condition: frame.visible && !viz.schema.legendConfig.select,
|
|
11080
11520
|
enter: transform,
|
|
11081
11521
|
parent: viz._select,
|
|
11082
11522
|
duration: viz.schema.duration,
|
|
11083
11523
|
update: transform
|
|
11084
11524
|
}).node();
|
|
11085
|
-
viz._legendClass.renderMode("compute").id(legendKey).align(
|
|
11525
|
+
viz._legendClass.renderMode("compute").id(legendKey).align(frame.align).direction(frame.direction).duration(viz.schema.duration).data(frame.visible ? legendData : []).height(frame.height).locale(viz.schema.locale).parent(viz).select(legendGroup).shape((d, i)=>{
|
|
11526
|
+
const shape = viz.schema.shape(d, i);
|
|
11527
|
+
return shape === "Circle" || shape === "Line" ? shape : "Rect";
|
|
11528
|
+
}).verticalAlign(frame.verticalAlign).width(frame.width).shapeConfig(configPrep.bind(viz)(viz.schema.shapeConfig, "legend")).shapeConfig({
|
|
11086
11529
|
fill: (d, i)=>hidden(d, i) ? viz.schema.hiddenColor(d, i) : getAttr(d, i, "fill"),
|
|
11087
11530
|
labelConfig: {
|
|
11088
11531
|
fontOpacity: (d, i)=>hidden(d, i) ? viz.schema.hiddenOpacity(d, i) : 1
|
|
11089
11532
|
}
|
|
11090
11533
|
}).config(viz.schema.legendConfig).render();
|
|
11534
|
+
}
|
|
11535
|
+
/**
|
|
11536
|
+
Whether the legend shows at all: `position === false` forces it off so
|
|
11537
|
+
`.legendPosition(false)` is an actual hide signal (the legend's render
|
|
11538
|
+
runs against [] data, which exits any prior DOM and emits no scene).
|
|
11539
|
+
*/ function legendVisible(viz, built) {
|
|
11540
|
+
const config = resolveSpec(viz);
|
|
11541
|
+
const position = sanitizePosition(viz.schema.legendPosition.bind(viz)(config));
|
|
11542
|
+
return position === false ? false : Boolean(viz.schema.legend.bind(viz)(config, built.legendData));
|
|
11543
|
+
}
|
|
11544
|
+
/**
|
|
11545
|
+
Lays the legend out to be drawn inside the chart (see
|
|
11546
|
+
`pipeline/insetPlacement.ts`): at the origin — Viz.toScene moves it into
|
|
11547
|
+
place — as a column or a row sized against the chart area `area`.
|
|
11548
|
+
Returns the legend's measured size, or null when it isn't showing or
|
|
11549
|
+
couldn't fit its labels.
|
|
11550
|
+
*/ function paintLegendInset(viz, orient, area, built = buildLegendData(viz)) {
|
|
11551
|
+
const visible = legendVisible(viz, built) && !viz.schema.legendConfig.select;
|
|
11552
|
+
const frame = insetFrame(orient, area);
|
|
11553
|
+
paintLegend(viz, built, {
|
|
11554
|
+
x: 0,
|
|
11555
|
+
y: 0,
|
|
11556
|
+
...frame,
|
|
11557
|
+
align: "left",
|
|
11558
|
+
direction: orient,
|
|
11559
|
+
verticalAlign: "top",
|
|
11560
|
+
visible
|
|
11561
|
+
});
|
|
11562
|
+
if (!visible) return null;
|
|
11563
|
+
const legend = viz._legendClass;
|
|
11564
|
+
const labelsFit = (legend._lineData || []).every((d)=>d.width > 0);
|
|
11565
|
+
const { width, height } = legend.outerBounds();
|
|
11566
|
+
return labelsFit && width && height ? {
|
|
11567
|
+
width,
|
|
11568
|
+
height
|
|
11569
|
+
} : null;
|
|
11570
|
+
}
|
|
11571
|
+
/**
|
|
11572
|
+
Positions and renders the legend, then returns the margin claim derived
|
|
11573
|
+
from the previous render's outerBounds. Claims nothing while the legend
|
|
11574
|
+
is being laid out for the chart's interior.
|
|
11575
|
+
*/ function renderLegendFeature(viz, built, layoutMargin) {
|
|
11576
|
+
if (isInsetPending(viz, "legend")) {
|
|
11577
|
+
paintLegendInset(viz, insetOrient(viz, "legend"), {
|
|
11578
|
+
width: viz.schema.width - layoutMargin.left - layoutMargin.right,
|
|
11579
|
+
height: viz.schema.height - layoutMargin.top - layoutMargin.bottom
|
|
11580
|
+
}, built);
|
|
11581
|
+
return {
|
|
11582
|
+
panel: null,
|
|
11583
|
+
margin: {}
|
|
11584
|
+
};
|
|
11585
|
+
}
|
|
11586
|
+
// The margin *claim* uses the previous render's outerBounds; on first
|
|
11587
|
+
// render it's zero and the Legend re-flows on the second render with the
|
|
11588
|
+
// real space.
|
|
11589
|
+
const legendBounds = viz._legendClass.outerBounds();
|
|
11590
|
+
const config = resolveSpec(viz);
|
|
11591
|
+
const position = sanitizePosition(viz.schema.legendPosition.bind(viz)(config));
|
|
11592
|
+
const wide = [
|
|
11593
|
+
"top",
|
|
11594
|
+
"bottom"
|
|
11595
|
+
].includes(position);
|
|
11596
|
+
const padding = viz.schema.legendPadding(viz) ? viz._padding : {
|
|
11597
|
+
top: 0,
|
|
11598
|
+
right: 0,
|
|
11599
|
+
bottom: 0,
|
|
11600
|
+
left: 0
|
|
11601
|
+
};
|
|
11602
|
+
const { inset, drop, insetRight, shorten } = legendCornerClearance(viz, position, layoutMargin, padding);
|
|
11603
|
+
paintLegend(viz, built, {
|
|
11604
|
+
x: (wide ? layoutMargin.left + padding.left : layoutMargin.left) + inset,
|
|
11605
|
+
y: (wide ? layoutMargin.top : layoutMargin.top + padding.top) + drop,
|
|
11606
|
+
width: (wide ? viz.schema.width - (layoutMargin.left + layoutMargin.right + padding.left + padding.right) : viz.schema.width - (layoutMargin.left + layoutMargin.right)) - inset * 2 - insetRight,
|
|
11607
|
+
height: (wide ? viz.schema.height - (layoutMargin.bottom + layoutMargin.top) : viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top)) - drop - shorten,
|
|
11608
|
+
align: wide ? "center" : position,
|
|
11609
|
+
direction: wide ? "row" : "column",
|
|
11610
|
+
verticalAlign: !wide ? "middle" : position,
|
|
11611
|
+
visible: legendVisible(viz, built)
|
|
11612
|
+
});
|
|
11091
11613
|
// Margin claim from the *previous* render's outerBounds:
|
|
11092
11614
|
// `outerBounds()` reads stored state, so on the first render the claim
|
|
11093
11615
|
// is zero and Legend overlaps the chart for one frame; the next render
|
|
@@ -11126,6 +11648,149 @@
|
|
|
11126
11648
|
}
|
|
11127
11649
|
};
|
|
11128
11650
|
|
|
11651
|
+
/** The colorScale's data: the chart's data rolled up per time/id, keeping rows with a colorScale value. */ function colorScaleData(viz) {
|
|
11652
|
+
const data$1 = Array.from(d3Array.rollup(viz._data, (leaves)=>data.merge(leaves, viz.schema.aggs), (d, i)=>`${viz.schema.time ? viz.schema.time(d, i) : "all"}-${viz._ids(d, i).join("_")}`).values());
|
|
11653
|
+
return data$1.filter((d, i)=>{
|
|
11654
|
+
const c = viz.schema.colorScale(d, i);
|
|
11655
|
+
return c !== undefined && c !== null;
|
|
11656
|
+
});
|
|
11657
|
+
}
|
|
11658
|
+
/**
|
|
11659
|
+
Configures and lays out the chart's `_colorScaleClass` into `frame`. It
|
|
11660
|
+
always runs in compute mode: Viz.toScene composes its scene, so the
|
|
11661
|
+
colorScale never paints a DOM copy of its own.
|
|
11662
|
+
*/ function paintColorScale(viz, frame, show) {
|
|
11663
|
+
const transform = {
|
|
11664
|
+
opacity: frame.orient ? 1 : 0,
|
|
11665
|
+
transform: `translate(${frame.x}, ${frame.y})`
|
|
11666
|
+
};
|
|
11667
|
+
const scaleGroup = dom.elem("g.d3plus-viz-colorScale", {
|
|
11668
|
+
condition: show && !viz.schema.colorScaleConfig.select,
|
|
11669
|
+
enter: transform,
|
|
11670
|
+
parent: viz._select,
|
|
11671
|
+
duration: viz.schema.duration,
|
|
11672
|
+
update: transform
|
|
11673
|
+
}).node();
|
|
11674
|
+
if (!viz.schema.colorScale) return;
|
|
11675
|
+
viz._colorScaleClass.renderMode("compute").align(frame.align).duration(viz.schema.duration).data(colorScaleData(viz)).height(frame.height).locale(viz.schema.locale).orient(frame.orient).select(scaleGroup).value(viz.schema.colorScale).width(frame.width).config(viz.schema.colorScaleConfig).render();
|
|
11676
|
+
}
|
|
11677
|
+
/** The colorScale's sanitized position side (false when hidden). */ function colorScalePosition(viz) {
|
|
11678
|
+
return sanitizePosition(viz.schema.colorScalePosition.bind(viz)(resolveSpec(viz)));
|
|
11679
|
+
}
|
|
11680
|
+
/**
|
|
11681
|
+
Lays the colorScale out to be drawn inside the chart: at the origin —
|
|
11682
|
+
Viz.toScene moves it into place — vertically (`"column"`) or
|
|
11683
|
+
horizontally (`"row"`), sized against the chart area `area`. Returns its
|
|
11684
|
+
measured size, or null when it isn't showing.
|
|
11685
|
+
*/ function paintColorScaleInset(viz, orient, area) {
|
|
11686
|
+
const show = Boolean(viz.schema.colorScale) && colorScalePosition(viz) !== false && !viz.schema.colorScaleConfig.select;
|
|
11687
|
+
const frame = insetFrame(orient, area);
|
|
11688
|
+
const maxSize = viz.schema.colorScaleMaxSize;
|
|
11689
|
+
paintColorScale(viz, {
|
|
11690
|
+
x: 0,
|
|
11691
|
+
y: 0,
|
|
11692
|
+
width: orient === "row" ? d3Array.min([
|
|
11693
|
+
maxSize,
|
|
11694
|
+
frame.width
|
|
11695
|
+
]) : frame.width,
|
|
11696
|
+
height: orient === "column" ? d3Array.min([
|
|
11697
|
+
maxSize,
|
|
11698
|
+
frame.height
|
|
11699
|
+
]) : frame.height,
|
|
11700
|
+
orient: orient === "column" ? "right" : "bottom",
|
|
11701
|
+
align: "start"
|
|
11702
|
+
}, show);
|
|
11703
|
+
if (!show) return null;
|
|
11704
|
+
const { width, height } = viz._colorScaleClass.outerBounds();
|
|
11705
|
+
return width && height ? {
|
|
11706
|
+
width,
|
|
11707
|
+
height
|
|
11708
|
+
} : null;
|
|
11709
|
+
}
|
|
11710
|
+
/**
|
|
11711
|
+
Converts `drawColorScale.ts` to a FeatureModule.
|
|
11712
|
+
|
|
11713
|
+
Visible only when `_colorScale` is truthy and `_colorScalePosition` resolves
|
|
11714
|
+
to a side. Renders the chart's `_colorScaleClass` ColorScale instance and
|
|
11715
|
+
claims margin along its position side.
|
|
11716
|
+
*/ const colorScaleFeature = {
|
|
11717
|
+
name: "colorScale",
|
|
11718
|
+
configFields: [
|
|
11719
|
+
"colorScale",
|
|
11720
|
+
"colorScaleConfig",
|
|
11721
|
+
"colorScaleMaxSize",
|
|
11722
|
+
"colorScalePadding",
|
|
11723
|
+
"colorScalePosition"
|
|
11724
|
+
],
|
|
11725
|
+
layout: ({ viz, layoutMargin })=>{
|
|
11726
|
+
if (isInsetPending(viz, "colorScale")) {
|
|
11727
|
+
paintColorScaleInset(viz, insetOrient(viz, "colorScale"), {
|
|
11728
|
+
width: viz.schema.width - layoutMargin.left - layoutMargin.right,
|
|
11729
|
+
height: viz.schema.height - layoutMargin.top - layoutMargin.bottom
|
|
11730
|
+
});
|
|
11731
|
+
return {
|
|
11732
|
+
panel: null,
|
|
11733
|
+
margin: {}
|
|
11734
|
+
};
|
|
11735
|
+
}
|
|
11736
|
+
const position = colorScalePosition(viz);
|
|
11737
|
+
const wide = [
|
|
11738
|
+
"top",
|
|
11739
|
+
"bottom"
|
|
11740
|
+
].includes(position);
|
|
11741
|
+
const showColorScale = viz.schema.colorScale && position;
|
|
11742
|
+
const padding = viz.schema.colorScalePadding(viz) ? viz._padding : {
|
|
11743
|
+
top: 0,
|
|
11744
|
+
right: 0,
|
|
11745
|
+
bottom: 0,
|
|
11746
|
+
left: 0
|
|
11747
|
+
};
|
|
11748
|
+
// Share the bottom band with the bottom-right corner panel (size legend):
|
|
11749
|
+
// a bottom colorScale fits beside it, a side one ends above it.
|
|
11750
|
+
const corner = bottomRightClearance(viz, position, layoutMargin.bottom + padding.bottom, layoutMargin.right + padding.right);
|
|
11751
|
+
const availableWidth = viz.schema.width - (layoutMargin.left + layoutMargin.right + padding.left + padding.right) - corner.inset;
|
|
11752
|
+
const width = wide ? d3Array.min([
|
|
11753
|
+
viz.schema.colorScaleMaxSize,
|
|
11754
|
+
availableWidth
|
|
11755
|
+
]) : viz.schema.width - (layoutMargin.left + layoutMargin.right);
|
|
11756
|
+
const availableHeight = viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top) - corner.drop;
|
|
11757
|
+
const height = !wide ? d3Array.min([
|
|
11758
|
+
viz.schema.colorScaleMaxSize,
|
|
11759
|
+
availableHeight
|
|
11760
|
+
]) : viz.schema.height - (layoutMargin.bottom + layoutMargin.top);
|
|
11761
|
+
paintColorScale(viz, {
|
|
11762
|
+
x: wide ? layoutMargin.left + padding.left + (availableWidth - width) / 2 : layoutMargin.left,
|
|
11763
|
+
y: wide ? layoutMargin.top : layoutMargin.top + padding.top + (availableHeight - height) / 2,
|
|
11764
|
+
width,
|
|
11765
|
+
height,
|
|
11766
|
+
orient: position,
|
|
11767
|
+
align: {
|
|
11768
|
+
bottom: "end",
|
|
11769
|
+
left: "start",
|
|
11770
|
+
right: "end",
|
|
11771
|
+
top: "start"
|
|
11772
|
+
}[position] || "bottom"
|
|
11773
|
+
}, Boolean(showColorScale));
|
|
11774
|
+
const margin = {};
|
|
11775
|
+
if (showColorScale) {
|
|
11776
|
+
const scaleBounds = viz._colorScaleClass.outerBounds();
|
|
11777
|
+
if (!viz.schema.colorScaleConfig.select && scaleBounds.height) {
|
|
11778
|
+
// Use the colorScale's OWN padding for its margin claim — not the
|
|
11779
|
+
// legend's, so a custom legendPadding doesn't shift the
|
|
11780
|
+
// colorScale's claim when the legend is hidden. The colorScale
|
|
11781
|
+
// class is the source of truth.
|
|
11782
|
+
const csPadding = typeof viz._colorScaleClass.padding === "function" ? viz._colorScaleClass.padding() : viz._legendClass.padding();
|
|
11783
|
+
if (wide) margin[position] = scaleBounds.height + csPadding * 2;
|
|
11784
|
+
else margin[position] = scaleBounds.width + csPadding * 2;
|
|
11785
|
+
}
|
|
11786
|
+
}
|
|
11787
|
+
return {
|
|
11788
|
+
panel: null,
|
|
11789
|
+
margin
|
|
11790
|
+
};
|
|
11791
|
+
}
|
|
11792
|
+
};
|
|
11793
|
+
|
|
11129
11794
|
/**
|
|
11130
11795
|
Shared geometry helpers for chart `_draw` methods and layout stages.
|
|
11131
11796
|
|
|
@@ -11667,107 +12332,8 @@
|
|
|
11667
12332
|
return {
|
|
11668
12333
|
panel: null,
|
|
11669
12334
|
margin: {
|
|
11670
|
-
bottom: timeline.outerBounds().height + timeline.padding() * 2
|
|
11671
|
-
}
|
|
11672
|
-
};
|
|
11673
|
-
}
|
|
11674
|
-
};
|
|
11675
|
-
/* ------------------------------- ColorScale ------------------------------ */ /**
|
|
11676
|
-
Converts `drawColorScale.ts` to a FeatureModule.
|
|
11677
|
-
|
|
11678
|
-
Visible only when `_colorScale` is truthy and `_colorScalePosition` resolves
|
|
11679
|
-
to a side. Renders the chart's `_colorScaleClass` ColorScale instance and
|
|
11680
|
-
claims margin along its position side.
|
|
11681
|
-
*/ const colorScaleFeature = {
|
|
11682
|
-
name: "colorScale",
|
|
11683
|
-
configFields: [
|
|
11684
|
-
"colorScale",
|
|
11685
|
-
"colorScaleConfig",
|
|
11686
|
-
"colorScaleMaxSize",
|
|
11687
|
-
"colorScalePadding",
|
|
11688
|
-
"colorScalePosition"
|
|
11689
|
-
],
|
|
11690
|
-
layout: ({ viz, layoutMargin })=>{
|
|
11691
|
-
const data$1 = Array.from(d3Array.rollup(viz._data, (leaves)=>data.merge(leaves, viz.schema.aggs), (d, i)=>`${viz.schema.time ? viz.schema.time(d, i) : "all"}-${viz._ids(d, i).join("_")}`).values());
|
|
11692
|
-
const position = sanitizePosition(viz.schema.colorScalePosition.bind(viz)(resolveSpec(viz)));
|
|
11693
|
-
const wide = [
|
|
11694
|
-
"top",
|
|
11695
|
-
"bottom"
|
|
11696
|
-
].includes(position);
|
|
11697
|
-
const showColorScale = viz.schema.colorScale && position;
|
|
11698
|
-
const padding = viz.schema.colorScalePadding(viz) ? viz._padding : {
|
|
11699
|
-
top: 0,
|
|
11700
|
-
right: 0,
|
|
11701
|
-
bottom: 0,
|
|
11702
|
-
left: 0
|
|
11703
|
-
};
|
|
11704
|
-
// Share the bottom band with the bottom-right corner panel (size legend):
|
|
11705
|
-
// a bottom colorScale fits beside it, a side one ends above it.
|
|
11706
|
-
const corner = bottomRightClearance(viz, position, layoutMargin.bottom + padding.bottom, layoutMargin.right + padding.right);
|
|
11707
|
-
const availableWidth = viz.schema.width - (layoutMargin.left + layoutMargin.right + padding.left + padding.right) - corner.inset;
|
|
11708
|
-
const width = wide ? d3Array.min([
|
|
11709
|
-
viz.schema.colorScaleMaxSize,
|
|
11710
|
-
availableWidth
|
|
11711
|
-
]) : viz.schema.width - (layoutMargin.left + layoutMargin.right);
|
|
11712
|
-
const availableHeight = viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top) - corner.drop;
|
|
11713
|
-
const height = !wide ? d3Array.min([
|
|
11714
|
-
viz.schema.colorScaleMaxSize,
|
|
11715
|
-
availableHeight
|
|
11716
|
-
]) : viz.schema.height - (layoutMargin.bottom + layoutMargin.top);
|
|
11717
|
-
const transform = {
|
|
11718
|
-
opacity: position ? 1 : 0,
|
|
11719
|
-
transform: `translate(${wide ? layoutMargin.left + padding.left + (availableWidth - width) / 2 : layoutMargin.left}, ${wide ? layoutMargin.top : layoutMargin.top + padding.top + (availableHeight - height) / 2})`
|
|
11720
|
-
};
|
|
11721
|
-
const scaleGroup = dom.elem("g.d3plus-viz-colorScale", {
|
|
11722
|
-
condition: showColorScale && !viz.schema.colorScaleConfig.select,
|
|
11723
|
-
enter: transform,
|
|
11724
|
-
parent: viz._select,
|
|
11725
|
-
duration: viz.schema.duration,
|
|
11726
|
-
update: transform
|
|
11727
|
-
}).node();
|
|
11728
|
-
if (!viz.schema.colorScale) return {
|
|
11729
|
-
panel: null,
|
|
11730
|
-
margin: {}
|
|
11731
|
-
};
|
|
11732
|
-
const scaleData = data$1.filter((d, i)=>{
|
|
11733
|
-
const c = viz.schema.colorScale(d, i);
|
|
11734
|
-
return c !== undefined && c !== null;
|
|
11735
|
-
});
|
|
11736
|
-
// Discrete (bucket/jenks/quantile) colorScales render their swatches via an
|
|
11737
|
-
// internal Legend, which composes cleanly through the Viz scene — so run
|
|
11738
|
-
// them in compute mode (like the legend) so the Viz's toScene owns them and
|
|
11739
|
-
// hover/active dimming applies. Without this they render full-mode, where
|
|
11740
|
-
// paintComponentScene paints a full-opacity copy that overlays and defeats
|
|
11741
|
-
// the dimming. The smooth-gradient variant stays full-mode: its gradient
|
|
11742
|
-
// fill is materialized through paintComponentScene, not the Viz scene.
|
|
11743
|
-
const csCfg = viz.schema.colorScaleConfig || {};
|
|
11744
|
-
const csDiscrete = !csCfg.bucketAxis && [
|
|
11745
|
-
"buckets",
|
|
11746
|
-
"jenks",
|
|
11747
|
-
"quantile"
|
|
11748
|
-
].includes(typeof csCfg.scale === "string" ? csCfg.scale : "");
|
|
11749
|
-
viz._colorScaleClass.renderMode(csDiscrete ? "compute" : "full").align({
|
|
11750
|
-
bottom: "end",
|
|
11751
|
-
left: "start",
|
|
11752
|
-
right: "end",
|
|
11753
|
-
top: "start"
|
|
11754
|
-
}[position] || "bottom").duration(viz.schema.duration).data(scaleData).height(height).locale(viz.schema.locale).orient(position).select(scaleGroup).value(viz.schema.colorScale).width(width).config(viz.schema.colorScaleConfig).render();
|
|
11755
|
-
const margin = {};
|
|
11756
|
-
if (showColorScale) {
|
|
11757
|
-
const scaleBounds = viz._colorScaleClass.outerBounds();
|
|
11758
|
-
if (!viz.schema.colorScaleConfig.select && scaleBounds.height) {
|
|
11759
|
-
// Use the colorScale's OWN padding for its margin claim — not the
|
|
11760
|
-
// legend's, so a custom legendPadding doesn't shift the
|
|
11761
|
-
// colorScale's claim when the legend is hidden. The colorScale
|
|
11762
|
-
// class is the source of truth.
|
|
11763
|
-
const csPadding = typeof viz._colorScaleClass.padding === "function" ? viz._colorScaleClass.padding() : viz._legendClass.padding();
|
|
11764
|
-
if (wide) margin[position] = scaleBounds.height + csPadding * 2;
|
|
11765
|
-
else margin[position] = scaleBounds.width + csPadding * 2;
|
|
11766
|
-
}
|
|
11767
|
-
}
|
|
11768
|
-
return {
|
|
11769
|
-
panel: null,
|
|
11770
|
-
margin
|
|
12335
|
+
bottom: timeline.outerBounds().height + timeline.padding() * 2
|
|
12336
|
+
}
|
|
11771
12337
|
};
|
|
11772
12338
|
}
|
|
11773
12339
|
};
|
|
@@ -12057,6 +12623,7 @@
|
|
|
12057
12623
|
// interaction-opacity pass, so repaint to apply/clear active state.
|
|
12058
12624
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
12059
12625
|
}
|
|
12626
|
+
broadcastLink(this, "active", _);
|
|
12060
12627
|
return this;
|
|
12061
12628
|
}
|
|
12062
12629
|
/**
|
|
@@ -12178,21 +12745,6 @@
|
|
|
12178
12745
|
*/ detectVisibleUnload(_) {
|
|
12179
12746
|
return arguments.length ? (this.schema.detectVisibleUnload = _, this) : this.schema.detectVisibleUnload;
|
|
12180
12747
|
}
|
|
12181
|
-
/**
|
|
12182
|
-
Shows a button that allows for downloading the current visualization.
|
|
12183
|
-
*/ downloadButton(_) {
|
|
12184
|
-
return arguments.length ? (this.schema.downloadButton = _, this) : this.schema.downloadButton;
|
|
12185
|
-
}
|
|
12186
|
-
/**
|
|
12187
|
-
Sets specific options of the saveElement function used when downloading the visualization.
|
|
12188
|
-
*/ downloadConfig(_) {
|
|
12189
|
-
return arguments.length ? (this.schema.downloadConfig = dom.assign(this.schema.downloadConfig, _), this) : this.schema.downloadConfig;
|
|
12190
|
-
}
|
|
12191
|
-
/**
|
|
12192
|
-
Defines which control group to add the download button into.
|
|
12193
|
-
*/ downloadPosition(_) {
|
|
12194
|
-
return arguments.length ? (this.schema.downloadPosition = _, this) : this.schema.downloadPosition;
|
|
12195
|
-
}
|
|
12196
12748
|
/**
|
|
12197
12749
|
The font family used throughout the visualization.
|
|
12198
12750
|
*/ fontFamily(_) {
|
|
@@ -12310,6 +12862,7 @@
|
|
|
12310
12862
|
// to one paint per frame so a fast pointer sweep doesn't saturate the main
|
|
12311
12863
|
// thread.
|
|
12312
12864
|
if (this._sceneRenderer && _ !== undefined && (this.schema.shapeConfig.hoverOpacity !== 1 || this._hoverBucket)) this._scheduleSceneRepaint();
|
|
12865
|
+
broadcastLink(this, "hover", _);
|
|
12313
12866
|
return this;
|
|
12314
12867
|
}
|
|
12315
12868
|
/**
|
|
@@ -12324,6 +12877,7 @@
|
|
|
12324
12877
|
// Scene-rendered charts express de-emphasis via the scene's
|
|
12325
12878
|
// interaction-opacity pass, so repaint to apply/clear the gray treatment.
|
|
12326
12879
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
12880
|
+
broadcastLink(this, "highlight", _);
|
|
12327
12881
|
return this;
|
|
12328
12882
|
}
|
|
12329
12883
|
/**
|
|
@@ -12348,6 +12902,16 @@
|
|
|
12348
12902
|
*/ legendFilterInvert(_) {
|
|
12349
12903
|
return arguments.length ? (this.schema.legendFilterInvert = typeof _ === "function" ? _ : constant(_), this) : this.schema.legendFilterInvert;
|
|
12350
12904
|
}
|
|
12905
|
+
/**
|
|
12906
|
+
Whether the chart may draw one of its legends inside the empty space around its marks instead of in a margin, for charts that leave room (Plot, Network, Pack, Pie, Rings, Tree, and Geomap). After the chart lays out, the size legend is tried first, then the legend, then the colorScale; the first that fits is drawn over a semi-transparent box (see `legendInsetConfig`), and any others keep their margins. Space enclosed by the marks, like the middle of a ring of points, is never used. A legend or colorScale whose position was set explicitly stays in that margin. Defaults to `true`; also accepts a function that receives the resolved chart config and returns a boolean.
|
|
12907
|
+
*/ legendInset(_) {
|
|
12908
|
+
return arguments.length ? (this.schema.legendInset = _, this) : this.schema.legendInset;
|
|
12909
|
+
}
|
|
12910
|
+
/**
|
|
12911
|
+
Style of the box drawn behind a legend placed inside the chart (see `legendInset`): `fill` (defaults to the chart's background color), `fillOpacity` (0.85), `stroke` (defaults to a faint contrasting line), `strokeWidth` (1), `rx` (corner radius, 4), `margin` (space between the box's edge and the legend, 6), and `padding` (space kept between the box and the chart's marks and edges, 10).
|
|
12912
|
+
*/ legendInsetConfig(_) {
|
|
12913
|
+
return arguments.length ? (this.schema.legendInsetConfig = dom.assign(this.schema.legendInsetConfig, _), this) : this.schema.legendInsetConfig;
|
|
12914
|
+
}
|
|
12351
12915
|
/**
|
|
12352
12916
|
Tells the legend whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the legend appears centered underneath the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.
|
|
12353
12917
|
*/ legendPadding(_) {
|
|
@@ -12727,13 +13291,6 @@
|
|
|
12727
13291
|
h.s = 0;
|
|
12728
13292
|
return `${h}`;
|
|
12729
13293
|
}
|
|
12730
|
-
/** Scene mark types that carry a fill/stroke a hover/active emphasis applies to. */ const MARK_TYPES = new Set([
|
|
12731
|
-
"rect",
|
|
12732
|
-
"circle",
|
|
12733
|
-
"line",
|
|
12734
|
-
"area",
|
|
12735
|
-
"path"
|
|
12736
|
-
]);
|
|
12737
13294
|
/**
|
|
12738
13295
|
Emphasizes a matched mark's stroke on hover/active — the v3 `hoverStyle` /
|
|
12739
13296
|
`activeStyle` look (a thicker, darker outline). v4 paints from the scene
|
|
@@ -12826,6 +13383,20 @@
|
|
|
12826
13383
|
};
|
|
12827
13384
|
return nodes.map(walk);
|
|
12828
13385
|
}
|
|
13386
|
+
/**
|
|
13387
|
+
Whether `predicate` matches `row` or any row it wraps. A mark's datum
|
|
13388
|
+
unwraps to its source row in one step, but its data label is wrapped once
|
|
13389
|
+
more (label → mark datum → row), so a label is only recognized as its
|
|
13390
|
+
mark's by following the `__d3plus__` chain down to the row.
|
|
13391
|
+
*/ function matchesChain(predicate, row, i) {
|
|
13392
|
+
let d = row;
|
|
13393
|
+
if (predicate(d, i)) return true;
|
|
13394
|
+
while(d && d.__d3plus__ && d.data){
|
|
13395
|
+
d = d.data;
|
|
13396
|
+
if (predicate(d, i)) return true;
|
|
13397
|
+
}
|
|
13398
|
+
return false;
|
|
13399
|
+
}
|
|
12829
13400
|
function applyInteractionOpacity(nodes, viz) {
|
|
12830
13401
|
// Precedence (hover → active → highlight) and the dim-vs-gray treatment are
|
|
12831
13402
|
// resolved once in dimSettings; picking one source avoids ambiguous
|
|
@@ -12847,7 +13418,7 @@
|
|
|
12847
13418
|
// the row; for label nodes it's the layout node whose `.data` is the row.
|
|
12848
13419
|
const row = datum.data ?? datum;
|
|
12849
13420
|
const i = typeof node.index === "number" ? node.index : typeof row.i === "number" ? row.i : 0;
|
|
12850
|
-
if (!predicate
|
|
13421
|
+
if (!matchesChain(predicate, row, i)) {
|
|
12851
13422
|
const paint = node.paint ?? {};
|
|
12852
13423
|
if (gray) {
|
|
12853
13424
|
// highlight: recolor the mark to the de-emphasis gray so the
|
|
@@ -12878,15 +13449,16 @@
|
|
|
12878
13449
|
// adds no outline. An active node keeps the stronger active stroke even
|
|
12879
13450
|
// while hovered, rather than dropping to the thinner hover stroke.
|
|
12880
13451
|
if (kind !== "highlight" && MARK_TYPES.has(node.type)) {
|
|
12881
|
-
const active = kind === "active" || (activePredicate
|
|
13452
|
+
const active = kind === "active" || (activePredicate ? matchesChain(activePredicate, row, i) : false);
|
|
12882
13453
|
next = active ? emphasizeStroke(node, 1, 3) : emphasizeStroke(node, 0.5, 2);
|
|
12883
13454
|
}
|
|
12884
13455
|
if (isHover) {
|
|
12885
13456
|
// Raise the hovered node above its siblings. Both renderers paint by
|
|
12886
13457
|
// ascending `z`; restore is automatic — the next repaint rebuilds the
|
|
12887
|
-
// scene with no `z`.
|
|
12888
|
-
//
|
|
12889
|
-
//
|
|
13458
|
+
// scene with no `z`. A matched mark's data label matches too (see
|
|
13459
|
+
// `matchesChain`), so it's raised with its mark and, emitted after it,
|
|
13460
|
+
// still paints on top. Only for hover: highlight relies on
|
|
13461
|
+
// color-vs-gray, not z-order.
|
|
12890
13462
|
next = {
|
|
12891
13463
|
...next,
|
|
12892
13464
|
z: HOVER_RAISE_Z
|
|
@@ -13923,6 +14495,444 @@
|
|
|
13923
14495
|
}
|
|
13924
14496
|
};
|
|
13925
14497
|
|
|
14498
|
+
/** Maps a point through a node transform: rotate (about its anchor), scale, then translate. */ function applyTransform([px, py], t) {
|
|
14499
|
+
if (!t) return [
|
|
14500
|
+
px,
|
|
14501
|
+
py
|
|
14502
|
+
];
|
|
14503
|
+
let x = px, y = py;
|
|
14504
|
+
if (t.rotate) {
|
|
14505
|
+
const [ax, ay] = t.rotateAnchor ?? [
|
|
14506
|
+
0,
|
|
14507
|
+
0
|
|
14508
|
+
];
|
|
14509
|
+
const a = t.rotate * Math.PI / 180, cos = Math.cos(a), sin = Math.sin(a);
|
|
14510
|
+
const dx = x - ax, dy = y - ay;
|
|
14511
|
+
x = ax + dx * cos - dy * sin;
|
|
14512
|
+
y = ay + dx * sin + dy * cos;
|
|
14513
|
+
}
|
|
14514
|
+
const s = t.scale ?? 1;
|
|
14515
|
+
return [
|
|
14516
|
+
x * s + (t.x ?? 0),
|
|
14517
|
+
y * s + (t.y ?? 0)
|
|
14518
|
+
];
|
|
14519
|
+
}
|
|
14520
|
+
/** How finely a path's curves are traced into outline points, in pixels. */ const PATH_STEP = 10;
|
|
14521
|
+
/** A zero-size box at a series vertex. */ const vertexBox = ([x, y])=>({
|
|
14522
|
+
x,
|
|
14523
|
+
y,
|
|
14524
|
+
width: 0,
|
|
14525
|
+
height: 0
|
|
14526
|
+
});
|
|
14527
|
+
/** One box per laid-out line of a text node, from its anchor, baseline, and font size. */ function textBoxes(node) {
|
|
14528
|
+
const size = node.font?.size ?? 0;
|
|
14529
|
+
const anchor = node.font?.anchor ?? "start";
|
|
14530
|
+
const baseline = node.font?.baseline ?? "alphabetic";
|
|
14531
|
+
const above = baseline === "hanging" ? 0 : baseline === "middle" ? size / 2 : size * 0.8;
|
|
14532
|
+
return (node.lines || []).filter((line)=>line.text && line.width).map((line)=>{
|
|
14533
|
+
const shift = anchor === "middle" ? line.width / 2 : anchor === "end" ? line.width : 0;
|
|
14534
|
+
return {
|
|
14535
|
+
x: node.x + line.x - shift,
|
|
14536
|
+
y: node.y + line.y - above,
|
|
14537
|
+
width: line.width,
|
|
14538
|
+
height: size
|
|
14539
|
+
};
|
|
14540
|
+
});
|
|
14541
|
+
}
|
|
14542
|
+
/** Boxes of a node's own geometry, before its transform. Line/area series and paths contribute one box per outline point. */ function ownBoxes(node) {
|
|
14543
|
+
switch(node.type){
|
|
14544
|
+
case "rect":
|
|
14545
|
+
case "image":
|
|
14546
|
+
return [
|
|
14547
|
+
{
|
|
14548
|
+
x: node.x,
|
|
14549
|
+
y: node.y,
|
|
14550
|
+
width: node.width,
|
|
14551
|
+
height: node.height
|
|
14552
|
+
}
|
|
14553
|
+
];
|
|
14554
|
+
case "circle":
|
|
14555
|
+
return [
|
|
14556
|
+
{
|
|
14557
|
+
x: node.cx - node.r,
|
|
14558
|
+
y: node.cy - node.r,
|
|
14559
|
+
width: node.r * 2,
|
|
14560
|
+
height: node.r * 2
|
|
14561
|
+
}
|
|
14562
|
+
];
|
|
14563
|
+
case "path":
|
|
14564
|
+
{
|
|
14565
|
+
// Its outline, so a curved shape (a pie wedge, a map region) doesn't
|
|
14566
|
+
// claim the empty corners of its bounding box.
|
|
14567
|
+
const outline = math.path2polygon(node.d, PATH_STEP);
|
|
14568
|
+
return outline.length ? outline.map(vertexBox) : [
|
|
14569
|
+
math.pathBounds(node.d)
|
|
14570
|
+
];
|
|
14571
|
+
}
|
|
14572
|
+
case "line":
|
|
14573
|
+
return node.points.map(vertexBox);
|
|
14574
|
+
case "area":
|
|
14575
|
+
return [
|
|
14576
|
+
...node.topline,
|
|
14577
|
+
...node.baseline
|
|
14578
|
+
].map(vertexBox);
|
|
14579
|
+
case "text":
|
|
14580
|
+
return textBoxes(node);
|
|
14581
|
+
default:
|
|
14582
|
+
return [];
|
|
14583
|
+
}
|
|
14584
|
+
}
|
|
14585
|
+
/** Composes a chain of transforms (outermost first) into one point mapper. */ function mapper(chain) {
|
|
14586
|
+
return (p)=>chain.reduceRight((q, t)=>applyTransform(q, t), p);
|
|
14587
|
+
}
|
|
14588
|
+
/** The axis-aligned box around a box mapped through `map`. */ function mapBox(b, map) {
|
|
14589
|
+
const corners = [
|
|
14590
|
+
map([
|
|
14591
|
+
b.x,
|
|
14592
|
+
b.y
|
|
14593
|
+
]),
|
|
14594
|
+
map([
|
|
14595
|
+
b.x + b.width,
|
|
14596
|
+
b.y
|
|
14597
|
+
]),
|
|
14598
|
+
map([
|
|
14599
|
+
b.x,
|
|
14600
|
+
b.y + b.height
|
|
14601
|
+
]),
|
|
14602
|
+
map([
|
|
14603
|
+
b.x + b.width,
|
|
14604
|
+
b.y + b.height
|
|
14605
|
+
])
|
|
14606
|
+
];
|
|
14607
|
+
const xs = corners.map((c)=>c[0]), ys = corners.map((c)=>c[1]);
|
|
14608
|
+
const x = Math.min(...xs), y = Math.min(...ys);
|
|
14609
|
+
return {
|
|
14610
|
+
x,
|
|
14611
|
+
y,
|
|
14612
|
+
width: Math.max(...xs) - x,
|
|
14613
|
+
height: Math.max(...ys) - y
|
|
14614
|
+
};
|
|
14615
|
+
}
|
|
14616
|
+
/**
|
|
14617
|
+
Boxes, in the coordinate space of `nodes` after `base` is applied, of
|
|
14618
|
+
every data mark and label in a scene: datum-bearing nodes at any depth,
|
|
14619
|
+
with group transforms composed. `::hit` duplicates and chart decorations
|
|
14620
|
+
(axes, gridlines and other nodes without a datum) are skipped.
|
|
14621
|
+
@param nodes The chart's scene nodes (e.g. `viz._chartScene`).
|
|
14622
|
+
@param base A transform applied to all of them (e.g. `viz._chartTransform`).
|
|
14623
|
+
@param skip Excludes a node and everything inside it, for decorations that carry a datum (like axis ticks).
|
|
14624
|
+
*/ function markBoxes(nodes, base, skip) {
|
|
14625
|
+
const out = [];
|
|
14626
|
+
const walk = (list, chain)=>{
|
|
14627
|
+
for (const node of list){
|
|
14628
|
+
if (String(node.key).endsWith("::hit") || skip && skip(node)) continue;
|
|
14629
|
+
const next = node.transform ? [
|
|
14630
|
+
...chain,
|
|
14631
|
+
node.transform
|
|
14632
|
+
] : chain;
|
|
14633
|
+
if (node.type === "group") {
|
|
14634
|
+
walk(node.children, next);
|
|
14635
|
+
continue;
|
|
14636
|
+
}
|
|
14637
|
+
if (node.datum === undefined) continue;
|
|
14638
|
+
const map = mapper(next);
|
|
14639
|
+
for (const b of ownBoxes(node)){
|
|
14640
|
+
if ([
|
|
14641
|
+
b.x,
|
|
14642
|
+
b.y,
|
|
14643
|
+
b.width,
|
|
14644
|
+
b.height
|
|
14645
|
+
].every(Number.isFinite)) out.push(mapBox(b, map));
|
|
14646
|
+
}
|
|
14647
|
+
}
|
|
14648
|
+
};
|
|
14649
|
+
walk(nodes, base ? [
|
|
14650
|
+
base
|
|
14651
|
+
] : []);
|
|
14652
|
+
return out;
|
|
14653
|
+
}
|
|
14654
|
+
|
|
14655
|
+
/**
|
|
14656
|
+
The default inset region: the chart area (or `bounds`, in surface
|
|
14657
|
+
coordinates), with the boxes of every data mark in the chart's scene as
|
|
14658
|
+
obstacles (less any subtree `skip` excludes). Charts opt in by returning
|
|
14659
|
+
this from their `insetRegion`.
|
|
14660
|
+
*/ function sceneInsetRegion(viz, bounds, skip) {
|
|
14661
|
+
const { width, height } = chartBounds(viz);
|
|
14662
|
+
return {
|
|
14663
|
+
bounds: bounds ?? {
|
|
14664
|
+
x: viz._margin.left,
|
|
14665
|
+
y: viz._margin.top,
|
|
14666
|
+
width,
|
|
14667
|
+
height
|
|
14668
|
+
},
|
|
14669
|
+
obstacles: markBoxes(viz._chartScene || [], viz._chartTransform, skip)
|
|
14670
|
+
};
|
|
14671
|
+
}
|
|
14672
|
+
/** Whether `legendInset` is on for this draw. */ function insetEnabled(viz) {
|
|
14673
|
+
const flag = viz.schema.legendInset;
|
|
14674
|
+
return typeof flag === "function" ? Boolean(flag.bind(viz)(resolveSpec(viz))) : Boolean(flag);
|
|
14675
|
+
}
|
|
14676
|
+
/** The smallest a legend entry can be: a swatch (1.4× the 12px label font) plus its padding. */ const MIN_LEGEND_ENTRY = 12 * 1.4 + 5;
|
|
14677
|
+
/**
|
|
14678
|
+
Whether the legend could possibly lay out inside the chart: its entries,
|
|
14679
|
+
even with their labels dropped, must fit the largest frame an inset
|
|
14680
|
+
legend may take (see `insetFrame`). Rules out laying out a legend of
|
|
14681
|
+
hundreds of entries just to find it doesn't fit.
|
|
14682
|
+
*/ function legendCouldFit(viz) {
|
|
14683
|
+
const frame = insetFrame("column", {
|
|
14684
|
+
width: viz.schema.width || 0,
|
|
14685
|
+
height: viz.schema.height || 0
|
|
14686
|
+
});
|
|
14687
|
+
const entries = buildLegendData(viz).legendData.length;
|
|
14688
|
+
return entries * MIN_LEGEND_ENTRY * MIN_LEGEND_ENTRY <= frame.width * frame.height;
|
|
14689
|
+
}
|
|
14690
|
+
/**
|
|
14691
|
+
The candidates this draw may place inside the chart, in priority order.
|
|
14692
|
+
A legend or colorScale whose position the user set explicitly stays
|
|
14693
|
+
where they put it.
|
|
14694
|
+
*/ function insetCandidates(viz) {
|
|
14695
|
+
const auto = viz._insetAutoPositions;
|
|
14696
|
+
return INSET_PRIORITY.filter((key)=>{
|
|
14697
|
+
if (key === "legend") return (!auto || viz.schema.legendPosition === auto.legend) && legendCouldFit(viz);
|
|
14698
|
+
if (key === "colorScale") return !auto || viz.schema.colorScalePosition === auto.colorScale;
|
|
14699
|
+
return true;
|
|
14700
|
+
});
|
|
14701
|
+
}
|
|
14702
|
+
/** The orientations a candidate may take inside the chart. */ const ORIENTS = {
|
|
14703
|
+
sizeLegend: [
|
|
14704
|
+
"column"
|
|
14705
|
+
],
|
|
14706
|
+
legend: [
|
|
14707
|
+
"column",
|
|
14708
|
+
"row"
|
|
14709
|
+
],
|
|
14710
|
+
colorScale: [
|
|
14711
|
+
"column",
|
|
14712
|
+
"row"
|
|
14713
|
+
]
|
|
14714
|
+
};
|
|
14715
|
+
/** Whether a candidate laid out for the chart's interior this pass is showing at all. */ function isShowing(viz, key) {
|
|
14716
|
+
if (key === "sizeLegend") return Boolean(bottomRightControlsBox(viz)?.inset);
|
|
14717
|
+
if (key === "legend") return Boolean(viz._legendClass?._data?.length);
|
|
14718
|
+
return Boolean(viz.schema.colorScale) && sanitizePosition(viz.schema.colorScalePosition.bind(viz)(resolveSpec(viz))) !== false && !viz.schema.colorScaleConfig.select;
|
|
14719
|
+
}
|
|
14720
|
+
/**
|
|
14721
|
+
Lays a showing candidate out for the chart's interior in `orient` and
|
|
14722
|
+
returns its content size, or null when it can't lay out that way.
|
|
14723
|
+
*/ function measure(viz, key, orient, area) {
|
|
14724
|
+
if (key === "sizeLegend") {
|
|
14725
|
+
const box = bottomRightControlsBox(viz);
|
|
14726
|
+
return box ? {
|
|
14727
|
+
width: box.width,
|
|
14728
|
+
height: box.height
|
|
14729
|
+
} : null;
|
|
14730
|
+
}
|
|
14731
|
+
return key === "legend" ? paintLegendInset(viz, orient, area) : paintColorScaleInset(viz, orient, area);
|
|
14732
|
+
}
|
|
14733
|
+
/** The chart corners an inset box is tried in, most preferred first. */ const CORNERS = [
|
|
14734
|
+
{
|
|
14735
|
+
alignX: "right",
|
|
14736
|
+
alignY: "bottom"
|
|
14737
|
+
},
|
|
14738
|
+
{
|
|
14739
|
+
alignX: "right",
|
|
14740
|
+
alignY: "top"
|
|
14741
|
+
},
|
|
14742
|
+
{
|
|
14743
|
+
alignX: "left",
|
|
14744
|
+
alignY: "bottom"
|
|
14745
|
+
},
|
|
14746
|
+
{
|
|
14747
|
+
alignX: "left",
|
|
14748
|
+
alignY: "top"
|
|
14749
|
+
}
|
|
14750
|
+
];
|
|
14751
|
+
/**
|
|
14752
|
+
Where a box of `width` × `height` sits in the open rects (sorted largest
|
|
14753
|
+
first): in the first chart corner, in `CORNERS` order, that some rect
|
|
14754
|
+
reaching that corner has room for. When it fits in no corner, it goes in
|
|
14755
|
+
the first rect it fits, against whichever of the rect's sides lie on the
|
|
14756
|
+
region's edges (bottom-right when it touches both), centered along an
|
|
14757
|
+
axis otherwise.
|
|
14758
|
+
*/ function fitInset(rects, bounds, width, height) {
|
|
14759
|
+
const eps = 0.5;
|
|
14760
|
+
const fits = rects.filter((r)=>r.width >= width && r.height >= height);
|
|
14761
|
+
if (!fits.length) return null;
|
|
14762
|
+
const edges = (r)=>({
|
|
14763
|
+
right: Math.abs(r.x + r.width - (bounds.x + bounds.width)) < eps,
|
|
14764
|
+
left: Math.abs(r.x - bounds.x) < eps,
|
|
14765
|
+
bottom: Math.abs(r.y + r.height - (bounds.y + bounds.height)) < eps,
|
|
14766
|
+
top: Math.abs(r.y - bounds.y) < eps
|
|
14767
|
+
});
|
|
14768
|
+
const place = (r, alignX, alignY)=>({
|
|
14769
|
+
x: alignX === "right" ? r.x + r.width - width : alignX === "left" ? r.x : r.x + (r.width - width) / 2,
|
|
14770
|
+
y: alignY === "bottom" ? r.y + r.height - height : alignY === "top" ? r.y : r.y + (r.height - height) / 2,
|
|
14771
|
+
width,
|
|
14772
|
+
height,
|
|
14773
|
+
alignX,
|
|
14774
|
+
alignY
|
|
14775
|
+
});
|
|
14776
|
+
for (const { alignX, alignY } of CORNERS){
|
|
14777
|
+
const rect = fits.find((r)=>{
|
|
14778
|
+
const e = edges(r);
|
|
14779
|
+
return e[alignX] && e[alignY];
|
|
14780
|
+
});
|
|
14781
|
+
if (rect) return place(rect, alignX, alignY);
|
|
14782
|
+
}
|
|
14783
|
+
const rect = fits[0], e = edges(rect);
|
|
14784
|
+
return place(rect, e.right ? "right" : e.left ? "left" : "center", e.bottom ? "bottom" : e.top ? "top" : "middle");
|
|
14785
|
+
}
|
|
14786
|
+
/** Rough height of the attribution credit, a single line of small text. */ const ATTRIBUTION_HEIGHT = 22;
|
|
14787
|
+
/**
|
|
14788
|
+
Boxes of the chrome overlaid on the chart that inset chrome must also
|
|
14789
|
+
stay clear of: the zoom buttons (and the minimap that opens beneath
|
|
14790
|
+
them once zoomed), the top-left controls, and the attribution credit in
|
|
14791
|
+
the chart area's bottom-right corner (sized from its rendered node when
|
|
14792
|
+
there is one, otherwise from its text, up to the half of the chart it
|
|
14793
|
+
may span before collapsing to a badge).
|
|
14794
|
+
*/ function chromeBoxes(viz) {
|
|
14795
|
+
const boxes = [];
|
|
14796
|
+
const { width, height } = chartBounds(viz);
|
|
14797
|
+
const zoom = zoomControlsBox(viz);
|
|
14798
|
+
if (zoom) {
|
|
14799
|
+
const minimap = viz.schema.minimap ? (zoom.width - MINIMAP_RIGHT_INSET) * (height / Math.max(1, width)) : 0;
|
|
14800
|
+
boxes.push({
|
|
14801
|
+
x: viz.schema.width - zoom.width,
|
|
14802
|
+
y: 0,
|
|
14803
|
+
width: zoom.width,
|
|
14804
|
+
height: zoom.height + minimap
|
|
14805
|
+
});
|
|
14806
|
+
}
|
|
14807
|
+
const topLeft = topLeftControlsBox(viz, getTopLeftContributions(viz));
|
|
14808
|
+
if (topLeft) boxes.push({
|
|
14809
|
+
x: 0,
|
|
14810
|
+
y: 0,
|
|
14811
|
+
width: topLeft.width,
|
|
14812
|
+
height: topLeft.height
|
|
14813
|
+
});
|
|
14814
|
+
if (viz.schema.attribution) {
|
|
14815
|
+
const parent = viz._select?.node?.()?.parentNode;
|
|
14816
|
+
const node = parent?.querySelector?.("div.d3plus-attribution");
|
|
14817
|
+
const text = String(viz.schema.attribution).replace(/<[^>]*>/g, "");
|
|
14818
|
+
const w = Math.min(node?.offsetWidth || text.length * 6 + 30, width / 2);
|
|
14819
|
+
const h = node?.offsetHeight || ATTRIBUTION_HEIGHT;
|
|
14820
|
+
const right = viz.schema.width - viz._margin.right, bottom = viz.schema.height - viz._margin.bottom;
|
|
14821
|
+
boxes.push({
|
|
14822
|
+
x: right - w,
|
|
14823
|
+
y: bottom - h,
|
|
14824
|
+
width: w,
|
|
14825
|
+
height: h
|
|
14826
|
+
});
|
|
14827
|
+
}
|
|
14828
|
+
return boxes;
|
|
14829
|
+
}
|
|
14830
|
+
/** The open rects in the chart's region, kept `padding` clear of the marks and the region's edges. */ function openSpace(viz) {
|
|
14831
|
+
const region = viz._insetRegion?.();
|
|
14832
|
+
if (!region) return null;
|
|
14833
|
+
const { padding } = insetStyle(viz);
|
|
14834
|
+
const b = region.bounds;
|
|
14835
|
+
const bounds = {
|
|
14836
|
+
x: b.x + padding,
|
|
14837
|
+
y: b.y + padding,
|
|
14838
|
+
width: b.width - padding * 2,
|
|
14839
|
+
height: b.height - padding * 2
|
|
14840
|
+
};
|
|
14841
|
+
if (bounds.width <= 0 || bounds.height <= 0) return null;
|
|
14842
|
+
const exclude = chromeBoxes(viz);
|
|
14843
|
+
return {
|
|
14844
|
+
rects: math.negativeSpace(bounds, region.obstacles, {
|
|
14845
|
+
padding,
|
|
14846
|
+
exclude
|
|
14847
|
+
}),
|
|
14848
|
+
bounds,
|
|
14849
|
+
area: b
|
|
14850
|
+
};
|
|
14851
|
+
}
|
|
14852
|
+
/**
|
|
14853
|
+
Fits the first of `keys` that has room inside the chart. Returns the
|
|
14854
|
+
placement (or null) and which candidates are showing at all.
|
|
14855
|
+
*/ function choose(viz, keys) {
|
|
14856
|
+
const showing = keys.filter((key)=>isShowing(viz, key));
|
|
14857
|
+
const space = showing.length ? openSpace(viz) : null;
|
|
14858
|
+
if (!space || !space.rects.length) return {
|
|
14859
|
+
placement: null,
|
|
14860
|
+
showing
|
|
14861
|
+
};
|
|
14862
|
+
const { margin } = insetStyle(viz);
|
|
14863
|
+
for (const key of showing){
|
|
14864
|
+
for (const orient of ORIENTS[key]){
|
|
14865
|
+
const size = measure(viz, key, orient, space.area);
|
|
14866
|
+
const spot = size && fitInset(space.rects, space.bounds, size.width + margin * 2, size.height + margin * 2);
|
|
14867
|
+
if (spot) {
|
|
14868
|
+
return {
|
|
14869
|
+
placement: {
|
|
14870
|
+
key,
|
|
14871
|
+
orient,
|
|
14872
|
+
...spot
|
|
14873
|
+
},
|
|
14874
|
+
showing
|
|
14875
|
+
};
|
|
14876
|
+
}
|
|
14877
|
+
}
|
|
14878
|
+
}
|
|
14879
|
+
return {
|
|
14880
|
+
placement: null,
|
|
14881
|
+
showing
|
|
14882
|
+
};
|
|
14883
|
+
}
|
|
14884
|
+
/** Runs `_draw()` again from the margins the render started with. */ function redraw(viz, start) {
|
|
14885
|
+
viz._margin = {
|
|
14886
|
+
...start.margin
|
|
14887
|
+
};
|
|
14888
|
+
viz._padding = {
|
|
14889
|
+
...start.padding
|
|
14890
|
+
};
|
|
14891
|
+
viz._draw();
|
|
14892
|
+
}
|
|
14893
|
+
/**
|
|
14894
|
+
`viz._draw()`, placing chrome inside the chart's negative space when it
|
|
14895
|
+
fits (see the module docs). Leaves `viz._insetPlacement` set to what was
|
|
14896
|
+
placed, or null.
|
|
14897
|
+
*/ function drawWithInset(viz) {
|
|
14898
|
+
viz._insetPlacement = null;
|
|
14899
|
+
const keys = typeof viz._insetRegion === "function" && insetEnabled(viz) ? insetCandidates(viz) : [];
|
|
14900
|
+
if (!keys.length) {
|
|
14901
|
+
viz._insetPending = null;
|
|
14902
|
+
viz._draw();
|
|
14903
|
+
return;
|
|
14904
|
+
}
|
|
14905
|
+
const start = {
|
|
14906
|
+
margin: {
|
|
14907
|
+
...viz._margin
|
|
14908
|
+
},
|
|
14909
|
+
padding: {
|
|
14910
|
+
...viz._padding
|
|
14911
|
+
}
|
|
14912
|
+
};
|
|
14913
|
+
viz._insetPending = new Set(keys);
|
|
14914
|
+
viz._draw();
|
|
14915
|
+
const first = choose(viz, keys);
|
|
14916
|
+
const { showing } = first;
|
|
14917
|
+
let { placement } = first;
|
|
14918
|
+
if (!showing.length) return;
|
|
14919
|
+
if (placement && showing.some((k)=>k !== placement.key)) {
|
|
14920
|
+
viz._insetPending = new Set([
|
|
14921
|
+
placement.key
|
|
14922
|
+
]);
|
|
14923
|
+
redraw(viz, start);
|
|
14924
|
+
placement = choose(viz, [
|
|
14925
|
+
placement.key
|
|
14926
|
+
]).placement;
|
|
14927
|
+
}
|
|
14928
|
+
if (!placement) {
|
|
14929
|
+
viz._insetPending = new Set();
|
|
14930
|
+
redraw(viz, start);
|
|
14931
|
+
return;
|
|
14932
|
+
}
|
|
14933
|
+
viz._insetPlacement = placement;
|
|
14934
|
+
}
|
|
14935
|
+
|
|
13926
14936
|
/** The text/stroke color that reads against the chart's background. */ function inkColor(viz) {
|
|
13927
14937
|
const node = viz._select && typeof viz._select.node === "function" ? viz._select.node() : null;
|
|
13928
14938
|
const bg = node ? dom.backgroundColor(node) : "rgb(255, 255, 255)";
|
|
@@ -14001,10 +15011,12 @@
|
|
|
14001
15011
|
if (c) items.push(c);
|
|
14002
15012
|
}
|
|
14003
15013
|
const side = viz.schema.sizeLegendPosition === "bottom" ? "bottom" : "right";
|
|
15014
|
+
const inset = isInsetPending(viz, "sizeLegend");
|
|
14004
15015
|
viz._bottomRightBox = items.length ? {
|
|
14005
15016
|
...measureBottomRight(items),
|
|
14006
15017
|
bottom,
|
|
14007
15018
|
side,
|
|
15019
|
+
inset,
|
|
14008
15020
|
items
|
|
14009
15021
|
} : null;
|
|
14010
15022
|
}
|
|
@@ -14031,7 +15043,9 @@
|
|
|
14031
15043
|
// hold the BASE Viz behavior; subclasses' `super._preDraw()`/`super._draw()`
|
|
14032
15044
|
// calls hit the shim which delegates to the free functions.
|
|
14033
15045
|
viz._preDraw();
|
|
14034
|
-
|
|
15046
|
+
// `_draw()`, possibly more than once: chrome that fits inside the chart's
|
|
15047
|
+
// negative space is placed there after layout (see insetPlacement.ts).
|
|
15048
|
+
drawWithInset(viz);
|
|
14035
15049
|
// Post-draw features: zoom + brush event wiring, the minimap, the shared
|
|
14036
15050
|
// top-left controls panel (back / table-view button / search), the
|
|
14037
15051
|
// attribution overlay, and the table-view data-table overlay. All run
|
|
@@ -15113,9 +16127,9 @@
|
|
|
15113
16127
|
children.push({
|
|
15114
16128
|
type: "group",
|
|
15115
16129
|
key: `viz-${name}`,
|
|
15116
|
-
children: [
|
|
16130
|
+
children: name === "timeline" ? [
|
|
15117
16131
|
compScene
|
|
15118
|
-
]
|
|
16132
|
+
] : insetComponentScene(this, name, compScene, comp.outerBounds())
|
|
15119
16133
|
});
|
|
15120
16134
|
}
|
|
15121
16135
|
}
|
|
@@ -15151,6 +16165,14 @@
|
|
|
15151
16165
|
*/ _sizeLegendScale(_available) {
|
|
15152
16166
|
return null;
|
|
15153
16167
|
}
|
|
16168
|
+
/**
|
|
16169
|
+
The region chart chrome may be drawn inside, with the chart's mark boxes
|
|
16170
|
+
as obstacles (see `ChartDefinition.insetRegion`). Charts that leave
|
|
16171
|
+
negative space override this; the base chart offers none.
|
|
16172
|
+
@private
|
|
16173
|
+
*/ _insetRegion() {
|
|
16174
|
+
return null;
|
|
16175
|
+
}
|
|
15154
16176
|
/**
|
|
15155
16177
|
* Applies the threshold algorithm according to the type of chart used.
|
|
15156
16178
|
* @param {Array} data The data to process.
|
|
@@ -15525,6 +16547,7 @@
|
|
|
15525
16547
|
/**
|
|
15526
16548
|
Tears down the visualization: disconnects the ResizeObserver, stops listening for web font loads, and removes DOM event listeners. Call this when unmounting to avoid memory leaks.
|
|
15527
16549
|
*/ destroy() {
|
|
16550
|
+
unregisterLink(this);
|
|
15528
16551
|
this._resizeObserver?.disconnect();
|
|
15529
16552
|
this._fontsUnsubscribe?.();
|
|
15530
16553
|
this._fontsUnsubscribe = undefined;
|
|
@@ -15567,6 +16590,7 @@
|
|
|
15567
16590
|
*/ constructor(){
|
|
15568
16591
|
super();
|
|
15569
16592
|
initVizDefaults(this);
|
|
16593
|
+
initInsetDefaults(this);
|
|
15570
16594
|
}
|
|
15571
16595
|
}
|
|
15572
16596
|
|
|
@@ -15587,6 +16611,9 @@
|
|
|
15587
16611
|
_sizeLegendScale(available) {
|
|
15588
16612
|
return def.sizeLegendScale ? def.sizeLegendScale(this, available) : super._sizeLegendScale(available);
|
|
15589
16613
|
}
|
|
16614
|
+
_insetRegion() {
|
|
16615
|
+
return def.insetRegion ? def.insetRegion(this) : super._insetRegion();
|
|
16616
|
+
}
|
|
15590
16617
|
_thresholdFunction(data) {
|
|
15591
16618
|
return def.thresholdFunction ? def.thresholdFunction(this, data) : data;
|
|
15592
16619
|
}
|
|
@@ -15655,13 +16682,22 @@
|
|
|
15655
16682
|
}
|
|
15656
16683
|
return val;
|
|
15657
16684
|
}
|
|
16685
|
+
/**
|
|
16686
|
+
Resolve a datum's scene fill from a shape-config record: a
|
|
16687
|
+
`pattern:<json>` token when `sc.texture` is set for the datum (the
|
|
16688
|
+
renderer backends materialize it), otherwise the resolved `fill` when
|
|
16689
|
+
it is a string. `fill` is the datum's already-resolved `sc.fill`.
|
|
16690
|
+
*/ function textureFill(sc, d, i, fill) {
|
|
16691
|
+
const key = textureKey(resolveAccessor$6(sc.texture, d, i), ()=>fill, ()=>resolveAccessor$6(sc.stroke, d, i), sc.textureDefault);
|
|
16692
|
+
if (key) return `pattern:${key}`;
|
|
16693
|
+
return typeof fill === "string" ? fill : undefined;
|
|
16694
|
+
}
|
|
15658
16695
|
/**
|
|
15659
16696
|
Resolve the standard paint properties (`fill`, `stroke`, `strokeWidth`,
|
|
15660
16697
|
`opacity`) from a shape-config record for a single datum. Returns a
|
|
15661
|
-
`Paint`-shaped object compatible with `SceneNode.paint`. `fill`
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
do this same coercion).
|
|
16698
|
+
`Paint`-shaped object compatible with `SceneNode.paint`. `fill` resolves
|
|
16699
|
+
through `textureFill`, so a texture becomes a `pattern:<json>` token and
|
|
16700
|
+
a non-string fill becomes `undefined`.
|
|
15665
16701
|
*/ function paintFromShapeConfig(sc, d, i) {
|
|
15666
16702
|
const fill = resolveAccessor$6(sc.fill, d, i);
|
|
15667
16703
|
const stroke = resolveAccessor$6(sc.stroke, d, i);
|
|
@@ -15669,7 +16705,7 @@
|
|
|
15669
16705
|
const opacity = resolveAccessor$6(sc.opacity, d, i);
|
|
15670
16706
|
const ve = resolveAccessor$6(sc.vectorEffect, d, i);
|
|
15671
16707
|
return {
|
|
15672
|
-
fill:
|
|
16708
|
+
fill: textureFill(sc, d, i, fill),
|
|
15673
16709
|
stroke,
|
|
15674
16710
|
strokeWidth,
|
|
15675
16711
|
opacity,
|
|
@@ -15753,6 +16789,79 @@
|
|
|
15753
16789
|
}
|
|
15754
16790
|
}
|
|
15755
16791
|
|
|
16792
|
+
/** The calendar intervals a time axis is checked against, coarsest first. */ const intervals = [
|
|
16793
|
+
d3Time.timeYear,
|
|
16794
|
+
d3Time.timeMonth,
|
|
16795
|
+
d3Time.timeDay,
|
|
16796
|
+
d3Time.timeHour,
|
|
16797
|
+
d3Time.timeMinute,
|
|
16798
|
+
d3Time.timeSecond
|
|
16799
|
+
];
|
|
16800
|
+
/** The median of a non-empty list of numbers. */ function median(values) {
|
|
16801
|
+
const sorted = values.slice().sort((a, b)=>a - b);
|
|
16802
|
+
const mid = sorted.length >> 1;
|
|
16803
|
+
return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
|
|
16804
|
+
}
|
|
16805
|
+
/** Drops floating point noise from a stepped number (0.1 + 0.2 → 0.3). */ const clean = (n)=>+n.toPrecision(12);
|
|
16806
|
+
/**
|
|
16807
|
+
How to step along an independent axis: numbers by the median gap between
|
|
16808
|
+
distinct values; dates by the coarsest calendar interval every date lands
|
|
16809
|
+
on (years, months, days, …) times the median number of those intervals
|
|
16810
|
+
between dates, falling back to the median gap in milliseconds. Null for a
|
|
16811
|
+
category axis or fewer than two distinct values.
|
|
16812
|
+
@param order The independent axis's values.
|
|
16813
|
+
*/ function trendStep(order) {
|
|
16814
|
+
const time = order.some((v)=>v instanceof Date);
|
|
16815
|
+
if (order.some((v)=>!(v instanceof Date) && typeof v !== "number")) return null;
|
|
16816
|
+
const values = Array.from(new Set(order.map(Number).filter(Number.isFinite))).sort((a, b)=>a - b);
|
|
16817
|
+
if (values.length < 2) return null;
|
|
16818
|
+
const gaps = values.slice(1).map((v, i)=>v - values[i]);
|
|
16819
|
+
if (!time) {
|
|
16820
|
+
const step = median(gaps);
|
|
16821
|
+
return (v, k)=>clean(v + step * k);
|
|
16822
|
+
}
|
|
16823
|
+
const dates = values.map((v)=>new Date(v));
|
|
16824
|
+
const interval = intervals.find((t)=>dates.every((d)=>+t.floor(d) === +d));
|
|
16825
|
+
if (interval) {
|
|
16826
|
+
const step = Math.round(median(dates.slice(1).map((d, i)=>interval.count(dates[i], d))));
|
|
16827
|
+
if (step > 0) return (v, k)=>interval.offset(v, step * k);
|
|
16828
|
+
}
|
|
16829
|
+
const step = median(gaps);
|
|
16830
|
+
return (v, k)=>new Date(+v + step * k);
|
|
16831
|
+
}
|
|
16832
|
+
/** Most steps a `{to}` projection will add, so a far-off end can't run away. */ const MAX_STEPS = 1000;
|
|
16833
|
+
/**
|
|
16834
|
+
The future independent-axis positions a projection adds after the last
|
|
16835
|
+
value of `order`: `projection` steps, or every step up to and including
|
|
16836
|
+
`projection.to`. Empty when off, on a category axis, or when the end
|
|
16837
|
+
isn't past the last value.
|
|
16838
|
+
@param order The independent axis's values.
|
|
16839
|
+
@param projection The `trendLineConfig.projection` setting.
|
|
16840
|
+
*/ function projectionPositions(order, projection) {
|
|
16841
|
+
if (!projection) return [];
|
|
16842
|
+
const offset = trendStep(order);
|
|
16843
|
+
if (!offset) return [];
|
|
16844
|
+
const time = order.some((v)=>v instanceof Date);
|
|
16845
|
+
const last = order.reduce((a, b)=>+b > +a ? b : a, order[0]);
|
|
16846
|
+
if (typeof projection === "number") {
|
|
16847
|
+
const count = Math.min(Math.floor(projection), MAX_STEPS);
|
|
16848
|
+
return Array.from({
|
|
16849
|
+
length: Math.max(count, 0)
|
|
16850
|
+
}, (_, i)=>offset(last, i + 1));
|
|
16851
|
+
}
|
|
16852
|
+
const to = projection.to;
|
|
16853
|
+
if (to === undefined || to === null) return [];
|
|
16854
|
+
const end = time ? dom.date(to) : +to;
|
|
16855
|
+
if (!Number.isFinite(+end)) return [];
|
|
16856
|
+
const out = [];
|
|
16857
|
+
for(let k = 1; k <= MAX_STEPS; k++){
|
|
16858
|
+
const next = offset(last, k);
|
|
16859
|
+
if (+next > +end) break;
|
|
16860
|
+
out.push(next);
|
|
16861
|
+
}
|
|
16862
|
+
return out;
|
|
16863
|
+
}
|
|
16864
|
+
|
|
15756
16865
|
/** The regression types `trendLine` accepts. */ const trendTypes = [
|
|
15757
16866
|
"linear",
|
|
15758
16867
|
"exponential",
|
|
@@ -15770,6 +16879,10 @@
|
|
|
15770
16879
|
confidenceLevel: 0.95,
|
|
15771
16880
|
group: "series",
|
|
15772
16881
|
order: 2,
|
|
16882
|
+
projection: 0,
|
|
16883
|
+
projectionConfig: {
|
|
16884
|
+
strokeDasharray: "2 4"
|
|
16885
|
+
},
|
|
15773
16886
|
strokeDasharray: "6 4",
|
|
15774
16887
|
strokeWidth: 2,
|
|
15775
16888
|
tooltip: true
|
|
@@ -15817,6 +16930,33 @@
|
|
|
15817
16930
|
length: count
|
|
15818
16931
|
}, (_, i)=>lo + (hi - lo) * i / (count - 1));
|
|
15819
16932
|
}
|
|
16933
|
+
/**
|
|
16934
|
+
The independent-axis positions to sample a fit's projection at, past the
|
|
16935
|
+
end of its data: each projected category on a point scale, or on a
|
|
16936
|
+
continuous axis evenly spaced points (as dense as the fitted stretch)
|
|
16937
|
+
together with every projected step. The first position is the fit's last
|
|
16938
|
+
value, where the projection starts.
|
|
16939
|
+
@param extent The fit's `[min, max]` independent values.
|
|
16940
|
+
@param steps The axis positions the projection passes through, as numbers.
|
|
16941
|
+
@param categories The point scale's positions, or null on a continuous axis.
|
|
16942
|
+
*/ function trendProjectionPositions(extent, steps, categories) {
|
|
16943
|
+
const [lo, hi] = extent;
|
|
16944
|
+
const end = Math.max(...steps);
|
|
16945
|
+
if (!(end > hi)) return [];
|
|
16946
|
+
if (categories) return [
|
|
16947
|
+
hi,
|
|
16948
|
+
...categories.filter((n)=>n > hi && n <= end)
|
|
16949
|
+
];
|
|
16950
|
+
const count = hi > lo ? Math.round(SAMPLES * (end - hi) / (hi - lo)) : SAMPLES;
|
|
16951
|
+
const even = trendSamplePositions([
|
|
16952
|
+
hi,
|
|
16953
|
+
end
|
|
16954
|
+
], null, Math.min(Math.max(count, 2), SAMPLES) + 1);
|
|
16955
|
+
return Array.from(new Set([
|
|
16956
|
+
...even,
|
|
16957
|
+
...steps.filter((n)=>n > hi)
|
|
16958
|
+
])).sort((a, b)=>a - b);
|
|
16959
|
+
}
|
|
15820
16960
|
/** Whether an axis plots on a point (category) scale, matching `computePlotScales`. */ function isPointAxis(viz, axis) {
|
|
15821
16961
|
if (viz[`_${axis}Time`]) return false;
|
|
15822
16962
|
return viz.schema.discrete === axis && !isSpanAxis(viz, axis) || !!viz.schema[`${axis}Sort`];
|
|
@@ -15870,14 +17010,21 @@
|
|
|
15870
17010
|
if (drawn.some(([, points])=>points.length > 1)) return drawn;
|
|
15871
17011
|
return depth > 0 ? bySeries(depth - 1) : all;
|
|
15872
17012
|
}
|
|
15873
|
-
/**
|
|
17013
|
+
/**
|
|
17014
|
+
Fits the trend lines for the current data; empty when `trendLine` is off.
|
|
17015
|
+
`projected` lists future independent-axis positions (from
|
|
17016
|
+
`projectionPositions`) each line extends to, past the end of its data.
|
|
17017
|
+
*/ function computeTrendFits(viz, rows, order, projected = []) {
|
|
15874
17018
|
const type = resolveTrendType(viz._trendLine);
|
|
15875
17019
|
if (!type || !rows.length) return [];
|
|
15876
17020
|
const config = viz._trendLineConfig || {};
|
|
15877
17021
|
const axis = trendAxis(viz.schema.discrete);
|
|
15878
17022
|
const dep = axis === "x" ? "y" : "x";
|
|
15879
|
-
const { toNumber, fromNumber } = trendNumberScale(order);
|
|
15880
|
-
const categories = isPointAxis(viz, axis) ? order.map(toNumber).filter(Number.isFinite) : null;
|
|
17023
|
+
const { toNumber, fromNumber } = trendNumberScale(order.concat(projected));
|
|
17024
|
+
const categories = isPointAxis(viz, axis) ? order.concat(projected).map(toNumber).filter(Number.isFinite) : null;
|
|
17025
|
+
// With a projection on, a line projects through every axis position past
|
|
17026
|
+
// its data: the projected ones, and those other series still plot.
|
|
17027
|
+
const steps = projected.length ? order.concat(projected).map(toNumber).filter(Number.isFinite) : [];
|
|
15881
17028
|
const logDep = `${viz[`_${dep}Config`]?.scale}`.toLowerCase() === "log";
|
|
15882
17029
|
const fill = viz.schema.shapeConfig.fill;
|
|
15883
17030
|
const fits = [];
|
|
@@ -15886,18 +17033,28 @@
|
|
|
15886
17033
|
order: config.order
|
|
15887
17034
|
});
|
|
15888
17035
|
if (!fit) continue;
|
|
15889
|
-
const
|
|
17036
|
+
const banded = config.confidence && type === "linear";
|
|
17037
|
+
const level = config.confidenceLevel;
|
|
17038
|
+
// The fitted stretch bands the mean response; the projection widens to
|
|
17039
|
+
// where a new observation could fall.
|
|
17040
|
+
const band = banded ? math.linearConfidence(points, level) : null;
|
|
17041
|
+
const fan = banded ? math.linearPrediction(points, level) : null;
|
|
15890
17042
|
const samples = [];
|
|
15891
|
-
|
|
17043
|
+
const sampleAt = (n, projectedRun)=>{
|
|
15892
17044
|
const value = fit.predict(n);
|
|
15893
|
-
if (!Number.isFinite(value) || logDep && value <= 0)
|
|
17045
|
+
if (!Number.isFinite(value) || logDep && value <= 0) return;
|
|
15894
17046
|
const sample = {
|
|
15895
17047
|
[axis]: fromNumber(n),
|
|
15896
17048
|
[dep]: value
|
|
15897
17049
|
};
|
|
15898
|
-
|
|
17050
|
+
const bounds = projectedRun ? fan : band;
|
|
17051
|
+
if (bounds) [sample.lci, sample.hci] = bounds(n);
|
|
17052
|
+
if (projectedRun) sample.projected = true;
|
|
17053
|
+
if (projectedRun && n > fit.extent[1] && steps.includes(n)) sample.step = true;
|
|
15899
17054
|
samples.push(sample);
|
|
15900
|
-
}
|
|
17055
|
+
};
|
|
17056
|
+
trendSamplePositions(fit.extent, categories).forEach((n)=>sampleAt(n, false));
|
|
17057
|
+
trendProjectionPositions(fit.extent, steps, categories).forEach((n)=>sampleAt(n, true));
|
|
15901
17058
|
if (samples.length < 2) continue;
|
|
15902
17059
|
const row = source ? source.data : undefined;
|
|
15903
17060
|
const color = config.stroke ? config.stroke : row ? typeof fill === "function" ? fill(row, source.i) : fill : "#444";
|
|
@@ -15929,17 +17086,25 @@
|
|
|
15929
17086
|
`computePlotTrendFits` — runs after `computePlotAxisValues`: fits the
|
|
15930
17087
|
trend lines onto `viz._trendFits` and appends their values to the
|
|
15931
17088
|
dependent axis's values, so the non-stacked domain covers them (the
|
|
15932
|
-
stacked domain reads `viz._trendFits` directly).
|
|
17089
|
+
stacked domain reads `viz._trendFits` directly). A projection's future
|
|
17090
|
+
positions join the independent axis's values, widening it to fit.
|
|
15933
17091
|
*/ const computePlotTrendFits = ({ viz, plotFormattedData, xData, yData })=>{
|
|
15934
17092
|
const axis = trendAxis(viz.schema.discrete);
|
|
15935
|
-
const
|
|
17093
|
+
const order = (axis === "x" ? xData : yData) || [];
|
|
17094
|
+
const projected = resolveTrendType(viz._trendLine) ? projectionPositions(order, viz._trendLineConfig?.projection) : [];
|
|
17095
|
+
const fits = viz._trendFits = computeTrendFits(viz, plotFormattedData || [], order, projected);
|
|
15936
17096
|
if (!fits.length) return {};
|
|
15937
17097
|
const extra = trendDomainValues(fits);
|
|
15938
|
-
|
|
17098
|
+
const out = axis === "x" ? {
|
|
15939
17099
|
yData: (yData || []).concat(extra)
|
|
15940
17100
|
} : {
|
|
15941
17101
|
xData: (xData || []).concat(extra)
|
|
15942
17102
|
};
|
|
17103
|
+
if (!fits.some((f)=>f.samples.some((s)=>s.projected))) return out;
|
|
17104
|
+
return {
|
|
17105
|
+
...out,
|
|
17106
|
+
[`${axis}Data`]: order.concat(projected)
|
|
17107
|
+
};
|
|
15943
17108
|
};
|
|
15944
17109
|
|
|
15945
17110
|
/**
|
|
@@ -18013,6 +19178,8 @@
|
|
|
18013
19178
|
"confidence",
|
|
18014
19179
|
"confidenceLevel",
|
|
18015
19180
|
"confidenceConfig",
|
|
19181
|
+
"projection",
|
|
19182
|
+
"projectionConfig",
|
|
18016
19183
|
"tooltip",
|
|
18017
19184
|
"stroke"
|
|
18018
19185
|
];
|
|
@@ -18063,16 +19230,21 @@
|
|
|
18063
19230
|
children.push(...collectComputed(band).map((n)=>stamp(n, fit, false)));
|
|
18064
19231
|
}
|
|
18065
19232
|
const paint = Object.fromEntries(Object.entries(config).filter(([key])=>!FIT_KEYS.includes(key)));
|
|
18066
|
-
const line =
|
|
18067
|
-
|
|
18068
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
19233
|
+
const line = (samples, key, style)=>{
|
|
19234
|
+
if (samples.length < 2) return;
|
|
19235
|
+
const shape = makeShape("Line").renderMode("compute").duration(viz.schema.duration).data(samples).config({
|
|
19236
|
+
...paint,
|
|
19237
|
+
id: key,
|
|
19238
|
+
label: false,
|
|
19239
|
+
stroke: fit.color
|
|
19240
|
+
}).config(style).config({
|
|
19241
|
+
x: (d)=>x(d.x),
|
|
19242
|
+
y: (d)=>y(d.y)
|
|
19243
|
+
});
|
|
19244
|
+
children.push(...collectComputed(shape).map((n)=>stamp(n, fit, config.tooltip !== false)));
|
|
19245
|
+
};
|
|
19246
|
+
line(fit.samples.filter((d)=>!d.projected), id, {});
|
|
19247
|
+
line(fit.samples.filter((d)=>d.projected), ()=>`trend-${fit.id}-projection`, config.projectionConfig || {});
|
|
18076
19248
|
if (!children.length) return null;
|
|
18077
19249
|
return {
|
|
18078
19250
|
type: "group",
|
|
@@ -18593,20 +19765,13 @@
|
|
|
18593
19765
|
/** `[axis name, formatted value]` for one axis of a hovered row. */ function axisRow(viz, k, hover) {
|
|
18594
19766
|
const row = hover.rows[0];
|
|
18595
19767
|
const accessor = viz[`_${k}`];
|
|
18596
|
-
|
|
19768
|
+
// A projected row's datum is a source row of its series, not this column.
|
|
19769
|
+
const raw = accessor && !row.projected ? accessor(row.datum, row.index) : hover.value;
|
|
18597
19770
|
return [
|
|
18598
19771
|
axisName(viz, k),
|
|
18599
19772
|
axisValue(viz, k, raw)
|
|
18600
19773
|
];
|
|
18601
19774
|
}
|
|
18602
|
-
/**
|
|
18603
|
-
A small swatch filled with the series stroke, before the series name: a
|
|
18604
|
-
dot for Lines (echoing their markers), a square for Bars and Areas.
|
|
18605
|
-
*/ const swatch = (color, shape)=>{
|
|
18606
|
-
if (!color) return "";
|
|
18607
|
-
const radius = shape === "Line" || shape === "Circle" ? "50%" : "1px";
|
|
18608
|
-
return `<span class="d3plus-tooltip-swatch" style="display: inline-block; width: 8px; height: 8px; margin-right: 6px; vertical-align: middle; border-radius: ${radius}; background: ${color}"></span>`;
|
|
18609
|
-
};
|
|
18610
19775
|
/**
|
|
18611
19776
|
The tooltip's client position: the discrete-axis coordinate locked to the
|
|
18612
19777
|
snapped position (surface space → client space via the pointer's own
|
|
@@ -18652,6 +19817,27 @@
|
|
|
18652
19817
|
if (saved) viz._tooltipClass.arrow(saved.arrow).thead(saved.thead).tbody(saved.tbody);
|
|
18653
19818
|
viz._sharedTooltipSaved = undefined;
|
|
18654
19819
|
}
|
|
19820
|
+
/** A projected row's band bounds, as " (low – high)"; empty otherwise. */ function bounds(viz, k, row) {
|
|
19821
|
+
const band = row.projected;
|
|
19822
|
+
if (!band || band.lci === undefined || band.hci === undefined) return "";
|
|
19823
|
+
return ` (${axisValue(viz, k, band.lci)} – ${axisValue(viz, k, band.hci)})`;
|
|
19824
|
+
}
|
|
19825
|
+
/**
|
|
19826
|
+
Marks a shared column's projected values (`trendLineConfig.projection`):
|
|
19827
|
+
on the discrete value in the header when every row is projected, or on
|
|
19828
|
+
each projected row's name when the column mixes in plotted values.
|
|
19829
|
+
*/ function markProjected(viz, hover) {
|
|
19830
|
+
const label = ` (${viz.schema.translate("Projected")})`;
|
|
19831
|
+
const header = axisRow(viz, hover.axis, hover);
|
|
19832
|
+
const all = hover.rows.every((r)=>r.projected);
|
|
19833
|
+
return {
|
|
19834
|
+
header: all ? [
|
|
19835
|
+
header[0],
|
|
19836
|
+
`${header[1]}${label}`
|
|
19837
|
+
] : header,
|
|
19838
|
+
names: hover.rows.map((r)=>r.projected && !all ? `${r.name}${label}` : r.name)
|
|
19839
|
+
};
|
|
19840
|
+
}
|
|
18655
19841
|
/**
|
|
18656
19842
|
The shared tooltip: title from the continuous axis, a header row naming
|
|
18657
19843
|
the hovered discrete value, then one `[name, value]` row per series, the
|
|
@@ -18659,11 +19845,12 @@
|
|
|
18659
19845
|
apply first; the shared title/rows win.
|
|
18660
19846
|
*/ function renderSharedTooltip(viz, hover, event) {
|
|
18661
19847
|
const cont = other(hover.axis);
|
|
19848
|
+
const { header, names } = markProjected(viz, hover);
|
|
18662
19849
|
prepareTooltip(viz).data([
|
|
18663
19850
|
hover.rows[0].datum
|
|
18664
|
-
]).config(configPrep.bind(viz)(viz.schema.tooltipConfig)).title(()=>axisName(viz, cont)).thead(
|
|
18665
|
-
|
|
18666
|
-
axisValue(viz, cont, r.value)
|
|
19851
|
+
]).config(configPrep.bind(viz)(viz.schema.tooltipConfig)).title(()=>axisName(viz, cont)).thead(header).tbody(hover.rows.map((r, i)=>[
|
|
19852
|
+
withSwatch(tooltipSwatch(r.color, r.shape), names[i]),
|
|
19853
|
+
`${axisValue(viz, cont, r.value)}${bounds(viz, cont, r)}`
|
|
18667
19854
|
])).footer(false).arrow(false).position(snappedPosition(viz, hover, event)).render();
|
|
18668
19855
|
}
|
|
18669
19856
|
/**
|
|
@@ -18676,7 +19863,7 @@
|
|
|
18676
19863
|
const deeper = viz._drawDepth < viz.schema.groupBy.length - 1;
|
|
18677
19864
|
const tip = prepareTooltip(viz).data([
|
|
18678
19865
|
row.datum
|
|
18679
|
-
]).title(()=>viz._drawLabel(row.datum, row.index)).footer(deeper && viz.schema.on["click.shape"] ? viz.schema.translate("Click to Expand") : false).config(configPrep.bind(viz)(viz.schema.tooltipConfig));
|
|
19866
|
+
]).title(()=>withSwatch(tooltipSwatch(row.color, row.shape), viz._drawLabel(row.datum, row.index))).footer(deeper && viz.schema.on["click.shape"] ? viz.schema.translate("Click to Expand") : false).config(configPrep.bind(viz)(viz.schema.tooltipConfig));
|
|
18680
19867
|
const extra = tip.tbody();
|
|
18681
19868
|
tip.tbody([
|
|
18682
19869
|
axisRow(viz, "x", hover),
|
|
@@ -18741,15 +19928,31 @@
|
|
|
18741
19928
|
/** Abbreviates a coefficient, keeping three significant digits on tiny values. */ function coefficientFormat(locale) {
|
|
18742
19929
|
return (n)=>n !== 0 && Math.abs(n) < 1e-3 ? n.toPrecision(3) : format.formatAbbreviate(n, locale);
|
|
18743
19930
|
}
|
|
18744
|
-
/**
|
|
19931
|
+
/**
|
|
19932
|
+
The tooltip rows for a fit: type, equation, R², and observations. Given a
|
|
19933
|
+
projected sample, it leads with that projection: its independent-axis
|
|
19934
|
+
value (marked "Projected") and its predicted value, with the band's
|
|
19935
|
+
bounds when drawn.
|
|
19936
|
+
*/ function trendTooltipRows(viz, trend, sample) {
|
|
18745
19937
|
const { fit, axis } = trend;
|
|
18746
19938
|
const t = (s)=>viz.schema.translate(s);
|
|
18747
|
-
const rows = [
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
19939
|
+
const rows = [];
|
|
19940
|
+
if (sample && sample.projected) {
|
|
19941
|
+
const dep = axis === "x" ? "y" : "x";
|
|
19942
|
+
const value = (n)=>axisValue(viz, dep, n);
|
|
19943
|
+
const bounds = sample.lci !== undefined ? ` (${value(sample.lci)} – ${value(sample.hci)})` : "";
|
|
19944
|
+
rows.push([
|
|
19945
|
+
axisName(viz, axis),
|
|
19946
|
+
`${axisValue(viz, axis, sample[axis])} (${t("Projected")})`
|
|
19947
|
+
], [
|
|
19948
|
+
axisName(viz, dep),
|
|
19949
|
+
`${value(sample[dep])}${bounds}`
|
|
19950
|
+
]);
|
|
19951
|
+
}
|
|
19952
|
+
rows.push([
|
|
19953
|
+
t("Trend Line"),
|
|
19954
|
+
t(trendTypeNames[fit.type])
|
|
19955
|
+
]);
|
|
18753
19956
|
// An equation in milliseconds since 1970 says nothing a reader can use.
|
|
18754
19957
|
if (!viz[`_${axis}Time`]) rows.push([
|
|
18755
19958
|
t("Equation"),
|
|
@@ -18764,7 +19967,30 @@
|
|
|
18764
19967
|
]);
|
|
18765
19968
|
return rows;
|
|
18766
19969
|
}
|
|
18767
|
-
/**
|
|
19970
|
+
/**
|
|
19971
|
+
The projected step nearest a content-space pointer along the fit's
|
|
19972
|
+
independent axis, when the pointer is over the projection; undefined over
|
|
19973
|
+
the fitted stretch (or for a fit with no projection).
|
|
19974
|
+
*/ function nearestProjectedSample(viz, trend, cursor) {
|
|
19975
|
+
const position = trend.axis === "x" ? viz._xFunc : viz._yFunc;
|
|
19976
|
+
if (!position) return undefined;
|
|
19977
|
+
const target = trend.axis === "x" ? cursor[0] : cursor[1];
|
|
19978
|
+
const nearest = (samples)=>{
|
|
19979
|
+
let best;
|
|
19980
|
+
let gap = Infinity;
|
|
19981
|
+
for (const sample of samples){
|
|
19982
|
+
const d = Math.abs(position(sample[trend.axis]) - target);
|
|
19983
|
+
if (d < gap) [best, gap] = [
|
|
19984
|
+
sample,
|
|
19985
|
+
d
|
|
19986
|
+
];
|
|
19987
|
+
}
|
|
19988
|
+
return best;
|
|
19989
|
+
};
|
|
19990
|
+
const best = nearest(trend.samples);
|
|
19991
|
+
return best && best.projected ? nearest(trend.samples.filter((s)=>s.step)) : undefined;
|
|
19992
|
+
}
|
|
19993
|
+
/** Renders the trend tooltip at the pointer, leading with the nearest projected value when over the projection. */ function renderTrendTooltip(viz, trend, event, cursor) {
|
|
18768
19994
|
const native = event.nativeEvent;
|
|
18769
19995
|
const position = native && native.touches && native.touches.length ? [
|
|
18770
19996
|
native.touches[0].clientX,
|
|
@@ -18775,7 +20001,7 @@
|
|
|
18775
20001
|
] : event.point;
|
|
18776
20002
|
prepareTooltip(viz).data([
|
|
18777
20003
|
trend.row || {}
|
|
18778
|
-
]).config(configPrep.bind(viz)(viz.schema.tooltipConfig)).title(()=>trend.label).thead([]).tbody(trendTooltipRows(viz, trend)).footer(false).position(position).render();
|
|
20004
|
+
]).config(configPrep.bind(viz)(viz.schema.tooltipConfig)).title(()=>withSwatch(tooltipSwatch(trend.color, "Line"), trend.label)).thead([]).tbody(trendTooltipRows(viz, trend, cursor ? nearestProjectedSample(viz, trend, cursor) : undefined)).footer(false).position(position).render();
|
|
18779
20005
|
}
|
|
18780
20006
|
|
|
18781
20007
|
/**
|
|
@@ -18791,7 +20017,6 @@
|
|
|
18791
20017
|
(point[1] - (t?.y ?? 0)) / scale - (c?.y ?? 0)
|
|
18792
20018
|
];
|
|
18793
20019
|
}
|
|
18794
|
-
const visibleColor = (s)=>typeof s === "string" && s !== "none" && s !== "transparent" ? s : undefined;
|
|
18795
20020
|
const discreteKey = (v)=>v instanceof Date ? String(v.getTime()) : String(v);
|
|
18796
20021
|
/**
|
|
18797
20022
|
Whether a scene node is a data mark the shared tooltip reads: Line/Area
|
|
@@ -18876,9 +20101,67 @@
|
|
|
18876
20101
|
}
|
|
18877
20102
|
};
|
|
18878
20103
|
(viz._chartScene || []).forEach((node)=>walk(node));
|
|
20104
|
+
if (position) addProjectedColumns(viz, axis, columns, position);
|
|
18879
20105
|
return columns;
|
|
18880
20106
|
}
|
|
20107
|
+
/**
|
|
20108
|
+
Adds each trend line's projected steps (see `trendLineConfig.projection`)
|
|
20109
|
+
as column members, so the crosshair snaps onto future positions and lists
|
|
20110
|
+
every series' projected value there.
|
|
20111
|
+
*/ function addProjectedColumns(viz, axis, columns, position) {
|
|
20112
|
+
for (const fit of viz._trendFits || []){
|
|
20113
|
+
if (fit.axis !== axis || viz._trendLineConfig?.tooltip === false) continue;
|
|
20114
|
+
for (const sample of fit.samples){
|
|
20115
|
+
if (!sample.step) continue;
|
|
20116
|
+
const value = sample[axis];
|
|
20117
|
+
const px = position(value);
|
|
20118
|
+
if (!Number.isFinite(px)) continue;
|
|
20119
|
+
const key = discreteKey(value);
|
|
20120
|
+
let column = columns.get(key);
|
|
20121
|
+
if (!column) {
|
|
20122
|
+
column = {
|
|
20123
|
+
px,
|
|
20124
|
+
value,
|
|
20125
|
+
members: new Map(),
|
|
20126
|
+
bars: new Set(),
|
|
20127
|
+
markers: []
|
|
20128
|
+
};
|
|
20129
|
+
columns.set(key, column);
|
|
20130
|
+
}
|
|
20131
|
+
const wrapped = fit.row || {};
|
|
20132
|
+
column.members.set(`${fit.id}::projected`, {
|
|
20133
|
+
wrapped,
|
|
20134
|
+
color: fit.color,
|
|
20135
|
+
shape: "Line",
|
|
20136
|
+
trend: {
|
|
20137
|
+
fit,
|
|
20138
|
+
sample
|
|
20139
|
+
}
|
|
20140
|
+
});
|
|
20141
|
+
}
|
|
20142
|
+
}
|
|
20143
|
+
}
|
|
18881
20144
|
/** A row for one column member; null when its value isn't numeric or its tooltip is off. */ function memberRow(viz, axis, id, member) {
|
|
20145
|
+
if (member.trend) {
|
|
20146
|
+
const { fit, sample } = member.trend;
|
|
20147
|
+
const value = Number(sample[axis === "x" ? "y" : "x"]);
|
|
20148
|
+
if (!Number.isFinite(value)) return null;
|
|
20149
|
+
const name = String(fit.label);
|
|
20150
|
+
const datum = fit.row || {};
|
|
20151
|
+
return {
|
|
20152
|
+
id,
|
|
20153
|
+
name,
|
|
20154
|
+
value,
|
|
20155
|
+
color: member.color,
|
|
20156
|
+
shape: "Line",
|
|
20157
|
+
datum,
|
|
20158
|
+
index: 0,
|
|
20159
|
+
projected: {
|
|
20160
|
+
lci: sample.lci,
|
|
20161
|
+
hci: sample.hci
|
|
20162
|
+
}
|
|
20163
|
+
};
|
|
20164
|
+
}
|
|
18882
20165
|
const valueOf = axis === "x" ? viz._y : viz._x;
|
|
18883
20166
|
const datum = member.wrapped.data || member.wrapped;
|
|
18884
20167
|
const index = typeof member.wrapped.i === "number" ? member.wrapped.i : 0;
|
|
@@ -18962,7 +20245,7 @@
|
|
|
18962
20245
|
const row = memberRow(viz, axis, id, member);
|
|
18963
20246
|
if (row) rows.push(row);
|
|
18964
20247
|
});
|
|
18965
|
-
if (rows.length >= 2) {
|
|
20248
|
+
if (rows.length >= 2 || rows.some((r)=>r.projected)) {
|
|
18966
20249
|
sortRows(viz, axis, rows);
|
|
18967
20250
|
const stack = best.bars.size ? {
|
|
18968
20251
|
rows: best.bars,
|
|
@@ -19066,7 +20349,8 @@
|
|
|
19066
20349
|
const prev = viz._sharedHoverState;
|
|
19067
20350
|
viz._sharedHoverActive = true;
|
|
19068
20351
|
viz._sharedHoverState = null;
|
|
19069
|
-
|
|
20352
|
+
const cursor = Array.isArray(event.point) ? contentPoint(viz, event.point) : undefined;
|
|
20353
|
+
renderTrendTooltip(viz, trend, event, cursor);
|
|
19070
20354
|
if (prev) {
|
|
19071
20355
|
if (prev.mode === "shared" && typeof viz._hover === "function") viz.hover(false);
|
|
19072
20356
|
viz._scheduleSceneRepaint();
|
|
@@ -19084,8 +20368,12 @@
|
|
|
19084
20368
|
};
|
|
19085
20369
|
if (hover.mode === "single") {
|
|
19086
20370
|
if (prevMode === "shared") clear();
|
|
19087
|
-
} else if (stack)
|
|
19088
|
-
|
|
20371
|
+
} else if (stack) {
|
|
20372
|
+
// Non-bar marks stay bright in the column hover, but only the stack's
|
|
20373
|
+
// own rows are what linked charts should match.
|
|
20374
|
+
linkAs(viz, (d)=>stack.rows.has(d));
|
|
20375
|
+
viz.hover((d)=>stack.rows.has(d) || !stack.bars.has(d));
|
|
20376
|
+
} else clear();
|
|
19089
20377
|
}
|
|
19090
20378
|
|
|
19091
20379
|
/** Stamps a subtree inert chrome: no hit-testing, never dimmed by hover. */ function inert(node) {
|
|
@@ -19220,6 +20508,18 @@
|
|
|
19220
20508
|
];
|
|
19221
20509
|
}
|
|
19222
20510
|
|
|
20511
|
+
/** Axis groups carry tick data, but aren't marks to keep clear of. */ const AXIS_KEY = /^plot-(x|x2|y|y2)-axis$/;
|
|
20512
|
+
/** The plot area in surface coordinates, with its marks (not its axes) as obstacles; null before layout. */ function plotInsetRegion(viz) {
|
|
20513
|
+
const area = viz._plotArea, t = viz._chartTransform;
|
|
20514
|
+
if (!area || !t) return null;
|
|
20515
|
+
return sceneInsetRegion(viz, {
|
|
20516
|
+
x: area.x + (t.x ?? 0),
|
|
20517
|
+
y: area.y + (t.y ?? 0),
|
|
20518
|
+
width: area.width,
|
|
20519
|
+
height: area.height
|
|
20520
|
+
}, (node)=>AXIS_KEY.test(String(node.key)));
|
|
20521
|
+
}
|
|
20522
|
+
|
|
19223
20523
|
/**
|
|
19224
20524
|
@module barBuffer
|
|
19225
20525
|
Adds a buffer to either side of the non-discrete axis.
|
|
@@ -19751,6 +21051,13 @@
|
|
|
19751
21051
|
*/ _sizeLegendScale() {
|
|
19752
21052
|
return plotSizeLegendScale(this);
|
|
19753
21053
|
}
|
|
21054
|
+
/**
|
|
21055
|
+
The plot area, with the plotted marks as obstacles, for drawing a
|
|
21056
|
+
legend inside the plot's empty space (see `legendInset`).
|
|
21057
|
+
@private
|
|
21058
|
+
*/ _insetRegion() {
|
|
21059
|
+
return plotInsetRegion(this);
|
|
21060
|
+
}
|
|
19754
21061
|
/**
|
|
19755
21062
|
Paint phase: production axis rendering, shape buffer setup, and shape
|
|
19756
21063
|
emission with event handlers. Receives all cross-phase locals from
|
|
@@ -19879,6 +21186,8 @@
|
|
|
19879
21186
|
- `confidence`: draws a confidence band around a linear fit (default `false`).
|
|
19880
21187
|
- `confidenceLevel`: the band's confidence level (default `0.95`).
|
|
19881
21188
|
- `confidenceConfig`: Area shape config for the band (default `{fillOpacity: 0.15}`; fill defaults to the line color).
|
|
21189
|
+
- `projection`: extends each line past the end of its data, by a number of steps at the data's own spacing (e.g. `5` more years), or to an end value with `{to: 2030}` (default `0`, off). The axis widens to fit, and a linear fit's band becomes a prediction interval that fans out over the projection. Hovering a projected step lists each series' projected value. Ignored on a category axis.
|
|
21190
|
+
- `projectionConfig`: Line shape config for the projected stretch, over the line's own styles (default `{strokeDasharray: "2 4"}`).
|
|
19882
21191
|
- `tooltip`: shows the fitted equation and R² when hovering a line (default `true`).
|
|
19883
21192
|
- Any other key (`stroke`, `strokeWidth`, `strokeDasharray`, …) styles the Line shape.
|
|
19884
21193
|
|
|
@@ -20057,7 +21366,7 @@
|
|
|
20057
21366
|
};
|
|
20058
21367
|
this._labelPosition = constant("auto");
|
|
20059
21368
|
this._lineMarkerConfig = {
|
|
20060
|
-
fill: (d, i)=>color.colorAssign(this._id(d, i), this
|
|
21369
|
+
fill: (d, i)=>color.colorAssign(this._id(d, i), linkedColorDefaults(this)),
|
|
20061
21370
|
r: constant(3)
|
|
20062
21371
|
};
|
|
20063
21372
|
this._lineMarkers = defaults.lineMarkers;
|
|
@@ -20723,6 +22032,7 @@
|
|
|
20723
22032
|
// Scene-emit charts dim via the scene's interaction-opacity pass, not
|
|
20724
22033
|
// `_shapes`; a hover change only takes effect once a repaint is scheduled.
|
|
20725
22034
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
22035
|
+
broadcastLink(this, "hover", _);
|
|
20726
22036
|
return this;
|
|
20727
22037
|
};
|
|
20728
22038
|
},
|
|
@@ -20920,7 +22230,7 @@
|
|
|
20920
22230
|
endAngle: d.endAngle,
|
|
20921
22231
|
datum: d.data,
|
|
20922
22232
|
paint: {
|
|
20923
|
-
fill:
|
|
22233
|
+
fill: textureFill(sc, d.data, d.i ?? 0, fill),
|
|
20924
22234
|
stroke,
|
|
20925
22235
|
strokeWidth,
|
|
20926
22236
|
// Explicit (not the field's usual `undefined`) for the same reason
|
|
@@ -20979,7 +22289,7 @@
|
|
|
20979
22289
|
const arcMaker = (d)=>arcGen(d) ?? "";
|
|
20980
22290
|
const resolveInnerRadius = arcGen.innerRadius();
|
|
20981
22291
|
const resolveOuterRadius = arcGen.outerRadius();
|
|
20982
|
-
const sc = viz
|
|
22292
|
+
const sc = shapeConfigFor(viz, "Path");
|
|
20983
22293
|
// A drill-down click armed this draw AND the clicked node was itself a Pie
|
|
20984
22294
|
// wedge (parentStartAngle/parentEndAngle only ever come from this chart's
|
|
20985
22295
|
// own click capture, via NodeBase.startAngle/endAngle below) — build each
|
|
@@ -21104,6 +22414,7 @@
|
|
|
21104
22414
|
],
|
|
21105
22415
|
layoutStage: applyPieLayout,
|
|
21106
22416
|
emit: pieEmit,
|
|
22417
|
+
insetRegion: sceneInsetRegion,
|
|
21107
22418
|
chartTransform: (viz)=>centerChartTransform(viz, viz.ctx.pieWidth, viz.ctx.pieHeight),
|
|
21108
22419
|
// Pie's chartTransform centers the origin — wedges are drawn in
|
|
21109
22420
|
// [-pieWidth/2, pieWidth/2] × [-pieHeight/2, pieHeight/2], not the
|
|
@@ -21510,6 +22821,9 @@
|
|
|
21510
22821
|
const r = geomapPointSizeScale(v, pointData);
|
|
21511
22822
|
v._sizeLegendFinal = pointData.length ? r : null;
|
|
21512
22823
|
if (!v._zoomSet || !ctx.extentBounds) {
|
|
22824
|
+
// The point-radius padding belongs with the extent it was computed for,
|
|
22825
|
+
// so a later draw that reuses the cached extent fits the same way.
|
|
22826
|
+
ctx.effectivePadding = undefined;
|
|
21513
22827
|
const fitData = v.schema.fitObject ? topo2feature(v.schema.fitObject, v.schema.fitKey) : coordData;
|
|
21514
22828
|
ctx.extentBounds = {
|
|
21515
22829
|
type: "FeatureCollection",
|
|
@@ -21521,7 +22835,6 @@
|
|
|
21521
22835
|
}
|
|
21522
22836
|
}
|
|
21523
22837
|
const effectivePadding = ctx.effectivePadding || v.schema.projectionPadding;
|
|
21524
|
-
ctx.effectivePadding = undefined;
|
|
21525
22838
|
v.schema.projection = v.schema.projection.fitExtent(ctx.extentBounds.features.length ? [
|
|
21526
22839
|
[
|
|
21527
22840
|
effectivePadding.left,
|
|
@@ -21931,6 +23244,7 @@
|
|
|
21931
23244
|
return pointData.length ? geomapPointSizeScale(viz, pointData) : null;
|
|
21932
23245
|
},
|
|
21933
23246
|
emit: geomapEmit,
|
|
23247
|
+
insetRegion: sceneInsetRegion,
|
|
21934
23248
|
// Clip the geography to the map rectangle — the same box as the ocean rect and
|
|
21935
23249
|
// the imperative inner <svg> viewport — so projected paths and points can't
|
|
21936
23250
|
// spill past it (e.g. under the legend/timeline) when a `fitObject`/zoom pushes
|
|
@@ -22060,7 +23374,7 @@
|
|
|
22060
23374
|
const sc = viz.schema.shapeConfig.Path;
|
|
22061
23375
|
const c = typeof sc.fill === "function" ? sc.fill(d, i) : sc.fill;
|
|
22062
23376
|
const col = d3Color.color(c);
|
|
22063
|
-
return col ? col.darker() : c;
|
|
23377
|
+
return col ? col.darker().toString() : c;
|
|
22064
23378
|
},
|
|
22065
23379
|
strokeWidth: 1
|
|
22066
23380
|
},
|
|
@@ -22487,10 +23801,7 @@
|
|
|
22487
23801
|
};
|
|
22488
23802
|
};
|
|
22489
23803
|
|
|
22490
|
-
|
|
22491
|
-
`matrixEmit` — Rect cells positioned by the row/column scales stashed
|
|
22492
|
-
on `viz.ctx`.
|
|
22493
|
-
*/ function resolveAccessor$4(val, d, i) {
|
|
23804
|
+
function resolveAccessor$4(val, d, i) {
|
|
22494
23805
|
if (typeof val === "function") return val(d, i);
|
|
22495
23806
|
return val;
|
|
22496
23807
|
}
|
|
@@ -22502,7 +23813,7 @@
|
|
|
22502
23813
|
const cellWidth = viz.ctx.cellWidth;
|
|
22503
23814
|
const cellHeight = viz.ctx.cellHeight;
|
|
22504
23815
|
const cellPadding = viz.schema.cellPadding ?? 0;
|
|
22505
|
-
const sc = viz
|
|
23816
|
+
const sc = shapeConfigFor(viz, "Rect");
|
|
22506
23817
|
const colorScale = viz.schema.colorScale;
|
|
22507
23818
|
return cells.map((d, i)=>{
|
|
22508
23819
|
const fill = resolveAccessor$4(sc.fill, d, i);
|
|
@@ -22522,7 +23833,7 @@
|
|
|
22522
23833
|
height: h,
|
|
22523
23834
|
datum: d,
|
|
22524
23835
|
paint: {
|
|
22525
|
-
fill:
|
|
23836
|
+
fill: textureFill(sc, d, i, fill),
|
|
22526
23837
|
stroke,
|
|
22527
23838
|
strokeWidth
|
|
22528
23839
|
},
|
|
@@ -23413,6 +24724,7 @@
|
|
|
23413
24724
|
// Scene-emit charts dim via applyInteractionOpacity during toScene(), so a
|
|
23414
24725
|
// hover change only takes effect if a repaint is scheduled.
|
|
23415
24726
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
24727
|
+
broadcastLink(this, "hover", _);
|
|
23416
24728
|
return this;
|
|
23417
24729
|
};
|
|
23418
24730
|
}
|
|
@@ -23426,6 +24738,7 @@
|
|
|
23426
24738
|
layoutStage: applyNetworkLayout,
|
|
23427
24739
|
sizeLegendScale: (viz, { width, height })=>networkSizeLegendScale(viz, width, height),
|
|
23428
24740
|
emit: networkEmit,
|
|
24741
|
+
insetRegion: sceneInsetRegion,
|
|
23429
24742
|
// Network mounts its own zoom surface (with a background hitArea whose
|
|
23430
24743
|
// click handler closes over class state); `chartTransform` (default
|
|
23431
24744
|
// margin-origin) is fine for the scene.
|
|
@@ -23592,9 +24905,9 @@
|
|
|
23592
24905
|
const packEmit = ({ viz, shapeData })=>{
|
|
23593
24906
|
const nodes = shapeData ?? [];
|
|
23594
24907
|
if (!nodes.length) return [];
|
|
23595
|
-
const sc = viz
|
|
23596
|
-
// Pack's
|
|
23597
|
-
const circleConfig =
|
|
24908
|
+
const sc = shapeConfigFor(viz, "Circle");
|
|
24909
|
+
// Pack's label accessor is nested under `Circle`.
|
|
24910
|
+
const circleConfig = viz.schema.shapeConfig.Circle ?? {};
|
|
23598
24911
|
const labelFn = circleConfig.label;
|
|
23599
24912
|
const circleNodes = nodes.map((d, i)=>{
|
|
23600
24913
|
const datum = d.data;
|
|
@@ -23615,7 +24928,7 @@
|
|
|
23615
24928
|
shapeType: "Pack",
|
|
23616
24929
|
datum,
|
|
23617
24930
|
paint: {
|
|
23618
|
-
fill:
|
|
24931
|
+
fill: textureFill(sc, datum, i, fill),
|
|
23619
24932
|
stroke,
|
|
23620
24933
|
opacity: datum.__d3plusOpacity__,
|
|
23621
24934
|
strokeWidth
|
|
@@ -23695,6 +25008,7 @@
|
|
|
23695
25008
|
],
|
|
23696
25009
|
layoutStage: applyPackLayout,
|
|
23697
25010
|
emit: packEmit,
|
|
25011
|
+
insetRegion: sceneInsetRegion,
|
|
23698
25012
|
chartTransform: (viz)=>({
|
|
23699
25013
|
x: viz._margin.left + (viz.ctx.packOffsetX ?? 0),
|
|
23700
25014
|
y: viz._margin.top + (viz.ctx.packOffsetY ?? 0)
|
|
@@ -23930,7 +25244,7 @@
|
|
|
23930
25244
|
const xScale = viz.ctx.xScale;
|
|
23931
25245
|
const yScale = viz.ctx.yScale;
|
|
23932
25246
|
const bandWidth = viz.ctx.bandWidth;
|
|
23933
|
-
const sc = viz
|
|
25247
|
+
const sc = shapeConfigFor(viz, "Rect");
|
|
23934
25248
|
const rectNodes = data.map((d, i)=>{
|
|
23935
25249
|
const fill = resolveAccessor$2(sc.fill, d.data, i);
|
|
23936
25250
|
const stroke = resolveAccessor$2(sc.stroke, d.data, i);
|
|
@@ -23958,7 +25272,7 @@
|
|
|
23958
25272
|
height: bandWidth,
|
|
23959
25273
|
datum: d.data,
|
|
23960
25274
|
paint: {
|
|
23961
|
-
fill:
|
|
25275
|
+
fill: textureFill(sc, d.data, i, fill),
|
|
23962
25276
|
stroke,
|
|
23963
25277
|
strokeWidth
|
|
23964
25278
|
},
|
|
@@ -24471,10 +25785,7 @@
|
|
|
24471
25785
|
};
|
|
24472
25786
|
};
|
|
24473
25787
|
|
|
24474
|
-
|
|
24475
|
-
`radialMatrixEmit` — Path SceneNodes for each arc cell, using the
|
|
24476
|
-
`arcData` generator stashed on `viz.ctx`.
|
|
24477
|
-
*/ function resolveAccessor$1(val, d, i) {
|
|
25788
|
+
function resolveAccessor$1(val, d, i) {
|
|
24478
25789
|
if (typeof val === "function") return val(d, i);
|
|
24479
25790
|
return val;
|
|
24480
25791
|
}
|
|
@@ -24482,7 +25793,7 @@
|
|
|
24482
25793
|
const cells = shapeData ?? [];
|
|
24483
25794
|
if (!cells.length) return [];
|
|
24484
25795
|
const arcData = viz.ctx.arcData;
|
|
24485
|
-
const sc = viz
|
|
25796
|
+
const sc = shapeConfigFor(viz, "Path");
|
|
24486
25797
|
const colorScale = viz.schema.colorScale;
|
|
24487
25798
|
return cells.map((d, i)=>{
|
|
24488
25799
|
const fill = resolveAccessor$1(sc.fill, d, i);
|
|
@@ -24495,7 +25806,7 @@
|
|
|
24495
25806
|
d: arcData(d),
|
|
24496
25807
|
datum: d,
|
|
24497
25808
|
paint: {
|
|
24498
|
-
fill:
|
|
25809
|
+
fill: textureFill(sc, d, i, fill),
|
|
24499
25810
|
stroke,
|
|
24500
25811
|
strokeWidth
|
|
24501
25812
|
},
|
|
@@ -25352,6 +26663,7 @@
|
|
|
25352
26663
|
// Scene-emit charts dim via applyInteractionOpacity during toScene(); a
|
|
25353
26664
|
// hover change only takes effect once a repaint is scheduled.
|
|
25354
26665
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
26666
|
+
broadcastLink(this, "hover", _);
|
|
25355
26667
|
return this;
|
|
25356
26668
|
};
|
|
25357
26669
|
}
|
|
@@ -25365,6 +26677,7 @@
|
|
|
25365
26677
|
layoutStage: applyRingsLayout,
|
|
25366
26678
|
sizeLegendScale: (viz, { width, height })=>ringsSizeLegendScale(viz, width, height),
|
|
25367
26679
|
emit: ringsEmit,
|
|
26680
|
+
insetRegion: sceneInsetRegion,
|
|
25368
26681
|
setup: (viz)=>{
|
|
25369
26682
|
installRingsAccessors(viz);
|
|
25370
26683
|
const v = viz;
|
|
@@ -25427,7 +26740,7 @@
|
|
|
25427
26740
|
right: 0,
|
|
25428
26741
|
top: 0
|
|
25429
26742
|
};
|
|
25430
|
-
viz
|
|
26743
|
+
drawWithInset(viz);
|
|
25431
26744
|
// _draw() resets the feature panels; re-run the post-draw features so
|
|
25432
26745
|
// the corner controls, size legend, and attribution come back.
|
|
25433
26746
|
runPostDrawFeatures(viz);
|
|
@@ -25803,6 +27116,7 @@
|
|
|
25803
27116
|
// interaction-opacity pass re-reads `_hover` and dims non-matching nodes.
|
|
25804
27117
|
// Coalesced to one paint per frame (see Viz._scheduleSceneRepaint).
|
|
25805
27118
|
if (this._sceneRenderer) this._scheduleSceneRepaint();
|
|
27119
|
+
broadcastLink(this, "hover", _);
|
|
25806
27120
|
return this;
|
|
25807
27121
|
};
|
|
25808
27122
|
},
|
|
@@ -26253,6 +27567,7 @@
|
|
|
26253
27567
|
],
|
|
26254
27568
|
layoutStage: applyTreeLayout,
|
|
26255
27569
|
emit: treeEmit,
|
|
27570
|
+
insetRegion: sceneInsetRegion,
|
|
26256
27571
|
ctx: {
|
|
26257
27572
|
tree: d3Hierarchy.tree(),
|
|
26258
27573
|
previousShapes: []
|
|
@@ -26386,7 +27701,7 @@
|
|
|
26386
27701
|
if (!nodes.length) return [];
|
|
26387
27702
|
const locale = viz.schema.locale;
|
|
26388
27703
|
const drawLabel = viz._drawLabel;
|
|
26389
|
-
const sc = viz
|
|
27704
|
+
const sc = shapeConfigFor(viz, "Rect");
|
|
26390
27705
|
const rectNodes = nodes.map((d)=>{
|
|
26391
27706
|
const fill = resolveAccessor(sc.fill, d.data, d.i);
|
|
26392
27707
|
const stroke = resolveAccessor(sc.stroke, d.data, d.i);
|
|
@@ -26401,7 +27716,7 @@
|
|
|
26401
27716
|
height: d.y1 - d.y0,
|
|
26402
27717
|
datum: d.data,
|
|
26403
27718
|
paint: {
|
|
26404
|
-
fill:
|
|
27719
|
+
fill: textureFill(sc, d.data, d.i, fill),
|
|
26405
27720
|
stroke: typeof stroke === "string" || stroke == null ? stroke : String(stroke),
|
|
26406
27721
|
opacity,
|
|
26407
27722
|
strokeWidth
|
|
@@ -26683,10 +27998,12 @@
|
|
|
26683
27998
|
exports.Donut = index$e;
|
|
26684
27999
|
exports.Geomap = index$d;
|
|
26685
28000
|
exports.Histogram = index$c;
|
|
28001
|
+
exports.INSET_PRIORITY = INSET_PRIORITY;
|
|
26686
28002
|
exports.Image = Image;
|
|
26687
28003
|
exports.Legend = Legend;
|
|
26688
28004
|
exports.Line = Line;
|
|
26689
28005
|
exports.LinePlot = index$b;
|
|
28006
|
+
exports.MARK_TYPES = MARK_TYPES;
|
|
26690
28007
|
exports.Matrix = index$a;
|
|
26691
28008
|
exports.Message = Message;
|
|
26692
28009
|
exports.Network = index$9;
|
|
@@ -26734,6 +28051,8 @@
|
|
|
26734
28051
|
exports.bottomRightControlsFeature = bottomRightControlsFeature;
|
|
26735
28052
|
exports.bottomRightControlsInset = bottomRightControlsInset;
|
|
26736
28053
|
exports.bottomRightControlsShortfall = bottomRightControlsShortfall;
|
|
28054
|
+
exports.broadcastLegend = broadcastLegend;
|
|
28055
|
+
exports.broadcastLink = broadcastLink;
|
|
26737
28056
|
exports.chordDef = chordDef;
|
|
26738
28057
|
exports.colorScaleFeature = colorScaleFeature;
|
|
26739
28058
|
exports.computeAxisLayout = computeAxisLayout;
|
|
@@ -26743,11 +28062,28 @@
|
|
|
26743
28062
|
exports.constant = constant;
|
|
26744
28063
|
exports.createFluent = createFluent;
|
|
26745
28064
|
exports.defaultSizeLegendValues = defaultSizeLegendValues;
|
|
28065
|
+
exports.drawWithInset = drawWithInset;
|
|
28066
|
+
exports.fitInset = fitInset;
|
|
28067
|
+
exports.forEachSceneRow = forEachSceneRow;
|
|
26746
28068
|
exports.geomapDef = geomapDef;
|
|
26747
28069
|
exports.getTopLeftContributions = getTopLeftContributions;
|
|
26748
28070
|
exports.histogramDef = histogramDef;
|
|
28071
|
+
exports.insetBackground = insetBackground;
|
|
28072
|
+
exports.insetComponentOffset = insetComponentOffset;
|
|
28073
|
+
exports.insetFrame = insetFrame;
|
|
28074
|
+
exports.insetOrient = insetOrient;
|
|
28075
|
+
exports.insetPlacementFor = insetPlacementFor;
|
|
28076
|
+
exports.insetStyle = insetStyle;
|
|
26749
28077
|
exports.installFluent = installFluent;
|
|
28078
|
+
exports.isInsetPending = isInsetPending;
|
|
26750
28079
|
exports.legendFeature = legendFeature;
|
|
28080
|
+
exports.linkAs = linkAs;
|
|
28081
|
+
exports.linkKeys = linkKeys;
|
|
28082
|
+
exports.linkMembers = linkMembers;
|
|
28083
|
+
exports.linkPredicate = linkPredicate;
|
|
28084
|
+
exports.linkValues = linkValues;
|
|
28085
|
+
exports.linkedColorDefaults = linkedColorDefaults;
|
|
28086
|
+
exports.markBoxes = markBoxes;
|
|
26751
28087
|
exports.matrixDef = matrixDef;
|
|
26752
28088
|
exports.measureAxis = measureAxis;
|
|
26753
28089
|
exports.networkDef = networkDef;
|
|
@@ -26758,8 +28094,10 @@
|
|
|
26758
28094
|
exports.priestleyDef = priestleyDef;
|
|
26759
28095
|
exports.radarDef = radarDef;
|
|
26760
28096
|
exports.radialMatrixDef = radialMatrixDef;
|
|
28097
|
+
exports.registerLink = registerLink;
|
|
26761
28098
|
exports.renderAxes = renderAxes;
|
|
26762
28099
|
exports.reserveBottomRight = reserveBottomRight;
|
|
28100
|
+
exports.resolveLink = resolveLink;
|
|
26763
28101
|
exports.resolveSpec = resolveSpec;
|
|
26764
28102
|
exports.ringsDef = ringsDef;
|
|
26765
28103
|
exports.runLayout = runLayout;
|
|
@@ -26767,6 +28105,7 @@
|
|
|
26767
28105
|
exports.runStages = runStages;
|
|
26768
28106
|
exports.runVizPipeline = runVizPipeline;
|
|
26769
28107
|
exports.sankeyDef = sankeyDef;
|
|
28108
|
+
exports.sceneInsetRegion = sceneInsetRegion;
|
|
26770
28109
|
exports.searchContribution = searchContribution;
|
|
26771
28110
|
exports.sizeLegendContribution = sizeLegendContribution;
|
|
26772
28111
|
exports.subtitleFeature = subtitleFeature;
|
|
@@ -26777,6 +28116,7 @@
|
|
|
26777
28116
|
exports.totalFeature = totalFeature;
|
|
26778
28117
|
exports.treeDef = treeDef;
|
|
26779
28118
|
exports.treemapDef = treemapDef;
|
|
28119
|
+
exports.unregisterLink = unregisterLink;
|
|
26780
28120
|
exports.vizDraw = vizDraw;
|
|
26781
28121
|
exports.vizDrawPure = vizDrawPure;
|
|
26782
28122
|
exports.vizPostThresholdCtx = vizPostThresholdCtx;
|