@d3plus/core 3.0.5 → 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.
@@ -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;
@@ -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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3plus/core",
3
- "version": "3.0.5",
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.5",
38
- "@d3plus/data": "3.0.5",
39
- "@d3plus/dom": "3.0.5",
40
- "@d3plus/format": "3.0.5",
41
- "@d3plus/locales": "3.0.5",
42
- "@d3plus/math": "3.0.5",
43
- "@d3plus/text": "3.0.5",
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.5
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
@@ -33543,7 +33543,7 @@
33543
33543
  duration: this._duration,
33544
33544
  update: transform
33545
33545
  }).node();
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).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({
33547
33547
  fill: (d, i)=>hidden(d, i) ? this._hiddenColor(d, i) : getAttr(d, i, "fill"),
33548
33548
  labelConfig: {
33549
33549
  fontOpacity: (d, i)=>hidden(d, i) ? this._hiddenOpacity(d, i) : 1
@@ -34802,13 +34802,9 @@
34802
34802
  }
34803
34803
  /**
34804
34804
  @memberof Viz
34805
- @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.
34806
34806
  @param {String|Function|Array} [*value*]
34807
34807
  @chainable
34808
- @example
34809
- function value(d) {
34810
- return d.id;
34811
- }
34812
34808
  */ groupBy(_) {
34813
34809
  if (!arguments.length) return this._groupBy;
34814
34810
  this._groupByRaw = _;
@@ -35016,8 +35012,8 @@
35016
35012
  }
35017
35013
  /**
35018
35014
  @memberof Viz
35019
- @desc If *value* is specified, sets the shape accessor to the specified function or number and returns the current class instance.
35020
- @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*]
35021
35017
  @chainable
35022
35018
  */ shape(_) {
35023
35019
  return arguments.length ? (this._shape = typeof _ === "function" ? _ : constant$9(_), this) : this._shape;
@@ -56741,7 +56737,9 @@
56741
56737
  @private
56742
56738
  */ _draw(callback) {
56743
56739
  super._draw(callback);
56744
- 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;
56745
56743
  const treeData = this._treeData = this._tree.separation(this._separation).size([
56746
56744
  width,
56747
56745
  height
@@ -56766,7 +56764,7 @@
56766
56764
  const rBufferEnd = max$5(treeData, (d)=>d.children ? 0 : r(d.data, d.i));
56767
56765
  const yExtent = extent$1(treeData, (d)=>d.y);
56768
56766
  this._labelHeight = min$5([
56769
- this._orient === "vertical" ? 50 : 100,
56767
+ isVertical ? 50 : 100,
56770
56768
  (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)
56771
56769
  ]);
56772
56770
  this._labelWidths = nest(treeData, (d)=>d.depth).map((d)=>d.values.reduce((num, v, i)=>{
@@ -56783,7 +56781,7 @@
56783
56781
  ]);
56784
56782
  treeData.forEach((d)=>{
56785
56783
  const val = yScale(d.y);
56786
- if (this._orient === "horizontal") {
56784
+ if (isHorizontal) {
56787
56785
  d.y = d.x;
56788
56786
  d.x = val;
56789
56787
  } else d.y = val;
@@ -56797,51 +56795,61 @@
56797
56795
  transform
56798
56796
  }
56799
56797
  };
56800
- 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({
56801
56799
  d: (d)=>{
56802
56800
  let r = this._shapeConfig.r;
56803
56801
  if (typeof r === "function") r = r(d.data, d.i);
56804
- 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;
56805
- 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}`;
56806
56804
  },
56807
- id: (d, i)=>this._ids(d, i).join("-")
56805
+ id: (d, i)=>this._ids(d, i)[d.depth - 1]
56808
56806
  }).render());
56809
- this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
56810
- id: (d, i)=>this._ids(d, i).join("-"),
56807
+ const shapeConfig = {
56808
+ id: (d, i)=>this._ids(d, i)[d.depth - 1],
56811
56809
  label: (d, i)=>{
56812
56810
  if (this._label) return this._label(d.data, i);
56813
56811
  const ids = this._ids(d, i).slice(0, d.depth);
56814
56812
  return ids[ids.length - 1];
56815
56813
  },
56816
56814
  labelConfig: {
56817
- textAnchor: (d)=>this._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== this._groupBy.length ? "end" : "start",
56818
- 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"
56819
56817
  },
56820
56818
  hitArea: (d, i, s)=>{
56821
- 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];
56822
56820
  return {
56823
- width: this._orient === "vertical" ? w : s.r * 2 + w,
56824
- height: this._orient === "horizontal" ? h : s.r * 2 + h,
56825
- x: this._orient === "vertical" ? -w / 2 : d.children && d.depth !== this._groupBy.length ? -(s.r + w) : -s.r,
56826
- 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
56827
56825
  };
56828
56826
  },
56829
56827
  labelBounds: (d, i, s)=>{
56830
- 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";
56831
56829
  return {
56832
56830
  [width]: w,
56833
56831
  [height]: h,
56834
56832
  [x]: -w / 2,
56835
- [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
56836
56834
  };
56837
56835
  }
56838
- }).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;
56839
56847
  return this;
56840
56848
  }
56841
56849
  /**
56842
56850
  @memberof Tree
56843
- @desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
56844
- @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".
56845
56853
  */ orient(_) {
56846
56854
  return arguments.length ? (this._orient = _, this) : this._orient;
56847
56855
  }
@@ -56867,20 +56875,27 @@
56867
56875
  super();
56868
56876
  this._orient = "vertical";
56869
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 = [];
56870
56882
  this._shape = constant$9("Circle");
56871
56883
  this._shapeConfig = assign(this._shapeConfig, {
56872
56884
  ariaLabel: (d, i)=>this._treeData ? `${this._treeData[i].depth}. ${this._drawLabel(d, i)}.` : "",
56873
56885
  labelConfig: {
56874
- fontColor: "#444"
56886
+ fontColor: defaults.dark
56875
56887
  },
56876
56888
  Path: {
56877
56889
  fill: "none",
56878
- stroke: "#ccc",
56879
- strokeWidth: 1
56890
+ stroke: defaults.missing,
56891
+ strokeWidth: 2
56880
56892
  },
56881
- r: constant$9(5),
56882
- width: constant$9(10),
56883
- 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)
56884
56899
  });
56885
56900
  this._tree = tree();
56886
56901
  }