@d3plus/core 3.0.4 → 3.0.6

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.
@@ -89,8 +89,4 @@ var BoxWhisker = /*#__PURE__*/ function(Plot) {
89
89
  @class BoxWhisker
90
90
  @extends Plot
91
91
  @desc Creates a simple box and whisker based on an array of data.
92
- @example <caption>the equivalent of calling:</caption>
93
- new d3plus.Plot()
94
- .discrete("x")
95
- .shape("Box")
96
92
  */ export { BoxWhisker as default };
@@ -478,9 +478,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
478
478
  _this._x2Key = "x2";
479
479
  _this._x2Axis = new AxisTop().align("start");
480
480
  _this._x2Test = new AxisTop().align("start").gridSize(0);
481
- _this._x2Config = {
482
- padding: 0
483
- };
481
+ _this._x2Config = {};
484
482
  _this._y = accessor("y");
485
483
  _this._yKey = "y";
486
484
  _this._yAxis = new AxisLeft().align("start");
@@ -110,10 +110,12 @@ function _is_native_reflect_construct() {
110
110
  import { extent, min, max } from "d3-array";
111
111
  import { hierarchy, tree } from "d3-hierarchy";
112
112
  import { scaleLinear } from "d3-scale";
113
+ import { colorDefaults } from "@d3plus/color";
113
114
  import { assign, elem } from "@d3plus/dom";
114
115
  import { merge, nest } from "@d3plus/data";
115
116
  import { configPrep, constant } from "../utils/index.js";
116
- import { Circle, Path } from "../shapes/index.js";
117
+ import * as shapes from "../shapes/index.js";
118
+ import { legendLabel } from "./drawSteps/drawLegend.js";
117
119
  import Viz from "./Viz.js";
118
120
  var Tree = /*#__PURE__*/ function(Viz) {
119
121
  "use strict";
@@ -126,22 +128,31 @@ var Tree = /*#__PURE__*/ function(Viz) {
126
128
  _this._separation = function(a, b) {
127
129
  return a.parent === b.parent ? 1 : 2;
128
130
  };
131
+ _this._legendTooltip = assign(_this._legendTooltip, {
132
+ title: legendLabel.bind(_this)
133
+ });
134
+ _this._previousShapes = [];
129
135
  _this._shape = constant("Circle");
130
136
  _this._shapeConfig = assign(_this._shapeConfig, {
131
137
  ariaLabel: function(d, i) {
132
138
  return _this._treeData ? "".concat(_this._treeData[i].depth, ". ").concat(_this._drawLabel(d, i), ".") : "";
133
139
  },
134
140
  labelConfig: {
135
- fontColor: "#444"
141
+ fontColor: colorDefaults.dark
136
142
  },
137
143
  Path: {
138
144
  fill: "none",
139
- stroke: "#ccc",
140
- strokeWidth: 1
145
+ stroke: colorDefaults.missing,
146
+ strokeWidth: 2
141
147
  },
142
- r: constant(5),
143
- width: constant(10),
144
- height: constant(10)
148
+ r: constant(7),
149
+ width: constant(12),
150
+ height: constant(12)
151
+ });
152
+ _this._tooltipConfig = assign(_this._tooltipConfig, {
153
+ title: function(d, i, x) {
154
+ return _this._drawLabel(d, i, x.depth - 1);
155
+ }
145
156
  });
146
157
  _this._tree = tree();
147
158
  return _this;
@@ -155,7 +166,9 @@ var Tree = /*#__PURE__*/ function(Viz) {
155
166
  value: function _draw(callback) {
156
167
  var _this = this;
157
168
  _get(_get_prototype_of(Tree.prototype), "_draw", this).call(this, callback);
158
- var height = this._orient === "vertical" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = this._orient === "vertical" ? "left" : "top", that = this, transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")"), width = this._orient === "horizontal" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
169
+ var isVertical = this._orient === "vertical";
170
+ var isHorizontal = this._orient === "horizontal";
171
+ var height = isVertical ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = isVertical ? "left" : "top", that = this, transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")"), width = isHorizontal ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
159
172
  var treeData = this._treeData = this._tree.separation(this._separation).size([
160
173
  width,
161
174
  height
@@ -192,7 +205,7 @@ var Tree = /*#__PURE__*/ function(Viz) {
192
205
  return d.y;
193
206
  });
194
207
  this._labelHeight = min([
195
- this._orient === "vertical" ? 50 : 100,
208
+ isVertical ? 50 : 100,
196
209
  (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)
197
210
  ]);
198
211
  this._labelWidths = nest(treeData, function(d) {
@@ -213,7 +226,7 @@ var Tree = /*#__PURE__*/ function(Viz) {
213
226
  ]);
214
227
  treeData.forEach(function(d) {
215
228
  var val = yScale(d.y);
216
- if (_this._orient === "horizontal") {
229
+ if (isHorizontal) {
217
230
  d.y = d.x;
218
231
  d.x = val;
219
232
  } else d.y = val;
@@ -227,22 +240,24 @@ var Tree = /*#__PURE__*/ function(Viz) {
227
240
  transform: transform
228
241
  }
229
242
  };
230
- this._shapes.push(new Path().data(treeData.filter(function(d) {
243
+ this._shapes.push(new shapes.Path().data(treeData.filter(function(d) {
231
244
  return d.depth > 1;
245
+ }).map(function(d) {
246
+ return assign({}, d);
232
247
  })).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
233
248
  d: function(d) {
234
249
  var r = _this._shapeConfig.r;
235
250
  if (typeof r === "function") r = r(d.data, d.i);
236
- var px = d.parent.x - d.x + (_this._orient === "vertical" ? 0 : r), py = d.parent.y - d.y + (_this._orient === "vertical" ? r : 0), x = _this._orient === "vertical" ? 0 : -r, y = _this._orient === "vertical" ? -r : 0;
237
- return _this._orient === "vertical" ? "M".concat(x, ",").concat(y, "C").concat(x, ",").concat((y + py) / 2, " ").concat(px, ",").concat((y + py) / 2, " ").concat(px, ",").concat(py) : "M".concat(x, ",").concat(y, "C").concat((x + px) / 2, ",").concat(y, " ").concat((x + px) / 2, ",").concat(py, " ").concat(px, ",").concat(py);
251
+ var px = d.parent.x - d.x + (isVertical ? 0 : r), py = d.parent.y - d.y + (isVertical ? r : 0), x = isVertical ? 0 : -r, y = isVertical ? -r : 0;
252
+ return isVertical ? "M".concat(x, ",").concat(y, "C").concat(x, ",").concat((y + py) / 2, " ").concat(px, ",").concat((y + py) / 2, " ").concat(px, ",").concat(py) : "M".concat(x, ",").concat(y, "C").concat((x + px) / 2, ",").concat(y, " ").concat((x + px) / 2, ",").concat(py, " ").concat(px, ",").concat(py);
238
253
  },
239
254
  id: function(d, i) {
240
- return _this._ids(d, i).join("-");
255
+ return _this._ids(d, i)[d.depth - 1];
241
256
  }
242
257
  }).render());
243
- this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
258
+ var shapeConfig = {
244
259
  id: function(d, i) {
245
- return _this._ids(d, i).join("-");
260
+ return _this._ids(d, i)[d.depth - 1];
246
261
  },
247
262
  label: function(d, i) {
248
263
  if (_this._label) return _this._label(d.data, i);
@@ -250,36 +265,55 @@ var Tree = /*#__PURE__*/ function(Viz) {
250
265
  return ids[ids.length - 1];
251
266
  },
252
267
  labelConfig: {
253
- textAnchor: function(d) {
254
- return _this._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== _this._groupBy.length ? "end" : "start";
268
+ textAnchor: function(d, i, x) {
269
+ return isVertical ? "middle" : x.children && x.depth !== _this._drawDepth + 1 ? "end" : "start";
255
270
  },
256
- verticalAlign: function(d) {
257
- return _this._orient === "vertical" ? d.data.depth === 1 ? "bottom" : "top" : "middle";
271
+ verticalAlign: function(d, i, x) {
272
+ return isVertical ? x.depth === 1 ? "bottom" : "top" : "middle";
258
273
  }
259
274
  },
260
275
  hitArea: function(d, i, s) {
261
- var h = _this._labelHeight, w = _this._labelWidths[d.depth - 1];
276
+ var h = _this._labelHeight, offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = _this._labelWidths[d.depth - 1];
262
277
  return {
263
- width: _this._orient === "vertical" ? w : s.r * 2 + w,
264
- height: _this._orient === "horizontal" ? h : s.r * 2 + h,
265
- x: _this._orient === "vertical" ? -w / 2 : d.children && d.depth !== _this._groupBy.length ? -(s.r + w) : -s.r,
266
- y: _this._orient === "horizontal" ? -h / 2 : d.children && d.depth !== _this._groupBy.length ? -(s.r + _this._labelHeight) : -s.r
278
+ width: isVertical ? w : offset * 2 + w,
279
+ height: isHorizontal ? h : offset * 2 + h,
280
+ x: isVertical ? -w / 2 : d.children && d.depth !== _this._groupBy.length ? -(offset + w) : -offset,
281
+ y: isHorizontal ? -h / 2 : d.children && d.depth !== _this._groupBy.length ? -(offset + _this._labelHeight) : -offset
267
282
  };
268
283
  },
269
284
  labelBounds: function(d, i, s) {
270
- var h = _this._labelHeight, height = _this._orient === "vertical" ? "height" : "width", w = _this._labelWidths[d.depth - 1], width = _this._orient === "vertical" ? "width" : "height", x = _this._orient === "vertical" ? "x" : "y", y = _this._orient === "vertical" ? "y" : "x";
285
+ var h = _this._labelHeight, height = isVertical ? "height" : "width", offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = _this._labelWidths[d.depth - 1], width = isVertical ? "width" : "height", x = isVertical ? "x" : "y", y = isVertical ? "y" : "x";
271
286
  var _obj;
272
- return _obj = {}, _define_property(_obj, width, w), _define_property(_obj, height, h), _define_property(_obj, x, -w / 2), _define_property(_obj, y, d.children && d.depth !== _this._groupBy.length ? -(s.r + h) : s.r), _obj;
287
+ return _obj = {}, _define_property(_obj, width, w), _define_property(_obj, height, h), _define_property(_obj, x, -w / 2), _define_property(_obj, y, d.children && d.depth !== _this._groupBy.length ? -(offset + h) : offset), _obj;
273
288
  }
274
- }).render());
289
+ };
290
+ var shapeData = nest(treeData, function(d) {
291
+ return _this._shape(d.data);
292
+ });
293
+ var dataShapes = shapeData.map(function(d) {
294
+ return d.key;
295
+ });
296
+ var exitShapes = this._previousShapes.filter(function(d) {
297
+ return !dataShapes.includes(d);
298
+ });
299
+ shapeData.concat(exitShapes.map(function(key) {
300
+ return {
301
+ key: key,
302
+ values: []
303
+ };
304
+ })).forEach(function(param) {
305
+ var key = param.key, values = param.values;
306
+ _this._shapes.push(new shapes[key]().data(values).select(elem("g.d3plus-Tree-".concat(key), elemObject).node()).config(configPrep.bind(_this)(_this._shapeConfig, "shape", key)).config(shapeConfig).render());
307
+ });
308
+ this._previousShapes = dataShapes;
275
309
  return this;
276
310
  }
277
311
  },
278
312
  {
279
313
  /**
280
314
  @memberof Tree
281
- @desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
282
- @param {String} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
315
+ @desc Changes the orientation of the entire Tree, either "vertical" (top to bottom) or "horizontal" (left to right).
316
+ @param {'vertical'|'horizontal'} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
283
317
  */ key: "orient",
284
318
  value: function orient(_) {
285
319
  return arguments.length ? (this._orient = _, this) : this._orient;
@@ -1261,13 +1261,9 @@ If *data* is not specified, this method returns the current primary data array,
1261
1261
  {
1262
1262
  /**
1263
1263
  @memberof Viz
1264
- @desc If *value* is specified, sets the group accessor(s) to the specified string, function, or array of values and returns the current class instance.
1264
+ @desc Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.
1265
1265
  @param {String|Function|Array} [*value*]
1266
1266
  @chainable
1267
- @example
1268
- function value(d) {
1269
- return d.id;
1270
- }
1271
1267
  */ key: "groupBy",
1272
1268
  value: function groupBy(_) {
1273
1269
  var _this = this;
@@ -1281,7 +1277,7 @@ function value(d) {
1281
1277
  else {
1282
1278
  if (!_this._aggs[k]) {
1283
1279
  _this._aggs[k] = function(a, c) {
1284
- var v = unique(a.map(c).map(String));
1280
+ var v = unique(a.map(c));
1285
1281
  return v.length === 1 ? v[0] : v;
1286
1282
  };
1287
1283
  }
@@ -1551,8 +1547,8 @@ function value(d) {
1551
1547
  {
1552
1548
  /**
1553
1549
  @memberof Viz
1554
- @desc If *value* is specified, sets the shape accessor to the specified function or number and returns the current class instance.
1555
- @param {Function|String} [*value*]
1550
+ @desc Changes the primary shape used to represent each data point in a visualization. Not all visualizations support changing shapes, this method can be provided the String name of a D3plus shape class (for example, "Rect" or "Circle"), or an accessor Function that returns the String class name to be used for each individual data point.
1551
+ @param {String|Function} [*value*]
1556
1552
  @chainable
1557
1553
  */ key: "shape",
1558
1554
  value: function shape(_) {
@@ -103,7 +103,9 @@ var legendAttrs = [
103
103
  duration: this._duration,
104
104
  update: transform
105
105
  }).node();
106
- this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
106
+ this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).shape(function(d, i) {
107
+ return _this1._shape(d, i) === "Circle" ? "Circle" : "Rect";
108
+ }).verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
107
109
  fill: function(d, i) {
108
110
  return hidden(d, i) ? _this1._hiddenColor(d, i) : getAttr(d, i, "fill");
109
111
  },
@@ -154,7 +154,7 @@ import { assign, attrize, date, elem, rtl as detectRTL } from "@d3plus/dom";
154
154
  import { formatAbbreviate, formatDate } from "@d3plus/format";
155
155
  import { formatLocale, locale } from "@d3plus/locales";
156
156
  import { closest } from "@d3plus/math";
157
- import { textWrap } from "@d3plus/text";
157
+ import { fontFamily as d3plusFontFamily, textWrap } from "@d3plus/text";
158
158
  import { TextBox } from "../components/index.js";
159
159
  import * as shapes from "../shapes/index.js";
160
160
  import { configPrep, BaseClass, constant } from "../utils/index.js";
@@ -894,7 +894,8 @@ var Axis = /*#__PURE__*/ function(BaseClass) {
894
894
  function createTextData() {
895
895
  var _this = this;
896
896
  var offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1;
897
- var _this__shapeConfig_labelConfig = this._shapeConfig.labelConfig, fontFamily = _this__shapeConfig_labelConfig.fontFamily, fontSize = _this__shapeConfig_labelConfig.fontSize;
897
+ var fontSize = this._shapeConfig.labelConfig.fontSize;
898
+ var fontFamily = this._shapeConfig.labelConfig.fontFamily || d3plusFontFamily;
898
899
  var fontPadding = this._shapeConfig.labelConfig.padding;
899
900
  /**
900
901
  * Calculates the space each label would take up, given
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3plus/core",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,13 +34,13 @@
34
34
  "test": "eslint index.js src/**/*.js && eslint --global=it test && mocha 'test/**/*-test.js'"
35
35
  },
36
36
  "dependencies": {
37
- "@d3plus/color": "3.0.4",
38
- "@d3plus/data": "3.0.4",
39
- "@d3plus/dom": "3.0.4",
40
- "@d3plus/format": "3.0.4",
41
- "@d3plus/locales": "3.0.4",
42
- "@d3plus/math": "3.0.4",
43
- "@d3plus/text": "3.0.4",
37
+ "@d3plus/color": "3.0.6",
38
+ "@d3plus/data": "3.0.6",
39
+ "@d3plus/dom": "3.0.6",
40
+ "@d3plus/format": "3.0.6",
41
+ "@d3plus/locales": "3.0.6",
42
+ "@d3plus/math": "3.0.6",
43
+ "@d3plus/text": "3.0.6",
44
44
  "@popperjs/core": "^2.11.8",
45
45
  "d3-array": "^3.2.4",
46
46
  "d3-brush": "^3.0.0",
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v3.0.4
2
+ @d3plus/core v3.0.6
3
3
  Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
4
4
  Copyright (c) 2025 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -27030,13 +27030,14 @@
27030
27030
  }
27031
27031
  let textData = [];
27032
27032
  function createTextData(offset = 1) {
27033
- const { fontFamily, fontSize } = this._shapeConfig.labelConfig;
27033
+ const { fontSize } = this._shapeConfig.labelConfig;
27034
+ const fontFamily$1 = this._shapeConfig.labelConfig.fontFamily || fontFamily;
27034
27035
  const fontPadding = this._shapeConfig.labelConfig.padding;
27035
27036
  /**
27036
27037
  * Calculates the space each label would take up, given
27037
27038
  * the provided this._space size.
27038
27039
  */ textData = labels.map((d, i)=>{
27039
- const fF = typeof fontFamily === "function" ? fontFamily(d, i) : fontFamily, fP = typeof fontPadding === "function" ? fontPadding(d, i) : fontPadding, fS = typeof fontSize === "function" ? fontSize(d, i) : fontSize, position = this._getPosition(d);
27040
+ const fF = typeof fontFamily$1 === "function" ? fontFamily$1(d, i) : fontFamily$1, fP = typeof fontPadding === "function" ? fontPadding(d, i) : fontPadding, fS = typeof fontSize === "function" ? fontSize(d, i) : fontSize, position = this._getPosition(d);
27040
27041
  const lineHeight = this._shapeConfig.lineHeight ? this._shapeConfig.lineHeight(d, i) : fS * 1.4;
27041
27042
  const datum = {
27042
27043
  d,
@@ -33542,7 +33543,7 @@
33542
33543
  duration: this._duration,
33543
33544
  update: transform
33544
33545
  }).node();
33545
- this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
33546
+ this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).shape((d, i)=>this._shape(d, i) === "Circle" ? "Circle" : "Rect").verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
33546
33547
  fill: (d, i)=>hidden(d, i) ? this._hiddenColor(d, i) : getAttr(d, i, "fill"),
33547
33548
  labelConfig: {
33548
33549
  fontOpacity: (d, i)=>hidden(d, i) ? this._hiddenOpacity(d, i) : 1
@@ -34801,13 +34802,9 @@
34801
34802
  }
34802
34803
  /**
34803
34804
  @memberof Viz
34804
- @desc If *value* is specified, sets the group accessor(s) to the specified string, function, or array of values and returns the current class instance.
34805
+ @desc Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.
34805
34806
  @param {String|Function|Array} [*value*]
34806
34807
  @chainable
34807
- @example
34808
- function value(d) {
34809
- return d.id;
34810
- }
34811
34808
  */ groupBy(_) {
34812
34809
  if (!arguments.length) return this._groupBy;
34813
34810
  this._groupByRaw = _;
@@ -34819,7 +34816,7 @@
34819
34816
  else {
34820
34817
  if (!this._aggs[k]) {
34821
34818
  this._aggs[k] = (a, c)=>{
34822
- const v = unique(a.map(c).map(String));
34819
+ const v = unique(a.map(c));
34823
34820
  return v.length === 1 ? v[0] : v;
34824
34821
  };
34825
34822
  }
@@ -35015,8 +35012,8 @@
35015
35012
  }
35016
35013
  /**
35017
35014
  @memberof Viz
35018
- @desc If *value* is specified, sets the shape accessor to the specified function or number and returns the current class instance.
35019
- @param {Function|String} [*value*]
35015
+ @desc Changes the primary shape used to represent each data point in a visualization. Not all visualizations support changing shapes, this method can be provided the String name of a D3plus shape class (for example, "Rect" or "Circle"), or an accessor Function that returns the String class name to be used for each individual data point.
35016
+ @param {String|Function} [*value*]
35020
35017
  @chainable
35021
35018
  */ shape(_) {
35022
35019
  return arguments.length ? (this._shape = typeof _ === "function" ? _ : constant$9(_), this) : this._shape;
@@ -37526,9 +37523,7 @@
37526
37523
  this._x2Key = "x2";
37527
37524
  this._x2Axis = new AxisTop().align("start");
37528
37525
  this._x2Test = new AxisTop().align("start").gridSize(0);
37529
- this._x2Config = {
37530
- padding: 0
37531
- };
37526
+ this._x2Config = {};
37532
37527
  this._y = accessor("y");
37533
37528
  this._yKey = "y";
37534
37529
  this._yAxis = new AxisLeft().align("start");
@@ -56742,7 +56737,9 @@
56742
56737
  @private
56743
56738
  */ _draw(callback) {
56744
56739
  super._draw(callback);
56745
- const height = this._orient === "vertical" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = this._orient === "vertical" ? "left" : "top", that = this, transform = `translate(${this._margin.left}, ${this._margin.top})`, width = this._orient === "horizontal" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
56740
+ const isVertical = this._orient === "vertical";
56741
+ const isHorizontal = this._orient === "horizontal";
56742
+ const height = isVertical ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = isVertical ? "left" : "top", that = this, transform = `translate(${this._margin.left}, ${this._margin.top})`, width = isHorizontal ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
56746
56743
  const treeData = this._treeData = this._tree.separation(this._separation).size([
56747
56744
  width,
56748
56745
  height
@@ -56767,7 +56764,7 @@
56767
56764
  const rBufferEnd = max$5(treeData, (d)=>d.children ? 0 : r(d.data, d.i));
56768
56765
  const yExtent = extent$1(treeData, (d)=>d.y);
56769
56766
  this._labelHeight = min$5([
56770
- this._orient === "vertical" ? 50 : 100,
56767
+ isVertical ? 50 : 100,
56771
56768
  (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)
56772
56769
  ]);
56773
56770
  this._labelWidths = nest(treeData, (d)=>d.depth).map((d)=>d.values.reduce((num, v, i)=>{
@@ -56784,7 +56781,7 @@
56784
56781
  ]);
56785
56782
  treeData.forEach((d)=>{
56786
56783
  const val = yScale(d.y);
56787
- if (this._orient === "horizontal") {
56784
+ if (isHorizontal) {
56788
56785
  d.y = d.x;
56789
56786
  d.x = val;
56790
56787
  } else d.y = val;
@@ -56798,51 +56795,61 @@
56798
56795
  transform
56799
56796
  }
56800
56797
  };
56801
- this._shapes.push(new Path$2().data(treeData.filter((d)=>d.depth > 1)).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
56798
+ this._shapes.push(new Path$2().data(treeData.filter((d)=>d.depth > 1).map((d)=>assign({}, d))).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
56802
56799
  d: (d)=>{
56803
56800
  let r = this._shapeConfig.r;
56804
56801
  if (typeof r === "function") r = r(d.data, d.i);
56805
- const px = d.parent.x - d.x + (this._orient === "vertical" ? 0 : r), py = d.parent.y - d.y + (this._orient === "vertical" ? r : 0), x = this._orient === "vertical" ? 0 : -r, y = this._orient === "vertical" ? -r : 0;
56806
- return this._orient === "vertical" ? `M${x},${y}C${x},${(y + py) / 2} ${px},${(y + py) / 2} ${px},${py}` : `M${x},${y}C${(x + px) / 2},${y} ${(x + px) / 2},${py} ${px},${py}`;
56802
+ const px = d.parent.x - d.x + (isVertical ? 0 : r), py = d.parent.y - d.y + (isVertical ? r : 0), x = isVertical ? 0 : -r, y = isVertical ? -r : 0;
56803
+ return isVertical ? `M${x},${y}C${x},${(y + py) / 2} ${px},${(y + py) / 2} ${px},${py}` : `M${x},${y}C${(x + px) / 2},${y} ${(x + px) / 2},${py} ${px},${py}`;
56807
56804
  },
56808
- id: (d, i)=>this._ids(d, i).join("-")
56805
+ id: (d, i)=>this._ids(d, i)[d.depth - 1]
56809
56806
  }).render());
56810
- this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
56811
- id: (d, i)=>this._ids(d, i).join("-"),
56807
+ const shapeConfig = {
56808
+ id: (d, i)=>this._ids(d, i)[d.depth - 1],
56812
56809
  label: (d, i)=>{
56813
56810
  if (this._label) return this._label(d.data, i);
56814
56811
  const ids = this._ids(d, i).slice(0, d.depth);
56815
56812
  return ids[ids.length - 1];
56816
56813
  },
56817
56814
  labelConfig: {
56818
- textAnchor: (d)=>this._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== this._groupBy.length ? "end" : "start",
56819
- verticalAlign: (d)=>this._orient === "vertical" ? d.data.depth === 1 ? "bottom" : "top" : "middle"
56815
+ textAnchor: (d, i, x)=>isVertical ? "middle" : x.children && x.depth !== this._drawDepth + 1 ? "end" : "start",
56816
+ verticalAlign: (d, i, x)=>isVertical ? x.depth === 1 ? "bottom" : "top" : "middle"
56820
56817
  },
56821
56818
  hitArea: (d, i, s)=>{
56822
- const h = this._labelHeight, w = this._labelWidths[d.depth - 1];
56819
+ const h = this._labelHeight, offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = this._labelWidths[d.depth - 1];
56823
56820
  return {
56824
- width: this._orient === "vertical" ? w : s.r * 2 + w,
56825
- height: this._orient === "horizontal" ? h : s.r * 2 + h,
56826
- x: this._orient === "vertical" ? -w / 2 : d.children && d.depth !== this._groupBy.length ? -(s.r + w) : -s.r,
56827
- y: this._orient === "horizontal" ? -h / 2 : d.children && d.depth !== this._groupBy.length ? -(s.r + this._labelHeight) : -s.r
56821
+ width: isVertical ? w : offset * 2 + w,
56822
+ height: isHorizontal ? h : offset * 2 + h,
56823
+ x: isVertical ? -w / 2 : d.children && d.depth !== this._groupBy.length ? -(offset + w) : -offset,
56824
+ y: isHorizontal ? -h / 2 : d.children && d.depth !== this._groupBy.length ? -(offset + this._labelHeight) : -offset
56828
56825
  };
56829
56826
  },
56830
56827
  labelBounds: (d, i, s)=>{
56831
- const h = this._labelHeight, height = this._orient === "vertical" ? "height" : "width", w = this._labelWidths[d.depth - 1], width = this._orient === "vertical" ? "width" : "height", x = this._orient === "vertical" ? "x" : "y", y = this._orient === "vertical" ? "y" : "x";
56828
+ const h = this._labelHeight, height = isVertical ? "height" : "width", offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = this._labelWidths[d.depth - 1], width = isVertical ? "width" : "height", x = isVertical ? "x" : "y", y = isVertical ? "y" : "x";
56832
56829
  return {
56833
56830
  [width]: w,
56834
56831
  [height]: h,
56835
56832
  [x]: -w / 2,
56836
- [y]: d.children && d.depth !== this._groupBy.length ? -(s.r + h) : s.r
56833
+ [y]: d.children && d.depth !== this._groupBy.length ? -(offset + h) : offset
56837
56834
  };
56838
56835
  }
56839
- }).render());
56836
+ };
56837
+ const shapeData = nest(treeData, (d)=>this._shape(d.data));
56838
+ const dataShapes = shapeData.map((d)=>d.key);
56839
+ const exitShapes = this._previousShapes.filter((d)=>!dataShapes.includes(d));
56840
+ shapeData.concat(exitShapes.map((key)=>({
56841
+ key,
56842
+ values: []
56843
+ }))).forEach(({ key, values })=>{
56844
+ this._shapes.push(new shapes[key]().data(values).select(elem(`g.d3plus-Tree-${key}`, elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", key)).config(shapeConfig).render());
56845
+ });
56846
+ this._previousShapes = dataShapes;
56840
56847
  return this;
56841
56848
  }
56842
56849
  /**
56843
56850
  @memberof Tree
56844
- @desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
56845
- @param {String} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
56851
+ @desc Changes the orientation of the entire Tree, either "vertical" (top to bottom) or "horizontal" (left to right).
56852
+ @param {'vertical'|'horizontal'} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
56846
56853
  */ orient(_) {
56847
56854
  return arguments.length ? (this._orient = _, this) : this._orient;
56848
56855
  }
@@ -56868,20 +56875,27 @@
56868
56875
  super();
56869
56876
  this._orient = "vertical";
56870
56877
  this._separation = (a, b)=>a.parent === b.parent ? 1 : 2;
56878
+ this._legendTooltip = assign(this._legendTooltip, {
56879
+ title: legendLabel.bind(this)
56880
+ });
56881
+ this._previousShapes = [];
56871
56882
  this._shape = constant$9("Circle");
56872
56883
  this._shapeConfig = assign(this._shapeConfig, {
56873
56884
  ariaLabel: (d, i)=>this._treeData ? `${this._treeData[i].depth}. ${this._drawLabel(d, i)}.` : "",
56874
56885
  labelConfig: {
56875
- fontColor: "#444"
56886
+ fontColor: defaults.dark
56876
56887
  },
56877
56888
  Path: {
56878
56889
  fill: "none",
56879
- stroke: "#ccc",
56880
- strokeWidth: 1
56890
+ stroke: defaults.missing,
56891
+ strokeWidth: 2
56881
56892
  },
56882
- r: constant$9(5),
56883
- width: constant$9(10),
56884
- height: constant$9(10)
56893
+ r: constant$9(7),
56894
+ width: constant$9(12),
56895
+ height: constant$9(12)
56896
+ });
56897
+ this._tooltipConfig = assign(this._tooltipConfig, {
56898
+ title: (d, i, x)=>this._drawLabel(d, i, x.depth - 1)
56885
56899
  });
56886
56900
  this._tree = tree();
56887
56901
  }