@d3plus/core 3.0.5 → 3.0.7
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.
- package/README.md +83 -90
- package/es/src/charts/Tree.js +64 -30
- package/es/src/charts/Viz.js +3 -7
- package/es/src/charts/drawSteps/drawLegend.js +3 -1
- package/es/src/components/Timeline.js +6 -6
- package/package.json +8 -8
- package/umd/d3plus-core.full.js +56 -41
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +13 -17
- package/umd/d3plus-core.js +56 -41
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +111 -115
package/es/src/charts/Tree.js
CHANGED
|
@@ -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
|
|
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:
|
|
141
|
+
fontColor: colorDefaults.dark
|
|
136
142
|
},
|
|
137
143
|
Path: {
|
|
138
144
|
fill: "none",
|
|
139
|
-
stroke:
|
|
140
|
-
strokeWidth:
|
|
145
|
+
stroke: colorDefaults.missing,
|
|
146
|
+
strokeWidth: 2
|
|
141
147
|
},
|
|
142
|
-
r: constant(
|
|
143
|
-
width: constant(
|
|
144
|
-
height: constant(
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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 + (
|
|
237
|
-
return
|
|
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).
|
|
255
|
+
return _this._ids(d, i)[d.depth - 1];
|
|
241
256
|
}
|
|
242
257
|
}).render());
|
|
243
|
-
|
|
258
|
+
var shapeConfig = {
|
|
244
259
|
id: function(d, i) {
|
|
245
|
-
return _this._ids(d, i).
|
|
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
|
|
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
|
|
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:
|
|
264
|
-
height:
|
|
265
|
-
x:
|
|
266
|
-
y:
|
|
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 =
|
|
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 ? -(
|
|
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
|
-
}
|
|
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
|
|
282
|
-
@param {
|
|
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;
|
package/es/src/charts/Viz.js
CHANGED
|
@@ -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
|
|
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
|
|
1555
|
-
@param {Function
|
|
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).
|
|
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
|
},
|
|
@@ -112,7 +112,7 @@ import { locale } from "@d3plus/locales";
|
|
|
112
112
|
import { closest } from "@d3plus/math";
|
|
113
113
|
import { textWrap } from "@d3plus/text";
|
|
114
114
|
import { Axis, TextBox } from "../components/index.js";
|
|
115
|
-
import { constant } from "../utils/index.js";
|
|
115
|
+
import { configPrep, constant } from "../utils/index.js";
|
|
116
116
|
var colorMid = "#bbb";
|
|
117
117
|
var Timeline = /*#__PURE__*/ function(Axis) {
|
|
118
118
|
"use strict";
|
|
@@ -209,14 +209,14 @@ var Timeline = /*#__PURE__*/ function(Axis) {
|
|
|
209
209
|
fontColor: colorDefaults.dark,
|
|
210
210
|
fontSize: 15,
|
|
211
211
|
text: function() {
|
|
212
|
-
return _this._playTimer ? "
|
|
212
|
+
return _this._playTimer ? "⏸" : "⏵";
|
|
213
213
|
},
|
|
214
214
|
textAnchor: "middle",
|
|
215
215
|
verticalAlign: "middle"
|
|
216
216
|
};
|
|
217
217
|
_this._playButtonInterval = 1000;
|
|
218
218
|
_this._selectionConfig = {
|
|
219
|
-
|
|
219
|
+
fill: "#228be6",
|
|
220
220
|
"fill-opacity": function() {
|
|
221
221
|
return _this._buttonBehaviorCurrent === "buttons" ? 0.3 : 1;
|
|
222
222
|
},
|
|
@@ -494,7 +494,7 @@ var Timeline = /*#__PURE__*/ function(Axis) {
|
|
|
494
494
|
});
|
|
495
495
|
this._ticksWidth = maxLabel * ticks.length;
|
|
496
496
|
}
|
|
497
|
-
var playButtonWidth = this._playButton ? this._buttonHeight : 0;
|
|
497
|
+
var playButtonWidth = this._playButton ? this._playButtonConfig.width || this._buttonHeight : 0;
|
|
498
498
|
var space = this._width - playButtonWidth;
|
|
499
499
|
this._buttonBehaviorCurrent = this._buttonBehavior === "auto" ? this._ticksWidth < space ? "buttons" : "ticks" : this._buttonBehavior;
|
|
500
500
|
var hiddenHandles = this._hiddenHandles = this._buttonBehaviorCurrent === "buttons" && !this._brushing;
|
|
@@ -564,9 +564,9 @@ var Timeline = /*#__PURE__*/ function(Axis) {
|
|
|
564
564
|
x: this._paddingLeft - playButtonWidth,
|
|
565
565
|
y: this._buttonBehaviorCurrent === "buttons" ? this._align === "middle" ? this._height / 2 - this._buttonHeight / 2 : this._align === "start" ? this._margin.top : this._height - this._buttonHeight - this._margin.bottom : this._outerBounds.y,
|
|
566
566
|
width: playButtonWidth,
|
|
567
|
-
height:
|
|
567
|
+
height: this._buttonHeight
|
|
568
568
|
}
|
|
569
|
-
] : []).select(playButtonGroup.node()).config(this._playButtonConfig).render();
|
|
569
|
+
] : []).select(playButtonGroup.node()).config(configPrep.bind(this)(this._playButtonConfig)).render();
|
|
570
570
|
return this;
|
|
571
571
|
}
|
|
572
572
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3plus/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
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.
|
|
38
|
-
"@d3plus/data": "3.0.
|
|
39
|
-
"@d3plus/dom": "3.0.
|
|
40
|
-
"@d3plus/format": "3.0.
|
|
41
|
-
"@d3plus/locales": "3.0.
|
|
42
|
-
"@d3plus/math": "3.0.
|
|
43
|
-
"@d3plus/text": "3.0.
|
|
37
|
+
"@d3plus/color": "3.0.7",
|
|
38
|
+
"@d3plus/data": "3.0.7",
|
|
39
|
+
"@d3plus/dom": "3.0.7",
|
|
40
|
+
"@d3plus/format": "3.0.7",
|
|
41
|
+
"@d3plus/locales": "3.0.7",
|
|
42
|
+
"@d3plus/math": "3.0.7",
|
|
43
|
+
"@d3plus/text": "3.0.7",
|
|
44
44
|
"@popperjs/core": "^2.11.8",
|
|
45
45
|
"d3-array": "^3.2.4",
|
|
46
46
|
"d3-brush": "^3.0.0",
|
package/umd/d3plus-core.full.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/core v3.0.
|
|
2
|
+
@d3plus/core v3.0.7
|
|
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
|
|
@@ -30240,7 +30240,7 @@
|
|
|
30240
30240
|
});
|
|
30241
30241
|
this._ticksWidth = maxLabel * ticks.length;
|
|
30242
30242
|
}
|
|
30243
|
-
const playButtonWidth = this._playButton ? this._buttonHeight : 0;
|
|
30243
|
+
const playButtonWidth = this._playButton ? this._playButtonConfig.width || this._buttonHeight : 0;
|
|
30244
30244
|
const space = this._width - playButtonWidth;
|
|
30245
30245
|
this._buttonBehaviorCurrent = this._buttonBehavior === "auto" ? this._ticksWidth < space ? "buttons" : "ticks" : this._buttonBehavior;
|
|
30246
30246
|
const hiddenHandles = this._hiddenHandles = this._buttonBehaviorCurrent === "buttons" && !this._brushing;
|
|
@@ -30306,9 +30306,9 @@
|
|
|
30306
30306
|
x: this._paddingLeft - playButtonWidth,
|
|
30307
30307
|
y: this._buttonBehaviorCurrent === "buttons" ? this._align === "middle" ? this._height / 2 - this._buttonHeight / 2 : this._align === "start" ? this._margin.top : this._height - this._buttonHeight - this._margin.bottom : this._outerBounds.y,
|
|
30308
30308
|
width: playButtonWidth,
|
|
30309
|
-
height:
|
|
30309
|
+
height: this._buttonHeight
|
|
30310
30310
|
}
|
|
30311
|
-
] : []).select(playButtonGroup.node()).config(this._playButtonConfig).render();
|
|
30311
|
+
] : []).select(playButtonGroup.node()).config(configPrep.bind(this)(this._playButtonConfig)).render();
|
|
30312
30312
|
return this;
|
|
30313
30313
|
}
|
|
30314
30314
|
/**
|
|
@@ -30529,13 +30529,13 @@
|
|
|
30529
30529
|
this._playButtonConfig = {
|
|
30530
30530
|
fontColor: defaults.dark,
|
|
30531
30531
|
fontSize: 15,
|
|
30532
|
-
text: ()=>this._playTimer ? "
|
|
30532
|
+
text: ()=>this._playTimer ? "⏸" : "⏵",
|
|
30533
30533
|
textAnchor: "middle",
|
|
30534
30534
|
verticalAlign: "middle"
|
|
30535
30535
|
};
|
|
30536
30536
|
this._playButtonInterval = 1000;
|
|
30537
30537
|
this._selectionConfig = {
|
|
30538
|
-
|
|
30538
|
+
fill: "#228be6",
|
|
30539
30539
|
"fill-opacity": ()=>this._buttonBehaviorCurrent === "buttons" ? 0.3 : 1,
|
|
30540
30540
|
"stroke-width": 0
|
|
30541
30541
|
};
|
|
@@ -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
|
|
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
|
|
35020
|
-
@param {Function
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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 + (
|
|
56805
|
-
return
|
|
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).
|
|
56805
|
+
id: (d, i)=>this._ids(d, i)[d.depth - 1]
|
|
56808
56806
|
}).render());
|
|
56809
|
-
|
|
56810
|
-
id: (d, i)=>this._ids(d, i).
|
|
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)=>
|
|
56818
|
-
verticalAlign: (d)=>
|
|
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:
|
|
56824
|
-
height:
|
|
56825
|
-
x:
|
|
56826
|
-
y:
|
|
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 =
|
|
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 ? -(
|
|
56833
|
+
[y]: d.children && d.depth !== this._groupBy.length ? -(offset + h) : offset
|
|
56836
56834
|
};
|
|
56837
56835
|
}
|
|
56838
|
-
}
|
|
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
|
|
56844
|
-
@param {
|
|
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:
|
|
56886
|
+
fontColor: defaults.dark
|
|
56875
56887
|
},
|
|
56876
56888
|
Path: {
|
|
56877
56889
|
fill: "none",
|
|
56878
|
-
stroke:
|
|
56879
|
-
strokeWidth:
|
|
56890
|
+
stroke: defaults.missing,
|
|
56891
|
+
strokeWidth: 2
|
|
56880
56892
|
},
|
|
56881
|
-
r: constant$9(
|
|
56882
|
-
width: constant$9(
|
|
56883
|
-
height: constant$9(
|
|
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
|
}
|