@d3plus/core 4.3.0 → 4.5.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 (197) hide show
  1. package/README.md +1820 -714
  2. package/es/index.js +1 -1
  3. package/es/index.js.map +1 -1
  4. package/es/internal.js +7 -1
  5. package/es/internal.js.map +1 -1
  6. package/es/src/charts/AreaPlot/index.js +1 -2
  7. package/es/src/charts/AreaPlot/index.js.map +1 -1
  8. package/es/src/charts/BarChart/index.js +1 -2
  9. package/es/src/charts/BarChart/index.js.map +1 -1
  10. package/es/src/charts/BoxWhisker/index.js +1 -2
  11. package/es/src/charts/BoxWhisker/index.js.map +1 -1
  12. package/es/src/charts/BumpChart/index.js +1 -2
  13. package/es/src/charts/BumpChart/index.js.map +1 -1
  14. package/es/src/charts/Chord/applyLayout.js +205 -0
  15. package/es/src/charts/Chord/applyLayout.js.map +1 -0
  16. package/es/src/charts/Chord/emit.js +168 -0
  17. package/es/src/charts/Chord/emit.js.map +1 -0
  18. package/es/src/charts/Chord/index.js +234 -0
  19. package/es/src/charts/Chord/index.js.map +1 -0
  20. package/es/src/charts/Geomap/basemapTheme.js +78 -0
  21. package/es/src/charts/Geomap/basemapTheme.js.map +1 -0
  22. package/es/src/charts/Geomap/emit.js +18 -9
  23. package/es/src/charts/Geomap/emit.js.map +1 -1
  24. package/es/src/charts/Geomap/index.js +69 -104
  25. package/es/src/charts/Geomap/index.js.map +1 -1
  26. package/es/src/charts/LinePlot/index.js +1 -2
  27. package/es/src/charts/LinePlot/index.js.map +1 -1
  28. package/es/src/charts/Matrix/emit.js +6 -0
  29. package/es/src/charts/Matrix/emit.js.map +1 -1
  30. package/es/src/charts/Matrix/index.js +1 -2
  31. package/es/src/charts/Matrix/index.js.map +1 -1
  32. package/es/src/charts/Network/emit.js +58 -24
  33. package/es/src/charts/Network/emit.js.map +1 -1
  34. package/es/src/charts/Network/index.js +34 -54
  35. package/es/src/charts/Network/index.js.map +1 -1
  36. package/es/src/charts/Pack/emit.js +3 -0
  37. package/es/src/charts/Pack/emit.js.map +1 -1
  38. package/es/src/charts/Pack/index.js +1 -2
  39. package/es/src/charts/Pack/index.js.map +1 -1
  40. package/es/src/charts/Pie/emit.js +6 -2
  41. package/es/src/charts/Pie/emit.js.map +1 -1
  42. package/es/src/charts/Pie/index.js +1 -2
  43. package/es/src/charts/Pie/index.js.map +1 -1
  44. package/es/src/charts/Plot/index.js +26 -6
  45. package/es/src/charts/Plot/index.js.map +1 -1
  46. package/es/src/charts/Plot/pipeline.js +1 -2
  47. package/es/src/charts/Plot/pipeline.js.map +1 -1
  48. package/es/src/charts/Plot/plotZoom.js +278 -0
  49. package/es/src/charts/Plot/plotZoom.js.map +1 -0
  50. package/es/src/charts/Priestley/emit.js +4 -0
  51. package/es/src/charts/Priestley/emit.js.map +1 -1
  52. package/es/src/charts/Priestley/index.js +1 -2
  53. package/es/src/charts/Priestley/index.js.map +1 -1
  54. package/es/src/charts/Radar/emit.js +4 -1
  55. package/es/src/charts/Radar/emit.js.map +1 -1
  56. package/es/src/charts/Radar/index.js +1 -2
  57. package/es/src/charts/Radar/index.js.map +1 -1
  58. package/es/src/charts/RadialMatrix/emit.js +6 -0
  59. package/es/src/charts/RadialMatrix/emit.js.map +1 -1
  60. package/es/src/charts/RadialMatrix/index.js +1 -2
  61. package/es/src/charts/RadialMatrix/index.js.map +1 -1
  62. package/es/src/charts/Rings/emit.js +74 -8
  63. package/es/src/charts/Rings/emit.js.map +1 -1
  64. package/es/src/charts/Rings/index.js +11 -3
  65. package/es/src/charts/Rings/index.js.map +1 -1
  66. package/es/src/charts/Sankey/emit.js +55 -11
  67. package/es/src/charts/Sankey/emit.js.map +1 -1
  68. package/es/src/charts/Sankey/index.js +8 -2
  69. package/es/src/charts/Sankey/index.js.map +1 -1
  70. package/es/src/charts/StackedArea/index.js +1 -2
  71. package/es/src/charts/StackedArea/index.js.map +1 -1
  72. package/es/src/charts/Tree/emit.js +8 -2
  73. package/es/src/charts/Tree/emit.js.map +1 -1
  74. package/es/src/charts/Tree/index.js +1 -2
  75. package/es/src/charts/Tree/index.js.map +1 -1
  76. package/es/src/charts/Treemap/index.js +1 -2
  77. package/es/src/charts/Treemap/index.js.map +1 -1
  78. package/es/src/charts/definition/ChartDefinition.js.map +1 -1
  79. package/es/src/charts/drawSteps/backControl.js +70 -0
  80. package/es/src/charts/drawSteps/backControl.js.map +1 -0
  81. package/es/src/charts/drawSteps/controlButtonStyle.js +108 -0
  82. package/es/src/charts/drawSteps/controlButtonStyle.js.map +1 -0
  83. package/es/src/charts/drawSteps/minimap.js +370 -0
  84. package/es/src/charts/drawSteps/minimap.js.map +1 -0
  85. package/es/src/charts/drawSteps/minimapMarkup.js +147 -0
  86. package/es/src/charts/drawSteps/minimapMarkup.js.map +1 -0
  87. package/es/src/charts/drawSteps/searchControls.js +358 -0
  88. package/es/src/charts/drawSteps/searchControls.js.map +1 -0
  89. package/es/src/charts/drawSteps/searchControlsMarkup.js +430 -0
  90. package/es/src/charts/drawSteps/searchControlsMarkup.js.map +1 -0
  91. package/es/src/charts/drawSteps/tableView.js +173 -0
  92. package/es/src/charts/drawSteps/tableView.js.map +1 -0
  93. package/es/src/charts/drawSteps/tableViewControl.js +39 -0
  94. package/es/src/charts/drawSteps/tableViewControl.js.map +1 -0
  95. package/es/src/charts/drawSteps/tableViewMarkup.js +647 -0
  96. package/es/src/charts/drawSteps/tableViewMarkup.js.map +1 -0
  97. package/es/src/charts/drawSteps/topLeftControls.js +73 -0
  98. package/es/src/charts/drawSteps/topLeftControls.js.map +1 -0
  99. package/es/src/charts/drawSteps/topLeftControlsMarkup.js +227 -0
  100. package/es/src/charts/drawSteps/topLeftControlsMarkup.js.map +1 -0
  101. package/es/src/charts/drawSteps/zoomControls.js +314 -175
  102. package/es/src/charts/drawSteps/zoomControls.js.map +1 -1
  103. package/es/src/charts/drawSteps/zoomControlsMarkup.js +280 -0
  104. package/es/src/charts/drawSteps/zoomControlsMarkup.js.map +1 -0
  105. package/es/src/charts/features/attributionFeature.js +137 -0
  106. package/es/src/charts/features/attributionFeature.js.map +1 -0
  107. package/es/src/charts/features/axes.js +20 -8
  108. package/es/src/charts/features/axes.js.map +1 -1
  109. package/es/src/charts/features/chartGeometry.js +16 -2
  110. package/es/src/charts/features/chartGeometry.js.map +1 -1
  111. package/es/src/charts/features/edgeArrows.js +155 -0
  112. package/es/src/charts/features/edgeArrows.js.map +1 -0
  113. package/es/src/charts/features/emitHelpers.js +8 -0
  114. package/es/src/charts/features/emitHelpers.js.map +1 -1
  115. package/es/src/charts/features/ensureZoomDom.js +63 -12
  116. package/es/src/charts/features/ensureZoomDom.js.map +1 -1
  117. package/es/src/charts/features/features.js +83 -110
  118. package/es/src/charts/features/features.js.map +1 -1
  119. package/es/src/charts/features/featuresLegend.js +45 -17
  120. package/es/src/charts/features/featuresLegend.js.map +1 -1
  121. package/es/src/charts/features/plotPaint.js +32 -7
  122. package/es/src/charts/features/plotPaint.js.map +1 -1
  123. package/es/src/charts/features/zoomExtent.js +185 -0
  124. package/es/src/charts/features/zoomExtent.js.map +1 -0
  125. package/es/src/charts/helpers/tileAttributions.js +26 -0
  126. package/es/src/charts/helpers/tileAttributions.js.map +1 -1
  127. package/es/src/charts/index.js +1 -0
  128. package/es/src/charts/index.js.map +1 -1
  129. package/es/src/charts/pipeline/runVizPipeline.js +33 -14
  130. package/es/src/charts/pipeline/runVizPipeline.js.map +1 -1
  131. package/es/src/charts/pipeline/vizDrawPure.js +32 -6
  132. package/es/src/charts/pipeline/vizDrawPure.js.map +1 -1
  133. package/es/src/charts/viz/Viz.js +39 -51
  134. package/es/src/charts/viz/Viz.js.map +1 -1
  135. package/es/src/charts/viz/VizBase.js +157 -4
  136. package/es/src/charts/viz/VizBase.js.map +1 -1
  137. package/es/src/charts/viz/VizBaseConfig.js +32 -2
  138. package/es/src/charts/viz/VizBaseConfig.js.map +1 -1
  139. package/es/src/charts/viz/vizDefaults.js +243 -50
  140. package/es/src/charts/viz/vizDefaults.js.map +1 -1
  141. package/es/src/charts/viz/vizTypes.js.map +1 -1
  142. package/es/src/components/Axis/Axis.js +10 -1
  143. package/es/src/components/Axis/Axis.js.map +1 -1
  144. package/es/src/components/Axis/axisLayoutLabels.js +2 -1
  145. package/es/src/components/Axis/axisLayoutLabels.js.map +1 -1
  146. package/es/src/components/Axis/axisRender.js +5 -1
  147. package/es/src/components/Axis/axisRender.js.map +1 -1
  148. package/es/src/components/Legend/legendConfig.js +86 -20
  149. package/es/src/components/Legend/legendConfig.js.map +1 -1
  150. package/es/src/utils/D3plusConfig.js.map +1 -1
  151. package/package.json +11 -10
  152. package/types/index.d.ts +1 -1
  153. package/types/internal.d.ts +8 -1
  154. package/types/src/charts/Chord/applyLayout.d.ts +43 -0
  155. package/types/src/charts/Chord/emit.d.ts +10 -0
  156. package/types/src/charts/Chord/index.d.ts +19 -0
  157. package/types/src/charts/Geomap/basemapTheme.d.ts +35 -0
  158. package/types/src/charts/Plot/index.d.ts +12 -3
  159. package/types/src/charts/Plot/plotZoom.d.ts +65 -0
  160. package/types/src/charts/definition/ChartDefinition.d.ts +3 -1
  161. package/types/src/charts/drawSteps/backControl.d.ts +29 -0
  162. package/types/src/charts/drawSteps/controlButtonStyle.d.ts +45 -0
  163. package/types/src/charts/drawSteps/minimap.d.ts +19 -0
  164. package/types/src/charts/drawSteps/minimapMarkup.d.ts +45 -0
  165. package/types/src/charts/drawSteps/searchControls.d.ts +3 -0
  166. package/types/src/charts/drawSteps/searchControlsMarkup.d.ts +111 -0
  167. package/types/src/charts/drawSteps/tableView.d.ts +23 -0
  168. package/types/src/charts/drawSteps/tableViewControl.d.ts +21 -0
  169. package/types/src/charts/drawSteps/tableViewMarkup.d.ts +119 -0
  170. package/types/src/charts/drawSteps/topLeftControls.d.ts +32 -0
  171. package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +72 -0
  172. package/types/src/charts/drawSteps/zoomControls.d.ts +48 -8
  173. package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +138 -0
  174. package/types/src/charts/features/attributionFeature.d.ts +21 -0
  175. package/types/src/charts/features/axes.d.ts +1 -1
  176. package/types/src/charts/features/chartGeometry.d.ts +9 -3
  177. package/types/src/charts/features/edgeArrows.d.ts +92 -0
  178. package/types/src/charts/features/emitHelpers.d.ts +11 -0
  179. package/types/src/charts/features/ensureZoomDom.d.ts +6 -2
  180. package/types/src/charts/features/features.d.ts +32 -17
  181. package/types/src/charts/features/featuresLegend.d.ts +15 -0
  182. package/types/src/charts/features/plotPaint.d.ts +15 -2
  183. package/types/src/charts/features/zoomExtent.d.ts +25 -0
  184. package/types/src/charts/index.d.ts +1 -0
  185. package/types/src/charts/pipeline/runVizPipeline.d.ts +6 -3
  186. package/types/src/charts/viz/VizBase.d.ts +86 -4
  187. package/types/src/charts/viz/VizBaseConfig.d.ts +20 -2
  188. package/types/src/charts/viz/vizDefaults.d.ts +155 -0
  189. package/types/src/charts/viz/vizTypes.d.ts +57 -1
  190. package/types/src/components/Axis/Axis.d.ts +2 -0
  191. package/types/src/utils/D3plusConfig.d.ts +102 -8
  192. package/umd/d3plus-core.full.js +39613 -35374
  193. package/umd/d3plus-core.full.js.map +1 -1
  194. package/umd/d3plus-core.full.min.js +5747 -4361
  195. package/umd/d3plus-core.js +13132 -9289
  196. package/umd/d3plus-core.js.map +1 -1
  197. package/umd/d3plus-core.min.js +3658 -2302
