@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.
Files changed (236) hide show
  1. package/es/internal.js +3 -1
  2. package/es/src/charts/BoxWhisker/index.js +73 -4
  3. package/es/src/charts/BoxWhisker/outliers.js +68 -0
  4. package/es/src/charts/BoxWhisker/summary.js +83 -0
  5. package/es/src/charts/BoxWhisker/tooltip.js +122 -0
  6. package/es/src/charts/Bullet/index.js +2 -1
  7. package/es/src/charts/BumpChart/index.js +5 -0
  8. package/es/src/charts/Calendar/index.js +2 -1
  9. package/es/src/charts/Candlestick/aggregate.js +11 -1
  10. package/es/src/charts/Candlestick/index.js +5 -5
  11. package/es/src/charts/Chord/index.js +3 -2
  12. package/es/src/charts/Funnel/index.js +2 -1
  13. package/es/src/charts/Gauge/index.js +2 -1
  14. package/es/src/charts/Geomap/index.js +9 -3
  15. package/es/src/charts/Histogram/index.js +5 -1
  16. package/es/src/charts/Matrix/index.js +3 -2
  17. package/es/src/charts/Network/index.js +9 -4
  18. package/es/src/charts/Pack/index.js +2 -1
  19. package/es/src/charts/Pie/index.js +2 -1
  20. package/es/src/charts/Plot/axisHover.js +180 -0
  21. package/es/src/charts/Plot/axisHoverAnchors.js +174 -0
  22. package/es/src/charts/Plot/axisHoverScene.js +202 -0
  23. package/es/src/charts/Plot/barHitArea.js +81 -0
  24. package/es/src/charts/Plot/barLabelFit.js +123 -0
  25. package/es/src/charts/Plot/barWidth.js +2 -2
  26. package/es/src/charts/Plot/confidenceConfig.js +2 -2
  27. package/es/src/charts/Plot/draw.js +6 -2
  28. package/es/src/charts/Plot/index.js +25 -6
  29. package/es/src/charts/Plot/labelPlacement.js +9 -1
  30. package/es/src/charts/Plot/openDomainEnds.js +2 -5
  31. package/es/src/charts/Plot/pipeline.js +5 -3
  32. package/es/src/charts/Plot/pipelineAxisLayout.js +38 -8
  33. package/es/src/charts/Plot/pipelineDomains.js +7 -3
  34. package/es/src/charts/Plot/pipelineLineLabels.js +1 -1
  35. package/es/src/charts/Plot/plotInit.js +15 -0
  36. package/es/src/charts/Plot/plotZoom.js +15 -6
  37. package/es/src/charts/Plot/shapeDefaults.js +4 -4
  38. package/es/src/charts/Plot/sharedHoverScene.js +50 -31
  39. package/es/src/charts/Plot/sharedTooltip.js +19 -7
  40. package/es/src/charts/Plot/stackHelpers.js +13 -1
  41. package/es/src/charts/Plot/stackShareTooltip.js +9 -4
  42. package/es/src/charts/Plot/stackThreshold.js +154 -0
  43. package/es/src/charts/PolarArea/index.js +3 -2
  44. package/es/src/charts/Priestley/index.js +3 -2
  45. package/es/src/charts/Pyramid/index.js +4 -2
  46. package/es/src/charts/Radar/index.js +3 -2
  47. package/es/src/charts/RadialBar/index.js +2 -1
  48. package/es/src/charts/RadialMatrix/index.js +3 -2
  49. package/es/src/charts/Rings/index.js +5 -3
  50. package/es/src/charts/Sankey/index.js +3 -2
  51. package/es/src/charts/Treemap/applyLayout.js +14 -1
  52. package/es/src/charts/Treemap/emit.js +8 -2
  53. package/es/src/charts/Treemap/emitGroupHeaders.js +104 -0
  54. package/es/src/charts/Treemap/groupHeaders.js +95 -0
  55. package/es/src/charts/Treemap/index.js +15 -2
  56. package/es/src/charts/Treemap/thresholdFunction.js +11 -9
  57. package/es/src/charts/Waffle/index.js +4 -2
  58. package/es/src/charts/Waffle/tooltip.js +6 -2
  59. package/es/src/charts/Waterfall/index.js +4 -2
  60. package/es/src/charts/definition/makeChart.js +12 -5
  61. package/es/src/charts/drawSteps/saveChart.js +176 -0
  62. package/es/src/charts/drawSteps/saveControl.js +148 -0
  63. package/es/src/charts/drawSteps/saveControlMarkup.js +104 -0
  64. package/es/src/charts/drawSteps/tableViewMarkup.js +1 -1
  65. package/es/src/charts/drawSteps/topLeftControls.js +3 -1
  66. package/es/src/charts/drawSteps/topLeftControlsMarkup.js +1 -1
  67. package/es/src/charts/events/click.shape.js +30 -1
  68. package/es/src/charts/events/mouseenter.js +9 -0
  69. package/es/src/charts/events/mousemove.legend.js +3 -0
  70. package/es/src/charts/events/mousemove.shape.js +7 -2
  71. package/es/src/charts/facet/facetConfig.js +2 -2
  72. package/es/src/charts/facet/facetData.js +2 -2
  73. package/es/src/charts/features/axes.js +7 -6
  74. package/es/src/charts/features/axesFinal.js +23 -3
  75. package/es/src/charts/features/axesMeasure.js +54 -2
  76. package/es/src/charts/features/colorScaleBucket.js +17 -0
  77. package/es/src/charts/features/colorScaleHover.js +69 -0
  78. package/es/src/charts/features/features.js +13 -1
  79. package/es/src/charts/features/featuresColorScale.js +44 -4
  80. package/es/src/charts/features/featuresLegend.js +6 -8
  81. package/es/src/charts/features/plotPaint.js +4 -4
  82. package/es/src/charts/features/shapeEmit.js +23 -2
  83. package/es/src/charts/features/shareKey.js +15 -0
  84. package/es/src/charts/features/thresholdMembers.js +71 -0
  85. package/es/src/charts/helpers/densityChart.js +3 -1
  86. package/es/src/charts/helpers/valueTitle.js +6 -3
  87. package/es/src/charts/partition/chartFields.js +4 -3
  88. package/es/src/charts/partition/hierarchy.js +2 -0
  89. package/es/src/charts/pipeline/preDrawData.js +31 -10
  90. package/es/src/charts/pipeline/vizDraw.js +40 -29
  91. package/es/src/charts/pipeline/vizPreDraw.js +24 -15
  92. package/es/src/charts/viz/Viz.js +43 -8
  93. package/es/src/charts/viz/VizBase.js +32 -12
  94. package/es/src/charts/viz/dataPoller.js +52 -0
  95. package/es/src/charts/viz/groupRow.js +35 -0
  96. package/es/src/charts/viz/interactionOpacity.js +19 -5
  97. package/es/src/charts/viz/missingFields.js +122 -0
  98. package/es/src/charts/viz/reportHandlerError.js +10 -0
  99. package/es/src/charts/viz/shapeClassTargets.js +18 -2
  100. package/es/src/charts/viz/simpleHover.js +2 -0
  101. package/es/src/charts/viz/vizClassName.js +31 -0
  102. package/es/src/charts/viz/vizDataPolling.js +167 -0
  103. package/es/src/charts/viz/vizDefaults.js +66 -0
  104. package/es/src/charts/viz/vizFields.js +18 -2
  105. package/es/src/charts/viz/vizRender.js +8 -2
  106. package/es/src/components/Axis/Axis.js +28 -0
  107. package/es/src/components/Axis/axisDefaults.js +3 -1
  108. package/es/src/components/Axis/axisLabelAngle.js +175 -0
  109. package/es/src/components/Axis/axisLabelThinning.js +13 -4
  110. package/es/src/components/Axis/axisLayout.js +86 -19
  111. package/es/src/components/Axis/axisLayoutLabels.js +66 -13
  112. package/es/src/components/Axis/axisLayoutScale.js +3 -0
  113. package/es/src/components/Axis/axisRender.js +38 -9
  114. package/es/src/components/Axis/axisRounding.js +15 -4
  115. package/es/src/components/Axis/axisSlantWrap.js +39 -0
  116. package/es/src/components/Axis/powTicks.js +73 -0
  117. package/es/src/components/ColorScale/ColorScale.js +28 -28
  118. package/es/src/components/ColorScale/bucketBounds.js +35 -0
  119. package/es/src/components/ColorScale/colorScaleHoverMark.js +327 -0
  120. package/es/src/components/ColorScale/colorScaleRender.js +25 -1
  121. package/es/src/components/ColorScale/colorScaleScale.js +15 -9
  122. package/es/src/components/ColorScale/colorScaleType.js +26 -0
  123. package/es/src/components/TextBox.js +2 -0
  124. package/es/src/components/Timeline/Timeline.js +43 -52
  125. package/es/src/components/Timeline/brushSpan.js +78 -0
  126. package/es/src/components/Timeline/timelineConfig.js +7 -0
  127. package/es/src/components/Timeline/timelineRender.js +44 -6
  128. package/es/src/components/Tooltip.js +13 -8
  129. package/es/src/shapes/Box.js +66 -79
  130. package/es/src/shapes/boxOutlierShape.js +19 -0
  131. package/es/src/shapes/boxStats.js +35 -0
  132. package/es/src/shapes/boxStyle.js +78 -0
  133. package/es/src/shapes/boxSummary.js +174 -0
  134. package/es/src/shapes/shapeStandalone.js +2 -0
  135. package/es/src/utils/BaseClass.js +19 -0
  136. package/es/src/utils/className.js +78 -0
  137. package/es/src/utils/configWarnings.js +25 -0
  138. package/es/src/utils/fieldAccessor.js +31 -0
  139. package/es/src/utils/paintComponentScene.js +2 -0
  140. package/package.json +10 -9
  141. package/types/index.d.ts +3 -1
  142. package/types/internal.d.ts +3 -1
  143. package/types/src/charts/BoxWhisker/index.d.ts +3 -1
  144. package/types/src/charts/BoxWhisker/outliers.d.ts +25 -0
  145. package/types/src/charts/BoxWhisker/summary.d.ts +39 -0
  146. package/types/src/charts/BoxWhisker/tooltip.d.ts +36 -0
  147. package/types/src/charts/Candlestick/aggregate.d.ts +6 -0
  148. package/types/src/charts/Plot/axisHover.d.ts +68 -0
  149. package/types/src/charts/Plot/axisHoverAnchors.d.ts +88 -0
  150. package/types/src/charts/Plot/axisHoverScene.d.ts +88 -0
  151. package/types/src/charts/Plot/barHitArea.d.ts +59 -0
  152. package/types/src/charts/Plot/barLabelFit.d.ts +81 -0
  153. package/types/src/charts/Plot/index.d.ts +13 -0
  154. package/types/src/charts/Plot/labelPlacement.d.ts +5 -0
  155. package/types/src/charts/Plot/plotInit.d.ts +9 -2
  156. package/types/src/charts/Plot/plotZoom.d.ts +2 -0
  157. package/types/src/charts/Plot/sharedHoverScene.d.ts +3 -3
  158. package/types/src/charts/Plot/sharedTooltip.d.ts +11 -4
  159. package/types/src/charts/Plot/stackHelpers.d.ts +5 -0
  160. package/types/src/charts/Plot/stackThreshold.d.ts +75 -0
  161. package/types/src/charts/Treemap/emit.d.ts +2 -1
  162. package/types/src/charts/Treemap/emitGroupHeaders.d.ts +16 -0
  163. package/types/src/charts/Treemap/groupHeaders.d.ts +91 -0
  164. package/types/src/charts/Treemap/index.d.ts +2 -0
  165. package/types/src/charts/Treemap/thresholdFunction.d.ts +5 -2
  166. package/types/src/charts/definition/ChartDefinition.d.ts +14 -2
  167. package/types/src/charts/definition/makeChart.d.ts +4 -3
  168. package/types/src/charts/drawSteps/saveChart.d.ts +47 -0
  169. package/types/src/charts/drawSteps/saveControl.d.ts +9 -0
  170. package/types/src/charts/drawSteps/saveControlMarkup.d.ts +44 -0
  171. package/types/src/charts/drawSteps/tableViewMarkup.d.ts +1 -0
  172. package/types/src/charts/drawSteps/topLeftControls.d.ts +1 -1
  173. package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +1 -1
  174. package/types/src/charts/facet/facetData.d.ts +1 -1
  175. package/types/src/charts/features/axesMeasure.d.ts +9 -1
  176. package/types/src/charts/features/colorScaleBucket.d.ts +9 -0
  177. package/types/src/charts/features/colorScaleHover.d.ts +32 -0
  178. package/types/src/charts/features/features.d.ts +8 -0
  179. package/types/src/charts/features/plotPaint.d.ts +2 -0
  180. package/types/src/charts/features/shapeEmit.d.ts +2 -0
  181. package/types/src/charts/features/shareKey.d.ts +9 -0
  182. package/types/src/charts/features/thresholdMembers.d.ts +38 -0
  183. package/types/src/charts/helpers/valueTitle.d.ts +4 -2
  184. package/types/src/charts/pipeline/stages.d.ts +2 -0
  185. package/types/src/charts/pipeline/vizDraw.d.ts +8 -3
  186. package/types/src/charts/pipeline/vizPreDraw.d.ts +3 -2
  187. package/types/src/charts/viz/Viz.d.ts +28 -4
  188. package/types/src/charts/viz/VizBase.d.ts +12 -3
  189. package/types/src/charts/viz/dataPoller.d.ts +28 -0
  190. package/types/src/charts/viz/groupRow.d.ts +24 -0
  191. package/types/src/charts/viz/interactionOpacity.d.ts +3 -1
  192. package/types/src/charts/viz/missingFields.d.ts +57 -0
  193. package/types/src/charts/viz/reportHandlerError.d.ts +7 -0
  194. package/types/src/charts/viz/shapeClassTargets.d.ts +6 -0
  195. package/types/src/charts/viz/simpleHover.d.ts +2 -1
  196. package/types/src/charts/viz/vizClassName.d.ts +23 -0
  197. package/types/src/charts/viz/vizDataPolling.d.ts +48 -0
  198. package/types/src/charts/viz/vizDefaults.d.ts +49 -0
  199. package/types/src/charts/viz/vizFields.d.ts +15 -0
  200. package/types/src/charts/viz/vizTypes.d.ts +33 -1
  201. package/types/src/components/Axis/Axis.d.ts +36 -8
  202. package/types/src/components/Axis/axisLabelAngle.d.ts +110 -0
  203. package/types/src/components/Axis/axisLabelThinning.d.ts +3 -7
  204. package/types/src/components/Axis/axisLayout.d.ts +5 -0
  205. package/types/src/components/Axis/axisLayoutLabels.d.ts +13 -0
  206. package/types/src/components/Axis/axisRounding.d.ts +6 -3
  207. package/types/src/components/Axis/axisSlantWrap.d.ts +22 -0
  208. package/types/src/components/Axis/powTicks.d.ts +29 -0
  209. package/types/src/components/ColorScale/ColorScale.d.ts +13 -0
  210. package/types/src/components/ColorScale/bucketBounds.d.ts +14 -0
  211. package/types/src/components/ColorScale/colorScaleHoverMark.d.ts +86 -0
  212. package/types/src/components/ColorScale/colorScaleScale.d.ts +3 -0
  213. package/types/src/components/ColorScale/colorScaleType.d.ts +17 -0
  214. package/types/src/components/Timeline/brushSpan.d.ts +41 -0
  215. package/types/src/components/Timeline/timelineConfig.d.ts +6 -0
  216. package/types/src/components/Timeline/timelineRender.d.ts +8 -0
  217. package/types/src/components/Tooltip.d.ts +8 -0
  218. package/types/src/shapes/Box.d.ts +1 -8
  219. package/types/src/shapes/boxOutlierShape.d.ts +9 -0
  220. package/types/src/shapes/boxStats.d.ts +19 -0
  221. package/types/src/shapes/boxStyle.d.ts +25 -0
  222. package/types/src/shapes/boxSummary.d.ts +66 -0
  223. package/types/src/shapes/emitLabels.d.ts +1 -1
  224. package/types/src/shapes/shapeConfig.d.ts +42 -4
  225. package/types/src/utils/BaseClass.d.ts +23 -0
  226. package/types/src/utils/D3Scale.d.ts +3 -0
  227. package/types/src/utils/D3plusConfig.d.ts +261 -5
  228. package/types/src/utils/className.d.ts +64 -0
  229. package/types/src/utils/configWarnings.d.ts +21 -2
  230. package/types/src/utils/fieldAccessor.d.ts +24 -0
  231. package/types/src/utils/index.d.ts +1 -1
  232. package/types/src/utils/paintComponentScene.d.ts +3 -1
  233. package/umd/d3plus-core.full.js +6405 -1068
  234. package/umd/d3plus-core.full.min.js +2 -2
  235. package/umd/d3plus-core.js +5328 -1002
  236. package/umd/d3plus-core.min.js +2 -2
