@d3plus/core 4.5.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 +3930 -2032
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/internal.js +11 -1
- package/es/internal.js.map +1 -1
- package/es/src/charts/BarChart/index.js +8 -1
- package/es/src/charts/BarChart/index.js.map +1 -1
- package/es/src/charts/BoxWhisker/index.js +5 -0
- package/es/src/charts/BoxWhisker/index.js.map +1 -1
- package/es/src/charts/Chord/emit.js +55 -3
- package/es/src/charts/Chord/emit.js.map +1 -1
- package/es/src/charts/Chord/index.js +17 -0
- package/es/src/charts/Chord/index.js.map +1 -1
- package/es/src/charts/Geomap/applyLayout.js +20 -11
- package/es/src/charts/Geomap/applyLayout.js.map +1 -1
- package/es/src/charts/Geomap/index.js +8 -2
- package/es/src/charts/Geomap/index.js.map +1 -1
- package/es/src/charts/Histogram/binData.js +225 -0
- package/es/src/charts/Histogram/binData.js.map +1 -0
- package/es/src/charts/Histogram/index.js +271 -0
- package/es/src/charts/Histogram/index.js.map +1 -0
- package/es/src/charts/Matrix/emit.js +5 -4
- package/es/src/charts/Matrix/emit.js.map +1 -1
- package/es/src/charts/Network/applyLayout.js +52 -4
- package/es/src/charts/Network/applyLayout.js.map +1 -1
- package/es/src/charts/Network/emit.js +4 -4
- package/es/src/charts/Network/emit.js.map +1 -1
- package/es/src/charts/Network/index.js +10 -1
- package/es/src/charts/Network/index.js.map +1 -1
- package/es/src/charts/Pack/emit.js +42 -7
- package/es/src/charts/Pack/emit.js.map +1 -1
- package/es/src/charts/Pack/index.js +15 -0
- package/es/src/charts/Pack/index.js.map +1 -1
- package/es/src/charts/Pie/applyLayout.js +20 -2
- package/es/src/charts/Pie/applyLayout.js.map +1 -1
- package/es/src/charts/Pie/emit.js +275 -35
- package/es/src/charts/Pie/emit.js.map +1 -1
- package/es/src/charts/Pie/index.js +48 -1
- package/es/src/charts/Pie/index.js.map +1 -1
- package/es/src/charts/Plot/discreteSpan.js +42 -0
- package/es/src/charts/Plot/discreteSpan.js.map +1 -0
- package/es/src/charts/Plot/draw.js +3 -1
- package/es/src/charts/Plot/draw.js.map +1 -1
- package/es/src/charts/Plot/index.js +143 -14
- 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/pipeline.js +47 -20
- package/es/src/charts/Plot/pipeline.js.map +1 -1
- package/es/src/charts/Plot/pipelineDomains.js +84 -8
- package/es/src/charts/Plot/pipelineDomains.js.map +1 -1
- package/es/src/charts/Plot/shapeDefaults.js +3 -3
- package/es/src/charts/Plot/shapeDefaults.js.map +1 -1
- package/es/src/charts/Plot/sharedHover.js +532 -0
- package/es/src/charts/Plot/sharedHover.js.map +1 -0
- package/es/src/charts/Plot/sharedHoverScene.js +230 -0
- package/es/src/charts/Plot/sharedHoverScene.js.map +1 -0
- package/es/src/charts/Plot/sharedTooltip.js +183 -0
- package/es/src/charts/Plot/sharedTooltip.js.map +1 -0
- package/es/src/charts/Plot/stackShareLabels.js +137 -0
- package/es/src/charts/Plot/stackShareLabels.js.map +1 -0
- package/es/src/charts/Plot/stackShareTooltip.js +31 -0
- package/es/src/charts/Plot/stackShareTooltip.js.map +1 -0
- package/es/src/charts/Plot/trendLines.js +469 -0
- package/es/src/charts/Plot/trendLines.js.map +1 -0
- 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 +234 -0
- package/es/src/charts/Plot/trendScene.js.map +1 -0
- package/es/src/charts/Plot/trendTooltip.js +222 -0
- package/es/src/charts/Plot/trendTooltip.js.map +1 -0
- package/es/src/charts/Priestley/emit.js +34 -6
- package/es/src/charts/Priestley/emit.js.map +1 -1
- package/es/src/charts/Radar/index.js +15 -2
- package/es/src/charts/Radar/index.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/RadialMatrix/index.js +17 -1
- package/es/src/charts/RadialMatrix/index.js.map +1 -1
- package/es/src/charts/Rings/applyLayout.js +72 -116
- package/es/src/charts/Rings/applyLayout.js.map +1 -1
- package/es/src/charts/Rings/emit.js +2 -3
- package/es/src/charts/Rings/emit.js.map +1 -1
- package/es/src/charts/Rings/index.js +18 -3
- package/es/src/charts/Rings/index.js.map +1 -1
- package/es/src/charts/Rings/ringsSizing.js +189 -0
- package/es/src/charts/Rings/ringsSizing.js.map +1 -0
- package/es/src/charts/Sankey/index.js +2 -0
- package/es/src/charts/Sankey/index.js.map +1 -1
- package/es/src/charts/StackedArea/index.js +8 -1
- package/es/src/charts/StackedArea/index.js.map +1 -1
- package/es/src/charts/Tree/emit.js +2 -2
- package/es/src/charts/Tree/emit.js.map +1 -1
- package/es/src/charts/Tree/index.js +7 -3
- package/es/src/charts/Tree/index.js.map +1 -1
- package/es/src/charts/Treemap/emit.js +58 -6
- 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 +14 -1
- package/es/src/charts/definition/makeChart.js.map +1 -1
- package/es/src/charts/drawSteps/backControl.js +17 -2
- package/es/src/charts/drawSteps/backControl.js.map +1 -1
- package/es/src/charts/drawSteps/bottomRightControls.js +196 -0
- package/es/src/charts/drawSteps/bottomRightControls.js.map +1 -0
- package/es/src/charts/drawSteps/bottomRightControlsMarkup.js +292 -0
- package/es/src/charts/drawSteps/bottomRightControlsMarkup.js.map +1 -0
- package/es/src/charts/drawSteps/minimap.js +34 -9
- package/es/src/charts/drawSteps/minimap.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/drawSteps/zoomControls.js +3 -0
- package/es/src/charts/drawSteps/zoomControls.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/click.shape.js +24 -1
- package/es/src/charts/events/click.shape.js.map +1 -1
- package/es/src/charts/events/mouseenter.js +3 -0
- package/es/src/charts/events/mouseenter.js.map +1 -1
- package/es/src/charts/events/mouseleave.js +3 -0
- package/es/src/charts/events/mouseleave.js.map +1 -1
- package/es/src/charts/events/mousemove.shape.js +10 -1
- package/es/src/charts/events/mousemove.shape.js.map +1 -1
- package/es/src/charts/features/axes.js +4 -1
- package/es/src/charts/features/axes.js.map +1 -1
- package/es/src/charts/features/emitHelpers.js +43 -5
- package/es/src/charts/features/emitHelpers.js.map +1 -1
- package/es/src/charts/features/features.js +3 -104
- 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 +155 -34
- 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/plotPaint.js +51 -24
- package/es/src/charts/features/plotPaint.js.map +1 -1
- package/es/src/charts/features/sceneBounds.js +271 -0
- package/es/src/charts/features/sceneBounds.js.map +1 -0
- package/es/src/charts/features/shapeEmit.js +20 -2
- package/es/src/charts/features/shapeEmit.js.map +1 -1
- package/es/src/charts/features/tooltipSwatch.js +73 -0
- package/es/src/charts/features/tooltipSwatch.js.map +1 -0
- package/es/src/charts/index.js +1 -0
- package/es/src/charts/index.js.map +1 -1
- package/es/src/charts/pipeline/drillMorph.js +159 -0
- package/es/src/charts/pipeline/drillMorph.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/runChartDraw.js +35 -1
- package/es/src/charts/pipeline/runChartDraw.js.map +1 -1
- package/es/src/charts/pipeline/runVizPipeline.js +22 -3
- package/es/src/charts/pipeline/runVizPipeline.js.map +1 -1
- package/es/src/charts/pipeline/vizDrawPure.js +20 -0
- package/es/src/charts/pipeline/vizDrawPure.js.map +1 -1
- package/es/src/charts/viz/Viz.js +82 -11
- package/es/src/charts/viz/Viz.js.map +1 -1
- package/es/src/charts/viz/VizBase.js +29 -1
- package/es/src/charts/viz/VizBase.js.map +1 -1
- package/es/src/charts/viz/VizBaseConfig.js +25 -21
- 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/ordinalColor.js +2 -2
- package/es/src/charts/viz/ordinalColor.js.map +1 -1
- 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 +39 -15
- package/es/src/charts/viz/vizDefaults.js.map +1 -1
- package/es/src/charts/viz/vizRender.js +54 -4
- package/es/src/charts/viz/vizRender.js.map +1 -1
- package/es/src/charts/viz/vizTypes.js.map +1 -1
- package/es/src/charts/viz/vizVisibility.js +145 -0
- package/es/src/charts/viz/vizVisibility.js.map +1 -0
- package/es/src/components/Axis/Axis.js +8 -8
- package/es/src/components/Axis/Axis.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 +11 -11
- package/es/src/components/ColorScale/ColorScale.js.map +1 -1
- package/es/src/components/ColorScale/colorScaleScale.js +22 -10
- package/es/src/components/ColorScale/colorScaleScale.js.map +1 -1
- package/es/src/components/Legend/Legend.js +8 -5
- package/es/src/components/Legend/Legend.js.map +1 -1
- package/es/src/components/Legend/legendConfig.js +3 -2
- package/es/src/components/Legend/legendConfig.js.map +1 -1
- package/es/src/components/Legend/legendRender.js +70 -26
- package/es/src/components/Legend/legendRender.js.map +1 -1
- package/es/src/components/SizeLegend/SizeLegend.js +411 -0
- package/es/src/components/SizeLegend/SizeLegend.js.map +1 -0
- package/es/src/components/SizeLegend/sizeLegendLayout.js +285 -0
- package/es/src/components/SizeLegend/sizeLegendLayout.js.map +1 -0
- package/es/src/components/TextBox.js +1 -1
- package/es/src/components/TextBox.js.map +1 -1
- package/es/src/components/Timeline/timelineConfig.js +8 -4
- package/es/src/components/Timeline/timelineConfig.js.map +1 -1
- package/es/src/components/Timeline/timelineRender.js +1 -2
- package/es/src/components/Timeline/timelineRender.js.map +1 -1
- package/es/src/components/Tooltip.js +27 -7
- package/es/src/components/Tooltip.js.map +1 -1
- package/es/src/components/index.js +1 -0
- package/es/src/components/index.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 +5 -3
- 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 +10 -37
- package/es/src/shapes/Shape.js.map +1 -1
- package/es/src/shapes/Whisker.js +4 -3
- 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/shapes/validateShapeConfig.js +141 -0
- package/es/src/shapes/validateShapeConfig.js.map +1 -0
- package/es/src/utils/BaseClass.js +134 -4
- package/es/src/utils/BaseClass.js.map +1 -1
- package/es/src/utils/D3plusConfig.js.map +1 -1
- package/es/src/utils/configDefault.js +17 -0
- package/es/src/utils/configDefault.js.map +1 -0
- package/es/src/utils/configPrep.js +2 -1
- package/es/src/utils/configPrep.js.map +1 -1
- package/es/src/utils/configWarnings.js +37 -0
- package/es/src/utils/configWarnings.js.map +1 -0
- package/es/src/utils/index.js +1 -0
- package/es/src/utils/index.js.map +1 -1
- package/package.json +12 -10
- package/types/index.d.ts +5 -4
- package/types/internal.d.ts +15 -1
- package/types/src/charts/BarChart/index.d.ts +2 -1
- package/types/src/charts/Geomap/applyLayout.d.ts +9 -1
- package/types/src/charts/Histogram/binData.d.ts +37 -0
- package/types/src/charts/Histogram/index.d.ts +14 -0
- package/types/src/charts/Network/applyLayout.d.ts +8 -0
- package/types/src/charts/Plot/discreteSpan.d.ts +9 -0
- package/types/src/charts/Plot/index.d.ts +47 -0
- package/types/src/charts/Plot/insetRegion.d.ts +4 -0
- package/types/src/charts/Plot/pipeline.d.ts +14 -0
- package/types/src/charts/Plot/sharedHover.d.ts +84 -0
- package/types/src/charts/Plot/sharedHoverScene.d.ts +11 -0
- package/types/src/charts/Plot/sharedTooltip.d.ts +36 -0
- package/types/src/charts/Plot/stackShareLabels.d.ts +21 -0
- package/types/src/charts/Plot/stackShareTooltip.d.ts +9 -0
- package/types/src/charts/Plot/trendLines.d.ts +90 -0
- package/types/src/charts/Plot/trendProjection.d.ts +28 -0
- package/types/src/charts/Plot/trendScene.d.ts +19 -0
- package/types/src/charts/Plot/trendTooltip.d.ts +30 -0
- package/types/src/charts/Rings/applyLayout.d.ts +9 -0
- package/types/src/charts/Rings/ringsSizing.d.ts +49 -0
- package/types/src/charts/StackedArea/index.d.ts +2 -1
- package/types/src/charts/definition/ChartDefinition.d.ts +39 -0
- package/types/src/charts/definition/makeChart.d.ts +2 -1
- package/types/src/charts/drawSteps/bottomRightControls.d.ts +26 -0
- package/types/src/charts/drawSteps/bottomRightControlsMarkup.d.ts +110 -0
- package/types/src/charts/drawSteps/searchControlsMarkup.d.ts +7 -5
- package/types/src/charts/features/emitHelpers.d.ts +18 -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/plotPaint.d.ts +25 -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/index.d.ts +1 -0
- package/types/src/charts/pipeline/drillMorph.d.ts +29 -0
- package/types/src/charts/pipeline/insetPlacement.d.ts +45 -0
- package/types/src/charts/pipeline/runVizPipeline.d.ts +10 -1
- package/types/src/charts/viz/Viz.d.ts +27 -2
- package/types/src/charts/viz/VizBase.d.ts +13 -0
- package/types/src/charts/viz/VizBaseConfig.d.ts +11 -11
- 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 +164 -3
- package/types/src/charts/viz/vizVisibility.d.ts +34 -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 +9 -3
- package/types/src/components/SizeLegend/SizeLegend.d.ts +107 -0
- package/types/src/components/SizeLegend/sizeLegendLayout.d.ts +101 -0
- package/types/src/components/TextBox.d.ts +1 -1
- package/types/src/components/Tooltip.d.ts +18 -3
- package/types/src/components/index.d.ts +1 -0
- 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/shapes/validateShapeConfig.d.ts +10 -0
- package/types/src/utils/BaseClass.d.ts +15 -1
- package/types/src/utils/D3plusConfig.d.ts +139 -0
- package/types/src/utils/configDefault.d.ts +11 -0
- package/types/src/utils/configWarnings.d.ts +28 -0
- package/types/src/utils/index.d.ts +2 -1
- package/umd/d3plus-core.full.js +9325 -3024
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +3348 -1727
- package/umd/d3plus-core.js +5412 -831
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +2199 -948
|
@@ -8,12 +8,64 @@
|
|
|
8
8
|
function _array_without_holes(arr) {
|
|
9
9
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
10
10
|
}
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
11
24
|
function _iterable_to_array(iter) {
|
|
12
25
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
13
26
|
}
|
|
14
27
|
function _non_iterable_spread() {
|
|
15
28
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
16
29
|
}
|
|
30
|
+
function _object_spread(target) {
|
|
31
|
+
for(var i = 1; i < arguments.length; i++){
|
|
32
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
33
|
+
var ownKeys = Object.keys(source);
|
|
34
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
35
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
36
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
ownKeys.forEach(function(key) {
|
|
40
|
+
_define_property(target, key, source[key]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return target;
|
|
44
|
+
}
|
|
45
|
+
function ownKeys(object, enumerableOnly) {
|
|
46
|
+
var keys = Object.keys(object);
|
|
47
|
+
if (Object.getOwnPropertySymbols) {
|
|
48
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
49
|
+
if (enumerableOnly) {
|
|
50
|
+
symbols = symbols.filter(function(sym) {
|
|
51
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
keys.push.apply(keys, symbols);
|
|
55
|
+
}
|
|
56
|
+
return keys;
|
|
57
|
+
}
|
|
58
|
+
function _object_spread_props(target, source) {
|
|
59
|
+
source = source != null ? source : {};
|
|
60
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
61
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
62
|
+
} else {
|
|
63
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
64
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
17
69
|
function _to_consumable_array(arr) {
|
|
18
70
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
19
71
|
}
|
|
@@ -26,48 +78,241 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
26
78
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
27
79
|
}
|
|
28
80
|
import { colorContrast } from "@d3plus/color";
|
|
81
|
+
import { formatAbbreviate } from "@d3plus/format";
|
|
29
82
|
import { largestRect, path2polygon } from "@d3plus/math";
|
|
30
83
|
import constant from "../../utils/constant.js";
|
|
31
84
|
import { emitLabels } from "../../shapes/emitLabels.js";
|
|
85
|
+
import { userLabelConfig, textureFill, shapeConfigFor } from "../features/emitHelpers.js";
|
|
32
86
|
function resolveAccessor(val, d, i) {
|
|
33
87
|
if (typeof val === "function") {
|
|
34
88
|
return val(d, i);
|
|
35
89
|
}
|
|
36
90
|
return val;
|
|
37
91
|
}
|
|
92
|
+
/** d3.pie()'s default span (Pie/applyLayout.ts never overrides startAngle/endAngle) — the range every slice's own startAngle/endAngle is relative to. */ var FULL_TURN = Math.PI * 2;
|
|
93
|
+
/**
|
|
94
|
+
Builds one wedge's Path SceneNode — pulled out of `pieEmit` to keep that
|
|
95
|
+
function under the file's max-lines-per-function limit. See `pieEmit`'s
|
|
96
|
+
own comments for what `flipFromArc`/`reunionFromArc` are and why.
|
|
97
|
+
*/ function buildPathNode(d, rank, ctx) {
|
|
98
|
+
var _d_i, _d_i1, _d_i2, _d_i3, _d_i4, _d_i5, _d_i6, _d_i7, _d_i8;
|
|
99
|
+
var viz = ctx.viz, arcMaker = ctx.arcMaker, resolveInnerRadius = ctx.resolveInnerRadius, resolveOuterRadius = ctx.resolveOuterRadius, sc = ctx.sc, value = ctx.value, sharePct = ctx.sharePct, flipSource = ctx.flipSource, isReunionDraw = ctx.isReunionDraw;
|
|
100
|
+
var fill = resolveAccessor(sc.fill, d.data, (_d_i = d.i) !== null && _d_i !== void 0 ? _d_i : 0);
|
|
101
|
+
var stroke = resolveAccessor(sc.stroke, d.data, (_d_i1 = d.i) !== null && _d_i1 !== void 0 ? _d_i1 : 0);
|
|
102
|
+
var strokeWidth = resolveAccessor(sc.strokeWidth, d.data, (_d_i2 = d.i) !== null && _d_i2 !== void 0 ? _d_i2 : 0);
|
|
103
|
+
var arc = {
|
|
104
|
+
innerRadius: resolveInnerRadius(d, (_d_i3 = d.i) !== null && _d_i3 !== void 0 ? _d_i3 : 0),
|
|
105
|
+
outerRadius: resolveOuterRadius(d, (_d_i4 = d.i) !== null && _d_i4 !== void 0 ? _d_i4 : 0),
|
|
106
|
+
startAngle: d.startAngle,
|
|
107
|
+
endAngle: d.endAngle,
|
|
108
|
+
padAngle: d.padAngle
|
|
109
|
+
};
|
|
110
|
+
var flipFromArc = flipSource ? _object_spread_props(_object_spread({}, arc), {
|
|
111
|
+
startAngle: flipSource.start + d.startAngle / FULL_TURN * flipSource.span,
|
|
112
|
+
endAngle: flipSource.start + d.endAngle / FULL_TURN * flipSource.span
|
|
113
|
+
}) : undefined;
|
|
114
|
+
var reunionFromArc = isReunionDraw ? _object_spread_props(_object_spread({}, arc), {
|
|
115
|
+
startAngle: 0,
|
|
116
|
+
endAngle: FULL_TURN
|
|
117
|
+
}) : undefined;
|
|
118
|
+
return {
|
|
119
|
+
type: "path",
|
|
120
|
+
key: "pie-".concat(viz._ids(d.data, (_d_i5 = d.i) !== null && _d_i5 !== void 0 ? _d_i5 : 0).join("-")),
|
|
121
|
+
d: arcMaker(d),
|
|
122
|
+
arc: arc,
|
|
123
|
+
flipFromArc: flipFromArc,
|
|
124
|
+
reunionFromArc: reunionFromArc,
|
|
125
|
+
// Lets the render layer's drill-down morph collapse this wedge to/from
|
|
126
|
+
// an external box (isFlipEligible/collapseTo) — the same mechanism
|
|
127
|
+
// StackedArea's shapeType: "Area" bands use.
|
|
128
|
+
shapeType: "Pie",
|
|
129
|
+
// Explicit identity transform (not the field's usual `undefined`) so
|
|
130
|
+
// the SVG backend's transition tweens the "transform" attribute from
|
|
131
|
+
// collapse()/collapseTo()'s scaled-down start toward this real target
|
|
132
|
+
// string — a `null` target attr removes immediately instead of
|
|
133
|
+
// tweening (d3-transition can't interpolate "toward absent"), which
|
|
134
|
+
// would otherwise skip the whole morph animation.
|
|
135
|
+
transform: {
|
|
136
|
+
x: 0,
|
|
137
|
+
y: 0
|
|
138
|
+
},
|
|
139
|
+
// Carried for the NEXT click's capture (click.shape.ts, chart-agnostic)
|
|
140
|
+
// to read off the clicked node — see `_pendingEnterOrigin.parentStartAngle`.
|
|
141
|
+
startAngle: d.startAngle,
|
|
142
|
+
endAngle: d.endAngle,
|
|
143
|
+
datum: d.data,
|
|
144
|
+
paint: {
|
|
145
|
+
fill: textureFill(sc, d.data, (_d_i6 = d.i) !== null && _d_i6 !== void 0 ? _d_i6 : 0, fill),
|
|
146
|
+
stroke: stroke,
|
|
147
|
+
strokeWidth: strokeWidth,
|
|
148
|
+
// Explicit (not the field's usual `undefined`) for the same reason
|
|
149
|
+
// as `transform` above: a plain, non-morph sibling exit's opacity
|
|
150
|
+
// fade (SvgRenderer's `reconcileExit` fast path,
|
|
151
|
+
// `.attr("opacity", 0)`) tweens FROM whatever's already on the live
|
|
152
|
+
// DOM element — an absent attribute reads back as `null`, and
|
|
153
|
+
// d3-interpolate's string interpolator can't align "null" against
|
|
154
|
+
// "0" (a different count of numeric tokens), so it snaps to the
|
|
155
|
+
// target on the very first tick instead of fading. Stamping this
|
|
156
|
+
// wedge's own steady-state opacity here gives every later exit a
|
|
157
|
+
// real starting value to fade from.
|
|
158
|
+
opacity: 1
|
|
159
|
+
},
|
|
160
|
+
aria: {
|
|
161
|
+
label: "".concat(rank + 1, ". ").concat(viz._drawLabel(d.data, (_d_i7 = d.i) !== null && _d_i7 !== void 0 ? _d_i7 : 0), ", ").concat(value(d.data, (_d_i8 = d.i) !== null && _d_i8 !== void 0 ? _d_i8 : 0), ", ").concat(sharePct(d), ".")
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
Marks each label as eligible for the drill-down morph (isFlipEligible),
|
|
167
|
+
so it moves along with its wedge instead of just fading in in place —
|
|
168
|
+
distinct from every other text this chart (or any other) emits
|
|
169
|
+
(title/subtitle/legend), which is never stamped this way and so never
|
|
170
|
+
flip-morphs. When a drill-down click armed `flipSource` (the clicked
|
|
171
|
+
parent's confined angular range), also gives each label a real
|
|
172
|
+
`flipFromTransform` start: the label's own position is already somewhere
|
|
173
|
+
within its wedge's angular span (that's how it got placed there) — so
|
|
174
|
+
remapping its OWN angle linearly into the confined range, at its OWN
|
|
175
|
+
radius, lands it proportionally in the same spot within the confined
|
|
176
|
+
wedge, exactly mirroring `flipFromArc`'s remap of the wedge's
|
|
177
|
+
start/endAngle. No need to look up the owning slice's angles separately.
|
|
178
|
+
*/ function stampLabelFlip(labelNodes, flipSource) {
|
|
179
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
180
|
+
try {
|
|
181
|
+
for(var _iterator = labelNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
182
|
+
var n = _step.value;
|
|
183
|
+
var _tn_transform, _tr_x, _tr_y;
|
|
184
|
+
var tn = n;
|
|
185
|
+
tn.shapeType = "Label";
|
|
186
|
+
if (!flipSource) continue;
|
|
187
|
+
var tr = (_tn_transform = tn.transform) !== null && _tn_transform !== void 0 ? _tn_transform : {};
|
|
188
|
+
var x = (_tr_x = tr.x) !== null && _tr_x !== void 0 ? _tr_x : 0, y = (_tr_y = tr.y) !== null && _tr_y !== void 0 ? _tr_y : 0;
|
|
189
|
+
var radius = Math.hypot(x, y);
|
|
190
|
+
// d3's angle convention: 0 rad = straight up, increasing clockwise —
|
|
191
|
+
// atan2(x, -y) inverts the x = r·sin(θ), y = -r·cos(θ) used below.
|
|
192
|
+
var angle = Math.atan2(x, -y);
|
|
193
|
+
var normalized = angle < 0 ? angle + FULL_TURN : angle;
|
|
194
|
+
var mapped = flipSource.start + normalized / FULL_TURN * flipSource.span;
|
|
195
|
+
tn.flipFromTransform = {
|
|
196
|
+
x: radius * Math.sin(mapped),
|
|
197
|
+
y: -radius * Math.cos(mapped)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
} catch (err) {
|
|
201
|
+
_didIteratorError = true;
|
|
202
|
+
_iteratorError = err;
|
|
203
|
+
} finally{
|
|
204
|
+
try {
|
|
205
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
206
|
+
_iterator.return();
|
|
207
|
+
}
|
|
208
|
+
} finally{
|
|
209
|
+
if (_didIteratorError) {
|
|
210
|
+
throw _iteratorError;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
38
215
|
export var pieEmit = function pieEmit(param) {
|
|
39
216
|
var viz = param.viz, shapeData = param.shapeData;
|
|
40
|
-
var _viz_schema_shapeConfig;
|
|
41
217
|
var slices = shapeData !== null && shapeData !== void 0 ? shapeData : [];
|
|
42
218
|
if (!slices.length) return [];
|
|
43
|
-
var
|
|
44
|
-
var
|
|
219
|
+
var arcGen = viz.ctx.arcData;
|
|
220
|
+
var arcMaker = function arcMaker(d) {
|
|
221
|
+
var _arcGen;
|
|
222
|
+
return (_arcGen = arcGen(d)) !== null && _arcGen !== void 0 ? _arcGen : "";
|
|
223
|
+
};
|
|
224
|
+
var resolveInnerRadius = arcGen.innerRadius();
|
|
225
|
+
var resolveOuterRadius = arcGen.outerRadius();
|
|
226
|
+
var sc = shapeConfigFor(viz, "Path");
|
|
227
|
+
// A drill-down click armed this draw AND the clicked node was itself a Pie
|
|
228
|
+
// wedge (parentStartAngle/parentEndAngle only ever come from this chart's
|
|
229
|
+
// own click capture, via NodeBase.startAngle/endAngle below) — build each
|
|
230
|
+
// entering wedge's real "confined to the parent's old angular slice, at
|
|
231
|
+
// full final radius" start shape, using the actual arc generator (the
|
|
232
|
+
// render layer has none of its own, so it can't reconstruct this).
|
|
233
|
+
var origin = viz._pendingEnterOrigin;
|
|
234
|
+
var parentStart = origin === null || origin === void 0 ? void 0 : origin.parentStartAngle;
|
|
235
|
+
var parentEnd = origin === null || origin === void 0 ? void 0 : origin.parentEndAngle;
|
|
236
|
+
var flipSource = parentStart !== undefined && parentEnd !== undefined ? {
|
|
237
|
+
start: parentStart,
|
|
238
|
+
span: parentEnd - parentStart
|
|
239
|
+
} : undefined;
|
|
240
|
+
// A Back click armed this draw — every entering wedge gets a "full circle,
|
|
241
|
+
// at my own real radii" start built here (the render layer has no arc
|
|
242
|
+
// generator to build one itself); collapseTo only ever actually applies it
|
|
243
|
+
// to the one wedge resolveDrillMorph later resolves as the reunion match,
|
|
244
|
+
// so there's no need to know which slice that'll be yet.
|
|
245
|
+
var isReunionDraw = Boolean(viz._pendingExitReunion);
|
|
45
246
|
var value = viz.schema.value;
|
|
247
|
+
var locale = viz.schema.locale;
|
|
248
|
+
var sharePct = function sharePct(d) {
|
|
249
|
+
var _d_share;
|
|
250
|
+
return "".concat(formatAbbreviate(((_d_share = d.share) !== null && _d_share !== void 0 ? _d_share : 0) * 100, locale), "%");
|
|
251
|
+
};
|
|
252
|
+
var pathCtx = {
|
|
253
|
+
viz: viz,
|
|
254
|
+
arcMaker: arcMaker,
|
|
255
|
+
resolveInnerRadius: resolveInnerRadius,
|
|
256
|
+
resolveOuterRadius: resolveOuterRadius,
|
|
257
|
+
sc: sc,
|
|
258
|
+
value: value,
|
|
259
|
+
sharePct: sharePct,
|
|
260
|
+
flipSource: flipSource,
|
|
261
|
+
isReunionDraw: isReunionDraw
|
|
262
|
+
};
|
|
46
263
|
var pathNodes = slices.map(function(d, rank) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
264
|
+
return buildPathNode(d, rank, pathCtx);
|
|
265
|
+
});
|
|
266
|
+
// Each label sits in its slice's largest inscribed rectangle: the name
|
|
267
|
+
// above and the share percentage below, meeting at the rectangle's center.
|
|
268
|
+
// Short rectangles skip the share line so it can't crowd out the name.
|
|
269
|
+
var labelBoxes = slices.map(function(d) {
|
|
270
|
+
var r = largestRect(path2polygon(arcMaker(d)), {
|
|
271
|
+
angle: 0
|
|
272
|
+
});
|
|
273
|
+
if (!r) return false;
|
|
274
|
+
var x = r.cx - r.width / 2;
|
|
275
|
+
var y = r.cy - r.height / 2;
|
|
276
|
+
if (r.height < 50) return [
|
|
277
|
+
{
|
|
278
|
+
angle: r.angle,
|
|
279
|
+
width: r.width,
|
|
280
|
+
height: r.height,
|
|
281
|
+
x: x,
|
|
282
|
+
y: y
|
|
283
|
+
}
|
|
284
|
+
];
|
|
285
|
+
var padding = 5;
|
|
286
|
+
var band = Math.min(32, (r.height - padding * 2) * 0.3) + padding * 2;
|
|
287
|
+
return [
|
|
288
|
+
{
|
|
289
|
+
angle: r.angle,
|
|
290
|
+
width: r.width,
|
|
291
|
+
height: r.height - band,
|
|
292
|
+
x: x,
|
|
293
|
+
y: y
|
|
60
294
|
},
|
|
61
|
-
|
|
62
|
-
|
|
295
|
+
{
|
|
296
|
+
angle: r.angle,
|
|
297
|
+
width: r.width,
|
|
298
|
+
height: band,
|
|
299
|
+
x: x,
|
|
300
|
+
y: y + r.height - band
|
|
63
301
|
}
|
|
64
|
-
|
|
302
|
+
];
|
|
65
303
|
});
|
|
66
304
|
var labelNodes = emitLabels({
|
|
67
305
|
data: slices,
|
|
68
306
|
label: function label(_d, i) {
|
|
69
307
|
var _slices_i_i;
|
|
70
|
-
|
|
308
|
+
var name = viz._drawLabel(slices[i].data, (_slices_i_i = slices[i].i) !== null && _slices_i_i !== void 0 ? _slices_i_i : i);
|
|
309
|
+
var box = labelBoxes[i];
|
|
310
|
+
return box && box.length > 1 ? [
|
|
311
|
+
name,
|
|
312
|
+
sharePct(slices[i])
|
|
313
|
+
] : [
|
|
314
|
+
name
|
|
315
|
+
];
|
|
71
316
|
},
|
|
72
317
|
// The largest inscribed rectangle is in chart-centered path coordinates,
|
|
73
318
|
// so the anchor is the origin and labelBounds carries the absolute box.
|
|
@@ -85,30 +330,25 @@ export var pieEmit = function pieEmit(param) {
|
|
|
85
330
|
return "pie-label-".concat(i);
|
|
86
331
|
},
|
|
87
332
|
labelBounds: function labelBounds(_d, i) {
|
|
88
|
-
|
|
89
|
-
angle: 0
|
|
90
|
-
});
|
|
91
|
-
if (!r) return false;
|
|
92
|
-
return {
|
|
93
|
-
angle: r.angle,
|
|
94
|
-
width: r.width,
|
|
95
|
-
height: r.height,
|
|
96
|
-
x: r.cx - r.width / 2,
|
|
97
|
-
y: r.cy - r.height / 2
|
|
98
|
-
};
|
|
333
|
+
return labelBoxes[i];
|
|
99
334
|
},
|
|
100
|
-
labelConfig: {
|
|
335
|
+
labelConfig: _object_spread({
|
|
101
336
|
fontColor: function fontColor(d) {
|
|
102
337
|
var _d_data, _slice_i;
|
|
103
338
|
var slice = (_d_data = d.data) !== null && _d_data !== void 0 ? _d_data : d;
|
|
104
339
|
var fill = resolveAccessor(sc.fill, slice.data, (_slice_i = slice.i) !== null && _slice_i !== void 0 ? _slice_i : 0);
|
|
105
|
-
return colorContrast(typeof fill === "string" ? fill : "rgb(255, 255, 255)");
|
|
340
|
+
return colorContrast(typeof fill === "string" ? fill : "rgb(255, 255, 255)", viz.schema.colorDefaults);
|
|
106
341
|
},
|
|
107
342
|
fontResize: true,
|
|
108
343
|
textAnchor: "middle",
|
|
109
|
-
verticalAlign:
|
|
110
|
-
|
|
344
|
+
verticalAlign: function verticalAlign(d) {
|
|
345
|
+
if (d && d.l === 1) return "top";
|
|
346
|
+
var box = d && d.data ? labelBoxes[slices.indexOf(d.data)] : false;
|
|
347
|
+
return box && box.length > 1 ? "bottom" : "middle";
|
|
348
|
+
}
|
|
349
|
+
}, userLabelConfig(viz, "Path"))
|
|
111
350
|
});
|
|
351
|
+
stampLabelFlip(labelNodes, flipSource);
|
|
112
352
|
return _to_consumable_array(pathNodes).concat(_to_consumable_array(labelNodes));
|
|
113
353
|
};
|
|
114
354
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/charts/Pie/emit.ts"],"sourcesContent":["/**\n `pieEmit` — Path SceneNodes (one per slice) + label TextNodes.\n*/\n\nimport type {PieArcDatum} from \"d3-shape\";\nimport {colorContrast} from \"@d3plus/color\";\nimport {largestRect, path2polygon} from \"@d3plus/math\";\nimport type {DataPoint} from \"@d3plus/data\";\nimport type {SceneNode} from \"@d3plus/render\";\n\nimport constant from \"../../utils/constant.js\";\nimport {emitLabels} from \"../../shapes/emitLabels.js\";\nimport type {ChartEmit} from \"../definition/ChartDefinition.js\";\n\nfunction resolveAccessor<T>(\n val: unknown,\n d: DataPoint,\n i: number,\n): T | undefined {\n if (typeof val === \"function\") {\n return (val as (d: DataPoint, i: number) => T)(d, i);\n }\n return val as T | undefined;\n}\n\ntype Slice = PieArcDatum<DataPoint> & {__d3plus__?: true; i?: number};\n\nexport const pieEmit: ChartEmit = ({viz, shapeData}) => {\n const slices = (shapeData ?? []) as Slice[];\n if (!slices.length) return [];\n\n const arcMaker = viz.ctx.arcData as (d: Slice) => string;\n const sc = (viz.schema.shapeConfig ?? {}) as Record<string, unknown>;\n\n const value = viz.schema.value as (d: DataPoint, i: number) => number;\n const pathNodes: SceneNode[] = slices.map((d, rank) => {\n const fill = resolveAccessor<string>(sc.fill, d.data as DataPoint, d.i ?? 0);\n const stroke = resolveAccessor<string>(sc.stroke, d.data as DataPoint, d.i ?? 0);\n const strokeWidth = resolveAccessor<number>(sc.strokeWidth, d.data as DataPoint, d.i ?? 0);\n return {\n type: \"path\",\n key: `pie-${viz._ids(d.data as DataPoint, d.i ?? 0).join(\"-\")}`,\n d: arcMaker(d),\n datum: d.data,\n paint: {\n fill: typeof fill === \"string\" ? fill : undefined,\n stroke,\n strokeWidth,\n },\n aria: {\n label: `${rank + 1}. ${viz._drawLabel(d.data as DataPoint, d.i ?? 0)}, ${value(d.data as DataPoint, d.i ?? 0)}.`,\n },\n } as SceneNode;\n });\n\n const labelNodes = emitLabels({\n data: slices as unknown as DataPoint[],\n label: (_d, i) => viz._drawLabel((slices[i].data as DataPoint), slices[i].i ?? i),\n // The largest inscribed rectangle is in chart-centered path coordinates,\n // so the anchor is the origin and labelBounds carries the absolute box.\n x: () => 0,\n y: () => 0,\n aes: () => ({}),\n rotate: constant(0),\n id: (_d, i) => `pie-label-${i}`,\n labelBounds: (_d, i) => {\n const r = largestRect(path2polygon(arcMaker(slices[i])), {angle: 0});\n if (!r) return false;\n return {\n angle: r.angle,\n width: r.width,\n height: r.height,\n x: r.cx - r.width / 2,\n y: r.cy - r.height / 2,\n };\n },\n labelConfig: {\n fontColor: (d: {data?: Slice}) => {\n const slice = (d.data ?? d) as Slice;\n const fill = resolveAccessor<string>(\n sc.fill,\n slice.data as DataPoint,\n slice.i ?? 0,\n );\n return colorContrast(typeof fill === \"string\" ? fill : \"rgb(255, 255, 255)\");\n },\n fontResize: true,\n textAnchor: \"middle\",\n verticalAlign: \"middle\",\n },\n });\n\n return [...pathNodes, ...labelNodes];\n};\n"],"names":["colorContrast","largestRect","path2polygon","constant","emitLabels","resolveAccessor","val","d","i","pieEmit","viz","shapeData","slices","length","arcMaker","ctx","arcData","sc","schema","shapeConfig","value","pathNodes","map","rank","fill","data","stroke","strokeWidth","type","key","_ids","join","datum","paint","undefined","aria","label","_drawLabel","labelNodes","_d","x","y","aes","rotate","id","labelBounds","r","angle","width","height","cx","cy","labelConfig","fontColor","slice","fontResize","textAnchor","verticalAlign"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAQA,aAAa,QAAO,gBAAgB;AAC5C,SAAQC,WAAW,EAAEC,YAAY,QAAO,eAAe;AAIvD,OAAOC,cAAc,0BAA0B;AAC/C,SAAQC,UAAU,QAAO,6BAA6B;AAGtD,SAASC,gBACPC,GAAY,EACZC,CAAY,EACZC,CAAS;IAET,IAAI,OAAOF,QAAQ,YAAY;QAC7B,OAAO,AAACA,IAAuCC,GAAGC;IACpD;IACA,OAAOF;AACT;AAIA,OAAO,IAAMG,UAAqB;QAAEC,YAAAA,KAAKC,kBAAAA;QAK3BD;IAJZ,IAAME,SAAUD,sBAAAA,uBAAAA,YAAa,EAAE;IAC/B,IAAI,CAACC,OAAOC,MAAM,EAAE,OAAO,EAAE;IAE7B,IAAMC,WAAWJ,I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":["/**\n `pieEmit` — Path SceneNodes (one per slice) + label TextNodes.\n*/\n\nimport type {Arc, PieArcDatum} from \"d3-shape\";\nimport {colorContrast} from \"@d3plus/color\";\nimport {formatAbbreviate} from \"@d3plus/format\";\nimport {largestRect, path2polygon} from \"@d3plus/math\";\nimport type {DataPoint} from \"@d3plus/data\";\nimport type {ArcGeometry, SceneNode, TextNode} from \"@d3plus/render\";\n\nimport constant from \"../../utils/constant.js\";\nimport {emitLabels} from \"../../shapes/emitLabels.js\";\nimport {userLabelConfig, textureFill, shapeConfigFor} from \"../features/emitHelpers.js\";\nimport type {ChartEmit} from \"../definition/ChartDefinition.js\";\n\nfunction resolveAccessor<T>(\n val: unknown,\n d: DataPoint,\n i: number,\n): T | undefined {\n if (typeof val === \"function\") {\n return (val as (d: DataPoint, i: number) => T)(d, i);\n }\n return val as T | undefined;\n}\n\ntype Slice = PieArcDatum<DataPoint> & {\n __d3plus__?: true;\n i?: number;\n share?: number;\n};\n\n/** d3.pie()'s default span (Pie/applyLayout.ts never overrides startAngle/endAngle) — the range every slice's own startAngle/endAngle is relative to. */\nconst FULL_TURN = Math.PI * 2;\n\n/** Shared, per-draw context `buildPathNode` needs for every slice — bundled to keep its own parameter list short. */\ninterface PathNodeCtx {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- VizContext.viz is deliberately `any` (see ChartEmit's definition); threaded through unchanged.\n viz: any;\n arcMaker: (d: Slice) => string;\n resolveInnerRadius: (d: Slice, i: number) => number;\n resolveOuterRadius: (d: Slice, i: number) => number;\n sc: Record<string, unknown>;\n value: (d: DataPoint, i: number) => number;\n sharePct: (d: Slice) => string;\n /** The clicked parent's confined angular range (a forward drill click), if this draw is one. */\n flipSource: {start: number; span: number} | undefined;\n /** Whether a Back click armed this draw (see `pieEmit`'s own comment on `isReunionDraw`). */\n isReunionDraw: boolean;\n}\n\n/**\n Builds one wedge's Path SceneNode — pulled out of `pieEmit` to keep that\n function under the file's max-lines-per-function limit. See `pieEmit`'s\n own comments for what `flipFromArc`/`reunionFromArc` are and why.\n*/\nfunction buildPathNode(d: Slice, rank: number, ctx: PathNodeCtx): SceneNode {\n const {viz, arcMaker, resolveInnerRadius, resolveOuterRadius, sc, value, sharePct, flipSource, isReunionDraw} = ctx;\n const fill = resolveAccessor<string>(sc.fill, d.data as DataPoint, d.i ?? 0);\n const stroke = resolveAccessor<string>(sc.stroke, d.data as DataPoint, d.i ?? 0);\n const strokeWidth = resolveAccessor<number>(sc.strokeWidth, d.data as DataPoint, d.i ?? 0);\n const arc: ArcGeometry = {\n innerRadius: resolveInnerRadius(d, d.i ?? 0),\n outerRadius: resolveOuterRadius(d, d.i ?? 0),\n startAngle: d.startAngle,\n endAngle: d.endAngle,\n padAngle: d.padAngle,\n };\n const flipFromArc: ArcGeometry | undefined = flipSource\n ? {\n ...arc,\n startAngle: flipSource.start + (d.startAngle / FULL_TURN) * flipSource.span,\n endAngle: flipSource.start + (d.endAngle / FULL_TURN) * flipSource.span,\n }\n : undefined;\n const reunionFromArc: ArcGeometry | undefined = isReunionDraw\n ? {...arc, startAngle: 0, endAngle: FULL_TURN}\n : undefined;\n return {\n type: \"path\",\n key: `pie-${viz._ids(d.data as DataPoint, d.i ?? 0).join(\"-\")}`,\n d: arcMaker(d),\n arc,\n flipFromArc,\n reunionFromArc,\n // Lets the render layer's drill-down morph collapse this wedge to/from\n // an external box (isFlipEligible/collapseTo) — the same mechanism\n // StackedArea's shapeType: \"Area\" bands use.\n shapeType: \"Pie\",\n // Explicit identity transform (not the field's usual `undefined`) so\n // the SVG backend's transition tweens the \"transform\" attribute from\n // collapse()/collapseTo()'s scaled-down start toward this real target\n // string — a `null` target attr removes immediately instead of\n // tweening (d3-transition can't interpolate \"toward absent\"), which\n // would otherwise skip the whole morph animation.\n transform: {x: 0, y: 0},\n // Carried for the NEXT click's capture (click.shape.ts, chart-agnostic)\n // to read off the clicked node — see `_pendingEnterOrigin.parentStartAngle`.\n startAngle: d.startAngle,\n endAngle: d.endAngle,\n datum: d.data,\n paint: {\n fill: textureFill(sc, d.data as DataPoint, d.i ?? 0, fill),\n stroke,\n strokeWidth,\n // Explicit (not the field's usual `undefined`) for the same reason\n // as `transform` above: a plain, non-morph sibling exit's opacity\n // fade (SvgRenderer's `reconcileExit` fast path,\n // `.attr(\"opacity\", 0)`) tweens FROM whatever's already on the live\n // DOM element — an absent attribute reads back as `null`, and\n // d3-interpolate's string interpolator can't align \"null\" against\n // \"0\" (a different count of numeric tokens), so it snaps to the\n // target on the very first tick instead of fading. Stamping this\n // wedge's own steady-state opacity here gives every later exit a\n // real starting value to fade from.\n opacity: 1,\n },\n aria: {\n label: `${rank + 1}. ${viz._drawLabel(d.data as DataPoint, d.i ?? 0)}, ${value(d.data as DataPoint, d.i ?? 0)}, ${sharePct(d)}.`,\n },\n } as SceneNode;\n}\n\n/**\n Marks each label as eligible for the drill-down morph (isFlipEligible),\n so it moves along with its wedge instead of just fading in in place —\n distinct from every other text this chart (or any other) emits\n (title/subtitle/legend), which is never stamped this way and so never\n flip-morphs. When a drill-down click armed `flipSource` (the clicked\n parent's confined angular range), also gives each label a real\n `flipFromTransform` start: the label's own position is already somewhere\n within its wedge's angular span (that's how it got placed there) — so\n remapping its OWN angle linearly into the confined range, at its OWN\n radius, lands it proportionally in the same spot within the confined\n wedge, exactly mirroring `flipFromArc`'s remap of the wedge's\n start/endAngle. No need to look up the owning slice's angles separately.\n*/\nfunction stampLabelFlip(\n labelNodes: SceneNode[],\n flipSource: {start: number; span: number} | undefined,\n): void {\n for (const n of labelNodes) {\n const tn = n as TextNode;\n tn.shapeType = \"Label\";\n if (!flipSource) continue;\n const tr = tn.transform ?? {};\n const x = tr.x ?? 0, y = tr.y ?? 0;\n const radius = Math.hypot(x, y);\n // d3's angle convention: 0 rad = straight up, increasing clockwise —\n // atan2(x, -y) inverts the x = r·sin(θ), y = -r·cos(θ) used below.\n const angle = Math.atan2(x, -y);\n const normalized = angle < 0 ? angle + FULL_TURN : angle;\n const mapped = flipSource.start + (normalized / FULL_TURN) * flipSource.span;\n tn.flipFromTransform = {x: radius * Math.sin(mapped), y: -radius * Math.cos(mapped)};\n }\n}\n\nexport const pieEmit: ChartEmit = ({viz, shapeData}) => {\n const slices = (shapeData ?? []) as Slice[];\n if (!slices.length) return [];\n\n const arcGen = viz.ctx.arcData as Arc<unknown, Slice>;\n const arcMaker = (d: Slice) => arcGen(d) ?? \"\";\n const resolveInnerRadius = arcGen.innerRadius();\n const resolveOuterRadius = arcGen.outerRadius();\n const sc = shapeConfigFor(viz, \"Path\");\n\n // A drill-down click armed this draw AND the clicked node was itself a Pie\n // wedge (parentStartAngle/parentEndAngle only ever come from this chart's\n // own click capture, via NodeBase.startAngle/endAngle below) — build each\n // entering wedge's real \"confined to the parent's old angular slice, at\n // full final radius\" start shape, using the actual arc generator (the\n // render layer has none of its own, so it can't reconstruct this).\n const origin = viz._pendingEnterOrigin as\n | {parentStartAngle?: number; parentEndAngle?: number}\n | undefined;\n const parentStart = origin?.parentStartAngle;\n const parentEnd = origin?.parentEndAngle;\n const flipSource = parentStart !== undefined && parentEnd !== undefined\n ? {start: parentStart, span: parentEnd - parentStart}\n : undefined;\n\n // A Back click armed this draw — every entering wedge gets a \"full circle,\n // at my own real radii\" start built here (the render layer has no arc\n // generator to build one itself); collapseTo only ever actually applies it\n // to the one wedge resolveDrillMorph later resolves as the reunion match,\n // so there's no need to know which slice that'll be yet.\n const isReunionDraw = Boolean(viz._pendingExitReunion);\n\n const value = viz.schema.value as (d: DataPoint, i: number) => number;\n const locale = viz.schema.locale;\n const sharePct = (d: Slice) => `${formatAbbreviate((d.share ?? 0) * 100, locale)}%`;\n const pathCtx: PathNodeCtx = {\n viz, arcMaker, resolveInnerRadius, resolveOuterRadius, sc, value, sharePct, flipSource, isReunionDraw,\n };\n const pathNodes: SceneNode[] = slices.map((d, rank) => buildPathNode(d, rank, pathCtx));\n\n // Each label sits in its slice's largest inscribed rectangle: the name\n // above and the share percentage below, meeting at the rectangle's center.\n // Short rectangles skip the share line so it can't crowd out the name.\n const labelBoxes = slices.map(d => {\n const r = largestRect(path2polygon(arcMaker(d)), {angle: 0});\n if (!r) return false;\n const x = r.cx - r.width / 2;\n const y = r.cy - r.height / 2;\n if (r.height < 50) return [{angle: r.angle, width: r.width, height: r.height, x, y}];\n const padding = 5;\n const band = Math.min(32, (r.height - padding * 2) * 0.3) + padding * 2;\n return [\n {angle: r.angle, width: r.width, height: r.height - band, x, y},\n {angle: r.angle, width: r.width, height: band, x, y: y + r.height - band},\n ];\n });\n\n const labelNodes = emitLabels({\n data: slices as unknown as DataPoint[],\n label: (_d, i) => {\n const name = viz._drawLabel(slices[i].data as DataPoint, slices[i].i ?? i);\n const box = labelBoxes[i];\n return box && box.length > 1 ? [name, sharePct(slices[i])] : [name];\n },\n // The largest inscribed rectangle is in chart-centered path coordinates,\n // so the anchor is the origin and labelBounds carries the absolute box.\n x: () => 0,\n y: () => 0,\n aes: () => ({}),\n rotate: constant(0),\n id: (_d, i) => `pie-label-${i}`,\n labelBounds: (_d, i) => labelBoxes[i],\n labelConfig: {\n fontColor: (d: {data?: Slice}) => {\n const slice = (d.data ?? d) as Slice;\n const fill = resolveAccessor<string>(\n sc.fill,\n slice.data as DataPoint,\n slice.i ?? 0,\n );\n return colorContrast(typeof fill === \"string\" ? fill : \"rgb(255, 255, 255)\", viz.schema.colorDefaults);\n },\n fontResize: true,\n textAnchor: \"middle\",\n verticalAlign: (d: {data?: Slice; l?: number}) => {\n if (d && d.l === 1) return \"top\";\n const box = d && d.data ? labelBoxes[slices.indexOf(d.data)] : false;\n return box && box.length > 1 ? \"bottom\" : \"middle\";\n },\n ...userLabelConfig(viz, \"Path\"),\n },\n });\n\n stampLabelFlip(labelNodes, flipSource);\n\n return [...pathNodes, ...labelNodes];\n};\n"],"names":["colorContrast","formatAbbreviate","largestRect","path2polygon","constant","emitLabels","userLabelConfig","textureFill","shapeConfigFor","resolveAccessor","val","d","i","FULL_TURN","Math","PI","buildPathNode","rank","ctx","viz","arcMaker","resolveInnerRadius","resolveOuterRadius","sc","value","sharePct","flipSource","isReunionDraw","fill","data","stroke","strokeWidth","arc","innerRadius","outerRadius","startAngle","endAngle","padAngle","flipFromArc","start","span","undefined","reunionFromArc","type","key","_ids","join","shapeType","transform","x","y","datum","paint","opacity","aria","label","_drawLabel","stampLabelFlip","labelNodes","n","tn","tr","radius","hypot","angle","atan2","normalized","mapped","flipFromTransform","sin","cos","pieEmit","shapeData","slices","length","arcGen","arcData","origin","_pendingEnterOrigin","parentStart","parentStartAngle","parentEnd","parentEndAngle","Boolean","_pendingExitReunion","schema","locale","share","pathCtx","pathNodes","map","labelBoxes","r","cx","width","cy","height","padding","band","min","_d","name","box","aes","rotate","id","labelBounds","labelConfig","fontColor","slice","colorDefaults","fontResize","textAnchor","verticalAlign","l","indexOf"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAQA,aAAa,QAAO,gBAAgB;AAC5C,SAAQC,gBAAgB,QAAO,iBAAiB;AAChD,SAAQC,WAAW,EAAEC,YAAY,QAAO,eAAe;AAIvD,OAAOC,cAAc,0BAA0B;AAC/C,SAAQC,UAAU,QAAO,6BAA6B;AACtD,SAAQC,eAAe,EAAEC,WAAW,EAAEC,cAAc,QAAO,6BAA6B;AAGxF,SAASC,gBACPC,GAAY,EACZC,CAAY,EACZC,CAAS;IAET,IAAI,OAAOF,QAAQ,YAAY;QAC7B,OAAO,AAACA,IAAuCC,GAAGC;IACpD;IACA,OAAOF;AACT;AAQA,uJAAuJ,GACvJ,IAAMG,YAAYC,KAAKC,EAAE,GAAG;AAkB5B;;;;AAIA,GACA,SAASC,cAAcL,CAAQ,EAAEM,IAAY,EAAEC,GAAgB;QAEMP,MACIA,OACUA,OAE5CA,OACAA,OAiBOA,OAsBGA,OAgBgBA,OAAyCA;IA7DxG,IAAOQ,MAAyGD,IAAzGC,KAAKC,WAAoG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5B8F,aAAa,SAAbA,YAAcN,IAAIxF;mBAAM+E,UAAU,CAAC/E,EAAE;;QACrC+F,aAAa;YACXC,WAAW,SAAXA,UAAYjG;oBACKA,SAIbkG;gBAJF,IAAMA,SAASlG,UAAAA,EAAEkB,IAAI,cAANlB,qBAAAA,UAAUA;gBACzB,IAAMiB,OAAOnB,gBACXc,GAAGK,IAAI,EACPiF,MAAMhF,IAAI,GACVgF,WAAAA,MAAMjG,CAAC,cAAPiG,sBAAAA,WAAW;gBAEb,OAAO7G,cAAc,OAAO4B,SAAS,WAAWA,OAAO,sBAAsBT,IAAIkE,MAAM,CAACyB,aAAa;YACvG;YACAC,YAAY;YACZC,YAAY;YACZC,eAAe,SAAfA,cAAgBtG;gBACd,IAAIA,KAAKA,EAAEuG,CAAC,KAAK,GAAG,OAAO;gBAC3B,IAAMZ,MAAM3F,KAAKA,EAAEkB,IAAI,GAAG8D,UAAU,CAAClB,OAAO0C,OAAO,CAACxG,EAAEkB,IAAI,EAAE,GAAG;gBAC/D,OAAOyE,OAAOA,IAAI5B,MAAM,GAAG,IAAI,WAAW;YAC5C;WACGpE,gBAAgBa,KAAK;IAE5B;IAEAsC,eAAeC,YAAYhC;IAE3B,OAAO,AAAC,qBAAG+D,kBAAW,qBAAG/B;AAC3B,EAAE"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
- `applyLayout.ts` — chart-specific `TransformStage`.
|
|
6
6
|
- `emit.ts` — Path + label scene nodes from the laid-out slices.
|
|
7
7
|
*/ import { pie as d3Pie } from "d3-shape";
|
|
8
|
+
import { backgroundColor } from "@d3plus/dom";
|
|
8
9
|
import { formatAbbreviate } from "@d3plus/format";
|
|
9
10
|
import accessor from "../../utils/accessor.js";
|
|
10
11
|
import { centerChartTransform } from "../features/chartGeometry.js";
|
|
@@ -13,6 +14,7 @@ import { colorScaleBucketShare } from "../features/colorScaleBucket.js";
|
|
|
13
14
|
import { makeChart } from "../definition/makeChart.js";
|
|
14
15
|
import { applyPieLayout } from "./applyLayout.js";
|
|
15
16
|
import { pieEmit } from "./emit.js";
|
|
17
|
+
import { sceneInsetRegion } from "../pipeline/insetPlacement.js";
|
|
16
18
|
export var pieDef = {
|
|
17
19
|
name: "Pie",
|
|
18
20
|
features: [
|
|
@@ -22,9 +24,35 @@ export var pieDef = {
|
|
|
22
24
|
],
|
|
23
25
|
layoutStage: applyPieLayout,
|
|
24
26
|
emit: pieEmit,
|
|
27
|
+
insetRegion: sceneInsetRegion,
|
|
25
28
|
chartTransform: function chartTransform(viz) {
|
|
26
29
|
return centerChartTransform(viz, viz.ctx.pieWidth, viz.ctx.pieHeight);
|
|
27
30
|
},
|
|
31
|
+
// Pie's chartTransform centers the origin — wedges are drawn in
|
|
32
|
+
// [-pieWidth/2, pieWidth/2] × [-pieHeight/2, pieHeight/2], not the
|
|
33
|
+
// top-left-origin box the default chartBodyRect assumes (that default is
|
|
34
|
+
// only correct for a marginOriginTransform chart like Treemap). Without
|
|
35
|
+
// this override, the drill-down morph's enter/exit fractions would be
|
|
36
|
+
// computed against the wrong origin.
|
|
37
|
+
//
|
|
38
|
+
// Uses the TIGHT circle (radius = pieOuterRadius, applyPieLayout's own
|
|
39
|
+
// actual, buffer-reduced outerRadius — see its comment on strokeBuffer)
|
|
40
|
+
// rather than the loose pieWidth × pieHeight box: pieWidth/pieHeight is
|
|
41
|
+
// the available space (not square when the chart area isn't, and larger
|
|
42
|
+
// than the wedges' real size by the hover-stroke buffer), and the
|
|
43
|
+
// drill-down morph's proportional remap (collapseTo's shapeType "Pie"
|
|
44
|
+
// case) uses this as the "whole pie" reference — a mismatched reference
|
|
45
|
+
// would stretch the circle into an ellipse, or off-scale it, as it grows.
|
|
46
|
+
chartBodyRect: function chartBodyRect(viz) {
|
|
47
|
+
var _viz_ctx_pieOuterRadius;
|
|
48
|
+
var r = (_viz_ctx_pieOuterRadius = viz.ctx.pieOuterRadius) !== null && _viz_ctx_pieOuterRadius !== void 0 ? _viz_ctx_pieOuterRadius : 0;
|
|
49
|
+
return {
|
|
50
|
+
x: -r,
|
|
51
|
+
y: -r,
|
|
52
|
+
width: r * 2,
|
|
53
|
+
height: r * 2
|
|
54
|
+
};
|
|
55
|
+
},
|
|
28
56
|
ctx: {
|
|
29
57
|
pie: d3Pie()
|
|
30
58
|
},
|
|
@@ -36,6 +64,12 @@ export var pieDef = {
|
|
|
36
64
|
{
|
|
37
65
|
key: "padAngle"
|
|
38
66
|
},
|
|
67
|
+
// Not used for the default wedge-to-wedge gap (see shapeConfig's
|
|
68
|
+
// stroke/strokeWidth below) — an angular gap's LINEAR width is
|
|
69
|
+
// proportional to radius, so it inevitably tapers to nothing as it
|
|
70
|
+
// approaches the pie's center, which a full (non-donut) Pie always
|
|
71
|
+
// touches. Left at 0; still available for a user who explicitly wants
|
|
72
|
+
// the angular look anyway.
|
|
39
73
|
{
|
|
40
74
|
key: "padPixel",
|
|
41
75
|
default: 0
|
|
@@ -79,7 +113,20 @@ export var pieDef = {
|
|
|
79
113
|
labelConfig: {
|
|
80
114
|
fontResize: true
|
|
81
115
|
}
|
|
82
|
-
}
|
|
116
|
+
},
|
|
117
|
+
// A visual, constant-WIDTH gap between wedges: an SVG stroke is
|
|
118
|
+
// measured in screen pixels regardless of the underlying path's
|
|
119
|
+
// radius, unlike padAngle (see padPixel's default above), so
|
|
120
|
+
// matching it to the chart's own background color "cuts out" an
|
|
121
|
+
// even border everywhere — including near the center, where an
|
|
122
|
+
// angular gap has nowhere left to taper from. Centered on each
|
|
123
|
+
// wedge's outline (SVG's default), so half its width falls on each
|
|
124
|
+
// side of an edge shared with a neighbor.
|
|
125
|
+
stroke: function stroke() {
|
|
126
|
+
var _viz__select;
|
|
127
|
+
return backgroundColor((_viz__select = viz._select) === null || _viz__select === void 0 ? void 0 : _viz__select.node());
|
|
128
|
+
},
|
|
129
|
+
strokeWidth: 2
|
|
83
130
|
};
|
|
84
131
|
}
|
|
85
132
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/charts/Pie/index.ts"],"sourcesContent":["/**\n Pie — d3-shape pie layout, one path per slice.\n\n Implementation files in this folder:\n - `applyLayout.ts` — chart-specific `TransformStage`.\n - `emit.ts` — Path + label scene nodes from the laid-out slices.\n*/\n\nimport {pie as d3Pie} from \"d3-shape\";\nimport {formatAbbreviate} from \"@d3plus/format\";\nimport type {DataPoint} from \"@d3plus/data\";\n\nimport accessor from \"../../utils/accessor.js\";\nimport {centerChartTransform} from \"../features/chartGeometry.js\";\nimport {subtitleFeature, titleFeature, totalFeature} from \"../features/features.js\";\nimport {colorScaleBucketShare} from \"../features/colorScaleBucket.js\";\nimport type {DataDrivenChartDefinition} from \"../definition/ChartDefinition.js\";\nimport type {D3plusConfig} from \"../../utils/D3plusConfig.js\";\nimport {makeChart} from \"../definition/makeChart.js\";\nimport type {VizInstance} from \"../viz/vizTypes.js\";\n\nimport {applyPieLayout} from \"./applyLayout.js\";\nimport {pieEmit} from \"./emit.js\";\n\nexport const pieDef: DataDrivenChartDefinition = {\n name: \"Pie\",\n\n features: [titleFeature, subtitleFeature, totalFeature],\n layoutStage: applyPieLayout,\n emit: pieEmit,\n\n chartTransform: (viz: VizInstance) =>\n centerChartTransform(\n viz,\n viz.ctx.pieWidth as number,\n viz.ctx.pieHeight as number,\n ),\n\n ctx: {\n pie: d3Pie(),\n },\n\n fields: [\n {key: \"innerRadius\", default: 0},\n {key: \"padAngle\"},\n {key: \"padPixel\", default: 0},\n {\n key: \"value\",\n default: accessor(\"value\"),\n coerce: v => (typeof v === \"function\" ? v : accessor(v as string)),\n },\n {\n key: \"sort\",\n factory: (viz: VizInstance) => {\n const valueFn = viz.schema.value as (d: DataPoint) => number;\n return (a: DataPoint, b: DataPoint) => valueFn(b) - valueFn(a);\n },\n },\n {\n key: \"legendSort\",\n factory: (viz: VizInstance) => {\n const valueFn = viz.schema.value as (d: DataPoint) => number;\n return (a: DataPoint, b: DataPoint) => valueFn(b) - valueFn(a);\n },\n },\n {\n key: \"shapeConfig\",\n merge: true,\n factory: (viz: VizInstance) => ({\n ariaLabel: (d: DataPoint, i: number) => {\n const pieData = viz.ctx.pieData as {index: number}[] | undefined;\n if (!pieData) return \"\";\n return `${++pieData[i].index}. ${viz._drawLabel(d, i)}, ${(viz.schema.value as (d: DataPoint, i: number) => number)(d, i)}.`;\n },\n Path: {labelConfig: {fontResize: true}},\n }),\n },\n {\n key: \"tooltipConfig\",\n merge: true,\n factory: (viz: VizInstance) => ({\n tbody: [\n [\n () => viz.schema.translate(\"Share\"),\n (_d: DataPoint, _i: number, x: Record<string, unknown>) => {\n // A ColorScale range swatch carries no per-row share, so sum the\n // share of every datum that falls in its color range.\n if (x._isColorScaleBucket) {\n const s = colorScaleBucketShare(\n viz,\n x.color,\n viz.schema.value as (d: DataPoint, i: number) => number,\n );\n return s == null\n ? \"\"\n : `${formatAbbreviate(s * 100, viz.schema.locale)}%`;\n }\n // A Legend bucket aggregates multiple rows, so `share` arrives\n // as an array of the members' shares — sum it; a single cell's\n // share is a plain number.\n const share = Array.isArray(x.share)\n ? (x.share as number[]).reduce((a, b) => a + b, 0)\n : (x.share as number);\n if (!Number.isFinite(share)) return \"\";\n return `${formatAbbreviate(share * 100, viz.schema.locale)}%`;\n },\n ],\n ],\n }),\n },\n {\n key: \"legend\",\n coerce: \"const\",\n factory: (viz: VizInstance) => {\n const base = viz.schema.legend as (config: D3plusConfig, arr: DataPoint[]) => unknown;\n return (config: D3plusConfig, arr: DataPoint[]) => {\n if (arr.length === viz._filteredData.length) return false;\n return base.call(viz, config, arr);\n };\n },\n },\n ],\n};\n\n/**\n Uses the d3 pie layout to create SVG arcs based on an array of data.\n*/\nexport default makeChart(pieDef);\n"],"names":["pie","d3Pie","formatAbbreviate","accessor","centerChartTransform","subtitleFeature","titleFeature","totalFeature","colorScaleBucketShare","makeChart","applyPieLayout","pieEmit","pieDef","name","features","layoutStage","emit","chartTransform","viz","ctx","pieWidth","pieHeight","fields","key","default","coerce","v","factory","valueFn","schema","value","a","b","merge","ariaLabel","d","i","pieData","index","_drawLabel","Path","labelConfig","fontResize","tbody","translate","_d","_i","x","_isColorScaleBucket","s","color","locale","share","Array","isArray","reduce","Number","isFinite","base","legend","config","arr","length","_filteredData","call"],"mappings":"AAAA;;;;;;AAMA,GAEA,SAAQA,OAAOC,KAAK,QAAO,WAAW;AACtC,SAAQC,gBAAgB,QAAO,iBAAiB;AAGhD,OAAOC,cAAc,0BAA0B;AAC/C,SAAQC,oBAAoB,QAAO,+BAA+B;AAClE,SAAQC,eAAe,EAAEC,YAAY,EAAEC,YAAY,QAAO,0BAA0B;AACpF,SAAQC,qBAAqB,QAAO,kCAAkC;AAGtE,SAAQC,SAAS,QAAO,6BAA6B;AAGrD,SAAQC,cAAc,QAAO,mBAAmB;AAChD,SAAQC,OAAO,QAAO,YAAY;AAElC,OAAO,IAAMC,SAAoC;IAC/CC,MAAM;IAENC,UAAU;QAACR;QAAcD;QAAiBE;KAAa;IACvDQ,aAAaL;IACbM,MAAML;IAENM,gBAAgB,SAAhBA,eAAiBC;eACfd,qBACEc,KACAA,IAAIC,GAAG,CAACC,QAAQ,EAChBF,IAAIC,GAAG,CAACE,SAAS;;IAGrBF,KAAK;QACHnB,KAAKC;IACP;IAEAqB,QAAQ;QACN;YAACC,KAAK;YAAeC,SAAS;QAAC;QAC/B;YAACD,KAAK;QAAU;QAChB;YAACA,KAAK;YAAYC,SAAS;QAAC;QAC5B;YACED,KAAK;YACLC,SAASrB,SAAS;YAClBsB,QAAQC,SAARD,OAAQC;uBAAM,OAAOA,MAAM,aAAaA,IAAIvB,SAASuB;;QACvD;QACA;YACEH,KAAK;YACLI,SAAS,SAATA,QAAUT;gBACR,IAAMU,UAAUV,IAAIW,MAAM,CAACC,KAAK;gBAChC,OAAO,SAACC,GAAcC;2BAAiBJ,QAAQI,KAAKJ,QAAQG;;YAC9D;QACF;QACA;YACER,KAAK;YACLI,SAAS,SAATA,QAAUT;gBACR,IAAMU,UAAUV,IAAIW,MAAM,CAACC,KAAK;gBA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OAAO,AAAC,GAAmD,OAAjDlD,iBAAiBkD,QAAQ,KAAKlC,IAAIW,MAAM,CAACsB,MAAM,GAAE;4BAC7D;yBACD;qBACF;gBACH;;QACF;QACA;YACE5B,KAAK;YACLE,QAAQ;YACRE,SAAS,SAATA,QAAUT;gBACR,IAAMwC,OAAOxC,IAAIW,MAAM,CAAC8B,MAAM;gBAC9B,OAAO,SAACC,QAAsBC;oBAC5B,IAAIA,IAAIC,MAAM,KAAK5C,IAAI6C,aAAa,CAACD,MAAM,EAAE,OAAO;oBACpD,OAAOJ,KAAKM,IAAI,CAAC9C,KAAK0C,QAAQC;gBAChC;YACF;QACF;KACD;AACH,EAAE;AAEF;;AAEA,GACA,eAAepD,UAAUG,QAAQ"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/charts/Pie/index.ts"],"sourcesContent":["/**\n Pie — d3-shape pie layout, one path per slice.\n\n Implementation files in this folder:\n - `applyLayout.ts` — chart-specific `TransformStage`.\n - `emit.ts` — Path + label scene nodes from the laid-out slices.\n*/\n\nimport {pie as d3Pie} from \"d3-shape\";\nimport {backgroundColor} from \"@d3plus/dom\";\nimport {formatAbbreviate} from \"@d3plus/format\";\nimport type {DataPoint} from \"@d3plus/data\";\n\nimport accessor from \"../../utils/accessor.js\";\nimport {centerChartTransform} from \"../features/chartGeometry.js\";\nimport {subtitleFeature, titleFeature, totalFeature} from \"../features/features.js\";\nimport {colorScaleBucketShare} from \"../features/colorScaleBucket.js\";\nimport type {DataDrivenChartDefinition} from \"../definition/ChartDefinition.js\";\nimport type {D3plusConfig} from \"../../utils/D3plusConfig.js\";\nimport {makeChart} from \"../definition/makeChart.js\";\nimport type {VizInstance} from \"../viz/vizTypes.js\";\n\nimport {applyPieLayout} from \"./applyLayout.js\";\nimport {pieEmit} from \"./emit.js\";\nimport {sceneInsetRegion} from \"../pipeline/insetPlacement.js\";\n\nexport const pieDef: DataDrivenChartDefinition = {\n name: \"Pie\",\n\n features: [titleFeature, subtitleFeature, totalFeature],\n layoutStage: applyPieLayout,\n emit: pieEmit,\n insetRegion: sceneInsetRegion,\n\n chartTransform: (viz: VizInstance) =>\n centerChartTransform(\n viz,\n viz.ctx.pieWidth as number,\n viz.ctx.pieHeight as number,\n ),\n\n // Pie's chartTransform centers the origin — wedges are drawn in\n // [-pieWidth/2, pieWidth/2] × [-pieHeight/2, pieHeight/2], not the\n // top-left-origin box the default chartBodyRect assumes (that default is\n // only correct for a marginOriginTransform chart like Treemap). Without\n // this override, the drill-down morph's enter/exit fractions would be\n // computed against the wrong origin.\n //\n // Uses the TIGHT circle (radius = pieOuterRadius, applyPieLayout's own\n // actual, buffer-reduced outerRadius — see its comment on strokeBuffer)\n // rather than the loose pieWidth × pieHeight box: pieWidth/pieHeight is\n // the available space (not square when the chart area isn't, and larger\n // than the wedges' real size by the hover-stroke buffer), and the\n // drill-down morph's proportional remap (collapseTo's shapeType \"Pie\"\n // case) uses this as the \"whole pie\" reference — a mismatched reference\n // would stretch the circle into an ellipse, or off-scale it, as it grows.\n chartBodyRect: (viz: VizInstance) => {\n const r = (viz.ctx.pieOuterRadius as number) ?? 0;\n return {x: -r, y: -r, width: r * 2, height: r * 2};\n },\n\n ctx: {\n pie: d3Pie(),\n },\n\n fields: [\n {key: \"innerRadius\", default: 0},\n {key: \"padAngle\"},\n // Not used for the default wedge-to-wedge gap (see shapeConfig's\n // stroke/strokeWidth below) — an angular gap's LINEAR width is\n // proportional to radius, so it inevitably tapers to nothing as it\n // approaches the pie's center, which a full (non-donut) Pie always\n // touches. Left at 0; still available for a user who explicitly wants\n // the angular look anyway.\n {key: \"padPixel\", default: 0},\n {\n key: \"value\",\n default: accessor(\"value\"),\n coerce: v => (typeof v === \"function\" ? v : accessor(v as string)),\n },\n {\n key: \"sort\",\n factory: (viz: VizInstance) => {\n const valueFn = viz.schema.value as (d: DataPoint) => number;\n return (a: DataPoint, b: DataPoint) => valueFn(b) - valueFn(a);\n },\n },\n {\n key: \"legendSort\",\n factory: (viz: VizInstance) => {\n const valueFn = viz.schema.value as (d: DataPoint) => number;\n return (a: DataPoint, b: DataPoint) => valueFn(b) - valueFn(a);\n },\n },\n {\n key: \"shapeConfig\",\n merge: true,\n factory: (viz: VizInstance) => ({\n ariaLabel: (d: DataPoint, i: number) => {\n const pieData = viz.ctx.pieData as {index: number}[] | undefined;\n if (!pieData) return \"\";\n return `${++pieData[i].index}. ${viz._drawLabel(d, i)}, ${(viz.schema.value as (d: DataPoint, i: number) => number)(d, i)}.`;\n },\n Path: {labelConfig: {fontResize: true}},\n // A visual, constant-WIDTH gap between wedges: an SVG stroke is\n // measured in screen pixels regardless of the underlying path's\n // radius, unlike padAngle (see padPixel's default above), so\n // matching it to the chart's own background color \"cuts out\" an\n // even border everywhere — including near the center, where an\n // angular gap has nowhere left to taper from. Centered on each\n // wedge's outline (SVG's default), so half its width falls on each\n // side of an edge shared with a neighbor.\n stroke: () => backgroundColor(viz._select?.node()),\n strokeWidth: 2,\n }),\n },\n {\n key: \"tooltipConfig\",\n merge: true,\n factory: (viz: VizInstance) => ({\n tbody: [\n [\n () => viz.schema.translate(\"Share\"),\n (_d: DataPoint, _i: number, x: Record<string, unknown>) => {\n // A ColorScale range swatch carries no per-row share, so sum the\n // share of every datum that falls in its color range.\n if (x._isColorScaleBucket) {\n const s = colorScaleBucketShare(\n viz,\n x.color,\n viz.schema.value as (d: DataPoint, i: number) => number,\n );\n return s == null\n ? \"\"\n : `${formatAbbreviate(s * 100, viz.schema.locale)}%`;\n }\n // A Legend bucket aggregates multiple rows, so `share` arrives\n // as an array of the members' shares — sum it; a single cell's\n // share is a plain number.\n const share = Array.isArray(x.share)\n ? (x.share as number[]).reduce((a, b) => a + b, 0)\n : (x.share as number);\n if (!Number.isFinite(share)) return \"\";\n return `${formatAbbreviate(share * 100, viz.schema.locale)}%`;\n },\n ],\n ],\n }),\n },\n {\n key: \"legend\",\n coerce: \"const\",\n factory: (viz: VizInstance) => {\n const base = viz.schema.legend as (config: D3plusConfig, arr: DataPoint[]) => unknown;\n return (config: D3plusConfig, arr: DataPoint[]) => {\n if (arr.length === viz._filteredData.length) return false;\n return base.call(viz, config, arr);\n };\n },\n },\n ],\n};\n\n/**\n Uses the d3 pie layout to create SVG arcs based on an array of data.\n*/\nexport default makeChart(pieDef);\n"],"names":["pie","d3Pie","backgroundColor","formatAbbreviate","accessor","centerChartTransform","subtitleFeature","titleFeature","totalFeature","colorScaleBucketShare","makeChart","applyPieLayout","pieEmit","sceneInsetRegion","pieDef","name","features","layoutStage","emit","insetRegion","chartTransform","viz","ctx","pieWidth","pieHeight","chartBodyRect","r","pieOuterRadius","x","y","width","height","fields","key","default","coerce","v","factory","valueFn","schema","value","a","b","merge","ariaLabel","d","i","pieData","index","_drawLabel","Path","labelConfig","fontResize","stroke","_select","node","strokeWidth","tbody","translate","_d","_i","_isColorScaleBucket","s","color","locale","share","Array","isArray","reduce","Number","isFinite","base","legend","config","arr","length","_filteredData","call"],"mappings":"AAAA;;;;;;AAMA,GAEA,SAAQA,OAAOC,KAAK,QAAO,WAAW;AACtC,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,gBAAgB,QAAO,iBAAiB;AAGhD,OAAOC,cAAc,0BAA0B;AAC/C,SAAQC,oBAAoB,QAAO,+BAA+B;AAClE,SAAQC,eAAe,EAAEC,YAAY,EAAEC,YAAY,QAAO,0BAA0B;AACpF,SAAQC,qBAAqB,QAAO,kCAAkC;AAGtE,SAAQC,SAAS,QAAO,6BAA6B;AAGrD,SAAQC,cAAc,QAAO,mBAAmB;AAChD,SAAQC,OAAO,QAAO,YAAY;AAClC,SAAQC,gBAAgB,QAAO,gCAAgC;AAE/D,OAAO,IAAMC,SAAoC;IAC/CC,MAAM;IAENC,UAAU;QAACT;QAAcD;QAAiBE;KAAa;IACvDS,aAAaN;IACbO,MAAMN;IACNO,aAAaN;IAEbO,gBAAgB,SAAhBA,eAAiBC;eACfhB,qBACEgB,KACAA,IAAIC,GAAG,CAACC,QAAQ,EAChBF,IAAIC,GAAG,CAACE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AIC;mCAAG,KAC7Cd,EAAEqC,KAAK;gCACZ,IAAI,CAACI,OAAOC,QAAQ,CAACL,QAAQ,OAAO;gCACpC,OAAO,AAAC,GAAmD,OAAjD9D,iBAAiB8D,QAAQ,KAAK5C,IAAIkB,MAAM,CAACyB,MAAM,GAAE;4BAC7D;yBACD;qBACF;gBACH;;QACF;QACA;YACE/B,KAAK;YACLE,QAAQ;YACRE,SAAS,SAATA,QAAUhB;gBACR,IAAMkD,OAAOlD,IAAIkB,MAAM,CAACiC,MAAM;gBAC9B,OAAO,SAACC,QAAsBC;oBAC5B,IAAIA,IAAIC,MAAM,KAAKtD,IAAIuD,aAAa,CAACD,MAAM,EAAE,OAAO;oBACpD,OAAOJ,KAAKM,IAAI,CAACxD,KAAKoD,QAAQC;gBAChC;YACF;QACF;KACD;AACH,EAAE;AAEF;;AAEA,GACA,eAAehE,UAAUI,QAAQ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Continuous discrete-axis support. When a chart sets `viz._discreteExtent`
|
|
3
|
+
(an accessor returning each datum's `[start, end]` along the discrete
|
|
4
|
+
axis), that axis becomes a linear scale spanning every datum's extent and
|
|
5
|
+
bars fill their own span instead of an evenly divided band.
|
|
6
|
+
*/ import { max, min } from "d3-array";
|
|
7
|
+
/** Whether `axis` is a span-valued discrete axis. */ export function isSpanAxis(viz, axis) {
|
|
8
|
+
return Boolean(viz._discreteExtent) && viz.schema.discrete === axis;
|
|
9
|
+
}
|
|
10
|
+
/** `[start, end]` of a formatted Plot row (reads its source `data`). */ export function rowSpan(viz, row) {
|
|
11
|
+
return viz._discreteExtent(row.data);
|
|
12
|
+
}
|
|
13
|
+
/** The `[min start, max end]` domain covering every row's span. */ export function spanDomain(viz, rows) {
|
|
14
|
+
var spans = rows.filter(function(d) {
|
|
15
|
+
return d.data;
|
|
16
|
+
}).map(function(d) {
|
|
17
|
+
return rowSpan(viz, d);
|
|
18
|
+
});
|
|
19
|
+
return [
|
|
20
|
+
min(spans, function(d) {
|
|
21
|
+
return d[0];
|
|
22
|
+
}),
|
|
23
|
+
max(spans, function(d) {
|
|
24
|
+
return d[1];
|
|
25
|
+
})
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
/** Every unique span boundary, ascending — the tick values for a span axis. */ export function spanEdges(viz, rows) {
|
|
29
|
+
var edges = new Set();
|
|
30
|
+
rows.filter(function(d) {
|
|
31
|
+
return d.data;
|
|
32
|
+
}).forEach(function(d) {
|
|
33
|
+
return rowSpan(viz, d).forEach(function(e) {
|
|
34
|
+
return edges.add(e);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return Array.from(edges).sort(function(a, b) {
|
|
38
|
+
return a - b;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=discreteSpan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/charts/Plot/discreteSpan.ts"],"sourcesContent":["/**\n Continuous discrete-axis support. When a chart sets `viz._discreteExtent`\n (an accessor returning each datum's `[start, end]` along the discrete\n axis), that axis becomes a linear scale spanning every datum's extent and\n bars fill their own span instead of an evenly divided band.\n*/\nimport {max, min} from \"d3-array\";\n\nimport type {DataPoint} from \"@d3plus/data\";\n\nimport type {VizInstance} from \"../viz/vizTypes.js\";\n\n/** Whether `axis` is a span-valued discrete axis. */\nexport function isSpanAxis(viz: VizInstance, axis: string): boolean {\n return Boolean(viz._discreteExtent) && viz.schema.discrete === axis;\n}\n\n/** `[start, end]` of a formatted Plot row (reads its source `data`). */\nexport function rowSpan(viz: VizInstance, row: Record<string, unknown>): [number, number] {\n return viz._discreteExtent!(row.data as DataPoint);\n}\n\n/** The `[min start, max end]` domain covering every row's span. */\nexport function spanDomain(viz: VizInstance, rows: Record<string, unknown>[]): number[] {\n const spans = rows.filter(d => d.data).map(d => rowSpan(viz, d));\n return [min(spans, d => d[0]) as number, max(spans, d => d[1]) as number];\n}\n\n/** Every unique span boundary, ascending — the tick values for a span axis. */\nexport function spanEdges(viz: VizInstance, rows: Record<string, unknown>[]): number[] {\n const edges = new Set<number>();\n rows.filter(d => d.data).forEach(d => rowSpan(viz, d).forEach(e => edges.add(e)));\n return Array.from(edges).sort((a, b) => a - b);\n}\n"],"names":["max","min","isSpanAxis","viz","axis","Boolean","_discreteExtent","schema","discrete","rowSpan","row","data","spanDomain","rows","spans","filter","d","map","spanEdges","edges","Set","forEach","e","add","Array","from","sort","a","b"],"mappings":"AAAA;;;;;AAKA,GACA,SAAQA,GAAG,EAAEC,GAAG,QAAO,WAAW;AAMlC,mDAAmD,GACnD,OAAO,SAASC,WAAWC,GAAgB,EAAEC,IAAY;IACvD,OAAOC,QAAQF,IAAIG,eAAe,KAAKH,IAAII,MAAM,CAACC,QAAQ,KAAKJ;AACjE;AAEA,sEAAsE,GACtE,OAAO,SAASK,QAAQN,GAAgB,EAAEO,GAA4B;IACpE,OAAOP,IAAIG,eAAe,CAAEI,IAAIC,IAAI;AACtC;AAEA,iEAAiE,GACjE,OAAO,SAASC,WAAWT,GAAgB,EAAEU,IAA+B;IAC1E,IAAMC,QAAQD,KAAKE,MAAM,CAACC,SAAAA;eAAKA,EAAEL,IAAI;OAAEM,GAAG,CAACD,SAAAA;eAAKP,QAAQN,KAAKa;;IAC7D,OAAO;QAACf,IAAIa,OAAOE,SAAAA;mBAAKA,CAAC,CAAC,EAAE;;QAAahB,IAAIc,OAAOE,SAAAA;mBAAKA,CAAC,CAAC,EAAE;;KAAY;AAC3E;AAEA,6EAA6E,GAC7E,OAAO,SAASE,UAAUf,GAAgB,EAAEU,IAA+B;IACzE,IAAMM,QAAQ,IAAIC;IAClBP,KAAKE,MAAM,CAACC,SAAAA;eAAKA,EAAEL,IAAI;OAAEU,OAAO,CAACL,SAAAA;eAAKP,QAAQN,KAAKa,GAAGK,OAAO,CAACC,SAAAA;mBAAKH,MAAMI,GAAG,CAACD;;;IAC7E,OAAOE,MAAMC,IAAI,CAACN,OAAOO,IAAI,CAAC,SAACC,GAAGC;eAAMD,IAAIC;;AAC9C"}
|
|
@@ -85,6 +85,7 @@ import { measureAxes } from "../features/axes.js";
|
|
|
85
85
|
import Viz from "../viz/Viz.js";
|
|
86
86
|
import { runStages } from "../pipeline/stages.js";
|
|
87
87
|
import { computePlotAxisValues, computePlotInitialDomains, computePlotScales, extendPlotOppScales, formatPlotData, measurePlotLineLabels, preparePlotAxisLayout } from "./pipeline.js";
|
|
88
|
+
import { computePlotTrendFits } from "./trendLines.js";
|
|
88
89
|
var testLineShape = new shapes.Line();
|
|
89
90
|
var testTextBox = new TextBox();
|
|
90
91
|
var superDraw = function superDraw(viz, callback) {
|
|
@@ -95,7 +96,8 @@ var superDraw = function superDraw(viz, callback) {
|
|
|
95
96
|
viz: viz
|
|
96
97
|
}, [
|
|
97
98
|
formatPlotData,
|
|
98
|
-
computePlotAxisValues
|
|
99
|
+
computePlotAxisValues,
|
|
100
|
+
computePlotTrendFits
|
|
99
101
|
]);
|
|
100
102
|
// Time flags (xTime/x2Time/yTime/y2Time) are written onto `viz` by
|
|
101
103
|
// `formatPlotData` and read directly via `viz._xTime` etc. downstream.
|