@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
@@ -0,0 +1,176 @@
1
+ /**
2
+ Saves a chart as a PNG, SVG, or JPG file through `@d3plus/export`'s
3
+ `saveElement`, for the top-left download button (`saveControl.ts`).
4
+
5
+ Only the drawing is saved: the chart's `<svg>` on the SVG backend, its
6
+ `<canvas>` on the Canvas backend. The controls, the open menu, and
7
+ tooltips live in HTML outside that element, so they never reach the
8
+ file. An SVG file from a Canvas chart re-renders the retained scene
9
+ through the SVG backend (`viz.toSVGString()`).
10
+
11
+ @module
12
+ */ import { saveElement } from "@d3plus/export";
13
+ import { chartBackground } from "../viz/backgroundInk.js";
14
+ const SVG_NS = "http://www.w3.org/2000/svg";
15
+ /** Every format the download button can save, in its default menu order. */ export const SAVE_FORMATS = [
16
+ "png",
17
+ "svg",
18
+ "jpg"
19
+ ];
20
+ /** The valid, de-duplicated formats in `value`, or every format when `value` isn't an array. */ export function saveFormats(value) {
21
+ if (!Array.isArray(value)) return SAVE_FORMATS.slice();
22
+ const formats = [];
23
+ for (const v of value){
24
+ const format = String(v).toLowerCase().replace("jpeg", "jpg");
25
+ if (SAVE_FORMATS.includes(format) && !formats.includes(format)) formats.push(format);
26
+ }
27
+ return formats;
28
+ }
29
+ /**
30
+ A filename (without extension) from a title: markup and characters that
31
+ file systems reject are dropped, whitespace collapsed, and the result
32
+ capped at 100 characters. `"download"` when nothing is left.
33
+ */ export function saveFilename(title) {
34
+ const name = typeof title === "string" || typeof title === "number" ? String(title).replace(/<[^>]*>/g, "").replace(/[\\/:*?"<>|\p{Cc}]/gu, "").replace(/\s+/g, " ").trim().slice(0, 100).trim() : "";
35
+ return name || "download";
36
+ }
37
+ /** The page color behind the chart. */ function pageBackground(viz) {
38
+ return chartBackground({
39
+ _select: viz._select
40
+ });
41
+ }
42
+ /** The chart's resolved title text, or `undefined` when it has none. */ function chartTitle(viz) {
43
+ const title = viz.schema.title;
44
+ return typeof title === "function" ? title(viz._filteredData || []) : undefined;
45
+ }
46
+ /** `saveControlConfig` with its defaults applied. */ export function resolveSaveConfig(viz) {
47
+ const { filename, formats, background, callback, ...renderOptions } = viz.schema.saveControlConfig || {};
48
+ return {
49
+ filename: typeof filename === "string" && filename.trim() ? saveFilename(filename) : saveFilename(chartTitle(viz)),
50
+ formats: saveFormats(formats),
51
+ background: background === false ? false : typeof background === "string" && background ? background : pageBackground(viz),
52
+ callback: typeof callback === "function" ? callback : undefined,
53
+ renderOptions
54
+ };
55
+ }
56
+ /** The chart's drawing surface: its `<canvas>` on the Canvas backend, else its `<svg>`. */ export function saveTarget(viz) {
57
+ const node = viz._renderer === "canvas" ? viz.toCanvas() : viz._select?.node?.();
58
+ const tag = viz._renderer === "canvas" ? "canvas" : "svg";
59
+ return node?.localName === tag ? node : null;
60
+ }
61
+ /** Page-placement attributes and styles a saved file has no use for. */ const PAGE_STYLES = [
62
+ "position",
63
+ "top",
64
+ "left",
65
+ "content-visibility",
66
+ "touch-action"
67
+ ];
68
+ /** Drops the on-page placement from a copy of the chart's `<svg>`. */ function standalone(svg) {
69
+ svg.removeAttribute("aria-hidden");
70
+ for (const prop of PAGE_STYLES)svg.style?.removeProperty(prop);
71
+ }
72
+ /**
73
+ A detached copy of the chart's `<svg>` to save as a file, with a rect
74
+ filling `background` behind everything (none when `false`). The SVG
75
+ backend copies its live `<svg>`; the Canvas backend parses the scene
76
+ re-rendered as SVG markup.
77
+ */ export function svgForSave(viz, background) {
78
+ let svg = null;
79
+ if (viz._renderer === "canvas") {
80
+ const markup = viz.toSVGString();
81
+ if (markup) {
82
+ const doc = new DOMParser().parseFromString(markup, "image/svg+xml");
83
+ svg = doc.querySelector("parsererror") ? null : doc.documentElement;
84
+ }
85
+ } else {
86
+ const node = saveTarget(viz);
87
+ svg = node ? node.cloneNode(true) : null;
88
+ if (svg) standalone(svg);
89
+ }
90
+ if (!svg || svg.localName !== "svg") return null;
91
+ if (background) {
92
+ const rect = svg.ownerDocument.createElementNS(SVG_NS, "rect");
93
+ rect.setAttribute("class", "d3plus-save-background");
94
+ rect.setAttribute("width", "100%");
95
+ rect.setAttribute("height", "100%");
96
+ rect.setAttribute("fill", background);
97
+ svg.insertBefore(rect, svg.firstChild);
98
+ }
99
+ return svg;
100
+ }
101
+ /** The pixel density a PNG or JPG is drawn at: `pixelRatio`, else the screen's. */ export function savePixelRatio(renderOptions) {
102
+ const ratio = renderOptions.pixelRatio;
103
+ if (typeof ratio === "number" && ratio > 0) return ratio;
104
+ return typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1;
105
+ }
106
+ /**
107
+ Whether a canvas has fewer backing pixels per CSS pixel than
108
+ `pixelRatio`, so drawing an image from it would come out blurry.
109
+ */ export function canvasTooCoarse(canvas, pixelRatio) {
110
+ const cssWidth = canvas.getBoundingClientRect().width;
111
+ return cssWidth > 0 && canvas.width / cssWidth < pixelRatio - 0.01;
112
+ }
113
+ /**
114
+ Rasterizes the scene re-rendered as SVG, for a Canvas chart whose canvas
115
+ is too coarse for the requested density. The copy is mounted off-screen
116
+ while it renders, since html-to-image measures and styles live nodes.
117
+ */ function saveFromVector(viz, canvas, options, renderOptions, done) {
118
+ const backgroundColor = renderOptions.backgroundColor;
119
+ const svg = svgForSave(viz, typeof backgroundColor === "string" ? backgroundColor : false);
120
+ const doc = canvas.ownerDocument;
121
+ if (!svg || !doc.body) return false;
122
+ const holder = doc.createElement("div");
123
+ holder.setAttribute("aria-hidden", "true");
124
+ holder.style.cssText = "position:fixed;left:-100000px;top:0;";
125
+ const copy = doc.importNode(svg, true);
126
+ holder.appendChild(copy);
127
+ doc.body.appendChild(holder);
128
+ saveElement(copy, {
129
+ ...options,
130
+ callback: (error)=>{
131
+ holder.remove();
132
+ done(error);
133
+ }
134
+ }, renderOptions);
135
+ return true;
136
+ }
137
+ /**
138
+ Saves the chart as a `format` file, named and styled by
139
+ `saveControlConfig`. Errors go to its `callback`, or to the console.
140
+ */ export function saveChart(viz, format) {
141
+ const { filename, background, callback, renderOptions } = resolveSaveConfig(viz);
142
+ const done = (error)=>{
143
+ if (callback) callback(error);
144
+ else if (error) console.error(error);
145
+ };
146
+ const unrendered = ()=>done(new Error("The chart has not been rendered, so it cannot be saved."));
147
+ if (format === "svg") {
148
+ const svg = svgForSave(viz, background);
149
+ if (!svg) return unrendered();
150
+ saveElement(svg, {
151
+ filename,
152
+ type: "svg",
153
+ callback: done
154
+ });
155
+ return;
156
+ }
157
+ const target = saveTarget(viz);
158
+ if (!target) return unrendered();
159
+ // A JPG has no transparency: without a background its empty pixels are black.
160
+ const backgroundColor = background || (format === "jpg" ? pageBackground(viz) : undefined);
161
+ const raster = {
162
+ ...renderOptions,
163
+ backgroundColor
164
+ };
165
+ const options = {
166
+ filename,
167
+ type: format
168
+ };
169
+ // A Canvas chart's pixels are fixed at its own density, so a sharper
170
+ // image comes from the scene re-rendered as SVG.
171
+ if (viz._renderer === "canvas" && canvasTooCoarse(target, savePixelRatio(raster)) && saveFromVector(viz, target, options, raster, done)) return;
172
+ saveElement(target, {
173
+ ...options,
174
+ callback: done
175
+ }, raster);
176
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ @name saveContribution
3
+ The download button's contribution to the shared top-left controls panel
4
+ (`topLeftControls.ts`). With several formats it opens a menu of them
5
+ (a menu button: arrow keys move between items, Escape closes and returns
6
+ focus to the button, a click outside closes it); with one format it
7
+ saves in one click. Saving runs through `saveChart`.
8
+
9
+ @module
10
+ */ import { saveChart } from "./saveChart.js";
11
+ import { paintSaveButton, paintSaveMenuItem, SAVE_MENU_OPEN_STYLE, SAVE_MENU_STYLE, saveButtonStyles, saveControlHtml, showsSaveControl } from "./saveControlMarkup.js";
12
+ /** Removes an open menu's outside-click listener, keyed by its root element. */ const outsideListeners = new WeakMap();
13
+ function rootOf(target) {
14
+ return target instanceof Element ? target.closest(".save-root") : null;
15
+ }
16
+ function toggleOf(root) {
17
+ return root.querySelector(".save-toggle");
18
+ }
19
+ function menuItems(root) {
20
+ return Array.from(root.querySelectorAll(".save-menu-item"));
21
+ }
22
+ /** Whether the menu inside `root` is open. */ export function isSaveMenuOpen(root) {
23
+ return toggleOf(root)?.getAttribute("aria-expanded") === "true";
24
+ }
25
+ function setMenuOpen(viz, root, open) {
26
+ const btn = toggleOf(root);
27
+ const menu = root.querySelector(".d3plus-save-menu");
28
+ if (!btn || !menu) return;
29
+ btn.setAttribute("aria-expanded", String(open));
30
+ btn.classList.toggle("active", open);
31
+ paintSaveButton(viz, btn, btn.matches(":hover"));
32
+ const style = open ? SAVE_MENU_OPEN_STYLE : SAVE_MENU_STYLE;
33
+ menu.style.setProperty("display", String(style.display));
34
+ }
35
+ /** Closes the menu inside `root`, returning focus to its button when `refocus`. */ export function closeSaveMenu(viz, root, refocus = false) {
36
+ outsideListeners.get(root)?.();
37
+ outsideListeners.delete(root);
38
+ setMenuOpen(viz, root, false);
39
+ if (refocus) toggleOf(root)?.focus();
40
+ }
41
+ /** Opens the menu inside `root` and focuses its first (or last) item. */ export function openSaveMenu(viz, root, focus = "first") {
42
+ setMenuOpen(viz, root, true);
43
+ const doc = root.ownerDocument;
44
+ const onPointerDown = (e)=>{
45
+ if (!root.isConnected || !root.contains(e.target)) closeSaveMenu(viz, root);
46
+ };
47
+ outsideListeners.get(root)?.();
48
+ doc.addEventListener("pointerdown", onPointerDown, true);
49
+ outsideListeners.set(root, ()=>doc.removeEventListener("pointerdown", onPointerDown, true));
50
+ const items = menuItems(root);
51
+ items[focus === "last" ? items.length - 1 : 0]?.focus();
52
+ }
53
+ function onToggleClick(viz, e) {
54
+ const root = rootOf(e.target);
55
+ const btn = root && toggleOf(root);
56
+ if (!root || !btn) return;
57
+ const format = btn.dataset.format;
58
+ if (format) saveChart(viz, format);
59
+ else if (isSaveMenuOpen(root)) closeSaveMenu(viz, root, true);
60
+ else openSaveMenu(viz, root);
61
+ }
62
+ function onToggleKeydown(viz, e) {
63
+ const key = e.key;
64
+ const root = rootOf(e.target);
65
+ if (!root || !root.querySelector(".d3plus-save-menu")) return;
66
+ if (key === "ArrowDown" || key === "ArrowUp") {
67
+ e.preventDefault();
68
+ openSaveMenu(viz, root, key === "ArrowUp" ? "last" : "first");
69
+ } else if (key === "Escape" && isSaveMenuOpen(root)) {
70
+ e.stopPropagation();
71
+ closeSaveMenu(viz, root, true);
72
+ }
73
+ }
74
+ /** Moves focus between menu items with the arrow, Home, and End keys; Escape and Tab close the menu. */ function onMenuKeydown(viz, e) {
75
+ const key = e.key;
76
+ const root = rootOf(e.target);
77
+ if (!root) return;
78
+ const items = menuItems(root);
79
+ const index = items.indexOf(e.target);
80
+ const focusAt = (i)=>{
81
+ e.preventDefault();
82
+ items[(i + items.length) % items.length]?.focus();
83
+ };
84
+ if (key === "ArrowDown") focusAt(index + 1);
85
+ else if (key === "ArrowUp") focusAt(index - 1);
86
+ else if (key === "Home") focusAt(0);
87
+ else if (key === "End") focusAt(items.length - 1);
88
+ else if (key === "Escape") {
89
+ e.preventDefault();
90
+ e.stopPropagation();
91
+ closeSaveMenu(viz, root, true);
92
+ } else if (key === "Tab") closeSaveMenu(viz, root);
93
+ }
94
+ function onItemClick(viz, e) {
95
+ const root = rootOf(e.target);
96
+ const item = e.target.closest(".save-menu-item");
97
+ if (!root || !item) return;
98
+ closeSaveMenu(viz, root, true);
99
+ saveChart(viz, item.dataset.format);
100
+ }
101
+ /** Closes the menu when keyboard focus moves somewhere outside it. */ function onRootFocusout(viz, e) {
102
+ const root = rootOf(e.target);
103
+ const next = e.relatedTarget;
104
+ if (root && next && !root.contains(next) && isSaveMenuOpen(root)) closeSaveMenu(viz, root);
105
+ }
106
+ /** Hovering an item focuses it, so the pointer and the keyboard share one highlight. */ function focusItem(e) {
107
+ e.target.closest(".save-menu-item")?.focus();
108
+ }
109
+ function paintItem(viz, e, focused) {
110
+ const item = e.target.closest(".save-menu-item");
111
+ if (item) paintSaveMenuItem(viz, item, focused);
112
+ }
113
+ export function saveContribution(viz) {
114
+ if (!showsSaveControl(viz)) return null;
115
+ return {
116
+ key: "save",
117
+ html: saveControlHtml(viz),
118
+ styleSignature: JSON.stringify(saveButtonStyles(viz)),
119
+ events: {
120
+ ".save-toggle": {
121
+ click: (e)=>onToggleClick(viz, e),
122
+ keydown: (e)=>onToggleKeydown(viz, e)
123
+ },
124
+ ".d3plus-save-menu": {
125
+ keydown: (e)=>onMenuKeydown(viz, e)
126
+ },
127
+ ".save-menu-item": {
128
+ click: (e)=>onItemClick(viz, e),
129
+ mouseover: (e)=>focusItem(e),
130
+ focusin: (e)=>paintItem(viz, e, true),
131
+ focusout: (e)=>paintItem(viz, e, false)
132
+ },
133
+ ".save-root": {
134
+ focusout: (e)=>onRootFocusout(viz, e)
135
+ }
136
+ },
137
+ // Hover can't be delegated (mouseenter/mouseleave don't bubble), so bind
138
+ // it once per button, as the other top-left controls do.
139
+ onUpdate: (host)=>{
140
+ const btn = host.querySelector(".save-toggle");
141
+ if (!btn || btn.dataset.saveBound) return;
142
+ btn.dataset.saveBound = "1";
143
+ paintSaveButton(viz, btn);
144
+ btn.addEventListener("mouseenter", ()=>paintSaveButton(viz, btn, true));
145
+ btn.addEventListener("mouseleave", ()=>paintSaveButton(viz, btn));
146
+ }
147
+ };
148
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ Markup and styling for the download button (`saveControl.ts`): a toggle
3
+ button and the menu of file formats it opens.
4
+
5
+ The menu's open state lives only in the DOM (its `display` and the
6
+ button's `aria-expanded`), never in the generated html, so opening it
7
+ neither changes the panel's measured size nor makes the next repaint
8
+ rewrite the open menu.
9
+
10
+ @module
11
+ */ import { controlButtonStyles, escapeHtml, kebab, paintControlButton, resolveControlStyle } from "./controlButtonStyle.js";
12
+ import { saveFormats } from "./saveChart.js";
13
+ import { DOWNLOAD_ICON } from "./tableViewMarkup.js";
14
+ import { saveControlMenuItemStyleDefault, saveControlMenuItemStyleHoverDefault, saveControlMenuStyleDefault, saveControlStyleActiveDefault, saveControlStyleDefault, saveControlStyleHoverDefault } from "../viz/vizDefaults.js";
15
+ /** The English label of each format's menu item, translated through `translate`. */ export const SAVE_FORMAT_LABELS = {
16
+ png: "PNG image",
17
+ svg: "SVG vector",
18
+ jpg: "JPG image"
19
+ };
20
+ /** The formats a chart's download button offers. */ function chartSaveFormats(viz) {
21
+ return saveFormats(viz.schema.saveControlConfig?.formats);
22
+ }
23
+ /** Whether a chart shows the download button. */ export function showsSaveControl(viz) {
24
+ return Boolean(viz.schema.saveControl) && !viz._ssr && chartSaveFormats(viz).length > 0;
25
+ }
26
+ /** The resolved base / active / hover styles of the download button. */ export function saveButtonStyles(viz) {
27
+ return controlButtonStyles(viz.schema, "saveControl", {
28
+ base: saveControlStyleDefault,
29
+ active: saveControlStyleActiveDefault,
30
+ hover: saveControlStyleHoverDefault
31
+ });
32
+ }
33
+ /** Paints the download button's inline style for its state (base, hover, menu open). */ export function paintSaveButton(viz, btn, hovered = false) {
34
+ paintControlButton(btn, saveButtonStyles(viz), hovered, btn.classList.contains("active"));
35
+ }
36
+ const ROOT_STYLE = {
37
+ position: "relative",
38
+ display: "inline-flex",
39
+ "align-items": "center"
40
+ };
41
+ /** The menu's fixed layout while closed; `SAVE_MENU_OPEN_STYLE` shows it. */ export const SAVE_MENU_STYLE = {
42
+ position: "absolute",
43
+ top: "100%",
44
+ left: "0",
45
+ "z-index": "1",
46
+ display: "none",
47
+ "flex-direction": "column",
48
+ "min-width": "max-content"
49
+ };
50
+ export const SAVE_MENU_OPEN_STYLE = {
51
+ display: "flex"
52
+ };
53
+ /** Each menu item's fixed layout. */ const ITEM_STYLE = {
54
+ display: "block",
55
+ width: "100%",
56
+ "text-align": "start",
57
+ "white-space": "nowrap",
58
+ cursor: "pointer"
59
+ };
60
+ /**
61
+ Resolves `saveControlMenuStyle`, `saveControlMenuItemStyle`, and
62
+ `saveControlMenuItemStyleHover`, with `saveControlMenuClassName`
63
+ dropping whichever are still the defaults.
64
+ */ export function saveMenuStyles(viz) {
65
+ const className = Boolean(viz.schema.saveControlMenuClassName);
66
+ const style = (key, fallback)=>resolveControlStyle(viz.schema[key], fallback, className);
67
+ return {
68
+ menu: style("saveControlMenuStyle", saveControlMenuStyleDefault),
69
+ item: style("saveControlMenuItemStyle", saveControlMenuItemStyleDefault),
70
+ itemHover: style("saveControlMenuItemStyleHover", saveControlMenuItemStyleHoverDefault)
71
+ };
72
+ }
73
+ /** Paints a menu item's inline style, with the hover style while it has focus. */ export function paintSaveMenuItem(viz, item, focused) {
74
+ const { item: base, itemHover: hover } = saveMenuStyles(viz);
75
+ paintControlButton(item, {
76
+ base: {
77
+ ...base,
78
+ ...ITEM_STYLE
79
+ },
80
+ hover
81
+ }, focused, false);
82
+ }
83
+ function styleAttr(...styles) {
84
+ return styles.flatMap((style)=>Object.entries(style)).filter(([, v])=>v !== undefined && v !== null && v !== false).map(([k, v])=>`${kebab(k)}:${escapeHtml(v)}`).join(";");
85
+ }
86
+ /**
87
+ The button's markup, plus its menu when more than one format is offered.
88
+ With one format, the button saves it directly and names it in its label.
89
+ */ export function saveControlHtml(viz) {
90
+ const formats = chartSaveFormats(viz);
91
+ const translate = (text)=>viz.schema.translate(text);
92
+ const download = translate("Download");
93
+ const extraClass = viz.schema.saveControlClassName ? ` ${escapeHtml(viz.schema.saveControlClassName)}` : "";
94
+ const button = (label, attrs)=>`<button type="button" class="save-control save-toggle${extraClass}" aria-label="${escapeHtml(label)}" title="${escapeHtml(label)}"${attrs}>${DOWNLOAD_ICON}</button>`;
95
+ if (formats.length === 1) {
96
+ const label = `${download} (${translate(SAVE_FORMAT_LABELS[formats[0]])})`;
97
+ return `<span class="save-root" style="${styleAttr(ROOT_STYLE)}">${button(label, ` data-format="${formats[0]}"`)}</span>`;
98
+ }
99
+ const styles = saveMenuStyles(viz);
100
+ const itemStyle = styleAttr(styles.item, ITEM_STYLE);
101
+ const menuClass = viz.schema.saveControlMenuClassName ? ` ${escapeHtml(viz.schema.saveControlMenuClassName)}` : "";
102
+ const items = formats.map((format)=>`<button type="button" role="menuitem" tabindex="-1" class="save-menu-item" data-format="${format}" style="${itemStyle}">${escapeHtml(translate(SAVE_FORMAT_LABELS[format]))}</button>`).join("");
103
+ return `<span class="save-root" style="${styleAttr(ROOT_STYLE)}">` + button(download, ' aria-haspopup="menu" aria-expanded="false"') + `<span class="d3plus-save-menu${menuClass}" role="menu" aria-label="${escapeHtml(download)}" style="${styleAttr(styles.menu, SAVE_MENU_STYLE)}">${items}</span>` + `</span>`;
104
+ }
@@ -80,7 +80,7 @@ export function setTableViewDataSource(viz, value) {
80
80
  // A simple spreadsheet-style grid: outer frame + one horizontal + one vertical divider.
81
81
  const TABLE_ICON = `<svg ${ICON_ATTRS}><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="12" y1="3" x2="12" y2="21"/></svg>`;
82
82
  // A downward arrow into a tray — the conventional "download" icon.
83
- const DOWNLOAD_ICON = `<svg ${ICON_ATTRS}><path d="M12 3v12"/><polyline points="7 11 12 16 17 11"/><path d="M4 18v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1"/></svg>`;
83
+ export const DOWNLOAD_ICON = `<svg ${ICON_ATTRS}><path d="M12 3v12"/><polyline points="7 11 12 16 17 11"/><path d="M4 18v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1"/></svg>`;
84
84
  // Two opposing horizontal arrows — the conventional "swap/exchange" icon.
85
85
  // One constant icon regardless of state (like TABLE_ICON above): only the
86
86
  // label/aria-pressed/active-class communicate which of the two datasets is
@@ -4,7 +4,7 @@
4
4
  zoom-controls panel's "N buttons, one flex-row `htmlOverlay` panel"
5
5
  composition (`zoomControls.ts`/`zoomControlsMarkup.ts`), except fed by
6
6
  independent contributor functions (`backContribution`,
7
- `tableViewContribution`, `searchContribution`) rather than one feature's
7
+ `tableViewContribution`, `saveContribution`, `searchContribution`) rather than one feature's
8
8
  own fixed button set. A downstream branch adding a new top-left control
9
9
  appends its own contributor function to `TOP_LEFT_CONTRIBUTORS` — a
10
10
  one-line diff, not a dynamic registry.
@@ -19,6 +19,7 @@
19
19
  @module
20
20
  */ import { backContribution } from "./backControl.js";
21
21
  import { tableViewContribution } from "./tableViewControl.js";
22
+ import { saveContribution } from "./saveControl.js";
22
23
  import { searchContribution } from "./searchControls.js";
23
24
  import { buildTopLeftPanel } from "./topLeftControlsMarkup.js";
24
25
  /**
@@ -27,6 +28,7 @@ import { buildTopLeftPanel } from "./topLeftControlsMarkup.js";
27
28
  */ export const TOP_LEFT_CONTRIBUTORS = [
28
29
  backContribution,
29
30
  tableViewContribution,
31
+ saveContribution,
30
32
  searchContribution
31
33
  ];
32
34
  /** The current, non-null contributions for a chart — computed once per layout/measurement. */ export function getTopLeftContributions(viz) {
@@ -122,7 +122,7 @@ const ESTIMATED_ITEM_HEIGHT = 20;
122
122
  The shared top-left panel's rendered size (padding included) as it will
123
123
  render in the chart's page, so top-positioned content can leave room for
124
124
  it — the same measure-a-hidden-probe technique `zoomControlsBox` uses,
125
- generalized to whichever mix of controls (back / table-view / search)
125
+ generalized to whichever mix of controls (back / table-view / save / search)
126
126
  is currently contributing, and to each contribution's OWN resolved
127
127
  button styling (not just its markup). Returns null when nothing is
128
128
  contributing.
@@ -1,10 +1,37 @@
1
1
  import { nodeRect } from "../pipeline/drillMorph.js";
2
+ import { groupDepthOf, groupNarrows, groupPath, inGroup } from "../viz/groupRow.js";
3
+ /**
4
+ Zooms into the group a group row stands for (see `viz/groupRow.ts`):
5
+ filters the data to that group, keeping the drawn depth, and records the
6
+ previous view on the drill-down history so Back steps out. Does nothing
7
+ when the group is already all that's drawn.
8
+ */ function zoomIntoGroup(viz, d, depth) {
9
+ const groupBy = viz.schema.groupBy;
10
+ const path = groupPath(groupBy, d, depth);
11
+ if (!groupNarrows(groupBy, path, viz._filteredData ?? [])) return;
12
+ viz._select.style("cursor", "auto");
13
+ viz.hover(false);
14
+ viz._tooltipClass.data([]).render();
15
+ const oldFilter = viz.schema.filter;
16
+ viz._history.push({
17
+ depth: viz.schema.depth,
18
+ filter: oldFilter
19
+ });
20
+ viz.config({
21
+ filter: (f, x)=>(!oldFilter || oldFilter(f, x)) && inGroup(groupBy, path, f, x)
22
+ }).render();
23
+ }
2
24
  /**
3
25
  @module clickShape
4
26
  On click event for all shapes in a Viz.
5
27
  @private
6
28
  */ export default function(d, i, x, event) {
7
29
  event.stopPropagation();
30
+ const groupDepth = groupDepthOf(d);
31
+ if (groupDepth !== undefined) {
32
+ zoomIntoGroup(this, d, groupDepth);
33
+ return;
34
+ }
8
35
  if (this._drawDepth < this.schema.groupBy.length - 1) {
9
36
  this._select.style("cursor", "auto");
10
37
  const filterGroup = this.schema.groupBy[this._drawDepth], filterId = filterGroup(d, i);
@@ -36,9 +63,11 @@ import { nodeRect } from "../pipeline/drillMorph.js";
36
63
  groupId: filterId,
37
64
  groupDepth: this._drawDepth
38
65
  });
66
+ // A threshold bucket's id lists the groups it holds; it opens onto them.
67
+ const inGroup = Array.isArray(filterId) ? (v)=>filterId.includes(v) : (v)=>v === filterId;
39
68
  this.config({
40
69
  depth: this._drawDepth + 1,
41
- filter: (f, x)=>(!oldFilter || oldFilter(f, x)) && filterGroup(f, x) === filterId
70
+ filter: (f, x)=>(!oldFilter || oldFilter(f, x)) && inGroup(filterGroup(f, x))
42
71
  }).render();
43
72
  }
44
73
  }
@@ -1,4 +1,5 @@
1
1
  import { colorScaleBucketOf, colorScaleBucketPredicate } from "../features/colorScaleBucket.js";
2
+ import { groupDepthOf, groupPath, inGroup } from "../viz/groupRow.js";
2
3
  import { shapeHoverEnabled } from "../viz/shapeHover.js";
3
4
  /**
4
5
  @module mouseEnter
@@ -29,6 +30,14 @@ import { shapeHoverEnabled } from "../viz/shapeHover.js";
29
30
  // (`_plotColumnHighlight`) owns it too: it highlights the mark's column.
30
31
  if (this._sharedHoverActive && this._plotColumnHighlight) return;
31
32
  if (shapeHoverEnabled(this)) {
33
+ // A group row highlights every row in its group.
34
+ const groupDepth = groupDepthOf(d);
35
+ if (groupDepth !== undefined) {
36
+ const groupBy = this.schema.groupBy;
37
+ const path = groupPath(groupBy, d, groupDepth);
38
+ this.hover((h, x)=>inGroup(groupBy, path, h, x));
39
+ return;
40
+ }
32
41
  let filterIds = this._id(d, i);
33
42
  if (!(filterIds instanceof Array)) filterIds = [
34
43
  filterIds
@@ -1,6 +1,7 @@
1
1
  import { merge } from "d3-array";
2
2
  import clickLegend from "./click.legend.js";
3
3
  import { legendLabel } from "../features/legendLabel.js";
4
+ import { appendThresholdMembers } from "../features/thresholdMembers.js";
4
5
  import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
5
6
  import { configPrep } from "../../utils/index.js";
6
7
  /**
@@ -49,6 +50,8 @@ import { configPrep } from "../../utils/index.js";
49
50
  this._tooltipClass.data([
50
51
  x || d
51
52
  ]).footer(hasDefaultClick ? invertedBehavior ? this._solo.length && !solo || hidden ? t("Click to Highlight") : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Highlight")}<br />${t("Shift+Click to Hide")}` : this._solo.length && !solo || hidden ? `${t("Click to Show")}<br />${t("Shift+Click to Highlight")}` : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Hide")}<br />${t("Shift+Click to Highlight")}` : false).title(this.schema.legendConfig.label ? this._legendClass.label() : legendLabel.bind(this)).titleSwatch(true).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig)).config(configPrep.bind(this)(this.schema.legendTooltip));
53
+ // A threshold bucket's entry lists what it holds.
54
+ appendThresholdMembers(this._tooltipClass, this, d);
52
55
  // The title leads with the hovered entry's swatch, as on the chart.
53
56
  leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
54
57
  }
@@ -1,5 +1,7 @@
1
1
  import { configPrep } from "../../utils/index.js";
2
2
  import clickShape from "./click.shape.js";
3
+ import { groupDepthOf, groupNarrows, groupPath } from "../viz/groupRow.js";
4
+ import { appendThresholdMembers } from "../features/thresholdMembers.js";
3
5
  import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
4
6
  /**
5
7
  @module mouseMoveShape
@@ -20,8 +22,9 @@ import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
20
22
  // does the shape still have our default "click.shape" event?
21
23
  // (if the user only sets "click", both functions will fire)
22
24
  const hasDefaultClick = this.schema.on["click.shape"] && this.schema.on["click.shape"].toString() === defaultClick;
23
- // can the viz show deeper data?
24
- const hasDeeperLevel = this._drawDepth < this.schema.groupBy.length - 1;
25
+ // can the viz show deeper data? A group row zooms into its group.
26
+ const groupDepth = groupDepthOf(d);
27
+ const hasDeeperLevel = groupDepth === undefined ? this._drawDepth < this.schema.groupBy.length - 1 : groupNarrows(this.schema.groupBy, groupPath(this.schema.groupBy, d, groupDepth), this._filteredData ?? []);
25
28
  // only show the hand cursor when the shape has a click event
26
29
  this._select.style("cursor", hasUserClick || hasDefaultClick && hasDeeperLevel ? "pointer" : "auto");
27
30
  // Plot's snapped hover (shared or single) owns the tooltip while active.
@@ -42,6 +45,8 @@ import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
42
45
  this._tooltipClass.data([
43
46
  tooltipDatum
44
47
  ]).footer(hasDefaultClick && hasDeeperLevel ? this.schema.translate("Click to Expand") : false).title((dd, ii)=>this._drawLabel(dd, ii)).titleSwatch(true).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig));
48
+ // A threshold bucket lists what it holds.
49
+ appendThresholdMembers(this._tooltipClass, this, tooltipDatum);
45
50
  // The title leads with a swatch of the hovered mark, as in the legend.
46
51
  leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
47
52
  }
@@ -3,7 +3,7 @@
3
3
  chart can supply to tune how its panels are laid out and drawn.
4
4
 
5
5
  @module
6
- */ import { accessor } from "../../utils/index.js";
6
+ */ import { fieldAccessor } from "../../utils/fieldAccessor.js";
7
7
  /** Default panel title style: smaller than the chart title, centered over its panel. */ export const FACET_TITLE_DEFAULTS = {
8
8
  fontSize: 12,
9
9
  fontWeight: 600,
@@ -17,7 +17,7 @@
17
17
  function is kept, and anything else (`false`, `undefined`) turns faceting off.
18
18
  */ export function coerceFacet(value) {
19
19
  if (typeof value === "function") return value;
20
- if (typeof value === "string" && value) return accessor(value);
20
+ if (typeof value === "string" && value) return fieldAccessor(value);
21
21
  return undefined;
22
22
  }
23
23
  /** `facetConfig` with defaults filled in. */ export function resolveFacetConfig(config) {
@@ -76,13 +76,13 @@ import { computeFilteredData, computeTimeFilter, dataFilter } from "../pipeline/
76
76
  /**
77
77
  One panel's drawable rows: `rows` run through the same time filter,
78
78
  rollup, legend hide/solo, and threshold the chart applies to its whole
79
- dataset. `timeFilter` is computed once from the whole dataset, so every
79
+ dataset (a threshold that weighs rows weighs the whole chart's). `timeFilter` is computed once from the whole dataset, so every
80
80
  panel shows the same period.
81
81
  */ export function facetFilteredData(viz, rows, timeFilter) {
82
82
  const out = {};
83
83
  computeFilteredData(viz, out, viz._drawDepth, viz._id, timeFilter, rows);
84
84
  let data = out.filteredData ?? [];
85
- if (rows.length && out._thresholdTree && viz._thresholdFunction) data = viz._thresholdFunction(data, out._thresholdTree);
85
+ if (rows.length && out._thresholdTree && viz._thresholdFunction) data = viz._thresholdFunction(data, out._thresholdTree, viz._thresholdRows ?? out.legendData);
86
86
  return data;
87
87
  }
88
88
  /** The time filter every panel shares (see `facetFilteredData`). */ export function facetTimeFilter(viz) {