@@ -7,6 +7,7 @@
7
7
  */ import { colorContrast } from "@d3plus/color";
8
8
  import { backgroundColor } from "@d3plus/dom";
9
9
  import accessor from "../../utils/accessor.js";
10
+ import { fieldAccessor } from "../../utils/fieldAccessor.js";
10
11
  import constant from "../../utils/constant.js";
11
12
  import { TextBox } from "../../components/index.js";
12
13
  import { centerChartTransform } from "../features/chartGeometry.js";
@@ -69,7 +70,7 @@ export const radialMatrixDef = {
69
70
  */ {
70
71
  key: "column",
71
72
  default: accessor("column"),
72
- coerce: (v)=>typeof v === "function" ? v : accessor(v)
73
+ coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v)
73
74
  },
74
75
  /**
75
76
  The row each data point falls in (one ring): a key present in every
@@ -79,7 +80,7 @@ export const radialMatrixDef = {
79
80
  */ {
80
81
  key: "row",
81
82
  default: accessor("row"),
82
- coerce: (v)=>typeof v === "function" ? v : accessor(v)
83
+ coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v)
83
84
  },
84
85
  /**
85
86
  A manual list of column values to draw, in place of the unique
@@ -8,7 +8,7 @@
8
8
  - `ringsGraph.ts` — node set + link resolution.
9
9
  - `ringsSizing.ts` — ring geometry + node sizing.
10
10
  */ import { addToQueue } from "@d3plus/data";
