@d3plus/core 4.9.0 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/internal.js +3 -1
- package/es/src/charts/BoxWhisker/index.js +73 -4
- package/es/src/charts/BoxWhisker/outliers.js +68 -0
- package/es/src/charts/BoxWhisker/summary.js +83 -0
- package/es/src/charts/BoxWhisker/tooltip.js +122 -0
- package/es/src/charts/Bullet/index.js +2 -1
- package/es/src/charts/BumpChart/index.js +5 -0
- package/es/src/charts/Calendar/index.js +2 -1
- package/es/src/charts/Candlestick/aggregate.js +11 -1
- package/es/src/charts/Candlestick/index.js +5 -5
- package/es/src/charts/Chord/index.js +3 -2
- package/es/src/charts/Funnel/index.js +2 -1
- package/es/src/charts/Gauge/index.js +2 -1
- package/es/src/charts/Geomap/index.js +9 -3
- package/es/src/charts/Histogram/index.js +5 -1
- package/es/src/charts/Matrix/index.js +3 -2
- package/es/src/charts/Network/index.js +9 -4
- package/es/src/charts/Pack/index.js +2 -1
- package/es/src/charts/Pie/index.js +2 -1
- package/es/src/charts/Plot/axisHover.js +180 -0
- package/es/src/charts/Plot/axisHoverAnchors.js +174 -0
- package/es/src/charts/Plot/axisHoverScene.js +202 -0
- package/es/src/charts/Plot/barHitArea.js +81 -0
- package/es/src/charts/Plot/barLabelFit.js +123 -0
- package/es/src/charts/Plot/barWidth.js +2 -2
- package/es/src/charts/Plot/confidenceConfig.js +2 -2
- package/es/src/charts/Plot/draw.js +6 -2
- package/es/src/charts/Plot/index.js +25 -6
- package/es/src/charts/Plot/labelPlacement.js +9 -1
- package/es/src/charts/Plot/openDomainEnds.js +2 -5
- package/es/src/charts/Plot/pipeline.js +5 -3
- package/es/src/charts/Plot/pipelineAxisLayout.js +38 -8
- package/es/src/charts/Plot/pipelineDomains.js +7 -3
- package/es/src/charts/Plot/pipelineLineLabels.js +1 -1
- package/es/src/charts/Plot/plotInit.js +15 -0
- package/es/src/charts/Plot/plotZoom.js +15 -6
- package/es/src/charts/Plot/shapeDefaults.js +4 -4
- package/es/src/charts/Plot/sharedHoverScene.js +50 -31
- package/es/src/charts/Plot/sharedTooltip.js +19 -7
- package/es/src/charts/Plot/stackHelpers.js +13 -1
- package/es/src/charts/Plot/stackShareTooltip.js +9 -4
- package/es/src/charts/Plot/stackThreshold.js +154 -0
- package/es/src/charts/PolarArea/index.js +3 -2
- package/es/src/charts/Priestley/index.js +3 -2
- package/es/src/charts/Pyramid/index.js +4 -2
- package/es/src/charts/Radar/index.js +3 -2
- package/es/src/charts/RadialBar/index.js +2 -1
- package/es/src/charts/RadialMatrix/index.js +3 -2
- package/es/src/charts/Rings/index.js +5 -3
- package/es/src/charts/Sankey/index.js +3 -2
- package/es/src/charts/Treemap/applyLayout.js +14 -1
- package/es/src/charts/Treemap/emit.js +8 -2
- package/es/src/charts/Treemap/emitGroupHeaders.js +104 -0
- package/es/src/charts/Treemap/groupHeaders.js +95 -0
- package/es/src/charts/Treemap/index.js +15 -2
- package/es/src/charts/Treemap/thresholdFunction.js +11 -9
- package/es/src/charts/Waffle/index.js +4 -2
- package/es/src/charts/Waffle/tooltip.js +6 -2
- package/es/src/charts/Waterfall/index.js +4 -2
- package/es/src/charts/definition/makeChart.js +12 -5
- package/es/src/charts/drawSteps/saveChart.js +176 -0
- package/es/src/charts/drawSteps/saveControl.js +148 -0
- package/es/src/charts/drawSteps/saveControlMarkup.js +104 -0
- package/es/src/charts/drawSteps/tableViewMarkup.js +1 -1
- package/es/src/charts/drawSteps/topLeftControls.js +3 -1
- package/es/src/charts/drawSteps/topLeftControlsMarkup.js +1 -1
- package/es/src/charts/events/click.shape.js +30 -1
- package/es/src/charts/events/mouseenter.js +9 -0
- package/es/src/charts/events/mousemove.legend.js +3 -0
- package/es/src/charts/events/mousemove.shape.js +7 -2
- package/es/src/charts/facet/facetConfig.js +2 -2
- package/es/src/charts/facet/facetData.js +2 -2
- package/es/src/charts/features/axes.js +7 -6
- package/es/src/charts/features/axesFinal.js +23 -3
- package/es/src/charts/features/axesMeasure.js +54 -2
- package/es/src/charts/features/colorScaleBucket.js +17 -0
- package/es/src/charts/features/colorScaleHover.js +69 -0
- package/es/src/charts/features/features.js +13 -1
- package/es/src/charts/features/featuresColorScale.js +44 -4
- package/es/src/charts/features/featuresLegend.js +6 -8
- package/es/src/charts/features/plotPaint.js +4 -4
- package/es/src/charts/features/shapeEmit.js +23 -2
- package/es/src/charts/features/shareKey.js +15 -0
- package/es/src/charts/features/thresholdMembers.js +71 -0
- package/es/src/charts/helpers/densityChart.js +3 -1
- package/es/src/charts/helpers/valueTitle.js +6 -3
- package/es/src/charts/partition/chartFields.js +4 -3
- package/es/src/charts/partition/hierarchy.js +2 -0
- package/es/src/charts/pipeline/preDrawData.js +31 -10
- package/es/src/charts/pipeline/vizDraw.js +40 -29
- package/es/src/charts/pipeline/vizPreDraw.js +24 -15
- package/es/src/charts/viz/Viz.js +43 -8
- package/es/src/charts/viz/VizBase.js +32 -12
- package/es/src/charts/viz/dataPoller.js +52 -0
- package/es/src/charts/viz/groupRow.js +35 -0
- package/es/src/charts/viz/interactionOpacity.js +19 -5
- package/es/src/charts/viz/missingFields.js +122 -0
- package/es/src/charts/viz/reportHandlerError.js +10 -0
- package/es/src/charts/viz/shapeClassTargets.js +18 -2
- package/es/src/charts/viz/simpleHover.js +2 -0
- package/es/src/charts/viz/vizClassName.js +31 -0
- package/es/src/charts/viz/vizDataPolling.js +167 -0
- package/es/src/charts/viz/vizDefaults.js +66 -0
- package/es/src/charts/viz/vizFields.js +18 -2
- package/es/src/charts/viz/vizRender.js +8 -2
- package/es/src/components/Axis/Axis.js +28 -0
- package/es/src/components/Axis/axisDefaults.js +3 -1
- package/es/src/components/Axis/axisLabelAngle.js +175 -0
- package/es/src/components/Axis/axisLabelThinning.js +13 -4
- package/es/src/components/Axis/axisLayout.js +86 -19
- package/es/src/components/Axis/axisLayoutLabels.js +66 -13
- package/es/src/components/Axis/axisLayoutScale.js +3 -0
- package/es/src/components/Axis/axisRender.js +38 -9
- package/es/src/components/Axis/axisRounding.js +15 -4
- package/es/src/components/Axis/axisSlantWrap.js +39 -0
- package/es/src/components/Axis/powTicks.js +73 -0
- package/es/src/components/ColorScale/ColorScale.js +28 -28
- package/es/src/components/ColorScale/bucketBounds.js +35 -0
- package/es/src/components/ColorScale/colorScaleHoverMark.js +327 -0
- package/es/src/components/ColorScale/colorScaleRender.js +25 -1
- package/es/src/components/ColorScale/colorScaleScale.js +15 -9
- package/es/src/components/ColorScale/colorScaleType.js +26 -0
- package/es/src/components/TextBox.js +2 -0
- package/es/src/components/Timeline/Timeline.js +43 -52
- package/es/src/components/Timeline/brushSpan.js +78 -0
- package/es/src/components/Timeline/timelineConfig.js +7 -0
- package/es/src/components/Timeline/timelineRender.js +44 -6
- package/es/src/components/Tooltip.js +13 -8
- package/es/src/shapes/Box.js +66 -79
- package/es/src/shapes/boxOutlierShape.js +19 -0
- package/es/src/shapes/boxStats.js +35 -0
- package/es/src/shapes/boxStyle.js +78 -0
- package/es/src/shapes/boxSummary.js +174 -0
- package/es/src/shapes/shapeStandalone.js +2 -0
- package/es/src/utils/BaseClass.js +19 -0
- package/es/src/utils/className.js +78 -0
- package/es/src/utils/configWarnings.js +25 -0
- package/es/src/utils/fieldAccessor.js +31 -0
- package/es/src/utils/paintComponentScene.js +2 -0
- package/package.json +10 -9
- package/types/index.d.ts +3 -1
- package/types/internal.d.ts +3 -1
- package/types/src/charts/BoxWhisker/index.d.ts +3 -1
- package/types/src/charts/BoxWhisker/outliers.d.ts +25 -0
- package/types/src/charts/BoxWhisker/summary.d.ts +39 -0
- package/types/src/charts/BoxWhisker/tooltip.d.ts +36 -0
- package/types/src/charts/Candlestick/aggregate.d.ts +6 -0
- package/types/src/charts/Plot/axisHover.d.ts +68 -0
- package/types/src/charts/Plot/axisHoverAnchors.d.ts +88 -0
- package/types/src/charts/Plot/axisHoverScene.d.ts +88 -0
- package/types/src/charts/Plot/barHitArea.d.ts +59 -0
- package/types/src/charts/Plot/barLabelFit.d.ts +81 -0
- package/types/src/charts/Plot/index.d.ts +13 -0
- package/types/src/charts/Plot/labelPlacement.d.ts +5 -0
- package/types/src/charts/Plot/plotInit.d.ts +9 -2
- package/types/src/charts/Plot/plotZoom.d.ts +2 -0
- package/types/src/charts/Plot/sharedHoverScene.d.ts +3 -3
- package/types/src/charts/Plot/sharedTooltip.d.ts +11 -4
- package/types/src/charts/Plot/stackHelpers.d.ts +5 -0
- package/types/src/charts/Plot/stackThreshold.d.ts +75 -0
- package/types/src/charts/Treemap/emit.d.ts +2 -1
- package/types/src/charts/Treemap/emitGroupHeaders.d.ts +16 -0
- package/types/src/charts/Treemap/groupHeaders.d.ts +91 -0
- package/types/src/charts/Treemap/index.d.ts +2 -0
- package/types/src/charts/Treemap/thresholdFunction.d.ts +5 -2
- package/types/src/charts/definition/ChartDefinition.d.ts +14 -2
- package/types/src/charts/definition/makeChart.d.ts +4 -3
- package/types/src/charts/drawSteps/saveChart.d.ts +47 -0
- package/types/src/charts/drawSteps/saveControl.d.ts +9 -0
- package/types/src/charts/drawSteps/saveControlMarkup.d.ts +44 -0
- package/types/src/charts/drawSteps/tableViewMarkup.d.ts +1 -0
- package/types/src/charts/drawSteps/topLeftControls.d.ts +1 -1
- package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +1 -1
- package/types/src/charts/facet/facetData.d.ts +1 -1
- package/types/src/charts/features/axesMeasure.d.ts +9 -1
- package/types/src/charts/features/colorScaleBucket.d.ts +9 -0
- package/types/src/charts/features/colorScaleHover.d.ts +32 -0
- package/types/src/charts/features/features.d.ts +8 -0
- package/types/src/charts/features/plotPaint.d.ts +2 -0
- package/types/src/charts/features/shapeEmit.d.ts +2 -0
- package/types/src/charts/features/shareKey.d.ts +9 -0
- package/types/src/charts/features/thresholdMembers.d.ts +38 -0
- package/types/src/charts/helpers/valueTitle.d.ts +4 -2
- package/types/src/charts/pipeline/stages.d.ts +2 -0
- package/types/src/charts/pipeline/vizDraw.d.ts +8 -3
- package/types/src/charts/pipeline/vizPreDraw.d.ts +3 -2
- package/types/src/charts/viz/Viz.d.ts +28 -4
- package/types/src/charts/viz/VizBase.d.ts +12 -3
- package/types/src/charts/viz/dataPoller.d.ts +28 -0
- package/types/src/charts/viz/groupRow.d.ts +24 -0
- package/types/src/charts/viz/interactionOpacity.d.ts +3 -1
- package/types/src/charts/viz/missingFields.d.ts +57 -0
- package/types/src/charts/viz/reportHandlerError.d.ts +7 -0
- package/types/src/charts/viz/shapeClassTargets.d.ts +6 -0
- package/types/src/charts/viz/simpleHover.d.ts +2 -1
- package/types/src/charts/viz/vizClassName.d.ts +23 -0
- package/types/src/charts/viz/vizDataPolling.d.ts +48 -0
- package/types/src/charts/viz/vizDefaults.d.ts +49 -0
- package/types/src/charts/viz/vizFields.d.ts +15 -0
- package/types/src/charts/viz/vizTypes.d.ts +33 -1
- package/types/src/components/Axis/Axis.d.ts +36 -8
- package/types/src/components/Axis/axisLabelAngle.d.ts +110 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +3 -7
- package/types/src/components/Axis/axisLayout.d.ts +5 -0
- package/types/src/components/Axis/axisLayoutLabels.d.ts +13 -0
- package/types/src/components/Axis/axisRounding.d.ts +6 -3
- package/types/src/components/Axis/axisSlantWrap.d.ts +22 -0
- package/types/src/components/Axis/powTicks.d.ts +29 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +13 -0
- package/types/src/components/ColorScale/bucketBounds.d.ts +14 -0
- package/types/src/components/ColorScale/colorScaleHoverMark.d.ts +86 -0
- package/types/src/components/ColorScale/colorScaleScale.d.ts +3 -0
- package/types/src/components/ColorScale/colorScaleType.d.ts +17 -0
- package/types/src/components/Timeline/brushSpan.d.ts +41 -0
- package/types/src/components/Timeline/timelineConfig.d.ts +6 -0
- package/types/src/components/Timeline/timelineRender.d.ts +8 -0
- package/types/src/components/Tooltip.d.ts +8 -0
- package/types/src/shapes/Box.d.ts +1 -8
- package/types/src/shapes/boxOutlierShape.d.ts +9 -0
- package/types/src/shapes/boxStats.d.ts +19 -0
- package/types/src/shapes/boxStyle.d.ts +25 -0
- package/types/src/shapes/boxSummary.d.ts +66 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/shapes/shapeConfig.d.ts +42 -4
- package/types/src/utils/BaseClass.d.ts +23 -0
- package/types/src/utils/D3Scale.d.ts +3 -0
- package/types/src/utils/D3plusConfig.d.ts +261 -5
- package/types/src/utils/className.d.ts +64 -0
- package/types/src/utils/configWarnings.d.ts +21 -2
- package/types/src/utils/fieldAccessor.d.ts +24 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/src/utils/paintComponentScene.d.ts +3 -1
- package/umd/d3plus-core.full.js +6405 -1068
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +5328 -1002
- package/umd/d3plus-core.min.js +2 -2
|
@@ -89,6 +89,7 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
89
89
|
y: axisAbsoluteTransforms[which].y - chartTransform.y
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
+
/** The rotation a test axis settled on, to draw its axis with: its angle, or `false`. */ const testRotation = (test)=>test._labelRotation ? test._labelAngle : false;
|
|
92
93
|
/**
|
|
93
94
|
Render the production x/x2 axes against `xRange`, queue their scenes, and
|
|
94
95
|
build the `viz._xFunc` position accessor.
|
|
@@ -100,7 +101,7 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
100
101
|
const xAxis = viz._xAxis;
|
|
101
102
|
const x2Axis = viz._x2Axis;
|
|
102
103
|
xAxis.renderMode("compute").select(null).domain(xDomain).height(height - (x2Height + topOffset + verticalMargin)).maxSize(height / 2).range(xRange).ticks(xTicks).width(width)// Rotate the labels as the test axis did when it claimed their height.
|
|
103
|
-
.labelRotation(pCtx.xTest
|
|
104
|
+
.labelRotation(testRotation(pCtx.xTest)).config({
|
|
104
105
|
...UNZOOMED_AXIS,
|
|
105
106
|
...xC
|
|
106
107
|
}).config(plotAxisConfig(viz, "x")).config(pCtx.zoomAxes?.x ?? {}).scale(xConfigScale);
|
|
@@ -117,7 +118,7 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
if (x2Exists) {
|
|
120
|
-
x2Axis.renderMode("compute").select(null).domain(x2Domain).height(height - (pCtx.xHeight + topOffset + verticalMargin)).range(xRange).ticks(x2Ticks).width(width).labelRotation(pCtx.x2Test
|
|
121
|
+
x2Axis.renderMode("compute").select(null).domain(x2Domain).height(height - (pCtx.xHeight + topOffset + verticalMargin)).range(xRange).ticks(x2Ticks).width(width).labelRotation(testRotation(pCtx.x2Test)).config({
|
|
121
122
|
...UNZOOMED_AXIS,
|
|
122
123
|
...xC
|
|
123
124
|
}).config(defaultX2Config).config(viz._x2Config).config(pCtx.zoomAxes?.x2 ?? {}).scale(x2ConfigScale).render();
|
|
@@ -130,10 +131,10 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
130
131
|
const xs = frozenAxis(xAxis), x2s = frozenAxis(x2Axis);
|
|
131
132
|
const x = (d, x)=>{
|
|
132
133
|
if (x === "x2") {
|
|
133
|
-
if (x2ConfigScale === "log" && d === 0) d = x2s.
|
|
134
|
+
if (x2ConfigScale === "log" && d === 0) d = x2s._givenDomain()[x2Domain[0] < 0 ? 1 : 0];
|
|
134
135
|
return x2s._getPosition(d);
|
|
135
136
|
} else {
|
|
136
|
-
if (xConfigScale === "log" && d === 0) d = xs.
|
|
137
|
+
if (xConfigScale === "log" && d === 0) d = xs._givenDomain()[xDomain[0] < 0 ? 1 : 0];
|
|
137
138
|
return xs._getPosition(d);
|
|
138
139
|
}
|
|
139
140
|
};
|
|
@@ -178,10 +179,10 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
178
179
|
const ys = frozenAxis(yAxis), y2s = frozenAxis(y2Axis);
|
|
179
180
|
const y = (d, y)=>{
|
|
180
181
|
if (y === "y2") {
|
|
181
|
-
if (y2ConfigScale === "log" && d === 0) d = y2Domain[1] < 0 ? y2s.
|
|
182
|
+
if (y2ConfigScale === "log" && d === 0) d = y2Domain[1] < 0 ? y2s._givenDomain(true)[0] : y2s._givenDomain()[1];
|
|
182
183
|
return y2s._getPosition(d) - x2Height;
|
|
183
184
|
} else {
|
|
184
|
-
if (yConfigScale === "log" && d === 0) d = yDomain[1] < 0 ? ys.
|
|
185
|
+
if (yConfigScale === "log" && d === 0) d = yDomain[1] < 0 ? ys._givenDomain(true)[0] : ys._givenDomain()[1];
|
|
185
186
|
return ys._getPosition(d) - x2Height;
|
|
186
187
|
}
|
|
187
188
|
};
|
|
@@ -82,6 +82,20 @@ import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
|
82
82
|
xTest.range(xRange).measure();
|
|
83
83
|
return xTest.outerBounds().height + xTest.padding();
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
How much further than the x axis's band slanted y-axis labels reach
|
|
87
|
+
below the y range (see `Axis._labelOverflow`): the room the y range
|
|
88
|
+
leaves above the x axis for them.
|
|
89
|
+
*/ function slantedLabelsBelow(pCtx, inset) {
|
|
90
|
+
const axes = [
|
|
91
|
+
pCtx.yTest,
|
|
92
|
+
...pCtx.y2Exists ? [
|
|
93
|
+
pCtx.y2Test
|
|
94
|
+
] : []
|
|
95
|
+
];
|
|
96
|
+
const reach = Math.max(0, ...axes.map((a)=>a._labelOverflow?.[1] ?? 0));
|
|
97
|
+
return Math.max(0, Math.ceil(reach - (pCtx.xHeight + inset)));
|
|
98
|
+
}
|
|
85
99
|
/**
|
|
86
100
|
The y/y2 axes' final solve, and the plot's y range, once the chrome has
|
|
87
101
|
taken its margins. A `frozen` layout (a zoom repaint) keeps the previous
|
|
@@ -97,10 +111,11 @@ import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
|
97
111
|
*/ export function solveFinalAxes(viz, pCtx, frozen) {
|
|
98
112
|
const { x2Height, topOffset, height, horizontalMargin, verticalMargin } = pCtx;
|
|
99
113
|
// The plot's bottom edge for an x axis `xHeight` tall, less the room a
|
|
100
|
-
// chart reserves between the value axis and the x axis
|
|
101
|
-
|
|
114
|
+
// chart reserves between the value axis and the x axis, and `labels`
|
|
115
|
+
// more for y-axis labels that reach below the range.
|
|
116
|
+
const bottom = (xHeight, labels = 0)=>{
|
|
102
117
|
const yBottom = height - (xHeight + topOffset + verticalMargin);
|
|
103
|
-
const insetBottom = frozen?.insetBottom ?? Math.max(0, viz._plotInsetBottom?.(yBottom - x2Height) ?? 0);
|
|
118
|
+
const insetBottom = frozen?.insetBottom ?? Math.max(0, viz._plotInsetBottom?.(yBottom - x2Height) ?? 0) + labels;
|
|
104
119
|
return {
|
|
105
120
|
yBottom,
|
|
106
121
|
insetBottom,
|
|
@@ -126,6 +141,11 @@ import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
|
126
141
|
fit = bottom(xHeight);
|
|
127
142
|
solved = solveFinalYAxes(viz, pCtx, fit.yRange);
|
|
128
143
|
}
|
|
144
|
+
const below = frozen ? 0 : slantedLabelsBelow(pCtx, fit.insetBottom);
|
|
145
|
+
if (below) {
|
|
146
|
+
fit = bottom(pCtx.xHeight, below);
|
|
147
|
+
solved = solveFinalYAxes(viz, pCtx, fit.yRange);
|
|
148
|
+
}
|
|
129
149
|
return {
|
|
130
150
|
pCtx,
|
|
131
151
|
...fit,
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
coupled offsets are solved, and the four-side claim is written to
|
|
5
5
|
`viz._padding.*`. Runs BEFORE the base `Viz` draw finalizes margins.
|
|
6
6
|
*/ import { max } from "d3-array";
|
|
7
|
+
import AxisBottom from "../../components/Axis/AxisBottom.js";
|
|
8
|
+
import { barLabelsNeedAxis } from "../Plot/barLabelFit.js";
|
|
7
9
|
import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
8
10
|
import { xRightInset } from "./axesFinal.js";
|
|
11
|
+
import { cornerControlsHeight } from "./features.js";
|
|
9
12
|
import { END_LABEL_AXIS_CONFIG, endLabelSpace, labelsXEnds, measureEndLabels } from "./plotEndLabels.js";
|
|
10
13
|
import { buildXConfig } from "./xAxisConfig.js";
|
|
11
14
|
/** Measure the y/y2 test axes and report their bounds + claimed widths. */ function measureYTestAxes(viz, inputs) {
|
|
@@ -118,8 +121,23 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
118
121
|
|
|
119
122
|
`measureLineLabels` is invoked once, after the first x-axis measure and
|
|
120
123
|
before the re-measure, so its `xRangeMax` can re-bound the x range.
|
|
121
|
-
*/ export function measureAxes(viz,
|
|
124
|
+
*/ export function measureAxes(viz, measureInputs, measureLineLabels) {
|
|
125
|
+
let inputs = measureInputs;
|
|
126
|
+
const check = inputs.barLabelCheck;
|
|
127
|
+
// Horizontal bars: the y axis measures first, so the x axis's height
|
|
128
|
+
// comes from a throwaway measure.
|
|
129
|
+
const yOnAxis = check?.axis === "y" && barLabelsNeedAxis(viz, check, barPlot(viz, inputs, 0, provisionalXHeight(viz, inputs) + provisionalTopOffset(viz, inputs)));
|
|
130
|
+
if (yOnAxis) inputs = {
|
|
131
|
+
...inputs,
|
|
132
|
+
yTicks: null
|
|
133
|
+
};
|
|
122
134
|
const { yBounds, yWidth, y2Bounds, y2Width } = measureYTestAxes(viz, inputs);
|
|
135
|
+
// Vertical bars: the y axes have claimed their width.
|
|
136
|
+
const xOnAxis = check?.axis === "x" && barLabelsNeedAxis(viz, check, barPlot(viz, inputs, (yWidth ?? 0) + (y2Width ?? 0), 0));
|
|
137
|
+
if (xOnAxis) inputs = {
|
|
138
|
+
...inputs,
|
|
139
|
+
xTicks: null
|
|
140
|
+
};
|
|
123
141
|
const ends = labelsXEnds(viz, inputs.showX, inputs.showY);
|
|
124
142
|
const xC = buildXConfig(viz, inputs);
|
|
125
143
|
const xResult = measureXTestAxes(viz, inputs, xC, yWidth, y2Width, measureLineLabels, ends);
|
|
@@ -133,6 +151,40 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
133
151
|
yWidth,
|
|
134
152
|
y2Width,
|
|
135
153
|
xC,
|
|
136
|
-
...xResult
|
|
154
|
+
...xResult,
|
|
155
|
+
barLabelsOnAxis: yOnAxis || xOnAxis,
|
|
156
|
+
xTicks: inputs.xTicks,
|
|
157
|
+
yTicks: inputs.yTicks
|
|
137
158
|
};
|
|
138
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
The plot area a bar's label gets measured against: the chart area less
|
|
162
|
+
the axes' claims (`left`, `bottom`) and the corner controls' reach,
|
|
163
|
+
which the top margin always clears (a small-multiples panel's chrome is
|
|
164
|
+
already claimed).
|
|
165
|
+
*/ function barPlot(viz, inputs, left, bottom) {
|
|
166
|
+
const corner = viz._facetStep === "panel" ? 0 : cornerControlsHeight(viz);
|
|
167
|
+
return {
|
|
168
|
+
width: inputs.width - left,
|
|
169
|
+
height: inputs.height - bottom - corner
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
The room above the plot for the y axis's top label (see
|
|
174
|
+
`measureXTestAxes`), read from the y test axis's config ahead of its
|
|
175
|
+
measure.
|
|
176
|
+
*/ function provisionalTopOffset(viz, inputs) {
|
|
177
|
+
const { yTest, yC, showY } = inputs;
|
|
178
|
+
if (showY) yTest.config(yC).config(plotAxisConfig(viz, "y"));
|
|
179
|
+
const labelConfig = yTest.shapeConfig().labelConfig;
|
|
180
|
+
return (showY ? labelConfig.fontSize() / 2 : 0) + (viz._plotInsetTop ?? 0);
|
|
181
|
+
}
|
|
182
|
+
/** The x axis's height, from a throwaway measure ahead of the joint solve. */ function provisionalXHeight(viz, inputs) {
|
|
183
|
+
if (!inputs.showX) return 0;
|
|
184
|
+
const axis = new AxisBottom().align("end").gridSize(0);
|
|
185
|
+
axis.domain(inputs.xDomain).height(inputs.height).maxSize(inputs.height / 2).range([
|
|
186
|
+
undefined,
|
|
187
|
+
undefined
|
|
188
|
+
]).ticks(inputs.xTicks).width(inputs.width).config(buildXConfig(viz, inputs)).config(plotAxisConfig(viz, "x")).scale(inputs.xConfigScale).measure();
|
|
189
|
+
return axis.outerBounds().height + axis.padding();
|
|
190
|
+
}
|
|
@@ -86,3 +86,20 @@
|
|
|
86
86
|
});
|
|
87
87
|
return colors;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
The first of the colorScale's rows in each bucket, keyed by bucket color,
|
|
91
|
+
with its index: the row a bucket's swatch takes the chart's shape styles
|
|
92
|
+
from. Null without a colorScale to read.
|
|
93
|
+
*/ export function colorScaleBucketRows(viz) {
|
|
94
|
+
const ctx = bucketCtx(viz);
|
|
95
|
+
if (!ctx) return null;
|
|
96
|
+
const rows = new Map();
|
|
97
|
+
ctx.rows.forEach((row, i)=>{
|
|
98
|
+
const color = ctx.colorOf(row, i);
|
|
99
|
+
if (!rows.has(color)) rows.set(color, {
|
|
100
|
+
row,
|
|
101
|
+
i
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
return rows;
|
|
105
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Drives the colorScale's hover mark (#770): hovering a chart shape marks
|
|
3
|
+
its colorScale value on the colorScale (see `ColorScale.hover`), and
|
|
4
|
+
leaving it, or hovering anything else, clears the mark.
|
|
5
|
+
*/ import { colorScaleBucketOf } from "./colorScaleBucket.js";
|
|
6
|
+
/**
|
|
7
|
+
The colorScale value of a hovered scene node: its datum unwrapped to the
|
|
8
|
+
source row (as the shapes' fill unwraps it), read through the chart's
|
|
9
|
+
`colorScale`. Null for chrome (legend, axes, the colorScale itself), a
|
|
10
|
+
node without a row, or a row without a finite value.
|
|
11
|
+
@param viz The chart.
|
|
12
|
+
@param node The hovered scene node.
|
|
13
|
+
*/ export function colorScaleHoverValue(viz, node) {
|
|
14
|
+
const colorScale = viz.schema.colorScale;
|
|
15
|
+
if (!node || typeof colorScale !== "function") return null;
|
|
16
|
+
if (node.interactionGroup) return null;
|
|
17
|
+
if (colorScaleBucketOf(node.datum)) return null;
|
|
18
|
+
let d = node.datum;
|
|
19
|
+
let i = typeof node.index === "number" ? node.index : 0;
|
|
20
|
+
while(d && d.__d3plus__ && d.data){
|
|
21
|
+
d = d.data;
|
|
22
|
+
if (typeof d.i === "number") i = d.i;
|
|
23
|
+
}
|
|
24
|
+
if (!d || typeof d !== "object") return null;
|
|
25
|
+
const value = colorScale(d, i);
|
|
26
|
+
if (value === null || value === undefined || value === "") return null;
|
|
27
|
+
if (typeof value !== "number" && typeof value !== "string") return null;
|
|
28
|
+
const n = +value;
|
|
29
|
+
return Number.isFinite(n) ? n : null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
Updates the colorScale's hover mark for a pointer event, repainting only
|
|
33
|
+
when the marked value changes. Moves are ignored while a transition is
|
|
34
|
+
in flight; leaving the chart always clears the mark.
|
|
35
|
+
@param viz The chart.
|
|
36
|
+
@param event The pointer event.
|
|
37
|
+
*/ export function handleColorScaleHover(viz, event) {
|
|
38
|
+
const cs = viz._colorScaleClass;
|
|
39
|
+
if (!cs || !viz.schema.colorScale) return;
|
|
40
|
+
let next = false;
|
|
41
|
+
if (event.type === "mousemove" || event.type === "mouseenter") {
|
|
42
|
+
if (viz._transitionEndsAt && Date.now() < viz._transitionEndsAt) return;
|
|
43
|
+
if (cs.hoverMark() === false) return;
|
|
44
|
+
next = colorScaleHoverValue(viz, event.pick?.node) ?? false;
|
|
45
|
+
} else if (event.type !== "mouseleave") return;
|
|
46
|
+
if ((cs.hover() ?? false) === next) return;
|
|
47
|
+
cs.hover(next);
|
|
48
|
+
viz._scheduleSceneRepaint();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
The swatch to keep lit for the colorScale's hovered value when the chart
|
|
52
|
+
has no hover predicate of its own (shape hover is off, as on Geomap,
|
|
53
|
+
Calendar, or past `dataCutoff`): the value's bucket color, and the
|
|
54
|
+
opacity the other swatches dim to (`hoverOpacity`, or 0.5 when that is
|
|
55
|
+
1). Null when the chart's own hover drives the highlight, nothing is
|
|
56
|
+
marked, `hoverMark` is off, or the scale isn't drawn as swatches.
|
|
57
|
+
@param viz The chart.
|
|
58
|
+
*/ export function hoveredSwatch(viz) {
|
|
59
|
+
const cs = viz._colorScaleClass;
|
|
60
|
+
if (!cs || typeof viz._hover === "function") return null;
|
|
61
|
+
const value = cs.hover();
|
|
62
|
+
if (typeof value !== "number" || !Number.isFinite(value) || cs.hoverMark() === false || cs._barGeometry || typeof cs._colorScale !== "function") return null;
|
|
63
|
+
const shapeConfig = viz.schema.shapeConfig;
|
|
64
|
+
const hoverOpacity = shapeConfig?.hoverOpacity;
|
|
65
|
+
return {
|
|
66
|
+
color: cs._colorScale(value),
|
|
67
|
+
dimOpacity: typeof hoverOpacity === "number" && hoverOpacity < 1 ? hoverOpacity : 0.5
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -144,6 +144,17 @@ const VALID_POSITIONS = new Set([
|
|
|
144
144
|
const inset = topLeftControlsInsetRaw(viz, top, left, contributions);
|
|
145
145
|
return inset > 0 ? inset + CORNER_INSET_GAP : 0;
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
How far a left or right legend/colorScale starting `top` px down the
|
|
149
|
+
chart, its outer edge `edge` px in from the chart's edge on that side,
|
|
150
|
+
must drop to start below the corner control panel on its side: the
|
|
151
|
+
top-left panel for `"left"`, the zoom controls for `"right"`. Zero when
|
|
152
|
+
that panel isn't showing, is narrower than `edge`, or ends above `top`.
|
|
153
|
+
*/ export function sideControlsDrop(viz, position, top, edge) {
|
|
154
|
+
if (position === "right" && zoomControlsInset(viz, top, edge)) return zoomControlsReach(viz) - top;
|
|
155
|
+
if (position === "left" && topLeftControlsInset(viz, top, edge)) return topLeftControlsReach(viz, getTopLeftContributions(viz)) - top;
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
147
158
|
/**
|
|
148
159
|
The combined left+right corner-panel insets for content starting `top`
|
|
149
160
|
px down the chart, plus the single symmetric amount CENTERED content
|
|
@@ -422,7 +433,8 @@ const VALID_POSITIONS = new Set([
|
|
|
422
433
|
// First render only: default to the *filtered* extent, which the
|
|
423
434
|
// synthesized default timeFilter pins to the latest period (see
|
|
424
435
|
// vizPreDraw) — the historical default. `timelineDefault` overrides it.
|
|
425
|
-
|
|
436
|
+
// A row merged across periods holds each of their times.
|
|
437
|
+
const filtered = extent((viz._filteredData || []).flatMap((d, i)=>viz.schema.time(d, i)).map((d)=>date(d)));
|
|
426
438
|
viz._timelineSelection = viz.schema.timelineDefault || (filtered[0] ? filtered : fullExtent);
|
|
427
439
|
} else {
|
|
428
440
|
if (viz._timelineSelection[0] < fullExtent[0]) viz._timelineSelection[0] = fullExtent[0];
|
|
@@ -8,9 +8,11 @@ import { merge } from "@d3plus/data";
|
|
|
8
8
|
import { elem } from "@d3plus/dom";
|
|
9
9
|
import { resolveSpec } from "../pipeline/resolveSpec.js";
|
|
10
10
|
import { bottomRightClearance } from "../drawSteps/bottomRightControlsMarkup.js";
|
|
11
|
-
import { sanitizePosition } from "./features.js";
|
|
11
|
+
import { sanitizePosition, sideControlsDrop } from "./features.js";
|
|
12
12
|
import { insetFrame, insetOrient, isInsetPending } from "./insetState.js";
|
|
13
13
|
import { facetKey } from "../facet/facetData.js";
|
|
14
|
+
import { colorScaleBucketRows } from "./colorScaleBucket.js";
|
|
15
|
+
import { resolveAccessor, shapeConfigFor } from "./emitHelpers.js";
|
|
14
16
|
/**
|
|
15
17
|
The colorScale's data: the chart's data rolled up per time/id (and per
|
|
16
18
|
small-multiples panel, the values the panels color by), keeping rows with
|
|
@@ -23,6 +25,40 @@ import { facetKey } from "../facet/facetData.js";
|
|
|
23
25
|
return c !== undefined && c !== null;
|
|
24
26
|
});
|
|
25
27
|
}
|
|
28
|
+
/** The paint a bucket swatch takes from the chart's shapes: all but its fill. */ const SWATCH_STYLES = [
|
|
29
|
+
"fillOpacity",
|
|
30
|
+
"opacity",
|
|
31
|
+
"stroke",
|
|
32
|
+
"strokeDasharray",
|
|
33
|
+
"strokeLinecap",
|
|
34
|
+
"strokeOpacity",
|
|
35
|
+
"strokeWidth"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
The `shapeConfig` that styles the colorScale's bucket swatches like the
|
|
39
|
+
chart's shapes, the way the legend's swatches are: each style resolves
|
|
40
|
+
from the chart's `shapeConfig` for the first row in the swatch's bucket
|
|
41
|
+
(any row, for a bucket without one), so a swatch's stroke is its shapes'
|
|
42
|
+
stroke. A Line row's swatch takes the shared styles, not the Line's own.
|
|
43
|
+
*/ function bucketSwatchConfig(viz) {
|
|
44
|
+
// Read on first use: the buckets exist once the ColorScale builds its scale.
|
|
45
|
+
let rows;
|
|
46
|
+
const configs = new Map();
|
|
47
|
+
const style = (bucket, key)=>{
|
|
48
|
+
if (rows === undefined) rows = colorScaleBucketRows(viz);
|
|
49
|
+
const source = rows?.get(bucket.color) ?? rows?.values().next().value;
|
|
50
|
+
if (!source) return undefined;
|
|
51
|
+
const { row, i } = source;
|
|
52
|
+
const shape = viz._colorScaleShape(row, i);
|
|
53
|
+
const nest = shape === "Line" ? "" : shape;
|
|
54
|
+
if (!configs.has(nest)) configs.set(nest, shapeConfigFor(viz, nest));
|
|
55
|
+
return resolveAccessor(configs.get(nest)[key], row, i);
|
|
56
|
+
};
|
|
57
|
+
return Object.fromEntries(SWATCH_STYLES.map((key)=>[
|
|
58
|
+
key,
|
|
59
|
+
(d)=>style(d, key)
|
|
60
|
+
]));
|
|
61
|
+
}
|
|
26
62
|
/**
|
|
27
63
|
Configures and lays out the chart's `_colorScaleClass` into `frame`. It
|
|
28
64
|
always runs in compute mode: Viz.toScene composes its scene, so the
|
|
@@ -42,7 +78,9 @@ import { facetKey } from "../facet/facetData.js";
|
|
|
42
78
|
update: transform
|
|
43
79
|
}).node();
|
|
44
80
|
if (!viz.schema.colorScale) return;
|
|
45
|
-
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).
|
|
81
|
+
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).legendConfig({
|
|
82
|
+
shapeConfig: bucketSwatchConfig(viz)
|
|
83
|
+
}).config(viz.schema.colorScaleConfig).hover(false).render();
|
|
46
84
|
}
|
|
47
85
|
/** The colorScale's sanitized position side (false when hidden). */ function colorScalePosition(viz) {
|
|
48
86
|
return sanitizePosition(viz.schema.colorScalePosition.bind(viz)(resolveSpec(viz)), viz);
|
|
@@ -115,6 +153,8 @@ import { facetKey } from "../facet/facetData.js";
|
|
|
115
153
|
bottom: 0,
|
|
116
154
|
left: 0
|
|
117
155
|
};
|
|
156
|
+
// A side colorScale starts below the corner control panel on its side.
|
|
157
|
+
const drop = sideControlsDrop(viz, position, layoutMargin.top, position === "left" ? layoutMargin.left : layoutMargin.right);
|
|
118
158
|
// Share the bottom band with the bottom-right corner panel (size legend):
|
|
119
159
|
// a bottom colorScale fits beside it, a side one ends above it.
|
|
120
160
|
const corner = bottomRightClearance(viz, position, layoutMargin.bottom + padding.bottom, layoutMargin.right + padding.right);
|
|
@@ -123,14 +163,14 @@ import { facetKey } from "../facet/facetData.js";
|
|
|
123
163
|
viz.schema.colorScaleMaxSize,
|
|
124
164
|
availableWidth
|
|
125
165
|
]) : viz.schema.width - (layoutMargin.left + layoutMargin.right);
|
|
126
|
-
const availableHeight = viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top) - corner.drop;
|
|
166
|
+
const availableHeight = viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top) - drop - corner.drop;
|
|
127
167
|
const height = !wide ? min([
|
|
128
168
|
viz.schema.colorScaleMaxSize,
|
|
129
169
|
availableHeight
|
|
130
170
|
]) : viz.schema.height - (layoutMargin.bottom + layoutMargin.top);
|
|
131
171
|
paintColorScale(viz, {
|
|
132
172
|
x: wide ? layoutMargin.left + padding.left + (availableWidth - width) / 2 : layoutMargin.left,
|
|
133
|
-
y: wide ? layoutMargin.top : layoutMargin.top + padding.top + (availableHeight - height) / 2,
|
|
173
|
+
y: wide ? layoutMargin.top : layoutMargin.top + padding.top + drop + (availableHeight - height) / 2,
|
|
134
174
|
width,
|
|
135
175
|
height,
|
|
136
176
|
orient: position,
|
|
@@ -6,11 +6,8 @@
|
|
|
6
6
|
*/ import { merge } from "@d3plus/data";
|
|
7
7
|
import { elem } from "@d3plus/dom";
|
|
8
8
|
import { configPrep } from "../../utils/index.js";
|
|
9
|
-
import { cornerPlacements, sanitizePosition,
|
|
9
|
+
import { cornerPlacements, sanitizePosition, sideControlsDrop } from "./features.js";
|
|
10
10
|
import { bottomRightClearance } from "../drawSteps/bottomRightControlsMarkup.js";
|
|
11
|
-
import { zoomControlsReach } from "../drawSteps/zoomControlsMarkup.js";
|
|
12
|
-
import { getTopLeftContributions } from "../drawSteps/topLeftControls.js";
|
|
13
|
-
import { topLeftControlsReach } from "../drawSteps/topLeftControlsMarkup.js";
|
|
14
11
|
import { resolveSpec } from "../pipeline/resolveSpec.js";
|
|
15
12
|
import { insetFrame, insetOrient, isInsetPending } from "./insetState.js";
|
|
16
13
|
import { legendCategories, legendMergesIds } from "./legendCategory.js";
|
|
@@ -78,7 +75,9 @@ import { legendCategories, legendMergesIds } from "./legendCategory.js";
|
|
|
78
75
|
}
|
|
79
76
|
// Entries that each merge several ids are labelled by their color category.
|
|
80
77
|
viz._legendCategories = legendMergesIds(viz, legendData) ? legendCategories(entries) : undefined;
|
|
81
|
-
|
|
78
|
+
// A threshold bucket's entry comes last, whatever the sort.
|
|
79
|
+
const bucket = (d)=>d._isAggregation ? 1 : 0;
|
|
80
|
+
legendData.sort((a, b)=>bucket(a) - bucket(b) || viz.schema.legendSort(a, b));
|
|
82
81
|
return {
|
|
83
82
|
legendData,
|
|
84
83
|
legendKey,
|
|
@@ -93,13 +92,12 @@ import { legendCategories, legendMergesIds } from "./legendCategory.js";
|
|
|
93
92
|
(`insetRight`) and a side legend shortens to end above it (`shorten`).
|
|
94
93
|
A top legend finds its own place beside them (see `paintTopLegend`).
|
|
95
94
|
*/ function legendCornerClearance(viz, position, layoutMargin, padding) {
|
|
96
|
-
const
|
|
97
|
-
const dropLeft = position === "left" && topLeftControlsInset(viz, layoutMargin.top, layoutMargin.left) ? topLeftControlsReach(viz, getTopLeftContributions(viz)) - layoutMargin.top : 0;
|
|
95
|
+
const drop = sideControlsDrop(viz, position, layoutMargin.top, position === "left" ? layoutMargin.left : layoutMargin.right);
|
|
98
96
|
// The bottom-right corner panel (size legend): a bottom legend pulls its
|
|
99
97
|
// right edge in beside it, a left/right legend stops short above it.
|
|
100
98
|
const corner = bottomRightClearance(viz, position, layoutMargin.bottom + padding.bottom, layoutMargin.right + padding.right);
|
|
101
99
|
return {
|
|
102
|
-
drop
|
|
100
|
+
drop,
|
|
103
101
|
insetRight: corner.inset,
|
|
104
102
|
shorten: corner.drop
|
|
105
103
|
};
|
|
@@ -18,6 +18,7 @@ import { collectComputed, makeShape } from "./emitHelpers.js";
|
|
|
18
18
|
import { emitLineLabelConnectors } from "./lineLabels.js";
|
|
19
19
|
import { collectAnnotationGroup, emitAnnotations } from "./plotAnnotations.js";
|
|
20
20
|
import { emitShape } from "./shapeEmit.js";
|
|
21
|
+
import { barHitsFirst } from "../Plot/barHitArea.js";
|
|
21
22
|
import { emitTrendLines } from "../Plot/trendScene.js";
|
|
22
23
|
import { emitForecast, forecastRows } from "../Plot/forecastScene.js";
|
|
23
24
|
import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
@@ -109,16 +110,15 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
109
110
|
x2Height: pCtx.x2Height,
|
|
110
111
|
yOffset
|
|
111
112
|
}),
|
|
113
|
+
barLabelsOnAxis: pCtx.barLabelsOnAxis,
|
|
112
114
|
insetBottom: mCtx.insetBottom ?? 0,
|
|
113
115
|
x2Height: pCtx.x2Height,
|
|
114
116
|
zoomRanges: pCtx.zoomRanges
|
|
115
117
|
};
|
|
116
|
-
shapeData.
|
|
117
|
-
out.push(...emitShape({
|
|
118
|
+
out.push(...barHitsFirst(shapeData.flatMap(([key, values])=>emitShape({
|
|
118
119
|
...shapeCtx,
|
|
119
120
|
values
|
|
120
|
-
}, key));
|
|
121
|
-
});
|
|
121
|
+
}, key))));
|
|
122
122
|
}
|
|
123
123
|
/** Runs shape exits in compute mode and updates `viz._previousShapes`. */ function emitShapeExits(viz, shapeData, shapeConfig) {
|
|
124
124
|
const dataShapes = shapeData.map(([key])=>key);
|
|
@@ -22,6 +22,7 @@ import { emitBarConfidence } from "../Plot/barConfidence.js";
|
|
|
22
22
|
import { emitLineBands } from "../Plot/lineBands.js";
|
|
23
23
|
import { clampBarConfig, valueAxis } from "../Plot/baselineBreak.js";
|
|
24
24
|
import { barSeries, seriesSlot } from "../Plot/barWidth.js";
|
|
25
|
+
import { applyBarHitArea, hitColumn } from "../Plot/barHitArea.js";
|
|
25
26
|
import { rowSpan } from "../Plot/discreteSpan.js";
|
|
26
27
|
import { emitFillBetween } from "../Plot/fillBetween.js";
|
|
27
28
|
import { applyStackShareLabels } from "../Plot/stackShareLabels.js";
|
|
@@ -78,6 +79,7 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
78
79
|
if (viz.schema.shapeConfig.duration === undefined) delete userConfig.duration;
|
|
79
80
|
s.config(userConfig);
|
|
80
81
|
if (override) s.config(override(userConfig));
|
|
82
|
+
if (key === "Bar" && ctx.barLabelsOnAxis) s.label(false);
|
|
81
83
|
if (viz.schema.stacked && key === "Bar") applyStackShareLabels(viz, s);
|
|
82
84
|
s.render();
|
|
83
85
|
const nodes = collectComputed(s);
|
|
@@ -170,6 +172,8 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
170
172
|
const zoomRange = zoomRanges?.[viz.schema.discrete];
|
|
171
173
|
if (scaleType !== "Point" && vals.length === 2) {
|
|
172
174
|
const allPositions = Array.from(new Set(values.map((d)=>scale(d[viz.schema.discrete]))));
|
|
175
|
+
// A reversed axis places the data from its far end.
|
|
176
|
+
if (allPositions[0] > allPositions[allPositions.length - 1]) allPositions.reverse();
|
|
173
177
|
const first = allPositions[0];
|
|
174
178
|
const last = allPositions[allPositions.length - 1];
|
|
175
179
|
allPositions.unshift(zoomRange ? 2 * zoomRange[0] - first : range[0] - first - range[0]);
|
|
@@ -181,8 +185,9 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
181
185
|
}
|
|
182
186
|
return n;
|
|
183
187
|
}, Infinity);
|
|
184
|
-
} else if (vals.length > 1) space = scale(vals[1]) - scale(vals[0]);
|
|
188
|
+
} else if (vals.length > 1) space = Math.abs(scale(vals[1]) - scale(vals[0]));
|
|
185
189
|
else space = range[range.length - 1] - range[0];
|
|
190
|
+
const step = space;
|
|
186
191
|
if (viz._groupPadding < space) space -= viz._groupPadding;
|
|
187
192
|
let barSize = space || 1;
|
|
188
193
|
const barGroups = groups(values, (d)=>d[viz.schema.discrete], (d)=>d.group);
|
|
@@ -190,6 +195,7 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
190
195
|
const uniqueIds = Array.from(new Set(ids));
|
|
191
196
|
const discreteKey = viz.schema.discrete;
|
|
192
197
|
const discreteFn = ctx.shapeConfig[discreteKey];
|
|
198
|
+
let column = ()=>hitColumn(step, 1, 0, 0);
|
|
193
199
|
if (max(barGroups.map(([, innerEntries])=>innerEntries.length)) === 1) {
|
|
194
200
|
s[discreteKey]((d, i)=>discreteFn(d, i));
|
|
195
201
|
} else {
|
|
@@ -203,9 +209,11 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
203
209
|
offset
|
|
204
210
|
]);
|
|
205
211
|
s[discreteKey]((d, i)=>discreteFn(d, i) + xMod(uniqueIds.indexOf(d.group)));
|
|
212
|
+
column = (d)=>hitColumn(step, uniqueIds.length, uniqueIds.indexOf(d.group), offset);
|
|
206
213
|
}
|
|
207
214
|
s.width(barSize);
|
|
208
215
|
s.height(barSize);
|
|
216
|
+
barHits(ctx, s, column);
|
|
209
217
|
return finishShape(ctx, "Bar", s);
|
|
210
218
|
};
|
|
211
219
|
/**
|
|
@@ -219,11 +227,16 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
219
227
|
const [start, end] = rowSpan(viz, d);
|
|
220
228
|
return Math.max(1, Math.abs(scale(end) - scale(start)) - viz._groupPadding);
|
|
221
229
|
};
|
|
230
|
+
const step = (d)=>{
|
|
231
|
+
const [start, end] = rowSpan(viz, d);
|
|
232
|
+
return Math.abs(scale(end) - scale(start));
|
|
233
|
+
};
|
|
222
234
|
const axis = viz.schema.discrete;
|
|
223
235
|
const series = viz._barSpans ? barSeries(values, axis) : [];
|
|
224
236
|
if (series.length < 2) {
|
|
225
237
|
s.width(space);
|
|
226
238
|
s.height(space);
|
|
239
|
+
barHits(ctx, s, (d)=>hitColumn(step(d), 1, 0, 0));
|
|
227
240
|
return finishShape(ctx, "Bar", s);
|
|
228
241
|
}
|
|
229
242
|
const slot = (d)=>seriesSlot(space(d), series.length, series.indexOf(d.group), viz.schema.barPadding);
|
|
@@ -231,8 +244,14 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
231
244
|
s[axis]((d, i)=>position(d, i) + slot(d).offset);
|
|
232
245
|
s.width((d)=>slot(d).size);
|
|
233
246
|
s.height((d)=>slot(d).size);
|
|
247
|
+
barHits(ctx, s, (d)=>hitColumn(step(d), series.length, series.indexOf(d.group), Math.max(0, space(d) - slot(d).size) / 2));
|
|
234
248
|
return finishShape(ctx, "Bar", s);
|
|
235
249
|
}
|
|
250
|
+
/** Side-by-side bars' hit areas (see `Plot/barHitArea.ts`); stacked bars take none. */ function barHits(ctx, s, column) {
|
|
251
|
+
const { viz } = ctx;
|
|
252
|
+
if (viz.schema.stacked) return;
|
|
253
|
+
applyBarHitArea(s, viz.schema.discrete === "y" ? "y" : "x", ctx.valueExtent, column);
|
|
254
|
+
}
|
|
236
255
|
/** Line — duration, optional confidence band, end-labels, and point markers. */ const lineEmit = (ctx)=>{
|
|
237
256
|
const { viz, values, width, showLineLabels, labelWidths, largestLabel, labelPositions } = ctx;
|
|
238
257
|
const out = [];
|
|
@@ -257,7 +276,9 @@ import { markSharedConfig } from "../../utils/configWarnings.js";
|
|
|
257
276
|
} : false,
|
|
258
277
|
labelBounds: showLineLabels ? (d, i, s)=>{
|
|
259
278
|
const [firstX, firstY] = s.points[0];
|
|
260
|
-
|
|
279
|
+
// The label sits past the line's right end (its first point when
|
|
280
|
+
// the x axis is reversed).
|
|
281
|
+
const [lastX, lastY] = s.points.reduce((a, b)=>b[0] >= a[0] ? b : a);
|
|
261
282
|
const height = viz.schema.height / 4;
|
|
262
283
|
const mod = labelPositions[d.id] ? lastY - labelPositions[d.id] : 0;
|
|
263
284
|
return {
|
|
@@ -27,6 +27,21 @@
|
|
|
27
27
|
if (Array.isArray(share)) return share.reduce((a, b)=>a + b, 0);
|
|
28
28
|
return typeof share === "number" ? share : NaN;
|
|
29
29
|
}
|
|
30
|
+
/** The data row under a shape or legend wrapper (`{__d3plus__, data}`). */ export function unwrapRow(d) {
|
|
31
|
+
let row = d;
|
|
32
|
+
while(row && row.__d3plus__ && row.data)row = row.data;
|
|
33
|
+
return row;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
`d`'s share of every row's total: the size of its `value` over the summed
|
|
37
|
+
size of every row's. NaN when that total is 0. A legend entry, which
|
|
38
|
+
merges a series over every position, reads its share of the whole chart
|
|
39
|
+
this way.
|
|
40
|
+
*/ export function shareOfRows(d, rows, value) {
|
|
41
|
+
let total = 0;
|
|
42
|
+
for (const row of rows)total += Math.abs(+value(row)) || 0;
|
|
43
|
+
return total > 0 ? Math.abs(+value(d)) / total : NaN;
|
|
44
|
+
}
|
|
30
45
|
/** Whether `key` is one d3plus writes onto data rows for its own use. */ export function isInternalKey(key) {
|
|
31
46
|
return key.startsWith(INTERNAL_KEY_PREFIX);
|
|
32
47
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The items a `threshold` bucket holds, listed in its tooltips. The bucket
|
|
3
|
+
row carries them under `MEMBERS_KEY`, largest first; a tooltip shows up
|
|
4
|
+
to `MEMBER_LIMIT` of them, then how many more it holds.
|
|
5
|
+
*/ import { formatAbbreviate } from "@d3plus/format";
|
|
6
|
+
import { INTERNAL_KEY_PREFIX } from "./shareKey.js";
|
|
7
|
+
/** The row key a threshold bucket lists its members under. */ export const MEMBERS_KEY = `${INTERNAL_KEY_PREFIX}Members`;
|
|
8
|
+
/** How many members a tooltip lists before summing up the rest as "+N more". */ export const MEMBER_LIMIT = 10;
|
|
9
|
+
/**
|
|
10
|
+
The members `rows` make up: one per `key`, labelled by its first row and
|
|
11
|
+
valued by the sum of its rows' `value`, largest first.
|
|
12
|
+
*/ export function thresholdMemberList(rows, key, label, value) {
|
|
13
|
+
const members = new Map();
|
|
14
|
+
rows.forEach((d, i)=>{
|
|
15
|
+
const k = `${key(d, i)}`;
|
|
16
|
+
const v = +value(d, i) || 0;
|
|
17
|
+
const member = members.get(k);
|
|
18
|
+
if (member) member.value += v;
|
|
19
|
+
else members.set(k, {
|
|
20
|
+
label: `${label(d, i)}`,
|
|
21
|
+
value: v
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
return Array.from(members.values()).sort((a, b)=>b.value - a.value);
|
|
25
|
+
}
|
|
26
|
+
/** The members a bucket row (or a wrapper around one) lists, or none. */ export function thresholdMembers(d) {
|
|
27
|
+
let row = d;
|
|
28
|
+
while(row && row.__d3plus__ && row.data)row = row.data;
|
|
29
|
+
const members = row ? row[MEMBERS_KEY] : undefined;
|
|
30
|
+
if (!members) return [];
|
|
31
|
+
// A merge of one bucket row unwraps a one-item list.
|
|
32
|
+
return Array.isArray(members) ? members : [
|
|
33
|
+
members
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
/** A member's name, indented under the bucket it belongs to. */ export const memberName = (label)=>`<span class="d3plus-tooltip-member" style="padding-left: 12px">${label}</span>`;
|
|
37
|
+
/**
|
|
38
|
+
Tooltip rows for a bucket's members: `[name, value]` for up to `limit`
|
|
39
|
+
of them, largest first, then a "+N more" row with the rest's summed
|
|
40
|
+
value. Empty for a row that isn't a bucket.
|
|
41
|
+
*/ export function thresholdMemberRows(viz, d, limit = MEMBER_LIMIT) {
|
|
42
|
+
const members = thresholdMembers(d);
|
|
43
|
+
if (!members.length) return [];
|
|
44
|
+
const format = viz._thresholdMemberFormat ?? ((v)=>formatAbbreviate(v, viz.schema.locale));
|
|
45
|
+
const rows = members.slice(0, limit).map((m)=>[
|
|
46
|
+
memberName(m.label),
|
|
47
|
+
format(m.value)
|
|
48
|
+
]);
|
|
49
|
+
const rest = members.slice(limit);
|
|
50
|
+
if (rest.length) rows.push([
|
|
51
|
+
memberName(`+${formatAbbreviate(rest.length, viz.schema.locale)} ${viz.schema.translate("more")}`),
|
|
52
|
+
format(rest.reduce((total, m)=>total + m.value, 0))
|
|
53
|
+
]);
|
|
54
|
+
return rows;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
Appends a bucket's member rows to `tooltip`'s `tbody`, after the rows it
|
|
58
|
+
already has. Does nothing for a row that isn't a bucket.
|
|
59
|
+
*/ export function appendThresholdMembers(tooltip, viz, d) {
|
|
60
|
+
const rows = thresholdMemberRows(viz, d);
|
|
61
|
+
if (!rows.length) return tooltip;
|
|
62
|
+
const base = tooltip.tbody();
|
|
63
|
+
tooltip.tbody((dd, ii)=>{
|
|
64
|
+
const own = typeof base === "function" ? base(dd, ii) : base;
|
|
65
|
+
return [
|
|
66
|
+
...Array.isArray(own) ? own : [],
|
|
67
|
+
...rows
|
|
68
|
+
];
|
|
69
|
+
});
|
|
70
|
+
return tooltip;
|
|
71
|
+
}
|