@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
@@ -13,6 +13,7 @@ import { applyAxisBreaks, breakTickValues } from "./axisBreak.js";
13
13
  import { axisDateCategories, axisShownDates, axisTimeDomain, axisTimeReference, isCategoryAxis, isValidDate, parseTimeValues } from "./timeValues.js";
14
14
  import { axisIsYearLike, formatYear } from "./yearValues.js";
15
15
  import { floorPow, isNegative, roundedDomain } from "./axisRounding.js";
16
+ import { powExponent } from "./powTicks.js";
16
17
  /**
17
18
  Builds the tick label formatter (user-supplied or scale-derived). With a
18
19
  `rotatedTickFormat`, the formatter reads `axis._labelRotation` on every
@@ -233,10 +234,12 @@ import { floorPow, isNegative, roundedDomain } from "./axisRounding.js";
233
234
  const scale = `scale${axis.schema.scale.charAt(0).toUpperCase()}${axis.schema.scale.slice(1)}`;
234
235
  const initialDomain = axis.schema.domain.slice();
235
236
  axis._d3Scale = scales[scale]().domain(axis.schema.scale === "time" ? axisTimeDomain(axis) : initialDomain).range(range);
237
+ if (axis.schema.scale === "pow" && axis._d3Scale.exponent) axis._d3Scale.exponent(powExponent(axis.schema.exponent));
236
238
  if (axis.schema.rounding !== "none") {
237
239
  const rounded = roundedDomain(initialDomain, axis.schema.rounding, axis.schema.scale);
238
240
  if (rounded) axis._d3Scale.domain(rounded);
239
241
  }
242
+ if (axis.schema.reverse) axis._d3Scale.domain(axis._d3Scale.domain().slice().reverse());
240
243
  if (axis._d3Scale.padding) axis._d3Scale.padding(axis.schema.scalePadding);
241
244
  if (axis._d3Scale.align) axis._d3Scale.align(axis.schema.scaleAlign);
242
245
  if (axis._d3Scale.paddingInner) axis._d3Scale.paddingInner(axis.schema.paddingInner);
@@ -4,9 +4,12 @@ import { elem } from "@d3plus/dom";
4
4
  import * as shapes from "../../shapes/index.js";
5
5
  import { addDomainEnds, crowdsEndLabel } from "./axisEndLabels.js";
6
6
  import { configPrep } from "../../utils/index.js";
7
+ import { wholeWordSplit } from "../../utils/wholeWords.js";
7
8
  import { brokenScaleTicks, isBrokenScale } from "./axisBreak.js";
8
9
  import { ceilPow, fixFloat, floorPow, isNegative } from "./axisRounding.js";
10
+ import { powTicks } from "./powTicks.js";
9
11
  import { timeDataInDomain } from "./timeValues.js";
12
+ import { slantedLabelBox } from "./axisLabelAngle.js";
10
13
  const maxTimezoneOffset = 1000 * 60 * 60 * 26;
11
14
  /**
12
15
  * Calculates ticks from a given scale (negative and/or positive)
@@ -76,6 +79,9 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
76
79
  ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scaleClone.ticks(step).filter((d)=>+`${d}`.replace("0.", "") % 2 === 0) : d3Range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
77
80
  powers[1]
78
81
  ]).filter((d)=>Math.abs(d) % powMod === 0).map((d)=>+`${(isNegative(d) ? -1 : 1) * (d ? Math.pow(10, Math.abs(d)) : Math.sign(1 / d) > 0 ? 1 : -1)}`.replace(/9+/g, "1"));
82
+ } else if (scaleClone.exponent && scaleClone.exponent() !== 1) {
83
+ // Labels take every other step, as the linear filter below does.
84
+ ticks = powTicks(domain, scaleClone.exponent(), Math.max(1, step / 2), minorTicks);
79
85
  } else {
80
86
  ticks = scaleClone.ticks(step);
81
87
  if (!minorTicks && ![
@@ -103,6 +109,28 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
103
109
  }
104
110
  return addDomainEnds(this, ticks, domain, scaleClone, !minorTicks);
105
111
  }
112
+ /** A slanted label's box, relative to its tick (see `slantedLabelBox`). */ function slantedBounds(axis, data, gap) {
113
+ const { x, y, width, height } = slantedLabelBox(axis.schema.orient, data.angle, data.width, data.height - data.fP, data.height, gap);
114
+ return {
115
+ x,
116
+ y,
117
+ width,
118
+ height
119
+ };
120
+ }
121
+ /**
122
+ An upright (±90 degree) label's box, relative to its tick: centered on
123
+ it, reaching out from the axis by the label's length.
124
+ */ function uprightBounds(axis, data, size) {
125
+ const { fP, fS, lineHeight, lines, width } = data;
126
+ const text = lineHeight * lines.length;
127
+ return {
128
+ x: -width / 2 + ((data.angle ?? -90) > 0 ? -1 : 1) * (fS / 4),
129
+ y: axis.schema.orient === "bottom" ? size + (width - text) / 2 + fP : size - (width + text) / 2 - 2 * fP,
130
+ width,
131
+ height: data.height
132
+ };
133
+ }
106
134
  /**
107
135
  Builds the per-tick config array consumed by the tick Shape. Extracted from
108
136
  `Axis.render` so the render method stays under the per-function line budget;
@@ -124,8 +152,6 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
124
152
  const data = textData.find((td)=>td.d === d);
125
153
  const xPos = axis._getPosition(d);
126
154
  const space = data ? data.space : 0;
127
- const lines = data ? data.lines.length : 1;
128
- const lineHeight = data ? data.lineHeight : 1;
129
155
  const fP = data ? data.fP : 0;
130
156
  const labelOffset = data && axis.schema.labelOffset ? data.offset ?? 0 : 0;
131
157
  const fitWidth = horizontal ? space : bounds.width - margin[axis._position.opposite] - hBuff - margin[axis.schema.orient] + p;
@@ -135,18 +161,14 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
135
161
  const offset = margin[opposite], size = (hBuff + labelOffset) * (flip ? -1 : 1), yPos = flip ? bounds[y] + bounds[height] - offset : bounds[y] + offset;
136
162
  const tickConfig = {
137
163
  id: d,
138
- labelBounds: rotated && data ? {
139
- x: -data.width / 2 + data.fS / 4,
140
- y: axis.schema.orient === "bottom" ? size + (data.width - lineHeight * lines) / 2 + fP : size - (data.width + lineHeight * lines) / 2 - 2 * fP,
141
- width: data.width,
142
- height: data.height
143
- } : {
164
+ labelBounds: data?.slant ? slantedBounds(axis, data, Math.abs(size) + (horizontal ? fP : p)) : rotated && data ? uprightBounds(axis, data, size) : {
144
165
  x: horizontal ? -space / 2 : axis.schema.orient === "left" ? -labelWidth - p + size : size + p,
145
166
  y: horizontal ? axis.schema.orient === "bottom" ? size + fP : size - labelHeight - fP : -space / 2,
146
167
  width: horizontal ? space : labelWidth,
147
168
  height: horizontal ? labelHeight : space
148
169
  },
149
170
  rotate: data ? data.rotate : false,
171
+ angle: data ? data.angle : 0,
150
172
  size: labels.includes(d) || axis.schema.scale === "log" && Math.log10(Math.abs(d)) % 1 === 0 ? size : ticks.includes(d) ? Math.ceil(size / 2) : axis._scaleData.find((t)=>+t === d) ? Math.ceil(size / 4) : 0,
151
173
  text: !data?.truncated && labels.includes(d) ? tickFormat(d) : false,
152
174
  tick: ticks.includes(d),
@@ -177,10 +199,17 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
177
199
  // would silently leak one <div> per tick render.
178
200
  .renderMode("compute").select(null).data(tickData).duration(axis.schema.duration).labelConfig({
179
201
  ellipsis: (d)=>d && d.length ? `${d}...` : "",
202
+ // Slanted labels wrap between words, as they were measured.
203
+ ...axis._labelRotation && axis._labelSlant ? {
204
+ split: wholeWordSplit
205
+ } : {},
180
206
  // The label TextBox invokes this with the laid-out label record, whose
181
207
  // tick datum (carrying `rotate`) sits on `.data`; fall back to the raw
182
208
  // datum for any path that passes it directly.
183
- rotate: (d)=>d.rotate ?? d.data?.rotate ? -90 : 0
209
+ rotate: (d)=>{
210
+ const datum = d.rotate !== undefined ? d : d.data;
211
+ return datum?.rotate ? Number(datum.angle ?? -90) : 0;
212
+ }
184
213
  });
185
214
  // v4 scene-only: tick shape stays compute-mode; toScene() composes ticks.
186
215
  // No `g.ticks` DOM wrapper needed in the detached compute.
@@ -46,12 +46,23 @@
46
46
  }
47
47
  return newDomain.map(fixFloat);
48
48
  }
49
+ /** The axis scales whose domains round to nice values (see `roundedDomain`). */ export const roundingScales = [
50
+ "linear",
51
+ "log",
52
+ "pow",
53
+ "sqrt"
54
+ ];
49
55
  /**
50
- A linear or log axis domain rounded the way an Axis with this `rounding`
51
- ("outside" or "inside") rounds it, or undefined when the axis leaves the
52
- domain as given (another scale, or nothing to round).
56
+ A linear, log or power axis domain rounded the way an Axis with this
57
+ `rounding` ("outside" or "inside") rounds it, or undefined when the axis
58
+ leaves the domain as given (another scale, or nothing to round). A power
59
+ scale's domain rounds as a linear one does.
53
60
  */ export function roundedDomain(initialDomain, rounding, scale) {
54
- if (scale === "linear") {
61
+ if ([
62
+ "linear",
63
+ "pow",
64
+ "sqrt"
65
+ ].includes(scale)) {
55
66
  return roundLinear(initialDomain, rounding, scale);
56
67
  } else if (scale === "log") {
57
68
  const powDomain = [];
@@ -0,0 +1,39 @@
1
+ /**
2
+ Wrapping for slanted axis labels (see `labelRotation`). Long labels wrap
3
+ onto two or three lines, as many as fit between neighbouring labels,
4
+ breaking only between words, so
5
+ a slanted label reaches less far from the axis than it would on one long
6
+ line. Every label wraps at one shared width: the narrowest at which the
7
+ longest label fits those lines, so the shorter ones stay whole on fewer.
8
+ */ import { textWidth } from "@d3plus/dom";
9
+ import { textWrap } from "@d3plus/text";
10
+ import { wholeWordSplit } from "../../utils/wholeWords.js";
11
+ /** The most lines a slanted label wraps onto. */ export const SLANTED_MAX_LINES = 3;
12
+ /** How many lines of `lineHeight` fit in a slanted label `thickness` thick: 1 to 3. */ export const slantedLines = (thickness, lineHeight)=>Math.max(1, Math.min(SLANTED_MAX_LINES, Math.floor(thickness / lineHeight + 1e-9)));
13
+ /**
14
+ The narrowest width, from `min` up to `max` in steps of `step` times the
15
+ last, at which text wraps onto at most `lines` lines, as `lineCount`
16
+ counts them at a width; `max` when none does.
17
+ */ export function narrowestWidth(lineCount, lines, min, max, step = 1.08) {
18
+ for(let width = Math.max(1, min); width < max; width *= step)if (lineCount(width) <= lines) return Math.ceil(width);
19
+ return max;
20
+ }
21
+ /**
22
+ The width slanted labels wrap at to fit on `lines` lines, at most `max`:
23
+ the widest any one of them needs, and never narrower than a word.
24
+ */ export function slantedLineWidth(labels, lines, max) {
25
+ if (lines < 2) return max;
26
+ const widths = labels.map(({ text, fontFamily, fontSize, lineHeight })=>{
27
+ const font = {
28
+ "font-family": fontFamily,
29
+ "font-size": fontSize
30
+ };
31
+ const whole = textWidth(`${text}`, font);
32
+ const words = `${text}`.split(/\s+/).filter(Boolean);
33
+ const word = Math.max(0, ...words.map((w)=>textWidth(w, font)));
34
+ const wrap = textWrap().fontFamily(fontFamily).fontSize(fontSize).lineHeight(lineHeight).split(wholeWordSplit).height(lineHeight * (lines + 1));
35
+ const count = (width)=>wrap.width(width)(`${text}`).lines.filter((l)=>l !== "").length;
36
+ return narrowestWidth(count, lines, Math.max(word + 1, whole / lines), max);
37
+ });
38
+ return Math.min(max, Math.max(0, ...widths));
39
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ Tick values for a power scale whose exponent isn't 1. Value-spaced ticks
3
+ bunch up where the exponent compresses the axis and leave long gaps
4
+ where it stretches it, so these are spaced evenly along the axis instead,
5
+ each rounded to a round number at the precision its neighbors allow.
6
+ */ /**
7
+ The exponent a `"pow"` axis uses: `exponent` when it is a positive
8
+ number, else 1.
9
+ */ export const powExponent = (exponent)=>typeof exponent === "number" && Number.isFinite(exponent) && exponent > 0 ? exponent : 1;
10
+ /** `value` raised to `exponent`, keeping its sign (as d3's `scalePow` does). */ const raise = (value, exponent)=>value < 0 ? -Math.pow(-value, exponent) : Math.pow(value, exponent);
11
+ /**
12
+ `value` rounded to the roundest number within `tolerance` of it: the
13
+ nearest multiple of the largest step (1, 2 or 5 times a power of ten)
14
+ that lands that close.
15
+ */ export function roundWithin(value, tolerance) {
16
+ if (!(tolerance > 0) || !Number.isFinite(tolerance)) return value;
17
+ let power = Math.floor(Math.log10(Math.max(Math.abs(value), tolerance))) + 1;
18
+ for(; power > -30; power--){
19
+ for (const m of [
20
+ 5,
21
+ 2,
22
+ 1
23
+ ]){
24
+ const step = m * Math.pow(10, power);
25
+ const rounded = Math.round(value / step) * step;
26
+ if (Math.abs(rounded - value) <= tolerance) return +rounded.toPrecision(12);
27
+ }
28
+ }
29
+ return value;
30
+ }
31
+ /**
32
+ Each value rounded to within a third of the distance to its nearest
33
+ neighbor in `neighbors`, so neighbors stay apart.
34
+ */ function roundEach(values, neighbors) {
35
+ return values.map((value)=>{
36
+ const spacing = Math.min(...neighbors.map((n)=>Math.abs(n - value)).filter((d)=>d > 0));
37
+ return roundWithin(value, spacing / 3);
38
+ });
39
+ }
40
+ /**
41
+ Tick values for a power scale: `count` equal steps along the axis (in the
42
+ scale's transformed space), each rounded to a round number. With
43
+ `minor`, the midpoints between those steps are added, so the major
44
+ ticks are always a subset of the minor ones. Returns ascending values
45
+ inside the domain, or the domain's own order when it runs high to low.
46
+ @param domain The scale's domain.
47
+ @param exponent The scale's exponent.
48
+ @param count How many steps to divide the axis into.
49
+ @param minor Whether to add a tick between each pair of steps.
50
+ */ export function powTicks(domain, exponent, count, minor = false) {
51
+ const [d0, d1] = domain.map(Number);
52
+ const lo = Math.min(d0, d1);
53
+ const hi = Math.max(d0, d1);
54
+ if (!Number.isFinite(lo) || !Number.isFinite(hi) || lo === hi || !exponent) return lo === hi && Number.isFinite(lo) ? [
55
+ lo
56
+ ] : [];
57
+ const steps = Math.max(1, Math.round(count));
58
+ const t0 = raise(lo, exponent);
59
+ const t1 = raise(hi, exponent);
60
+ const sample = (n)=>Array.from({
61
+ length: n + 1
62
+ }, (_, i)=>raise(t0 + (t1 - t0) * i / n, 1 / exponent));
63
+ const majorRaw = sample(steps);
64
+ const major = roundEach(majorRaw, majorRaw);
65
+ let ticks = major;
66
+ if (minor) {
67
+ const all = sample(steps * 2);
68
+ const mids = all.filter((_, i)=>i % 2);
69
+ ticks = major.concat(roundEach(mids, all));
70
+ }
71
+ const values = Array.from(new Set(ticks)).filter((d)=>d >= lo && d <= hi).sort((a, b)=>a - b);
72
+ return d1 < d0 ? values.reverse() : values;
73
+ }
@@ -1,4 +1,4 @@
1
- import { max, min } from "d3-array";
1
+ import { max } from "d3-array";
2
2
  import { select } from "d3-selection";
3
3
  import { transition } from "d3-transition";
4
4
  import { colorContrast } from "@d3plus/color";
@@ -10,8 +10,11 @@ import { accessor, BaseClass, paintComponentScene } from "../../utils/index.js";
10
10
  import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
11
11
  import Legend from "../Legend/Legend.js";
12
12
  import { formatYear, isYearLike } from "../Axis/yearValues.js";
13
+ import { bucketBounds } from "./bucketBounds.js";
13
14
  import { computeColorScale } from "./colorScaleScale.js";
14
15
  import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
16
+ import { isBucketScale } from "./colorScaleType.js";
17
+ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
15
18
  /** ColorScale's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const colorScaleSchema = [
16
19
  {
17
20
  key: "align",
@@ -78,6 +81,16 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
78
81
  coerce: "identity",
79
82
  default: 200
80
83
  },
84
+ {
85
+ key: "hoverMark",
86
+ coerce: "identity",
87
+ default: true
88
+ },
89
+ {
90
+ key: "hoverMarkConfig",
91
+ merge: true,
92
+ factory: hoverMarkDefaults
93
+ },
81
94
  {
82
95
  key: "midpoint",
83
96
  coerce: "identity",
@@ -134,6 +147,9 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
134
147
  _legendClass;
135
148
  _outerBounds;
136
149
  _rectClass;
150
+ /** The scale the last render built, with a `scale` function resolved. */ _scaleType = "linear";
151
+ /** Where the color bar sits, set when the bar variant renders (see colorScaleHoverMark). */ _barGeometry;
152
+ /** The value marked on the scale, set with `hover()`. */ _hoverValue;
137
153
  /** Smooth-gradient fill token (`gradient:<json>`), set by renderGradientStops. */ _gradientFill;
138
154
  // Standalone scene renderer (used when rendered on its own, not inside a
139
155
  // Viz). Reused across re-renders by paintComponentScene().
@@ -151,26 +167,13 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
151
167
  this._axisTest = new Axis();
152
168
  this.schema.bucketFormat = (tick, i, ticks, allValues)=>{
153
169
  const format = this.schema.axisConfig.tickFormat ? this.schema.axisConfig.tickFormat : isYearLike(allValues) ? (v)=>formatYear(v, this.schema.locale) : formatAbbreviate;
154
- const next = ticks[i + 1];
155
- const prev = i ? ticks[i - 1] : false;
156
170
  const last = i === ticks.length - 1;
157
- if (tick === next || last) {
171
+ if (tick === ticks[i + 1] || last) {
158
172
  const suffix = last && tick < max(allValues) ? "+" : "";
159
173
  return `${format(tick)}${suffix}`;
160
- } else {
161
- const mod = next ? next / 100 : tick / 100;
162
- const pow = mod >= 1 || mod <= -1 ? Math.round(mod).toString().length - 1 : mod.toString().split(".")[1].replace(/([1-9])[1-9].*$/, "$1").length * -1;
163
- const ten = Math.pow(10, pow);
164
- const prevValue = prev === tick && i === 1 ? format(min([
165
- tick + ten,
166
- allValues.find((d)=>d > tick && d < next)
167
- ])) : format(tick);
168
- const nextValue = tick && i === 1 ? format(next) : format(max([
169
- next - ten,
170
- allValues.reverse().find((d)=>d > tick && d < next)
171
- ]));
172
- return this.schema.bucketJoiner(prevValue, nextValue);
173
174
  }
175
+ const [lower, upper] = bucketBounds(tick, i, ticks, allValues, format);
176
+ return this.schema.bucketJoiner(format(lower), format(upper));
174
177
  };
175
178
  this._data = [];
176
179
  this._labelClass = new TextBox();
@@ -214,11 +217,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
214
217
  parent: this._select
215
218
  });
216
219
  const compute = computeColorScale(this);
217
- const gradient = this.schema.bucketAxis || ![
218
- "buckets",
219
- "jenks",
220
- "quantile"
221
- ].includes(this.schema.scale);
220
+ const gradient = this.schema.bucketAxis || !isBucketScale(compute.scale);
222
221
  const t = transition().duration(this.schema.duration);
223
222
  const groupParams = {
224
223
  enter: {
@@ -272,11 +271,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
272
271
  and the discrete variant use concrete per-bucket fills.
273
272
  */ toScene() {
274
273
  const children = [];
275
- const gradient = this.schema.bucketAxis || ![
276
- "buckets",
277
- "jenks",
278
- "quantile"
279
- ].includes(this.schema.scale);
274
+ const gradient = this.schema.bucketAxis || !isBucketScale(this._scaleType);
280
275
  const pushScene = (cls)=>{
281
276
  if (cls && typeof cls.toScene === "function") {
282
277
  const s = cls.toScene();
@@ -304,7 +299,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
304
299
  };
305
300
  }
306
301
  }
307
- return {
302
+ const group = {
308
303
  type: "group",
309
304
  key: `ColorScale-${this._uuid.slice(0, 8)}`,
310
305
  ...transform ? {
@@ -312,6 +307,8 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
312
307
  } : {},
313
308
  children
314
309
  };
310
+ addHoverMark(this, group);
311
+ return group;
315
312
  }
316
313
  axisConfig(_) {
317
314
  return arguments.length ? (this.schema.axisConfig = mergeConfigBag(this, "axisConfig", _), this) : this.schema.axisConfig;
@@ -319,6 +316,9 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
319
316
  data(_) {
320
317
  return arguments.length ? (this._data = _, this) : this._data;
321
318
  }
319
+ hover(_) {
320
+ return arguments.length ? (this._hoverValue = _, this) : this._hoverValue;
321
+ }
322
322
  labelConfig(_) {
323
323
  return arguments.length ? (this.schema.labelConfig = mergeConfigBag(this, "labelConfig", _), this) : this.schema.labelConfig;
324
324
  }
@@ -0,0 +1,35 @@
1
+ import { max } from "d3-array";
2
+ /**
3
+ The number of decimal places `value` is written with, read at 15
4
+ significant digits so float noise (`0.1 + 0.2`) doesn't count.
5
+ */ export function decimalPlaces(value) {
6
+ const [mantissa, exponent] = value.toExponential(14).split("e");
7
+ const decimals = mantissa.split(".")[1].replace(/0+$/, "");
8
+ return Math.max(0, decimals.length - Number(exponent));
9
+ }
10
+ /** `value` counted in steps of `10^-places`, with float noise rounded off. */ const toSteps = (value, places)=>+(value * 10 ** places).toPrecision(15);
11
+ /** The value of `steps` steps of `10^-places`. */ const fromSteps = (steps, places)=>+(steps / 10 ** places).toPrecision(15);
12
+ /**
13
+ The `[lower, upper]` values a ColorScale label shows for the bucket
14
+ `[ticks[i], ticks[i + 1])`: the first and last values the data's own
15
+ precision can write inside it, so integer data reads "1 - 2", "3 - 4".
16
+ When `format` prints the upper bound the same as the next bucket's lower
17
+ one (an abbreviation like "1.5k"), the upper bound drops a decimal place
18
+ at a time until it reads differently ("1.49k").
19
+ */ export function bucketBounds(tick, i, ticks, allValues, format) {
20
+ const next = ticks[i + 1];
21
+ const places = max(allValues.filter(Number.isFinite).map(decimalPlaces)) ?? 0;
22
+ const tickSteps = toSteps(tick, places);
23
+ // A repeated first tick labels its own value, so the bucket after it
24
+ // starts one step above.
25
+ const lower = fromSteps(i === 1 && ticks[0] === tick ? Math.floor(tickSteps) + 1 : Math.ceil(tickSteps), places);
26
+ const below = (p)=>fromSteps(Math.ceil(toSteps(next, p)) - 1, p);
27
+ const nextLabel = format(fromSteps(Math.ceil(toSteps(next, places)), places));
28
+ let p = places;
29
+ let upper = below(p);
30
+ while(format(upper) === nextLabel && below(p - 1) >= lower)upper = below(--p);
31
+ return [
32
+ lower,
33
+ upper
34
+ ];
35
+ }