11
- import accessor from "../../utils/accessor.js";
11
+ import { fieldAccessor } from "../../utils/fieldAccessor.js";
12
12
  import constant from "../../utils/constant.js";
13
13
  import { makeChart } from "../definition/makeChart.js";
14
14
  import { runPostDrawFeatures } from "../pipeline/runVizPipeline.js";
@@ -70,7 +70,7 @@ import { simpleHover } from "../viz/simpleHover.js";
70
70
  const vv = Array.from(new Set(a.map(c)));
71
71
  return vv.length === 1 ? vv[0] : vv;
72
72
  };
73
- return accessor(k);
73
+ return fieldAccessor(k);
74
74
  });
75
75
  return this;
76
76
  };
@@ -81,7 +81,7 @@ import { simpleHover } from "../viz/simpleHover.js";
81
81
  @type {string | function}
82
82
  */ v.size = function(_) {
83
83
  if (!arguments.length) return this._size;
84
- this._size = typeof _ === "function" || !_ ? _ : accessor(_);
84
+ this._size = typeof _ === "function" || !_ ? _ : fieldAccessor(_);
85
85
  this._sizeKey = typeof _ === "string" ? _ : undefined;
86
86
  return this;
87
87
  };
@@ -112,6 +112,8 @@ export const ringsDef = {
112
112
  const id = viz.schema.nodeGroupBy && viz.schema.nodeGroupBy[viz._drawDepth](d, i) ? viz.schema.nodeGroupBy[viz._drawDepth](d, i) : viz._id(d, i);
113
113
  const links = viz.ctx.linkLookup[id] ?? [];
114
114
  const node = viz.ctx.nodeLookup[id];
115
+ // An edge has no node to focus.
116
+ if (!node) return;
115
117
  const filterIds = [
116
118
  node.id
117
119
  ];
@@ -8,6 +8,7 @@
8
8
  */ import { sankey, sankeyCenter, sankeyJustify, sankeyLeft, sankeyLinkHorizontal, sankeyRight } from "./sankeyLayout.js";
9
9
  import { addToQueue } from "@d3plus/data";
10
10
  import accessor from "../../utils/accessor.js";
11
+ import { fieldAccessor } from "../../utils/fieldAccessor.js";
11
12
  import constant from "../../utils/constant.js";
12
13
  import { makeChart } from "../definition/makeChart.js";
13
14
  import { applySankeyLayout } from "./applyLayout.js";
@@ -116,7 +117,7 @@ export const sankeyDef = {
116
117
  sources and targets are matched against these ids.
117
118
  @type {string | function}
118
119
  */ v.nodeId = function(_) {
119
- return arguments.length ? (this.schema.nodeId = typeof _ === "function" ? _ : accessor(_), this) : this.schema.nodeId;
120
+ return arguments.length ? (this.schema.nodeId = typeof _ === "function" ? _ : fieldAccessor(_), this) : this.schema.nodeId;
120
121
  };
121
122
  /**
122
123
  The value of each link, which sets its width: a key or an accessor
@@ -125,7 +126,7 @@ export const sankeyDef = {
125
126
  @type {string | function}
126
127
  */ v.value = function(_) {
127
128
  if (!arguments.length) return this.schema.value;
128
- this.schema.value = typeof _ === "function" ? _ : accessor(_);
129
+ this.schema.value = typeof _ === "function" ? _ : fieldAccessor(_);
129
130
  return this;
130
131
  };
131
132
  v.hover = simpleHover;
@@ -4,6 +4,7 @@
4
4
  import { merge, nestGroups } from "@d3plus/data";
5
5
  import { chartBounds } from "../features/chartGeometry.js";
6
6
  import { stampShare } from "../features/shareKey.js";
7
+ import { attachGroupHeaders, groupLabelStyle, groupPaddingTop } from "./groupHeaders.js";
7
8
  export const applyTreemapLayout = ({ viz })=>{
8
9
  const data = viz._filteredData;
9
10
  if (!data || !data.length) return {
@@ -14,7 +15,14 @@ export const applyTreemapLayout = ({ viz })=>{
14
15
  const root = hierarchy({
15
16
  values: nestedData
16
17
  }, (d)=>d.values).sum(viz.schema.sum).sort(viz.schema.sort);
17
- const built = viz.ctx.treemap.padding(viz.schema.layoutPadding).size([
18
+ const padding = viz.schema.layoutPadding;
19
+ const strips = new Map();
20
+ const style = groupLabelStyle(viz);
21
+ const built = viz.ctx.treemap.padding(padding).paddingTop(groupPaddingTop({
22
+ drawDepth: viz._drawDepth,
23
+ padding,
24
+ style
25
+ }, strips)).size([
18
26
  width,
19
27
  height
20
28
  ]).tile(viz.schema.tile);
@@ -50,6 +58,11 @@ export const applyTreemapLayout = ({ viz })=>{
50
58
  d.data.rank = i;
51
59
  });
52
60
  const total = tmapData.value;
61
+ attachGroupHeaders(strips, {
62
+ aggs: viz.schema.aggs,
63
+ label: style?.label,
64
+ total
65
+ });
53
66
  const sumFn = viz.schema.sum;
54
67
  shapeData.forEach((d)=>{
55
68
  const share = sumFn(d.data) / total;
@@ -1,12 +1,15 @@
1
1
  /**
2
2
  `treemapEmit` — scene nodes for a laid-out Treemap: one rect per cell
3
- plus the title + share-% text labels for each cell, both as flat data.
3
+ plus the title + share-% text labels for each cell, both as flat data,
4
+ then the group header strips above them.
4
5
  */ import { colorContrast } from "@d3plus/color";
5
6
  import { formatAbbreviate } from "@d3plus/format";
6
7
  import constant from "../../utils/constant.js";
7
8
  import { emitLabels } from "../../shapes/emitLabels.js";
8
9
  import { userLabelConfig, textureFill, shapeConfigFor, resolveAccessor } from "../features/emitHelpers.js";
9
10
  import { backgroundImageNodes } from "../features/backgroundImageEmit.js";
11
+ import { groupHeaderNodes } from "./emitGroupHeaders.js";
12
+ import { collectGroupHeaders, groupLabelStyle } from "./groupHeaders.js";
10
13
  export const treemapEmit = ({ viz, shapeData })=>{
11
14
  const nodes = shapeData ?? [];
12
15
  if (!nodes.length) return [];
@@ -106,9 +109,12 @@ export const treemapEmit = ({ viz, shapeData })=>{
106
109
  nodes[k].data,
107
110
  nodes[k].i
108
111
  ]);
112
+ const style = groupLabelStyle(viz);
113
+ const headerNodes = style ? groupHeaderNodes(viz, collectGroupHeaders(nodes), style) : [];
109
114
  return [
110
115
  ...rectNodes,
111
116
  ...imageNodes,
112
- ...labelNodes
117
+ ...labelNodes,
118
+ ...headerNodes
113
119
  ];
114
120
  };
@@ -0,0 +1,104 @@
1
+ /**
2
+ Scene nodes for the Treemap's group headers: a strip rect per header and
3
+ its left-aligned, single-line name.
4
+ */ import { color } from "d3-color";
5
+ import { interpolateRgb } from "d3-interpolate";
6
+ import { colorContrast } from "@d3plus/color";
7
+ import { formatAbbreviate } from "@d3plus/format";
8
+ import constant from "../../utils/constant.js";
9
+ import { emitLabels } from "../../shapes/emitLabels.js";
10
+ import { resolveAccessor, shapeConfigFor } from "../features/emitHelpers.js";
11
+ import { summedShare } from "../features/shareKey.js";
12
+ import { backgroundInk, chartBackground } from "../viz/backgroundInk.js";
13
+ /**
14
+ A header strip's default fill: a darker shade of its group's color, or,
15
+ when a colorScale colors the tiles by value, a neutral tone between the
16
+ chart's background and its ink.
17
+ */ export function defaultGroupFill(viz, row, i) {
18
+ const neutral = ()=>interpolateRgb(chartBackground(viz), backgroundInk(viz))(0.7);
19
+ if (viz.schema.colorScale) return neutral();
20
+ const sc = shapeConfigFor(viz, "Rect");
21
+ const base = color(`${resolveAccessor(sc.fill, row, i)}`);
22
+ return base ? base.darker(0.8).formatHex() : neutral();
23
+ }
24
+ /** The strip rects and name labels for `headers`. */ export function groupHeaderNodes(viz, headers, style) {
25
+ if (!headers.length) return [];
26
+ const fills = new Map();
27
+ const fillOf = (h)=>{
28
+ let fill = fills.get(h);
29
+ if (fill === undefined) {
30
+ fill = resolveAccessor(style.fill, h.data, 0) ?? defaultGroupFill(viz, h.data, 0);
31
+ fills.set(h, fill);
32
+ }
33
+ return fill;
34
+ };
35
+ const sum = viz.schema.sum;
36
+ const name = (h)=>viz._drawLabel(h.data, 0, h.depth);
37
+ const rects = headers.map((h)=>({
38
+ type: "rect",
39
+ key: `treemap-group-${h.id}`,
40
+ x: h.x0,
41
+ y: h.y0,
42
+ width: h.x1 - h.x0,
43
+ height: h.y1 - h.y0,
44
+ datum: h.data,
45
+ paint: {
46
+ fill: fillOf(h)
47
+ },
48
+ aria: {
49
+ label: `${name(h)}, ${sum(h.data)}, ${formatAbbreviate(summedShare(h.data) * 100, viz.schema.locale)}%`
50
+ }
51
+ }));
52
+ const asHeader = (d)=>d;
53
+ const byRow = new Map(headers.map((h)=>[
54
+ h.data,
55
+ h
56
+ ]));
57
+ const labels = emitLabels({
58
+ data: headers,
59
+ label: (d)=>name(asHeader(d)),
60
+ x: (d)=>asHeader(d).x0,
61
+ y: (d)=>asHeader(d).y0,
62
+ aes: (d)=>{
63
+ const h = asHeader(d);
64
+ return {
65
+ width: h.x1 - h.x0,
66
+ height: h.y1 - h.y0
67
+ };
68
+ },
69
+ rotate: constant(0),
70
+ id: (d)=>`group-${asHeader(d).id}`,
71
+ datum: (d)=>asHeader(d).data,
72
+ labelBounds: (_d, _i, aes)=>{
73
+ const { width, height } = aes;
74
+ return {
75
+ x: 0,
76
+ y: 0,
77
+ width,
78
+ height
79
+ };
80
+ },
81
+ labelConfig: {
82
+ fontColor: (d)=>{
83
+ const h = byRow.get(d.data) ?? headers[0];
84
+ return resolveAccessor(style.fontColor, h.data, 0) ?? colorContrast(fillOf(h), viz.schema.colorDefaults);
85
+ },
86
+ ...style.fontFamily ? {
87
+ fontFamily: style.fontFamily
88
+ } : {},
89
+ fontResize: false,
90
+ fontSize: style.fontSize,
91
+ fontWeight: style.fontWeight,
92
+ maxLines: 1,
93
+ padding: style.padding,
94
+ textAnchor: "start",
95
+ verticalAlign: "middle"
96
+ }
97
+ });
98
+ // Moves with its strip in the drill-down morph, like the tile labels.
99
+ for (const n of labels)n.shapeType = "Label";
100
+ return [
101
+ ...rects,
102
+ ...labels
103
+ ];
104
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ Treemap group headers: with a nested `groupBy`, each group above the drawn
3
+ tiles gets a strip across its top naming it, and its tiles sit below the
4
+ strip. Every level above the tiles gets its own strip, nested inside its
5
+ parent's. A group too small for a readable strip gets none, and its tiles
6
+ fill it.
7
+
8
+ The layout reserves a strip through d3-hierarchy's `paddingTop`, which
9
+ sees each group's box before its children are tiled into it.
10
+ */ import { merge } from "@d3plus/data";
11
+ import { stampShare } from "../features/shareKey.js";
12
+ import { GROUP_DEPTH_KEY, GROUP_LABEL_KEY } from "../viz/groupRow.js";
13
+ import { MEMBERS_KEY } from "../features/thresholdMembers.js";
14
+ /** `groupLabelConfig` defaults, under the user's config. */ export const groupLabelDefaults = {
15
+ fontSize: 11,
16
+ fontWeight: 600,
17
+ padding: 3
18
+ };
19
+ /**
20
+ The chart's group-header style, or null when headers are off
21
+ (`groupLabels: false`).
22
+ */ export function groupLabelStyle(viz) {
23
+ if (viz.schema.groupLabels === false) return null;
24
+ const config = viz.schema.groupLabelConfig ?? {};
25
+ return {
26
+ ...groupLabelDefaults,
27
+ fontFamily: viz.schema.fontFamily,
28
+ ...config
29
+ };
30
+ }
31
+ /** A strip's height: one line of text plus its padding above and below. */ export function groupStripHeight(style) {
32
+ return Math.ceil(style.fontSize * 1.2 + style.padding * 2);
33
+ }
34
+ /**
35
+ Whether a group `width` × `height` pixels gets a strip: it keeps at least
36
+ a strip's height for its tiles below the strip, and is wide enough for a
37
+ few characters of its name.
38
+ */ export function groupStripFits(width, height, style) {
39
+ return height >= groupStripHeight(style) * 2 && width >= style.fontSize * 3 + style.padding * 2;
40
+ }
41
+ /**
42
+ The treemap's `paddingTop`: a group above the drawn tiles (hierarchy depth
43
+ 1 through `drawDepth`) that fits a strip reserves it, and is recorded in
44
+ `strips` with the strip's height; every other node keeps `padding`.
45
+ */ export function groupPaddingTop(opts, strips) {
46
+ const { drawDepth, padding, style } = opts;
47
+ return (node)=>{
48
+ const group = node;
49
+ if (!style || group.depth < 1 || group.depth > drawDepth || group.data.key == null || !groupStripFits(group.x1 - group.x0, group.y1 - group.y0, style)) return padding;
50
+ const height = groupStripHeight(style);
51
+ strips.set(group, height);
52
+ return height + padding;
53
+ };
54
+ }
55
+ /** The `id` of a group at a hierarchy node: its key at each level. */ function groupId(node) {
56
+ return node.ancestors().reverse().slice(1).map((n)=>`${n.data.key}`).join("/");
57
+ }
58
+ /**
59
+ Stamps each group that reserved a strip with its header: the strip's box
60
+ (in the group's final, rounded position) and the group's merged row,
61
+ carrying its share of `total` and, when `label` gives one, its own label.
62
+ */ export function attachGroupHeaders(strips, opts) {
63
+ for (const [node, height] of strips){
64
+ const rows = node.leaves().map((leaf)=>leaf.data);
65
+ const data = merge(rows, opts.aggs);
66
+ // A group holding the threshold bucket is still a real group.
67
+ delete data._isAggregation;
68
+ delete data._threshold;
69
+ delete data[MEMBERS_KEY];
70
+ data[GROUP_DEPTH_KEY] = node.depth - 1;
71
+ const text = opts.label ? opts.label(data, 0) : undefined;
72
+ if (text !== undefined && text !== null && text !== false && text !== "") data[GROUP_LABEL_KEY] = `${text}`;
73
+ stampShare(data, (node.value ?? 0) / opts.total);
74
+ node.groupHeader = {
75
+ __d3plus__: true,
76
+ data,
77
+ depth: node.depth - 1,
78
+ id: groupId(node),
79
+ x0: node.x0,
80
+ y0: node.y0,
81
+ x1: node.x1,
82
+ y1: Math.min(node.y1, node.y0 + height)
83
+ };
84
+ }
85
+ }
86
+ /** The headers above the laid-out tiles, shallowest level first. */ export function collectGroupHeaders(leaves) {
87
+ const seen = new Set();
88
+ for (const leaf of leaves){
89
+ let n = leaf.parent;
90
+ for(; n; n = n.parent)if (n.groupHeader) seen.add(n.groupHeader);
91
+ }
92
+ return [
93
+ ...seen
94
+ ].sort((a, b)=>a.depth - b.depth);
95
+ }
@@ -5,11 +5,14 @@
5
5
  - `applyLayout.ts` — chart-specific `TransformStage`.
6
6
  - `emit.ts` — rect + label scene nodes from the laid-out data.
7
7
  - `thresholdFunction.ts` — pure threshold-merge algorithm.
8
+ - `groupHeaders.ts` / `emitGroupHeaders.ts` — the header strip above
9
+ each group of a nested `groupBy`.
8
10
 
9
11
  The default export is the chart class via `makeChart(def)`; the named
10
12
  export is the def itself.
11
13
  */ import { treemap, treemapBinary, treemapDice, treemapResquarify, treemapSlice, treemapSliceDice, treemapSquarify } from "d3-hierarchy";
12
14
  import accessor from "../../utils/accessor.js";
15
+ import { fieldAccessor } from "../../utils/fieldAccessor.js";
13
16
  import { rowLegend, shareRow } from "../features/sharedFields.js";
14
17
  import { makeChart } from "../definition/makeChart.js";
15
18
  import { applyTreemapLayout } from "./applyLayout.js";
@@ -33,7 +36,8 @@ export const treemapDef = {
33
36
  drawDepth: viz._drawDepth,
34
37
  groupBy: viz.schema.groupBy,
35
38
  threshold: viz.schema.threshold,
36
- thresholdKey: viz.schema.thresholdKey
39
+ thresholdKey: viz.schema.thresholdKey,
40
+ label: (d, i)=>viz._drawLabel(d, i)
37
41
  }),
38
42
  ctx: {
39
43
  treemap: treemap().round(true)
@@ -46,6 +50,15 @@ export const treemapDef = {
46
50
  key: "layoutPadding",
47
51
  default: 1
48
52
  },
53
+ {
54
+ key: "groupLabels",
55
+ default: true
56
+ },
57
+ {
58
+ key: "groupLabelConfig",
59
+ default: {},
60
+ merge: true
61
+ },
49
62
  /**
50
63
  Comparator for sibling rectangles, given two d3-hierarchy nodes. Defaults to
51
64
  descending by summed value, with any threshold bucket last.
@@ -68,7 +81,7 @@ export const treemapDef = {
68
81
  */ {
69
82
  key: "sum",
70
83
  default: accessor("value"),
71
- coerce: (v)=>typeof v === "function" ? v : accessor(v),
84
+ coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v),
72
85
  onSet: (viz, v)=>{
73
86
  viz.schema.thresholdKey = v;
74
87
  }
@@ -4,13 +4,15 @@
4
4
  from the viz.
5
5
  */ import { group, sum } from "d3-array";
6
6
  import { merge } from "@d3plus/data";
7
+ import { MEMBERS_KEY, thresholdMemberList } from "../features/thresholdMembers.js";
7
8
  /**
8
9
  Walks `data` to `drawDepth` and merges entries whose `thresholdKey`
9
10
  value falls below `threshold(branchData) * totalSum` into a single
10
- aggregated row at that depth. Returns the kept set; original `data`
11
- is not mutated.
11
+ aggregated row at that depth, listing them (largest first) under
12
+ `MEMBERS_KEY`. A lone entry under the threshold stays as itself: a
13
+ bucket needs two. Returns the kept set; original `data` is not mutated.
12
14
  */ export function thresholdFunction(data, inputs) {
13
- const { aggs, drawDepth, groupBy, threshold, thresholdKey } = inputs;
15
+ const { aggs, drawDepth, groupBy, label, threshold, thresholdKey } = inputs;
14
16
  const totalSum = sum(data, thresholdKey);
15
17
  if (!threshold || !thresholdKey) return data;
16
18
  /**
@@ -37,12 +39,12 @@ import { merge } from "@d3plus/data";
37
39
  if (thresholdKey(datum) < thresholdValue) removedItems.push(datum);
38
40
  else kept.push(datum);
39
41
  }
40
- if (removedItems.length > 0) {
41
- const mergedItem = merge(removedItems, aggs);
42
- mergedItem._isAggregation = true;
43
- mergedItem._threshold = thresholdPercent;
44
- kept.push(mergedItem);
45
- }
42
+ if (removedItems.length < 2) return branchData;
43
+ const mergedItem = merge(removedItems, aggs);
44
+ mergedItem._isAggregation = true;
45
+ mergedItem._threshold = thresholdPercent;
46
+ mergedItem[MEMBERS_KEY] = thresholdMemberList(removedItems, (_d, i)=>i, label ?? ((d)=>groupBy[depth](d)), thresholdKey);
47
+ kept.push(mergedItem);
46
48
  return kept;
47
49
  }
48
50
  throw new Error("Depth is higher than the amount of grouping levels.");
@@ -9,6 +9,7 @@
9
9
  - `waffleLayout.ts` — pure allocation (largest remainder) and grid math.
10
10
  - `tooltip.ts` — the "Value" and "Share" tooltip rows.
11
11
  */ import accessor from "../../utils/accessor.js";
12
+ import { fieldAccessor } from "../../utils/fieldAccessor.js";
12
13
  import { makeChart } from "../definition/makeChart.js";
13
14
  import { sceneInsetRegion } from "../pipeline/insetPlacement.js";
14
15
  import { thresholdFunction } from "../Treemap/thresholdFunction.js";
@@ -34,7 +35,8 @@ export const waffleDef = {
34
35
  drawDepth: viz._drawDepth,
35
36
  groupBy: viz.schema.groupBy,
36
37
  threshold: viz.schema.threshold,
37
- thresholdKey: viz.schema.thresholdKey
38
+ thresholdKey: viz.schema.thresholdKey,
39
+ label: (d, i)=>viz._drawLabel(d, i)
38
40
  }),
39
41
  // The default 10 × 10 grid is square.
40
42
  facet: {
@@ -124,7 +126,7 @@ export const waffleDef = {
124
126
  */ {
125
127
  key: "sum",
126
128
  default: accessor("value"),
127
- coerce: (v)=>typeof v === "function" ? v : accessor(v),
129
+ coerce: (v)=>typeof v === "function" ? v : fieldAccessor(v),
128
130
  onSet: (viz, v)=>{
129
131
  viz.schema.thresholdKey = v;
130
132
  }
@@ -4,7 +4,7 @@
4
4
  @module
5
5
  */ import { formatAbbreviate } from "@d3plus/format";
6
6
  import { colorScaleBucketShare } from "../features/colorScaleBucket.js";
7
- import { summedShare } from "../features/shareKey.js";
7
+ import { shareOfRows, summedShare, unwrapRow } from "../features/shareKey.js";
8
8
  /** Formats a 0–1 share as an abbreviated percentage, or "" when not finite. */ export function formatShare(share, locale) {
9
9
  return share == null || !Number.isFinite(share) ? "" : `${formatAbbreviate(share * 100, locale)}%`;
10
10
  }
@@ -15,7 +15,11 @@ import { summedShare } from "../features/shareKey.js";
15
15
  */ export function waffleShare(viz, x) {
16
16
  const sum = viz.schema.sum;
17
17
  if (x._isColorScaleBucket) return colorScaleBucketShare(viz, x.color, sum);
18
- return summedShare(x);
18
+ const row = unwrapRow(x);
19
+ const share = summedShare(row);
20
+ // A legend entry the layout hasn't stamped (a threshold bucket) reads its
21
+ // share of every legend row's value.
22
+ return Number.isFinite(share) ? share : shareOfRows(row, viz._legendData || [], (d)=>sum(d, 0));
19
23
  }
20
24
  /** The `[label, value]` tooltip rows: the summed value, then its share. */ export function waffleTooltipRows(viz) {
21
25
  const locale = ()=>viz.schema.locale;
@@ -3,7 +3,7 @@
3
3
  the running total before it ended, and subtotal rows draw from zero to the
4
4
  running total. Bars are colored by whether they increase, decrease, or
5
5
  total, with thin connectors carrying each bar's end level to the next.
6
- */ import accessor from "../../utils/accessor.js";
6
+ */ import { fieldAccessor } from "../../utils/fieldAccessor.js";
7
7
  import { makeChart } from "../definition/makeChart.js";
8
8
  import BarChart from "../BarChart/index.js";
9
9
  import { backgroundInk } from "../viz/backgroundInk.js";
@@ -87,6 +87,8 @@ import { WATERFALL_KINDS, waterfallKinds, waterfallStackOffset } from "./steps.j
87
87
  export const waterfallDef = {
88
88
  name: "Waterfall",
89
89
  paintDriven: true,
90
+ // Each bar is a step of its own, so `threshold` folds nothing.
91
+ thresholdFunction: (_viz, data)=>data,
90
92
  setup: (viz)=>{
91
93
  viz.ctx.waterfall = {
92
94
  accessors: {
@@ -163,7 +165,7 @@ export const waterfallDef = {
163
165
  has its own value, the running total resets to that value.
164
166
  */ {
165
167
  key: "subtotal",
166
- coerce: (v)=>typeof v === "string" ? accessor(v) : typeof v === "function" ? v : undefined
168
+ coerce: (v)=>typeof v === "string" ? fieldAccessor(v) : typeof v === "function" ? v : undefined
167
169
  },
168
170
  /**
169
171
  Fill for subtotal bars. Defaults to `colorDefaults.sequential`.
@@ -5,9 +5,10 @@
5
5
  The class is identical for every chart: its constructor runs
6
6
  `applyDefinition(this, def)`, its `_draw` runs the shared Viz pipeline
7
7
  then the chart's own layout stage via `runChartDraw`, and its
8
- `_thresholdFunction` / `_sizeLegendScale` / `_insetRegion` delegate to
9
- `def.thresholdFunction` / `def.sizeLegendScale` / `def.insetRegion` if
10
- present, `_facetHooks` layers `def.facet` over the base chart's, and
8
+ `_thresholdFunction` / `_thresholdLegend` / `_sizeLegendScale` / `_insetRegion` /
9
+ `_colorScaleShape` delegate to `def.thresholdFunction` /
10
+ `def.sizeLegendScale` / `def.insetRegion` / `def.colorScaleShape` if
11
+ present (else to the base chart's), `_facetHooks` layers `def.facet` over the base chart's, and
11
12
  `toScene` passes the base chart's scene through `def.decorateScene`.
12
13
 
13
14
  A chart's `index.ts` becomes literally `export default makeChart(def)`.
@@ -43,14 +44,20 @@ import Viz from "../viz/Viz.js";
43
44
  _insetRegion() {
44
45
  return def.insetRegion ? def.insetRegion(this) : super._insetRegion();
45
46
  }
47
+ _colorScaleShape(d, i) {
48
+ return def.colorScaleShape ? def.colorScaleShape(this, d, i) : super._colorScaleShape(d, i);
49
+ }
46
50
  _facetHooks() {
47
51
  return def.facet ? {
48
52
  ...super._facetHooks(),
49
53
  ...def.facet
50
54
  } : super._facetHooks();
51
55
  }
52
- _thresholdFunction(data) {
53
- return def.thresholdFunction ? def.thresholdFunction(this, data) : data;
56
+ _thresholdLegend(legendData) {
57
+ return def.thresholdFunction ? def.thresholdFunction(this, legendData, legendData) : super._thresholdLegend(legendData);
58
+ }
59
+ _thresholdFunction(data, tree, all) {
60
+ return def.thresholdFunction ? def.thresholdFunction(this, data, all) : super._thresholdFunction(data, tree, all);
54
61
  }
55
62
  }
56
63
  Object.defineProperty(Chart, "name", {