@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
@@ -5,8 +5,11 @@ import { fontFamilyStringify } from "@d3plus/text";
5
5
  import { runVizPipeline } from "../pipeline/runVizPipeline.js";
6
6
  import touchstartBody from "../events/touchstart.body.js";
7
7
  import { reserveContainerSize } from "./reserveContainerSize.js";
8
+ import { applyClassName } from "../../utils/className.js";
9
+ import { ROOT_CLASS } from "./vizClassName.js";
8
10
  import { resetChromeBoxes } from "./resetChromeBoxes.js";
9
11
  import { canObserveVisibility, observeVisibility, syncUnloadObserver } from "./vizVisibility.js";
12
+ import { recordDataSignature, syncDataPolling } from "./vizDataPolling.js";
10
13
  /**
11
14
  Whether the chart counts as on-screen for this render. `_forceVisible` is set
12
15
  by the observer callbacks, whose margin admits charts that are just outside
@@ -71,12 +74,13 @@ import { canObserveVisibility, observeVisibility, syncUnloadObserver } from "./v
71
74
  @private
72
75
  */ function applyRootAttributes(viz, parent) {
73
76
  applyRootSize(viz);
74
- viz._select.attr("class", "d3plus-viz").attr("aria-hidden", viz.schema.ariaHidden).attr("aria-labelledby", `${viz._uuid}-title ${viz._uuid}-desc`).attr("role", "img").attr("xmlns", "http://www.w3.org/2000/svg").attr("xmlns:xlink", "http://www.w3.org/1999/xlink").style("position", "absolute").style("top", parent.style("padding-top")).style("left", parent.style("padding-left"))// Lets the browser skip layout and paint of the SVG's contents while it
77
+ viz._select.attr("class", ROOT_CLASS).attr("aria-hidden", viz.schema.ariaHidden).attr("aria-labelledby", `${viz._uuid}-title ${viz._uuid}-desc`).attr("role", "img").attr("xmlns", "http://www.w3.org/2000/svg").attr("xmlns:xlink", "http://www.w3.org/1999/xlink").style("position", "absolute").style("top", parent.style("padding-top")).style("left", parent.style("padding-left"))// Lets the browser skip layout and paint of the SVG's contents while it
75
78
  // is far off-screen. The SVG is absolutely positioned and explicitly sized,
76
79
  // so it needs no intrinsic size, and tooltips live outside it so are not
77
80
  // clipped. Unset with detectVisible(false), which also keeps it out of
78
81
  // static SVG/PNG output.
79
82
  .style("content-visibility", viz.schema.detectVisible ? "auto" : null);
83
+ applyClassName(viz);
80
84
  // sets "position: relative" on the SVG parent if currently undefined
81
85
  const position = parent.style("position");
82
86
  if (position === "static") parent.style("position", "relative");
@@ -167,8 +171,9 @@ import { canObserveVisibility, observeVisibility, syncUnloadObserver } from "./v
167
171
  const cache = viz.schema.cache ? viz._lrucache.get(`${p[3]}_${p[1]}`) : undefined;
168
172
  if (!cache) {
169
173
  promises.push(new Promise((resolve)=>{
170
- p[0](p[1], p[2], p[3], (err)=>{
174
+ p[0](p[1], p[2], p[3], (err, data)=>{
171
175
  if (err) console.error(err);
176
+ else if (p[3] === "data") recordDataSignature(viz, data);
172
177
  resolve();
173
178
  });
174
179
  }));
@@ -217,6 +222,7 @@ import { canObserveVisibility, observeVisibility, syncUnloadObserver } from "./v
217
222
  runVizPipeline(viz);
218
223
  viz._instantNextDraw = false;
219
224
  syncUnloadObserver(viz);
225
+ syncDataPolling(viz);
220
226
  if (viz._messageClass._isVisible && (!viz.schema.noDataMessage || viz._filteredData.length)) {
221
227
  viz._messageClass.hide();
222
228
  if (viz._select.attr("opacity") === "0") viz._select.transition().duration(viz.schema.duration).attr("opacity", 1);
@@ -49,6 +49,11 @@ import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
49
49
  coerce: "identity",
50
50
  default: 600
51
51
  },
52
+ {
53
+ key: "exponent",
54
+ coerce: "identity",
55
+ default: 1
56
+ },
52
57
  {
53
58
  key: "grid",
54
59
  coerce: "identity"
@@ -112,6 +117,11 @@ import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
112
117
  coerce: "identity",
113
118
  default: "full"
114
119
  },
120
+ {
121
+ key: "reverse",
122
+ coerce: "identity",
123
+ default: false
124
+ },
115
125
  {
116
126
  key: "rotatedTickFormat",
117
127
  coerce: "identity"
@@ -201,10 +211,20 @@ import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
201
211
  _data;
202
212
  /** The `data` values the scale reads, set by the layout pass (see `axisScaleData`). */ _scaleData = [];
203
213
  /** Whether the last layout pass rotated the labels (see `labelRotation`). */ _labelRotation;
214
+ /** The angle the last layout pass rotated the labels by (0 when flat). */ _labelAngle = 0;
215
+ /** Whether the last layout pass slanted the labels (see `settingTurn`). */ _labelSlant = false;
204
216
  /** The configured `labelRotation`: `undefined` lets the layout decide. */ _labelRotationSetting;
205
217
  _margin;
206
218
  _outerBounds;
207
219
  /** The measured size of the tick-label/title space, before margins (see `fixedSize`). */ _labelSpace;
220
+ /**
221
+ How far slanted labels reach past the start and end of the range, set
222
+ by the layout pass (see `labelRotation`). A Plot makes room for them
223
+ when its range is fixed.
224
+ */ _labelOverflow = [
225
+ 0,
226
+ 0
227
+ ];
208
228
  _position;
209
229
  _tickUnit;
210
230
  _titleClass;
@@ -290,6 +310,14 @@ import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
290
310
  ].includes(this.schema.scale) ? ticks : extent(ticks);
291
311
  return ticks[0] > ticks[1] ? domain.reverse() : domain;
292
312
  }
313
+ /**
314
+ The scale's domain (or its negative log half's, with `negative`) in the
315
+ order it was given, undoing `reverse`.
316
+ @private
317
+ */ _givenDomain(negative = false) {
318
+ const domain = (negative ? this._d3ScaleNegative : this._d3Scale).domain();
319
+ return this.schema.reverse ? domain.slice().reverse() : domain;
320
+ }
293
321
  /**
294
322
  Returns a value's scale position, taking into account negative and positive log scales.
295
323
  @param d @private
@@ -2,6 +2,7 @@ import { colorContrast } from "@d3plus/color";
2
2
  import { backgroundColor, rtl as detectRTL } from "@d3plus/dom";
3
3
  import { constant } from "../../utils/index.js";
4
4
  import { gridStroke } from "./gridStroke.js";
5
+ import { rotatedTextAnchor } from "./axisLabelAngle.js";
5
6
  /** A color that contrasts with the background behind the axis's container. */ function contrastInk(axis) {
6
7
  return ()=>{
7
8
  const bg = axis._select ? backgroundColor(axis._select.node()) : "rgb(255, 255, 255)";
@@ -45,8 +46,9 @@ import { gridStroke } from "./gridStroke.js";
45
46
  fontSize: constant(12),
46
47
  padding: 5,
47
48
  textAnchor: ()=>{
49
+ if (axis._labelRotation && axis._labelSlant) return rotatedTextAnchor(axis.schema.orient, axis._labelAngle);
48
50
  const rtl = detectRTL();
49
- return axis.schema.orient === "left" ? rtl ? "start" : "end" : axis.schema.orient === "right" ? rtl ? "end" : "start" : axis._labelRotation ? axis.schema.orient === "bottom" ? "end" : "start" : "middle";
51
+ return axis.schema.orient === "left" ? rtl ? "start" : "end" : axis.schema.orient === "right" ? rtl ? "end" : "start" : axis._labelRotation ? rotatedTextAnchor(axis.schema.orient, axis._labelAngle) : "middle";
50
52
  },
51
53
  verticalAlign: ()=>axis.schema.orient === "bottom" ? "top" : axis.schema.orient === "top" ? axis._labelRotation ? "top" : "bottom" : "middle"
52
54
  },
@@ -0,0 +1,175 @@
1
+ /**
2
+ Label angles for `labelRotation`. `true` rotates labels -90 degrees; a
3
+ number rotates them by that many degrees; left to the layout, crowded
4
+ labels slant 30 degrees (see `autoAngle`). Labels at an angle between the
5
+ two axis directions ("slanted", e.g. -45) hang off the axis from the end
6
+ of their text nearest it, so each one ends (or starts) at its tick.
7
+ */ /** The axis sides, as `Axis.orient` names them. */ /**
8
+ `degrees` brought into [-90, 90], turning upside-down text a half turn
9
+ so it reads left to right: 135 becomes -45, 180 becomes 0.
10
+ */ export function normalizeAngle(degrees) {
11
+ let a = (degrees % 360 + 360) % 360;
12
+ if (a > 180) a -= 360;
13
+ if (a > 90) a -= 180;
14
+ else if (a < -90) a += 180;
15
+ return a === 0 ? 0 : a;
16
+ }
17
+ /**
18
+ The angle a `labelRotation` setting rotates labels by when they rotate:
19
+ a number (normalized, see `normalizeAngle`), else -90.
20
+ */ export function settingAngle(setting) {
21
+ return typeof setting === "number" && Number.isFinite(setting) ? normalizeAngle(setting) : -90;
22
+ }
23
+ /** No rotation. */ export const FLAT = {
24
+ rotate: false,
25
+ angle: 0,
26
+ slant: false
27
+ };
28
+ /**
29
+ How a `labelRotation` setting draws an axis's labels before the layout
30
+ has its say: `true` upright (-90), a number at its angle, anything else
31
+ flat.
32
+ */ export function settingTurn(setting, horizontal) {
33
+ if (!settingRotates(setting)) return FLAT;
34
+ return {
35
+ rotate: true,
36
+ angle: settingAngle(setting),
37
+ slant: slantsLabels(setting, horizontal)
38
+ };
39
+ }
40
+ /**
41
+ The angle crowded labels slant at when the layout rotates them: -30 on
42
+ a bottom axis (rising to the right, ending at their ticks), 30 on a top
43
+ axis (the mirror image).
44
+ */ export const autoAngle = (orient)=>orient === "top" ? 30 : -30;
45
+ /**
46
+ Whether a `labelRotation` setting rotates the labels: `true`, or a
47
+ number that isn't a multiple of 180. `undefined` leaves it to the
48
+ layout, which this doesn't decide.
49
+ */ export function settingRotates(setting) {
50
+ if (typeof setting === "number") return Number.isFinite(setting) && normalizeAngle(setting) !== 0;
51
+ return setting === true;
52
+ }
53
+ /**
54
+ Whether a `labelRotation` setting lays its labels out at their angle
55
+ (see `slantedLabelBox`): a number that rotates them, except ±90 on a
56
+ horizontal axis, which stands them upright as `true` does.
57
+ */ export function slantsLabels(setting, horizontal) {
58
+ if (!settingRotates(setting) || typeof setting !== "number") return false;
59
+ return !horizontal || Math.abs(normalizeAngle(setting)) !== 90;
60
+ }
61
+ /**
62
+ The angle (in radians, 0 to π/2) between a label's text at `angle` and
63
+ the axis it labels: 0 when the text runs along the axis, π/2 when it
64
+ stands straight out from it.
65
+ */ export function axisCrossing(angle, horizontal) {
66
+ const a = Math.abs(angle) * Math.PI / 180;
67
+ return horizontal ? a : Math.PI / 2 - a;
68
+ }
69
+ /** The unit vector pointing away from the axis, toward its labels. */ function outward(orient) {
70
+ return orient === "bottom" ? {
71
+ x: 0,
72
+ y: 1
73
+ } : orient === "top" ? {
74
+ x: 0,
75
+ y: -1
76
+ } : orient === "left" ? {
77
+ x: -1,
78
+ y: 0
79
+ } : {
80
+ x: 1,
81
+ y: 0
82
+ };
83
+ }
84
+ /**
85
+ Which end of a rotated label's text sits at its tick: the end nearer the
86
+ axis. On a bottom axis, text rising to the right (a negative angle) ends
87
+ at its tick and text falling to the right starts at it; a top axis is
88
+ the reverse; a left axis's labels end at their ticks, a right axis's start
89
+ at them.
90
+ */ export function rotatedTextAnchor(orient, angle) {
91
+ const t = angle * Math.PI / 180;
92
+ const o = outward(orient);
93
+ const along = Math.cos(t) * o.x + Math.sin(t) * o.y;
94
+ return Math.abs(along) < 1e-9 ? "middle" : along < 0 ? "end" : "start";
95
+ }
96
+ /**
97
+ Where a slanted label goes: its text (`width` long, `textHeight` thick,
98
+ in a box `height` tall) rotated by `angle` about the box's center, with
99
+ the text's end nearest the axis (see `rotatedTextAnchor`) across from its
100
+ tick and every corner at least `gap` from the axis line.
101
+ */ export function slantedLabelBox(orient, angle, width, textHeight, height, gap) {
102
+ const t = angle * Math.PI / 180;
103
+ const u = {
104
+ x: Math.cos(t),
105
+ y: Math.sin(t)
106
+ };
107
+ const n = {
108
+ x: -Math.sin(t),
109
+ y: Math.cos(t)
110
+ };
111
+ const o = outward(orient);
112
+ const anchor = rotatedTextAnchor(orient, angle);
113
+ const across = Math.abs(n.x * o.x + n.y * o.y);
114
+ const a = {
115
+ x: o.x * (gap + textHeight / 2 * across),
116
+ y: o.y * (gap + textHeight / 2 * across)
117
+ };
118
+ // The anchor, in the text's own (unrotated) coordinates from its box's top left.
119
+ const ax = anchor === "end" ? width : anchor === "start" ? 0 : width / 2;
120
+ const ay = textHeight / 2;
121
+ const at = (px, py)=>({
122
+ x: a.x + (px - ax) * u.x + (py - ay) * n.x,
123
+ y: a.y + (px - ax) * u.y + (py - ay) * n.y
124
+ });
125
+ const center = at(width / 2, height / 2);
126
+ return {
127
+ x: center.x - width / 2,
128
+ y: center.y - height / 2,
129
+ width,
130
+ height,
131
+ corners: [
132
+ at(0, 0),
133
+ at(width, 0),
134
+ at(width, textHeight),
135
+ at(0, textHeight)
136
+ ]
137
+ };
138
+ }
139
+ /**
140
+ How far a slanted label reaches from its tick along the axis, before and
141
+ after it (toward lower and higher positions).
142
+ */ export function slantedReach(orient, angle, width, textHeight) {
143
+ const horizontal = orient === "top" || orient === "bottom";
144
+ const along = slantedLabelBox(orient, angle, width, textHeight, textHeight, 0).corners.map((c)=>horizontal ? c.x : c.y);
145
+ return [
146
+ Math.max(0, -Math.min(...along)),
147
+ Math.max(0, Math.max(...along))
148
+ ];
149
+ }
150
+ /**
151
+ How far a slanted label reaches out from the axis line: its text's
152
+ length and thickness projected across the axis.
153
+ */ export function slantedDepth(angle, horizontal, width, textHeight) {
154
+ const phi = axisCrossing(angle, horizontal);
155
+ return width * Math.sin(phi) + textHeight * Math.cos(phi);
156
+ }
157
+ /**
158
+ The longest and thickest a slanted label's text may be: as long as
159
+ reaches `depth` out from the axis (with one line of `lineHeight`), and
160
+ as thick as fits between labels `space` apart along the axis (at least
161
+ one line). Text running along the axis is `space` long and `depth`
162
+ thick.
163
+ */ export function slantedWrapSize(angle, horizontal, depth, space, lineHeight) {
164
+ const phi = axisCrossing(angle, horizontal);
165
+ const sin = Math.sin(phi);
166
+ // Text running along the axis wraps like flat labels on a horizontal one.
167
+ if (sin < 1e-9) return {
168
+ width: space,
169
+ height: depth
170
+ };
171
+ return {
172
+ width: Math.max(0, (depth - lineHeight * Math.cos(phi)) / sin),
173
+ height: Math.max(lineHeight, space * sin)
174
+ };
175
+ }
@@ -2,7 +2,8 @@
2
2
  Label thinning for `createTextData` (see `axisLayoutLabels.ts`): the
3
3
  passes that hide labels crowding their neighbors, and the widening of
4
4
  labels that each wrap within their own share of the axis.
5
- */ /**
5
+ */ import { axisCrossing } from "./axisLabelAngle.js";
6
+ /**
6
7
  A measured label's text extent along its axis, which the overlap pass
7
8
  spaces at least the label's padding apart. Text running along the axis
8
9
  spans its measured width. Stacked across the axis, it spans its lines'
@@ -10,11 +11,19 @@
10
11
  The measured `height` also holds the label's padding (see
11
12
  `calculateLabelSize`) and the leading above and below the text, which this
12
13
  leaves out, so neighbors are spaced by their padding alone, as they are
13
- along a horizontal axis.
14
+ along a horizontal axis. Slanted labels span their glyphs' thickness where
15
+ it crosses the axis.
14
16
  */ export function labelExtent(datum, horizontal) {
15
- if (Boolean(datum.rotate) !== horizontal) return datum.width;
16
17
  const lines = datum.lines.length;
17
- return lines ? (lines - 1) * datum.lineHeight + datum.fS : 0;
18
+ const glyphs = lines ? (lines - 1) * datum.lineHeight + datum.fS : 0;
19
+ // Slanted labels lie side by side: each one's text crosses the axis over
20
+ // its thickness, lengthened by the slant.
21
+ if (datum.slant) {
22
+ const sin = Math.sin(axisCrossing(datum.angle, horizontal));
23
+ return sin < 1e-9 ? datum.width : glyphs / sin;
24
+ }
25
+ if (Boolean(datum.rotate) !== horizontal) return datum.width;
26
+ return glyphs;
18
27
  }
19
28
  /**
20
29
  Fits flat labels that each wrap within their own share of the axis (see
@@ -26,6 +26,7 @@
26
26
  import { timeFormatDefaultLocale } from "d3-time-format";
27
27
  import { applyTitleMargin, computeAxisBounds, computeBuffers, createTextData, isDiscreteScale, wholeLineLabels } from "./axisLayoutLabels.js";
28
28
  import { buildTickFormat, labelSets, setAxisScale } from "./axisLayoutScale.js";
29
+ import { FLAT, autoAngle, settingTurn, slantedReach } from "./axisLabelAngle.js";
29
30
  import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
30
31
  /**
31
32
  The standalone axis layout pass. Accepts any object satisfying the
@@ -79,7 +80,7 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
79
80
  ownSpace
80
81
  };
81
82
  const setting = axis._labelRotationSetting;
82
- axis._labelRotation = setting ?? false;
83
+ turnLabels(axis, settingTurn(setting, horizontal));
83
84
  let textData = layoutLabels(axis, {
84
85
  range,
85
86
  labels
@@ -95,9 +96,11 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
95
96
  labels,
96
97
  tickFormat,
97
98
  ownSpace,
99
+ rangeOuter,
98
100
  relayout: ()=>layoutLabels(axis, rescale(), labelCtx)
99
101
  });
100
102
  hideTruncatedTicks(axis, textData, ticks);
103
+ axis._labelOverflow = slantedOverflow(axis, textData, range);
101
104
  const labelHeight = max(textData, (t)=>t.height) || 0;
102
105
  alignLabelOffsets(axis, textData);
103
106
  const bounds = computeAxisBounds(axis, {
@@ -126,6 +129,25 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
126
129
  bounds
127
130
  };
128
131
  }
132
+ /**
133
+ How far the first and last slanted labels shown reach past the start and
134
+ end of `range`, along the axis (0 when they don't, or aren't slanted).
135
+ */ export function slantedOverflow(axis, textData, range) {
136
+ const shown = textData.filter((t)=>!t.truncated && t.slant);
137
+ if (!shown.length) return [
138
+ 0,
139
+ 0
140
+ ];
141
+ const lo = Math.min(range[0], range[range.length - 1]);
142
+ const hi = Math.max(range[0], range[range.length - 1]);
143
+ const reach = (t)=>slantedReach(axis.schema.orient, t.angle, t.width, t.height - t.fP);
144
+ const first = shown[0];
145
+ const last = shown[shown.length - 1];
146
+ return [
147
+ Math.max(0, reach(first)[0] - (first.position - lo)),
148
+ Math.max(0, reach(last)[1] - (hi - last.position))
149
+ ];
150
+ }
129
151
  /** The ticks whose labels the layout hides no longer count as visible. */ function hideTruncatedTicks(axis, textData, ticks) {
130
152
  const hidden = new Set(textData.filter((t)=>t.truncated).map((t)=>t.d));
131
153
  if (hidden.size) axis._visibleTicks = ticks.filter((t)=>!hidden.has(t));
@@ -139,26 +161,63 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
139
161
  }
140
162
  /**
141
163
  Left to decide, a horizontal axis of categories rotates its labels when
142
- that leaves fewer of them cut short or hidden. Dates and numbers thin
143
- instead, and rotate only when even their first label alone can't lie
144
- flat on one line. Sets `axis._labelRotation` and returns the labels laid
145
- out as they end up.
164
+ that leaves fewer of them cut short or hidden: slanted 30 degrees (see
165
+ `autoAngle`), or upright when that leaves fewer still. Dates and numbers
166
+ thin instead, and rotate only when even their first label alone can't
167
+ lie flat on one line. A vertical axis's labels already lie across it,
168
+ so it never rotates them on its own. Sets `axis._labelRotation`,
169
+ `_labelAngle` and `_labelSlant` and returns the labels laid out as they
170
+ end up.
146
171
  */ function autoRotateLabels(axis, textData, ctx) {
147
- const { labels, tickFormat, ownSpace, relayout } = ctx;
148
- const rotate = rotatesLabels(axis, labels, tickFormat) ? (data)=>labelMisses(data) : wholeLineLabels(axis, labels) ? (data)=>data.length && !data[0].fits ? 1 : 0 : undefined;
172
+ const { labels, tickFormat, ownSpace, rangeOuter, relayout } = ctx;
173
+ const whole = wholeLineLabels(axis, labels);
174
+ const rotate = rotatesLabels(axis, labels, tickFormat) ? (data)=>labelMisses(data) : whole ? (data)=>data.length && !data[0].fits ? 1 : 0 : undefined;
149
175
  const misses = rotate ? rotate(textData) : 0;
150
176
  // Labels in their own shares rotate only as a last resort: a label that
151
177
  // can't fit is hidden, and the rest stay flat (each with its share line,
152
178
  // which a rotated label leaves out) unless half or more are hidden.
153
- if (rotate && misses && (!ownSpace || misses * 2 >= textData.length)) {
154
- axis._labelRotation = true;
155
- textData = relayout();
156
- if (rotate(textData) >= misses) {
157
- axis._labelRotation = false;
158
- textData = relayout();
179
+ if (!rotate || !misses || ownSpace && misses * 2 < textData.length) return textData;
180
+ // Slanted 30 degrees first; standing upright packs more labels side by
181
+ // side, so they stand when that leaves fewer cut short or hidden. Flat
182
+ // labels stay when neither helps.
183
+ let best = {
184
+ turn: FLAT,
185
+ misses,
186
+ data: textData
187
+ };
188
+ let last = FLAT;
189
+ for (const turn of [
190
+ {
191
+ rotate: true,
192
+ angle: autoAngle(axis.schema.orient),
193
+ slant: true
194
+ },
195
+ {
196
+ rotate: true,
197
+ angle: -90,
198
+ slant: false
159
199
  }
200
+ ]){
201
+ turnLabels(axis, last = turn);
202
+ const data = relayout();
203
+ // Rotated dates must keep their first label, which carries the year,
204
+ // and slanted labels must fit within the axis.
205
+ const tried = rotate(data) + (whole && data[0]?.truncated ? 1 : 0) + (turn.slant && slantedOverflow(axis, data, rangeOuter).some((o)=>o > 1) ? 1 : 0);
206
+ if (tried < best.misses) best = {
207
+ turn,
208
+ misses: tried,
209
+ data
210
+ };
211
+ if (!tried) break;
160
212
  }
161
- return textData;
213
+ if (best.turn === last) return best.data;
214
+ turnLabels(axis, best.turn);
215
+ return relayout();
216
+ }
217
+ /** Sets how the axis draws its labels for the next layout pass. */ function turnLabels(axis, turn) {
218
+ axis._labelRotation = turn.rotate;
219
+ axis._labelAngle = turn.angle;
220
+ axis._labelSlant = turn.slant;
162
221
  }
163
222
  /**
164
223
  Measures every label against the axis and narrows the range by however
@@ -204,14 +263,20 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
204
263
  if (!datum) return 0;
205
264
  const { height: dHeight, position, rotate, width: dWidth } = datum;
206
265
  const compPosition = index ? rangeOuter[1] : rangeOuter[0];
207
- const halfSpace = (rotate || !horizontal ? dHeight : dWidth) / 2;
266
+ // A slanted label reaches further to one side of its tick than the other.
267
+ const reach = datum.slant ? slantedReach(axis.schema.orient, datum.angle, dWidth, dHeight - datum.fP)[index] : (rotate || !horizontal ? dHeight : dWidth) / 2;
208
268
  // Room between the label's tick and the end of the range it faces.
209
269
  const room = index ? compPosition - position : position - compPosition;
210
- return room >= halfSpace ? 0 : halfSpace - room;
270
+ return room >= reach ? 0 : reach - room;
211
271
  });
272
+ // Slanted labels can reach far past an end: keep at least half the axis
273
+ // for the scale, however far they reach.
274
+ const room = last - first - (rangeOuter[1] - rangeOuter[0]) / 2;
275
+ const reach = spillovers[0] + spillovers[1];
276
+ const share = reach > room && shown.some((t)=>t.slant) ? Math.max(0, room) / reach : 1;
212
277
  const newRange = [
213
- first + spillovers[0],
214
- last - spillovers[1]
278
+ first + spillovers[0] * share,
279
+ last - spillovers[1] * share
215
280
  ];
216
281
  if (axis.schema.range) {
217
282
  if (axis.schema.range[0] !== undefined) newRange[0] = axis.schema.range[0];
@@ -231,7 +296,9 @@ import { axisScaleData, axisTimeLocale, resetAxisDates } from "./timeValues.js";
231
296
  ownSpace,
232
297
  offset: offsetEnabled ? 2 : 1
233
298
  });
234
- if (endLabels(textData) === ends) break;
299
+ // A slanted label's reach is lopsided, so its range narrows again until
300
+ // the label fits; others stop once the same labels end the axis.
301
+ if (endLabels(textData) === ends && !textData.some((t)=>t.slant)) break;
235
302
  }
236
303
  return textData;
237
304
  }
@@ -6,7 +6,20 @@
6
6
  */ import { max, min } from "d3-array";
7
7
  import { fontFamily as d3plusFontFamily, textWrap } from "@d3plus/text";
8
8
  import { wholeWordFit, wholeWordSplit } from "../../utils/wholeWords.js";
9
+ import { slantedDepth, slantedWrapSize } from "./axisLabelAngle.js";
10
+ import { slantedLineWidth, slantedLines } from "./axisSlantWrap.js";
9
11
  import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axisLabelThinning.js";
12
+ /** How far labels may reach out from the axis, past its ticks and margins. */ function labelRoom(axis, horizontal, hBuff, p) {
13
+ const wSize = min([
14
+ axis.schema.maxSize,
15
+ axis.schema.width
16
+ ]);
17
+ const hSize = min([
18
+ axis.schema.maxSize,
19
+ axis.schema.height
20
+ ]);
21
+ return horizontal ? hSize - hBuff - p - axis._margin.top - axis._margin.bottom : wSize - hBuff - p - axis._margin.left - axis._margin.right;
22
+ }
10
23
  /** Applies the axis title's wrapped height to the orient-side margin. */ export function applyTitleMargin(axis, ctx) {
11
24
  if (!axis.schema.title) return;
12
25
  const { range, p, height, margin } = ctx;
@@ -39,10 +52,16 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
39
52
  reuses that measurement.
40
53
  */ function calculateLabelSize(axis, datum, ctx, cache) {
41
54
  const { horizontal, hBuff, p, tickFormat } = ctx;
42
- const { d, i, fF, fP, fS, rotate, space } = datum;
55
+ const { d, i, fF, fP, fS, rotate, space, angle, slant } = datum;
43
56
  const h = rotate ? "width" : "height", w = rotate ? "height" : "width";
44
57
  const lineHeight = axis.schema.shapeConfig.lineHeight ? axis.schema.shapeConfig.lineHeight(d, i) : undefined;
45
58
  const text = tickFormat(d);
59
+ const wSize = min([
60
+ axis.schema.maxSize,
61
+ axis.schema.width
62
+ ]);
63
+ const depth = labelRoom(axis, horizontal, hBuff, p);
64
+ const slanted = slant ? slantedWrapSize(angle, horizontal, depth, space, lineHeight ?? Math.ceil(fS * 1.4)) : undefined;
46
65
  const key = cache && JSON.stringify([
47
66
  text,
48
67
  fF,
@@ -50,6 +69,8 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
50
69
  fS,
51
70
  lineHeight,
52
71
  rotate,
72
+ slant && angle,
73
+ slant && ctx.slantWidth,
53
74
  space
54
75
  ]);
55
76
  const cached = key ? cache.get(key) : undefined;
@@ -58,17 +79,14 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
58
79
  lines: cached.lines.slice(),
59
80
  widths: cached.widths.slice()
60
81
  };
61
- const wSize = min([
62
- axis.schema.maxSize,
63
- axis.schema.width
64
- ]);
65
- const hSize = min([
66
- axis.schema.maxSize,
67
- axis.schema.height
68
- ]);
69
82
  const wrap = textWrap().fontFamily(fF).fontSize(fS).lineHeight(lineHeight);
70
- wrap[w](horizontal ? space : wSize - hBuff - p - axis._margin.left - axis._margin.right);
71
- wrap[h](horizontal ? hSize - hBuff - p - axis._margin.top - axis._margin.bottom : space);
83
+ if (slanted) {
84
+ // Slanted labels wrap between words, never mid-word.
85
+ wrap.split(wholeWordSplit).width(Math.min(slanted.width, ctx.slantWidth ?? Infinity)).height(slanted.height);
86
+ } else {
87
+ wrap[w](horizontal ? space : depth);
88
+ wrap[h](horizontal ? depth : space);
89
+ }
72
90
  let res, fits;
73
91
  if (ctx.wholeLine) {
74
92
  // Measured across the whole axis (`maxSize` caps its depth, not its
@@ -123,6 +141,8 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
123
141
  const { fontSize } = axis.schema.shapeConfig.labelConfig;
124
142
  const fontFamilyConfig = axis.schema.shapeConfig.labelConfig.fontFamily || d3plusFontFamily;
125
143
  const fontPadding = axis.schema.shapeConfig.labelConfig.padding;
144
+ const angle = axis._labelRotation ? axis._labelAngle : 0;
145
+ const slant = !!axis._labelRotation && axis._labelSlant;
126
146
  return labels.map((d, i)=>{
127
147
  const fF = typeof fontFamilyConfig === "function" ? fontFamilyConfig(d, i) : fontFamilyConfig, fP = typeof fontPadding === "function" ? fontPadding(d, i) : fontPadding, fS = typeof fontSize === "function" ? fontSize(d, i) : fontSize, position = axis._getPosition(d);
128
148
  const lineHeight = axis.schema.shapeConfig.lineHeight ? axis.schema.shapeConfig.lineHeight(d, i) : fS * 1.4;
@@ -135,7 +155,9 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
135
155
  fS,
136
156
  lineHeight,
137
157
  position,
138
- rotate: axis._labelRotation
158
+ rotate: axis._labelRotation,
159
+ angle,
160
+ slant
139
161
  };
140
162
  });
141
163
  }
@@ -176,6 +198,10 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
176
198
  };
177
199
  let textData = baseTextData(axis, labels);
178
200
  const maxSpace = maxLabelSpace(axis, textData, rangeOuter);
201
+ labelCtx.slantWidth = slantedWidth(axis, textData, {
202
+ ...labelCtx,
203
+ space: maxSpace
204
+ });
179
205
  const spaces = ownSpace ? ownLabelSpaces(textData.map((d)=>d.position), rangeOuter) : undefined;
180
206
  // Thinning measures the labels again as they read the ones shown (see
181
207
  // `show`), mostly to the same text, so each text is measured once.
@@ -212,6 +238,24 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
212
238
  if (offset > 1) calculateOffset(textData, horizontal);
213
239
  return textData;
214
240
  }
241
+ /**
242
+ The width slanted labels wrap at: narrow enough to put a long label on
243
+ as many lines (up to three) as fit between neighbouring labels `space`
244
+ apart, so it reaches less far from the axis. Undefined when the labels
245
+ don't slant.
246
+ */ function slantedWidth(axis, textData, ctx) {
247
+ const first = textData[0];
248
+ if (!first?.slant) return undefined;
249
+ const { horizontal, hBuff, p, tickFormat, space } = ctx;
250
+ const lineHeight = (d)=>axis.schema.shapeConfig.lineHeight ? axis.schema.shapeConfig.lineHeight(d.d, d.i) : Math.ceil(d.fS * 1.4);
251
+ const limit = slantedWrapSize(first.angle, horizontal, labelRoom(axis, horizontal, hBuff, p), space - first.fP * 2, lineHeight(first));
252
+ return slantedLineWidth(textData.map((d)=>({
253
+ text: tickFormat(d.d),
254
+ fontFamily: d.fF,
255
+ fontSize: d.fS,
256
+ lineHeight: lineHeight(d)
257
+ })), slantedLines(limit.height, lineHeight(first)), limit.width);
258
+ }
215
259
  /**
216
260
  Each label's own share of an axis whose labels sit unevenly, such as one
217
261
  label per variable-width bar (see `Plot/barWidth.ts`): reaching halfway to
@@ -245,11 +289,20 @@ import { fitOwnSpaces, thinEvenly, thinGreedily, thinGreedilyShown } from "./axi
245
289
  "point"
246
290
  ].includes(scale);
247
291
  }
292
+ /**
293
+ How far a measured label reaches out from the axis: its height when it
294
+ lies flat along a horizontal axis, its width when it stands out from the
295
+ axis, and for a slanted label, both projected across the axis (with its
296
+ padding on a horizontal axis, as its height holds).
297
+ */ export function labelDepth(t, horizontal) {
298
+ if (t.slant) return slantedDepth(t.angle, horizontal, t.width, t.height - t.fP) + (horizontal ? t.fP : 0);
299
+ return t[t.rotate || !horizontal ? "width" : "height"];
300
+ }
248
301
  /** Derives `_outerBounds` + axis margins from the measured text data. */ export function computeAxisBounds(axis, ctx) {
249
302
  const { textData, rangeOuter, hBuff, horizontal, p, width, height, x, y, opposite, margin } = ctx;
250
303
  const tBuff = axis.schema.shape === "Line" ? 0 : hBuff;
251
304
  const bounds = axis._outerBounds = {
252
- [height]: (max(textData, (t)=>Math.ceil(t[t.rotate || !horizontal ? "width" : "height"] + (t.offset ?? 0))) || 0) + (textData.length ? p : 0),
305
+ [height]: (max(textData, (t)=>Math.ceil(labelDepth(t, horizontal) + (t.offset ?? 0))) || 0) + (textData.length ? p : 0),
253
306
  [width]: rangeOuter[rangeOuter.length - 1] - rangeOuter[0],
254
307
  [x]: rangeOuter[0]
255
308
  };