@@ -0,0 +1,647 @@
1
+ /**
2
+ Markup, styling, and state helpers for the table-view toggle button + the
3
+ data-table overlay it swaps in (sorting, CSV export, pagination).
4
+
5
+ The button's html (`tableViewButtonHtml`) is consumed two ways: as
6
+ `tableViewContribution`'s piece of the shared top-left controls panel
7
+ (`tableViewControl.ts`) while the chart is showing, and embedded at the
8
+ top of the full-chart data-table overlay (`tableView.ts`) while table
9
+ view is active — so a click there can toggle back. Kept as its own
10
+ module (rather than folded into `zoomControlsMarkup.ts`) because the two
11
+ features are independent chrome a chart can mix and match; sharing
12
+ styling *knobs* (config keys, defaults) between them would couple them
13
+ for no benefit. The button-painting *mechanism* is genuinely
14
+ feature-agnostic, though — `paintControlButton`/`resolveControlStyle`
15
+ come from the shared `controlButtonStyle.ts` (also used by zoom/back/
16
+ search), the same way `zoomControlsInset` and `topLeftControlsInset`
17
+ share the box-measuring pattern without sharing what they measure.
18
+ `overlayHost` is reused from `zoomControlsMarkup.ts`.
19
+
20
+ @module
21
+ */ function _instanceof(left, right) {
22
+ "@swc/helpers - instanceof";
23
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
24
+ return !!right[Symbol.hasInstance](left);
25
+ } else {
26
+ return left instanceof right;
27
+ }
28
+ }
29
+ import { fontFamilyStringify } from "@d3plus/text";
30
+ import { overlayHost } from "./zoomControlsMarkup.js";
31
+ import { paintControlButton, resolveControlStyle } from "./controlButtonStyle.js";
32
+ import { tableViewControlStyleActiveDefault, tableViewControlStyleDefault, tableViewControlStyleHoverDefault } from "../viz/vizDefaults.js";
33
+ /** Table-view mode is per-chart state, read/written via `viz._tableView`. */ export function isTableView(viz) {
34
+ return Boolean(viz._tableView);
35
+ }
36
+ export function setTableView(viz, value) {
37
+ viz._tableView = value;
38
+ }
39
+ /** The current page (0-indexed) of the paginated data table. */ export function getTableViewPage(viz) {
40
+ return viz._tableViewPage || 0;
41
+ }
42
+ export function setTableViewPage(viz, value) {
43
+ viz._tableViewPage = value;
44
+ }
45
+ /** The data table's current sort column + direction, if any (`viz._tableViewSort`). */ export function getTableViewSort(viz) {
46
+ return viz._tableViewSort;
47
+ }
48
+ export function setTableViewSort(viz, value) {
49
+ viz._tableViewSort = value;
50
+ }
51
+ /** Which dataset the table currently shows: `viz._data` (raw) or `viz._filteredData` (aggregate, the default — matches the chart's own on-screen behavior). */ export function getTableViewDataSource(viz) {
52
+ return viz._tableViewDataSource === "raw" ? "raw" : "aggregate";
53
+ }
54
+ export function setTableViewDataSource(viz, value) {
55
+ viz._tableViewDataSource = value;
56
+ }
57
+ /**
58
+ Whether `viz._data` (the chart's raw, untouched input) and
59
+ `viz._filteredData` (what it currently charts — after any filtering
60
+ AND, for many chart types, per-mark aggregation: Treemap/Pie/Donut, or a
61
+ Plot chart with repeated x per series, merge rows that share a
62
+ (groupBy, x) key) actually differ. Row-count comparison is the cheap,
63
+ sufficient signal: aggregation collapses count whenever it applies, and
64
+ when it doesn't, the two are the same array. A deep comparison would be
65
+ exact but costs exactly what virtualization exists to avoid paying on
66
+ every repaint of a huge dataset.
67
+ */ function hasDistinctRawData(viz) {
68
+ var raw = viz._data;
69
+ var aggregate = viz._filteredData || raw;
70
+ if (!raw || !aggregate || raw === aggregate) return false;
71
+ return raw.length !== aggregate.length;
72
+ }
73
+ /** The resolved base / active / hover button styles for a chart, also the cheap non-DOM basis for `tableViewContribution`'s `styleSignature`. */ function buttonStyles(viz) {
74
+ var className = Boolean(viz.schema.tableViewControlClassName);
75
+ return {
76
+ base: resolveControlStyle(viz.schema.tableViewControlStyle, tableViewControlStyleDefault, className),
77
+ active: resolveControlStyle(viz.schema.tableViewControlStyleActive, tableViewControlStyleActiveDefault, className),
78
+ hover: resolveControlStyle(viz.schema.tableViewControlStyleHover, tableViewControlStyleHoverDefault, className)
79
+ };
80
+ }
81
+ /** Paints the table-view button's inline style for its current state (base/hover/active) — see `paintControlButton`. */ export function paintTableViewButton(viz, btn) {
82
+ var hovered = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
83
+ paintControlButton(btn, buttonStyles(viz), hovered, btn.classList.contains("active"));
84
+ }
85
+ /** The cheap, non-DOM signature capturing the button's resolved style — see `Contribution.styleSignature`. */ export function tableViewButtonStyleSignature(viz) {
86
+ return JSON.stringify(buttonStyles(viz));
87
+ }
88
+ /** Shared icon attributes — see the long comment in `zoomControlsMarkup.ts` for why these exact properties matter. */ var ICON_ATTRS = 'viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:12px;height:12px;vertical-align:middle;flex-shrink:0"';
89
+ // A simple spreadsheet-style grid: outer frame + one horizontal + one vertical divider.
90
+ var TABLE_ICON = "<svg ".concat(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>');
91
+ // A downward arrow into a tray — the conventional "download" icon.
92
+ var DOWNLOAD_ICON = "<svg ".concat(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>');
93
+ // Two opposing horizontal arrows — the conventional "swap/exchange" icon.
94
+ // One constant icon regardless of state (like TABLE_ICON above): only the
95
+ // label/aria-pressed/active-class communicate which of the two datasets is
96
+ // currently showing, the same convention `tableViewButtonHtml` uses.
97
+ var SWAP_ICON = "<svg ".concat(ICON_ATTRS, '><polyline points="14 4 19 9 14 14"/><line x1="4" y1="9" x2="19" y2="9"/><polyline points="10 20 5 15 10 10"/><line x1="20" y1="15" x2="5" y2="15"/></svg>');
98
+ /**
99
+ Sort-direction chevrons for column headers — smaller than the toolbar
100
+ icons above (11px vs. 12px) since they sit inline with header text
101
+ rather than centered in their own button, with a left margin instead of
102
+ a leading space for consistent spacing. Deliberately vector, not the
103
+ Unicode ▲/▼ this replaced: a Unicode triangle glyph comes from the
104
+ browser's font-fallback chain like the toolbar icons' Unicode
105
+ predecessors did (see the icon-choice rationale in
106
+ `zoomControlsMarkup.ts`), and renders inconsistently thick/bold across
107
+ fonts and OSes — a plain stroked chevron matches this feature's own
108
+ icon language and reads the same everywhere.
109
+ */ var SORT_ICON_ATTRS = 'viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:11px;height:11px;vertical-align:middle;margin-left:4px;flex-shrink:0"';
110
+ var SORT_ASC_ICON = "<svg ".concat(SORT_ICON_ATTRS, '><polyline points="6 15 12 9 18 15"/></svg>');
111
+ var SORT_DESC_ICON = "<svg ".concat(SORT_ICON_ATTRS, '><polyline points="6 9 12 15 18 9"/></svg>');
112
+ /** The toggle button's markup — a real `<button>` so host-page button styling applies once `tableViewControlClassName` disables the inline defaults. */ export function tableViewButtonHtml(viz) {
113
+ var active = isTableView(viz);
114
+ var extraClass = viz.schema.tableViewControlClassName ? " ".concat(viz.schema.tableViewControlClassName) : "";
115
+ var label = viz.schema.translate(active ? "Show Chart" : "Show Data Table");
116
+ return '<button type="button" class="table-view-control table-view-toggle'.concat(active ? " active" : "").concat(extraClass, '" aria-label="').concat(label, '" aria-pressed="').concat(active, '">').concat(TABLE_ICON, "</button>");
117
+ }
118
+ /** The CSV-download button's markup — same structural button styling as the toggle, so the two sit flush in the overlay's toolbar row. */ function downloadButtonHtml(viz) {
119
+ var label = viz.schema.translate("Download");
120
+ return '<button type="button" class="table-view-control tableview-download-csv" aria-label="'.concat(label, '" title="').concat(label, ' CSV">').concat(DOWNLOAD_ICON, "</button>");
121
+ }
122
+ /**
123
+ The raw/aggregate data-source toggle's markup — next to the download
124
+ button, and (per `hasDistinctRawData`) only rendered at all when the two
125
+ datasets actually differ. `active`/`aria-pressed` track "currently
126
+ showing raw"; aggregate is the default (unpressed) state, matching what
127
+ the table showed before this toggle existed.
128
+ */ function dataSourceButtonHtml(viz) {
129
+ var showingRaw = getTableViewDataSource(viz) === "raw";
130
+ var extraClass = viz.schema.tableViewControlClassName ? " ".concat(viz.schema.tableViewControlClassName) : "";
131
+ var label = viz.schema.translate(showingRaw ? "Show Aggregate Data" : "Show Raw Data");
132
+ return '<button type="button" class="table-view-control tableview-source-toggle'.concat(showingRaw ? " active" : "").concat(extraClass, '" aria-label="').concat(label, '" title="').concat(label, '" aria-pressed="').concat(showingRaw, '">').concat(SWAP_ICON, "</button>");
133
+ }
134
+ /** Escapes a value for safe interpolation into `innerHTML`. */ function escapeHtml(value) {
135
+ return String(value !== null && value !== void 0 ? value : "").replace(/[&<>"']/g, function(c) {
136
+ return ({
137
+ "&": "&amp;",
138
+ "<": "&lt;",
139
+ ">": "&gt;",
140
+ '"': "&quot;",
141
+ "'": "&#39;"
142
+ })[c];
143
+ });
144
+ }
145
+ /** Renders one cell's value for on-screen display: numbers get locale grouping, dates a locale date string, everything else its plain string form. */ function formatCell(value, locale) {
146
+ if (value === null || value === undefined) return "";
147
+ if (_instanceof(value, Date)) return value.toLocaleDateString(locale);
148
+ if (typeof value === "number") return value.toLocaleString(locale);
149
+ return String(value);
150
+ }
151
+ /**
152
+ Renders one cell's value for CSV export: raw and machine-readable rather
153
+ than display-formatted — a plain (ungrouped) number and an ISO date
154
+ string, so the exported file round-trips through a spreadsheet without
155
+ locale-specific grouping/decimal separators getting misread as multiple
156
+ columns or the wrong magnitude.
157
+ */ function csvCellValue(value) {
158
+ if (value === null || value === undefined) return "";
159
+ if (_instanceof(value, Date)) return value.toISOString();
160
+ return String(value);
161
+ }
162
+ /** Quotes a CSV field per RFC 4046 whenever it contains a comma, quote, or line break (`\n` or a lone `\r`); doubles any interior quotes. */ function csvField(value) {
163
+ var str = csvCellValue(value);
164
+ return /[",\r\n]/.test(str) ? '"'.concat(str.replace(/"/g, '""'), '"') : str;
165
+ }
166
+ /** Serializes columns + rows into a CSV string (header row first, `\r\n` line endings per RFC 4046). */ function toCsv(columns, rows) {
167
+ var lines = [
168
+ columns.map(csvField).join(",")
169
+ ];
170
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
171
+ try {
172
+ var _loop = function() {
173
+ var row = _step.value;
174
+ lines.push(columns.map(function(c) {
175
+ return csvField(row[c]);
176
+ }).join(","));
177
+ };
178
+ for(var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
179
+ } catch (err) {
180
+ _didIteratorError = true;
181
+ _iteratorError = err;
182
+ } finally{
183
+ try {
184
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
185
+ _iterator.return();
186
+ }
187
+ } finally{
188
+ if (_didIteratorError) {
189
+ throw _iteratorError;
190
+ }
191
+ }
192
+ }
193
+ return lines.join("\r\n");
194
+ }
195
+ /**
196
+ Compares two cell values for sorting: numeric for two numbers,
197
+ chronological for two dates, else a locale-aware string compare (with
198
+ `numeric: true` so "Q2" sorts before "Q10"). `null`/`undefined` always
199
+ sort last, regardless of direction — a missing value isn't meaningfully
200
+ "low" or "high".
201
+ */ function compareValues(a, b, locale) {
202
+ var aNil = a === null || a === undefined;
203
+ var bNil = b === null || b === undefined;
204
+ if (aNil || bNil) return aNil && bNil ? 0 : aNil ? 1 : -1;
205
+ if (typeof a === "number" && typeof b === "number") return a - b;
206
+ if (_instanceof(a, Date) && _instanceof(b, Date)) return a.getTime() - b.getTime();
207
+ return String(a).localeCompare(String(b), locale, {
208
+ numeric: true
209
+ });
210
+ }
211
+ /**
212
+ A stable key for whichever `groupBy` group a row belongs to. Aggregation
213
+ (the `merge()` a chart's rollup runs per group) leaves the groupBy
214
+ field(s) unchanged — that's the definition of "group by X, merge the
215
+ rest" — so a raw row and the aggregate row its group collapsed into
216
+ always compute the same key here. Used only as `defaultRowOrder`'s
217
+ fallback (see below) — it identifies a GROUP, not a specific row, so
218
+ several raw rows legitimately share one key.
219
+ */ function groupByKey(viz, row, index) {
220
+ var groupBy = viz.schema.groupBy;
221
+ if (!groupBy || !groupBy.length) return "";
222
+ return groupBy.map(function(fn) {
223
+ return String(fn(row, index));
224
+ }).join("\u0000");
225
+ }
226
+ /**
227
+ Two first-occurrence-index lookups built in one pass over the chart's
228
+ raw `.data()` input, both keyed for `defaultRowOrder`:
229
+ - `exact`: by the row's full JSON content — an aggregate row that's
230
+ merely been REORDERED (not actually merged) serializes identically
231
+ to its one originating raw row, so this recovers its true original
232
+ index exactly.
233
+ - `group`: by `groupByKey` — the fallback for a row that WAS actually
234
+ merged (summed/concatenated fields mean its JSON no longer matches
235
+ any single raw row), where "first appearance of this group" is the
236
+ best available notion of original position.
237
+ Cached on `viz` (keyed by the raw array's own reference): both lookups
238
+ are an O(n) scan over potentially the chart's entire dataset, and every
239
+ table-view interaction (a page click, a sort click) calls
240
+ `defaultRowOrder` again — without the cache each one would re-pay that
241
+ scan even though `_data` itself hasn't changed.
242
+ */ function rowOrderLookups(viz) {
243
+ var raw = viz._data || [];
244
+ var cache = viz._tableViewGroupOrder;
245
+ if (cache && cache.data === raw) return cache;
246
+ var exact = new Map();
247
+ var group = new Map();
248
+ raw.forEach(function(d, i) {
249
+ var sig = JSON.stringify(d);
250
+ if (!exact.has(sig)) exact.set(sig, i);
251
+ var key = groupByKey(viz, d, i);
252
+ if (!group.has(key)) group.set(key, i);
253
+ });
254
+ var lookups = {
255
+ data: raw,
256
+ exact: exact,
257
+ group: group
258
+ };
259
+ viz._tableViewGroupOrder = lookups;
260
+ return lookups;
261
+ }
262
+ /**
263
+ Reorders rows to match the chart's original `.data()` insertion order —
264
+ undoing whatever order a chart's own pipeline left `_filteredData` in.
265
+ This matters for two distinct reasons a chart's pipeline reorders rows:
266
+ - Regrouping without merging: a BarChart given interleaved rows
267
+ (`{id:"B",x:"Q1"}, {id:"A",x:"Q1"}, {id:"B",x:"Q2"}, …`) ends up with
268
+ `_filteredData` ordered "all of B, then all of A" (grouped by series
269
+ for axis/domain computation) — same rows, just resequenced. Restored
270
+ EXACTLY via `rowOrderLookups().exact`.
271
+ - True aggregation: Treemap/Pie/etc. merge every row sharing a groupBy
272
+ key into one summed/concatenated row, which no longer matches any
273
+ single raw row's JSON. Falls back to `rowOrderLookups().group`:
274
+ ordering by when that GROUP first appeared — the best available
275
+ notion of "original position" for a row that never existed on its
276
+ own in the input.
277
+ Only called when there's no explicit column sort active — clicking any
278
+ header fully overrides this default, same as it would override natural
279
+ array order. Skipped (returns `rows` unchanged) when there's no raw
280
+ data to derive an order from.
281
+ */ function defaultRowOrder(viz, rows) {
282
+ var raw = viz._data;
283
+ if (!raw || !raw.length) return rows;
284
+ var _rowOrderLookups = rowOrderLookups(viz), exact = _rowOrderLookups.exact, group = _rowOrderLookups.group;
285
+ return rows.map(function(row, i) {
286
+ var _ref;
287
+ var exactOrder = exact.get(JSON.stringify(row));
288
+ var order = (_ref = exactOrder !== null && exactOrder !== void 0 ? exactOrder : group.get(groupByKey(viz, row, i))) !== null && _ref !== void 0 ? _ref : Number.MAX_SAFE_INTEGER;
289
+ return {
290
+ row: row,
291
+ order: order
292
+ };
293
+ }).sort(function(a, b) {
294
+ return a.order - b.order;
295
+ }).map(function(x) {
296
+ return x.row;
297
+ });
298
+ }
299
+ /**
300
+ The union of every row's own keys, in first-seen order. A plain
301
+ `Object.keys(rows[0])` would silently drop any column absent from the
302
+ first row but present on a later one — a real risk for data that's been
303
+ filtered/merged upstream and isn't perfectly homogeneous — so this scans
304
+ every row instead. Cheap relative to the sort `sortedTableViewRows`
305
+ already does when a sort is active (one O(n·k) pass vs. O(n log n)).
306
+ */ function allColumns(rows) {
307
+ var columns = [];
308
+ var seen = new Set();
309
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
310
+ try {
311
+ for(var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
312
+ var row = _step.value;
313
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
314
+ try {
315
+ for(var _iterator1 = Object.keys(row)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
316
+ var key = _step1.value;
317
+ if (!seen.has(key)) {
318
+ seen.add(key);
319
+ columns.push(key);
320
+ }
321
+ }
322
+ } catch (err) {
323
+ _didIteratorError1 = true;
324
+ _iteratorError1 = err;
325
+ } finally{
326
+ try {
327
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
328
+ _iterator1.return();
329
+ }
330
+ } finally{
331
+ if (_didIteratorError1) {
332
+ throw _iteratorError1;
333
+ }
334
+ }
335
+ }
336
+ }
337
+ } catch (err) {
338
+ _didIteratorError = true;
339
+ _iteratorError = err;
340
+ } finally{
341
+ try {
342
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
343
+ _iterator.return();
344
+ }
345
+ } finally{
346
+ if (_didIteratorError) {
347
+ throw _iteratorError;
348
+ }
349
+ }
350
+ }
351
+ return columns;
352
+ }
353
+ /**
354
+ The chart's current data-table rows and their columns (the union of
355
+ every row's own keys — see `allColumns`), sorted per
356
+ `viz._tableViewSort` when set. Shared by the on-screen table (which
357
+ further paginates this) and CSV export (which exports it in full,
358
+ unpaginated) — both automatically follow whichever data source
359
+ `dataSourceButtonHtml`'s toggle currently selects.
360
+
361
+ Source: `viz._filteredData` (aggregate — what's actually charted) by
362
+ default, or `viz._data` (raw, untouched input) once the toggle picks
363
+ "raw" — guarded by `hasDistinctRawData` so a stale `_tableViewDataSource`
364
+ from a previous, genuinely-different dataset can't silently switch a
365
+ chart whose raw/aggregate happen to now coincide.
366
+
367
+ Absent an explicit column sort, the AGGREGATE source is further
368
+ reordered (`defaultRowOrder`) to match the chart's original `.data()`
369
+ insertion order — raw is already in that order by definition, so it's
370
+ skipped there.
371
+ */ export function sortedTableViewRows(viz) {
372
+ var useRaw = getTableViewDataSource(viz) === "raw" && hasDistinctRawData(viz);
373
+ var source = useRaw ? viz._data : viz._filteredData || viz._data;
374
+ var rows = (source || []).slice();
375
+ var columns = allColumns(rows);
376
+ var sort = getTableViewSort(viz);
377
+ if (sort && columns.includes(sort.column)) {
378
+ var dir = sort.direction === "desc" ? -1 : 1;
379
+ var column = sort.column;
380
+ rows.sort(function(a, b) {
381
+ return dir * compareValues(a[column], b[column], viz.schema.locale);
382
+ });
383
+ } else if (!useRaw) {
384
+ rows = defaultRowOrder(viz, rows);
385
+ }
386
+ return {
387
+ rows: rows,
388
+ columns: columns
389
+ };
390
+ }
391
+ /** One page of rows, clamped/derived from `tableViewPageSize` + the current `_tableViewPage`. Clamps and writes back the page so it can't drift out of range as data/sort changes. Exported so `setupTableViewVirtualization` can re-derive the identical slice `tableViewOverlayHtml` built. */ export function paginate(viz, rows) {
392
+ var total = rows.length;
393
+ var pageSize = viz.schema.tableViewPageSize;
394
+ var size = typeof pageSize === "number" && pageSize > 0 ? pageSize : total || 1;
395
+ var totalPages = Math.max(1, Math.ceil(total / size));
396
+ var page = Math.min(Math.max(0, getTableViewPage(viz)), totalPages - 1);
397
+ setTableViewPage(viz, page);
398
+ var start = page * size;
399
+ var end = Math.min(start + size, total);
400
+ return {
401
+ slice: rows.slice(start, end),
402
+ page: page,
403
+ totalPages: totalPages,
404
+ start: start,
405
+ end: end,
406
+ total: total
407
+ };
408
+ }
409
+ /** Whether a chart shows the table-view toggle button. */ export function showsTableView(viz) {
410
+ return Boolean(viz.schema.tableView) && !viz._ssr;
411
+ }
412
+ /** Whether the data table's column headers are clickable to sort. */ function showsTableViewSort(viz) {
413
+ return viz.schema.tableViewSort !== false;
414
+ }
415
+ /** Whether the data table shows a "download CSV" button. */ function showsTableViewDownload(viz) {
416
+ return viz.schema.tableViewDownload !== false;
417
+ }
418
+ /**
419
+ Fixed per-row height (px), in sync with each `<tr>`'s own inline
420
+ `height`. Virtualization's spacer math (`startIndex * ROW_HEIGHT`)
421
+ depends on every row actually being this tall — the reason every row,
422
+ virtualized or not, gets an explicit height rather than natural sizing.
423
+ */ var ROW_HEIGHT = 30;
424
+ /**
425
+ Above this many rows in the currently-rendered page, the table switches
426
+ from "render every row" to scroll-driven virtualization (see
427
+ `setupTableViewVirtualization`). Default pagination (`tableViewPageSize`
428
+ 50) never approaches this — it only engages when a chart sets
429
+ `tableViewPageSize(false)` (or an equally large explicit size) on a
430
+ large dataset, the case plain rendering doesn't scale to.
431
+ */ var VIRTUALIZE_THRESHOLD = 300;
432
+ /** The initial guessed window a freshly-built (not yet mounted) virtualized table renders, corrected the instant it mounts (see `setupTableViewVirtualization`) — comfortably more than any real viewport shows, so there's no visible gap before the real measurement lands. */ var INITIAL_VIRTUAL_WINDOW = 60;
433
+ /** Rows of overscan rendered beyond each edge of the visible window, so a fast scroll doesn't flash empty space before the next frame's re-render catches up. */ var OVERSCAN = 10;
434
+ /**
435
+ A per-cell width cap. `max-width`/`text-overflow: ellipsis` on the
436
+ `<td>` ITSELF doesn't reliably constrain anything under this table's
437
+ default (non-virtualized) `table-layout: auto` — browsers largely
438
+ compute auto column widths from cells' unconstrained intrinsic content
439
+ width, so a `max-width` on the cell box often gets overridden by the
440
+ table's own sizing pass. Wrapping the text in a plain block-level `<div>`
441
+ (below) sidesteps that: an ordinary block element's `max-width` is
442
+ respected regardless of what layout algorithm its ancestor table uses.
443
+ Needed because some chart types' aggregated rows can be pathological
444
+ here — Treemap/Pie/etc.'s `merge()` concatenates every distinct value of
445
+ a non-summed field with commas, so one cell can legitimately hold
446
+ hundreds of joined values, which without this cap pushes every other
447
+ column off-screen to make room for it.
448
+ */ var CELL_MAX_WIDTH = "320px";
449
+ /** One data row's `<td>` cells. */ function rowCellsHtml(viz, columns, row) {
450
+ return columns.map(function(c) {
451
+ return '<td style="padding:6px 10px;border-bottom:1px solid #e0e0e0;"><div style="max-width:'.concat(CELL_MAX_WIDTH, ';overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">').concat(escapeHtml(formatCell(row[c], viz.schema.locale)), "</div></td>");
452
+ }).join("");
453
+ }
454
+ /** One data row, at the fixed `ROW_HEIGHT` every virtualization calculation assumes. */ function rowHtml(viz, columns, row) {
455
+ return '<tr style="height:'.concat(ROW_HEIGHT, 'px;">').concat(rowCellsHtml(viz, columns, row), "</tr>");
456
+ }
457
+ /** An invisible, zero-content `<tr>` standing in for rows outside the rendered window — its height is however much scrollable space those rows would occupy, so the scrollbar still reflects the full row count. */ function spacerRowHtml(heightPx, colspan) {
458
+ if (!heightPx) return "";
459
+ return '<tr aria-hidden="true" style="height:'.concat(heightPx, 'px;padding:0;border:0;"><td style="padding:0;border:0;" colspan="').concat(colspan, '"></td></tr>');
460
+ }
461
+ /**
462
+ The `<tbody>` contents for a `[startIndex, endIndex)` window of `rows`:
463
+ a top spacer (for everything before `startIndex`), the window's actual
464
+ `<tr>`s, and a bottom spacer (for everything after `endIndex`). Called
465
+ both when building the overlay's initial html and — with different
466
+ bounds — on every scroll tick once virtualization is active; the two
467
+ call sites' output is otherwise identical, which is what keeps the first
468
+ real frame (post-mount) indistinguishable from the guessed one it replaces.
469
+ */ function tbodyRowsHtml(viz, columns, rows, startIndex, endIndex, total) {
470
+ var colspan = Math.max(columns.length, 1);
471
+ return spacerRowHtml(startIndex * ROW_HEIGHT, colspan) + rows.slice(startIndex, endIndex).map(function(row) {
472
+ return rowHtml(viz, columns, row);
473
+ }).join("") + spacerRowHtml((total - endIndex) * ROW_HEIGHT, colspan);
474
+ }
475
+ /** One `<th>`: sort affordance (click/keyboard-toggleable, `aria-sort`, chevron indicator) when sortable, plain otherwise. */ function headerCellHtml(viz, column, sort) {
476
+ var label = escapeHtml(column);
477
+ if (!showsTableViewSort(viz)) {
478
+ return '<th style="position:sticky;top:0;background:#fff;text-align:left;padding:6px 10px;border-bottom:2px solid #ccc;white-space:nowrap;">'.concat(label, "</th>");
479
+ }
480
+ var active = (sort === null || sort === void 0 ? void 0 : sort.column) === column;
481
+ var ariaSort = active ? sort.direction === "desc" ? "descending" : "ascending" : "none";
482
+ var arrow = active ? sort.direction === "desc" ? SORT_DESC_ICON : SORT_ASC_ICON : "";
483
+ return '<th class="tableview-sort-header" data-column="'.concat(escapeHtml(column), '" role="button" tabindex="0" aria-sort="').concat(ariaSort, '" style="position:sticky;top:0;background:#fff;text-align:left;padding:6px 10px;border-bottom:2px solid #ccc;white-space:nowrap;cursor:pointer;user-select:none;">').concat(label).concat(arrow, "</th>");
484
+ }
485
+ /**
486
+ The full data-table overlay's markup: a toolbar (the toggle button, —
487
+ unless disabled — a "download CSV" button, and — only when raw and
488
+ aggregate data actually differ — the raw/aggregate source toggle), a
489
+ scrollable table with a sticky, click-to-sort header, and — when the
490
+ data doesn't fit on one page — Prev/Next pagination. Columns come from
491
+ the union of every row's own keys; every value is escaped, since it's
492
+ caller-supplied data landing in `innerHTML`.
493
+ */ export function tableViewOverlayHtml(viz) {
494
+ var sort = getTableViewSort(viz);
495
+ var _sortedTableViewRows = sortedTableViewRows(viz), rows = _sortedTableViewRows.rows, columns = _sortedTableViewRows.columns;
496
+ var _paginate = paginate(viz, rows), slice = _paginate.slice, page = _paginate.page, totalPages = _paginate.totalPages, start = _paginate.start, end = _paginate.end, total = _paginate.total;
497
+ // Only the CURRENT PAGE's row count matters here — with default pagination
498
+ // (small `tableViewPageSize`) `slice.length` never approaches the
499
+ // threshold no matter how huge the underlying dataset is; pagination
500
+ // itself already bounds the DOM in that case. Virtualization is for the
501
+ // "one big page" (`tableViewPageSize(false)`, or an equally large
502
+ // explicit size) case pagination doesn't cover.
503
+ var pageTotal = slice.length;
504
+ var virtualized = pageTotal > VIRTUALIZE_THRESHOLD;
505
+ // `tbodyRowsHtml`'s last argument is "how many rows are in the array
506
+ // being windowed" — that's `pageTotal` (the CURRENT PAGE's row count),
507
+ // never the dataset-wide `total`. They coincide when pagination isn't
508
+ // splitting anything, but differ whenever a big-but-bounded page size
509
+ // (e.g. `tableViewPageSize(500)` on 1000+ rows) makes both pagination
510
+ // and virtualization apply to the same page at once — using `total`
511
+ // there would size the bottom spacer against rows that aren't even in
512
+ // `slice`, well past its actual end.
513
+ var bodyHtml = !total ? '<tr><td style="padding:12px;color:#767676;" colspan="'.concat(Math.max(columns.length, 1), '">').concat(viz.schema.translate("No Data Available"), "</td></tr>") : tbodyRowsHtml(viz, columns, slice, 0, virtualized ? Math.min(pageTotal, INITIAL_VIRTUAL_WINDOW) : pageTotal, pageTotal);
514
+ var headHtml = columns.map(function(c) {
515
+ return headerCellHtml(viz, c, sort);
516
+ }).join("");
517
+ var paginationHtml = totalPages > 1 ? '<div class="d3plus-table-view-pagination" style="display:flex;align-items:center;gap:8px;padding:6px 10px;border-top:1px solid #e0e0e0;font-size:12px;flex:0 0 auto;">\n <button type="button" class="tableview-page-prev"'.concat(page <= 0 ? " disabled" : "", ">‹ ").concat(viz.schema.translate("Previous"), "</button>\n <span>").concat(total ? start + 1 : 0, "–").concat(end, " / ").concat(total, '</span>\n <button type="button" class="tableview-page-next"').concat(page >= totalPages - 1 ? " disabled" : "", ">").concat(viz.schema.translate("Next"), " ›</button>\n </div>") : "";
518
+ var extraClass = viz.schema.tableViewClassName ? " ".concat(viz.schema.tableViewClassName) : "";
519
+ var toolbarHtml = tableViewButtonHtml(viz) + (showsTableViewDownload(viz) ? downloadButtonHtml(viz) : "") + (hasDistinctRawData(viz) ? dataSourceButtonHtml(viz) : "");
520
+ // `table-layout:fixed` only while virtualizing: without it, column widths
521
+ // auto-fit whatever rows currently exist, which for a normal (fully
522
+ // rendered) table looks nicer, but for a virtualized one would jitter
523
+ // column widths every time the rendered window's content changes on
524
+ // scroll. Fixed layout divides width evenly (from the always-fully-
525
+ // rendered header row), trading that visual nicety for stability exactly
526
+ // where scrolling would otherwise disturb it.
527
+ var tableLayout = virtualized ? "table-layout:fixed;" : "";
528
+ return '\n <div style="display:flex;flex-direction:column;width:100%;height:100%;box-sizing:border-box;background:#fff;font:12px/1.4 '.concat(fontFamilyStringify(viz.schema.fontFamily || "sans-serif"), ';">\n <div style="flex:0 0 auto;display:flex;gap:4px;padding:4px;">').concat(toolbarHtml, '</div>\n <div class="d3plus-table-view-scroll"').concat(virtualized ? ' data-tableview-virtual="1"' : "", ' style="flex:1 1 auto;min-height:0;overflow:auto;">\n <table class="d3plus-table-view-table').concat(extraClass, '" style="border-collapse:collapse;width:100%;').concat(tableLayout, '">\n <thead><tr>').concat(headHtml, "</tr></thead>\n <tbody>").concat(bodyHtml, "</tbody>\n </table>\n </div>\n ").concat(paginationHtml, "\n </div>");
529
+ }
530
+ /** Builds the CSV and triggers a browser download of the chart's full (sorted, unpaginated) data-table rows. */ export function downloadTableViewCsv(viz) {
531
+ var _sortedTableViewRows = sortedTableViewRows(viz), rows = _sortedTableViewRows.rows, columns = _sortedTableViewRows.columns;
532
+ var csv = toCsv(columns, rows);
533
+ var blob = new Blob([
534
+ csv
535
+ ], {
536
+ type: "text/csv;charset=utf-8;"
537
+ });
538
+ var url = URL.createObjectURL(blob);
539
+ var a = document.createElement("a");
540
+ a.href = url;
541
+ a.download = "table-view.csv";
542
+ document.body.appendChild(a);
543
+ a.click();
544
+ document.body.removeChild(a);
545
+ URL.revokeObjectURL(url);
546
+ }
547
+ /**
548
+ Paints every `.table-view-control` button's inline style (base/active,
549
+ plus hover — which can't be delegated like click, since mouseenter/
550
+ mouseleave don't bubble) once per button DOM node, guarded by
551
+ `data-table-view-bound` the same way `buildZoomControlPanel`'s
552
+ `onUpdate` guards its four buttons. Shared by `tableViewContribution`
553
+ (the shared top-left panel's lone toggle button) and `tableView.ts`'s
554
+ full overlay (whose toolbar has both the toggle and the download button).
555
+ */ export function bindTableViewButton(host, viz) {
556
+ host.querySelectorAll(".table-view-control").forEach(function(btn) {
557
+ if (btn.dataset.tableViewBound) return;
558
+ btn.dataset.tableViewBound = "1";
559
+ paintTableViewButton(viz, btn);
560
+ btn.addEventListener("mouseenter", function() {
561
+ return paintTableViewButton(viz, btn, true);
562
+ });
563
+ btn.addEventListener("mouseleave", function() {
564
+ return paintTableViewButton(viz, btn);
565
+ });
566
+ });
567
+ }
568
+ /** Renders the `[startIndex, endIndex)` window implied by the wrapper's LIVE scroll position/height into `tbody` — the only DOM write a scroll tick ever does, regardless of total row count. */ function renderVisibleRows(viz, wrapper, tbody, rows, columns) {
569
+ var total = rows.length;
570
+ var visibleCount = Math.max(1, Math.ceil(wrapper.clientHeight / ROW_HEIGHT));
571
+ var startIndex = Math.max(0, Math.floor(wrapper.scrollTop / ROW_HEIGHT) - OVERSCAN);
572
+ var endIndex = Math.min(total, startIndex + visibleCount + OVERSCAN * 2);
573
+ tbody.innerHTML = tbodyRowsHtml(viz, columns, rows, startIndex, endIndex, total);
574
+ }
575
+ /**
576
+ Wires scroll-driven row virtualization for a data table whose current
577
+ page exceeds `VIRTUALIZE_THRESHOLD` rows (marked by
578
+ `tableViewOverlayHtml` via `data-tableview-virtual` on the scroll
579
+ wrapper) — a no-op otherwise, since that marker is only present on a
580
+ virtualized table. Only the visible window (+ `OVERSCAN`) of `<tr>`s is
581
+ ever in the DOM; the two spacer rows `tbodyRowsHtml` emits stand in for
582
+ everything else, resized on every scroll, so the scrollbar still
583
+ reflects the full row count. This is what makes `tableViewPageSize(false)`
584
+ on a huge dataset viable — without it, that setting would put every row
585
+ in the DOM at once.
586
+
587
+ Guarded by `data-tableview-virtual-bound`, idempotent across repeated
588
+ `onUpdate` calls (every repaint re-invokes every overlay's `onUpdate`,
589
+ not just table-view's own) — and naturally re-armed on a fresh DOM
590
+ subtree, since a sort/page/toggle rebuilds the overlay's innerHTML
591
+ wholesale, discarding the old wrapper + its scroll listener along with it.
592
+
593
+ The scroll handler itself calls `sortedTableViewRows`/`paginate` exactly
594
+ ONCE, at setup — not per scroll tick. `rows`/`columns` are captured in
595
+ the closure and reused for the table's whole mounted lifetime, so a fast
596
+ scroll over a 100k-row table costs one `tbody.innerHTML` write per
597
+ animation frame, never a re-sort.
598
+ */ function setupTableViewVirtualization(host, viz) {
599
+ var wrapper = host.querySelector(".d3plus-table-view-scroll[data-tableview-virtual]");
600
+ if (!wrapper || wrapper.dataset.tableviewVirtualBound) return;
601
+ var tbody = wrapper.querySelector("tbody");
602
+ if (!tbody) return;
603
+ wrapper.dataset.tableviewVirtualBound = "1";
604
+ var _sortedTableViewRows = sortedTableViewRows(viz), rows = _sortedTableViewRows.rows, columns = _sortedTableViewRows.columns;
605
+ var slice = paginate(viz, rows).slice;
606
+ var raf = 0;
607
+ var rerender = function rerender() {
608
+ raf = 0;
609
+ renderVisibleRows(viz, wrapper, tbody, slice, columns);
610
+ };
611
+ wrapper.addEventListener("scroll", function() {
612
+ if (!raf) raf = requestAnimationFrame(rerender);
613
+ }, {
614
+ passive: true
615
+ });
616
+ // The html the overlay mounted with only guessed at the visible window
617
+ // (`INITIAL_VIRTUAL_WINDOW`) — correct it immediately against the real,
618
+ // now-measurable wrapper height, before the browser's next paint.
619
+ rerender();
620
+ }
621
+ /** Wires both the toolbar buttons and (when applicable) row virtualization for the full data-table overlay. */ export function bindTableViewOverlay(host, viz) {
622
+ bindTableViewButton(host, viz);
623
+ setupTableViewVirtualization(host, viz);
624
+ }
625
+ /**
626
+ Reflects the current active state onto the shared top-left panel's
627
+ toggle button DOM directly — mirrors `syncBrushButton`. Needed because
628
+ toggling table view deliberately does NOT rebuild the shared panel (see
629
+ `refreshTableViewOverlay` in `tableView.ts`: `tableViewContribution`'s
630
+ html bakes in `isTableView(viz)` at the time THAT panel was last built,
631
+ which only happens on a full `_preDraw`/`_draw` pass). Without this, the
632
+ shared panel's copy of the button can go visibly stale: activate table
633
+ view, let any unrelated full re-render happen while still active (a
634
+ resize, a `.data()` call), then deactivate via the overlay's OWN
635
+ embedded copy of the button — the shared one, now uncovered again,
636
+ would otherwise still read "active" until the next full re-render.
637
+ */ export function syncSharedTableViewButton(viz) {
638
+ var _overlayHost;
639
+ var btn = (_overlayHost = overlayHost(viz)) === null || _overlayHost === void 0 ? void 0 : _overlayHost.querySelector(".d3plus-top-left-controls-item .table-view-toggle");
640
+ if (!btn) return;
641
+ var active = isTableView(viz);
642
+ btn.classList.toggle("active", active);
643
+ btn.setAttribute("aria-pressed", String(active));
644
+ paintTableViewButton(viz, btn, btn.matches(":hover"));
645
+ }
646
+
647
+ //# sourceMappingURL=tableViewMarkup.js.map