@d3plus/core 3.0.0-alpha.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.
- package/README.md +6219 -0
- package/es/index.js +4 -0
- package/es/src/charts/AreaPlot.js +86 -0
- package/es/src/charts/BarChart.js +93 -0
- package/es/src/charts/BoxWhisker.js +97 -0
- package/es/src/charts/BumpChart.js +148 -0
- package/es/src/charts/Donut.js +84 -0
- package/es/src/charts/Geomap.js +833 -0
- package/es/src/charts/LinePlot.js +84 -0
- package/es/src/charts/Matrix.js +358 -0
- package/es/src/charts/Network.js +787 -0
- package/es/src/charts/Pack.js +318 -0
- package/es/src/charts/Pie.js +242 -0
- package/es/src/charts/Plot.js +2212 -0
- package/es/src/charts/Priestley.js +312 -0
- package/es/src/charts/Radar.js +365 -0
- package/es/src/charts/RadialMatrix.js +393 -0
- package/es/src/charts/Rings.js +777 -0
- package/es/src/charts/Sankey.js +413 -0
- package/es/src/charts/StackedArea.js +80 -0
- package/es/src/charts/Tree.js +312 -0
- package/es/src/charts/Treemap.js +406 -0
- package/es/src/charts/Viz.js +2017 -0
- package/es/src/charts/drawSteps/drawAttribution.js +14 -0
- package/es/src/charts/drawSteps/drawBack.js +23 -0
- package/es/src/charts/drawSteps/drawColorScale.js +69 -0
- package/es/src/charts/drawSteps/drawLegend.js +120 -0
- package/es/src/charts/drawSteps/drawSubtitle.js +31 -0
- package/es/src/charts/drawSteps/drawTimeline.js +80 -0
- package/es/src/charts/drawSteps/drawTitle.js +31 -0
- package/es/src/charts/drawSteps/drawTotal.js +32 -0
- package/es/src/charts/drawSteps/zoomControls.js +254 -0
- package/es/src/charts/events/click.legend.js +76 -0
- package/es/src/charts/events/click.shape.js +26 -0
- package/es/src/charts/events/mouseenter.js +31 -0
- package/es/src/charts/events/mouseleave.js +21 -0
- package/es/src/charts/events/mousemove.legend.js +64 -0
- package/es/src/charts/events/mousemove.shape.js +42 -0
- package/es/src/charts/events/touchstart.body.js +7 -0
- package/es/src/charts/helpers/matrixData.js +104 -0
- package/es/src/charts/helpers/tileAttributions.js +34 -0
- package/es/src/charts/index.js +21 -0
- package/es/src/charts/plotBuffers/Bar.js +65 -0
- package/es/src/charts/plotBuffers/Box.js +60 -0
- package/es/src/charts/plotBuffers/Circle.js +39 -0
- package/es/src/charts/plotBuffers/Line.js +30 -0
- package/es/src/charts/plotBuffers/Rect.js +40 -0
- package/es/src/charts/plotBuffers/discreteBuffer.js +24 -0
- package/es/src/charts/plotBuffers/numericBuffer.js +111 -0
- package/es/src/components/Axis.js +1567 -0
- package/es/src/components/AxisBottom.js +77 -0
- package/es/src/components/AxisLeft.js +77 -0
- package/es/src/components/AxisRight.js +77 -0
- package/es/src/components/AxisTop.js +77 -0
- package/es/src/components/ColorScale.js +958 -0
- package/es/src/components/Legend.js +673 -0
- package/es/src/components/Message.js +95 -0
- package/es/src/components/TextBox.js +752 -0
- package/es/src/components/Timeline.js +760 -0
- package/es/src/components/Tooltip.js +726 -0
- package/es/src/components/index.js +11 -0
- package/es/src/shapes/Area.js +361 -0
- package/es/src/shapes/Bar.js +342 -0
- package/es/src/shapes/Box.js +482 -0
- package/es/src/shapes/Circle.js +201 -0
- package/es/src/shapes/Image.js +255 -0
- package/es/src/shapes/Line.js +289 -0
- package/es/src/shapes/Path.js +186 -0
- package/es/src/shapes/Rect.js +215 -0
- package/es/src/shapes/Shape.js +1156 -0
- package/es/src/shapes/Whisker.js +330 -0
- package/es/src/shapes/index.js +10 -0
- package/es/src/utils/BaseClass.js +204 -0
- package/es/src/utils/RESET.js +4 -0
- package/es/src/utils/accessor.js +19 -0
- package/es/src/utils/configPrep.js +76 -0
- package/es/src/utils/constant.js +15 -0
- package/es/src/utils/getProp.js +9 -0
- package/es/src/utils/index.js +7 -0
- package/es/src/utils/uuid.js +13 -0
- package/package.json +68 -0
- package/umd/d3plus-core.full.js +56459 -0
- package/umd/d3plus-core.full.js.map +1 -0
- package/umd/d3plus-core.full.min.js +7241 -0
- package/umd/d3plus-core.js +14422 -0
- package/umd/d3plus-core.js.map +1 -0
- package/umd/d3plus-core.min.js +4564 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function _assert_this_initialized(self) {
|
|
10
|
+
if (self === void 0) {
|
|
11
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
12
|
+
}
|
|
13
|
+
return self;
|
|
14
|
+
}
|
|
15
|
+
function _call_super(_this, derived, args) {
|
|
16
|
+
derived = _get_prototype_of(derived);
|
|
17
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
18
|
+
}
|
|
19
|
+
function _class_call_check(instance, Constructor) {
|
|
20
|
+
if (!(instance instanceof Constructor)) {
|
|
21
|
+
throw new TypeError("Cannot call a class as a function");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _defineProperties(target, props) {
|
|
25
|
+
for(var i = 0; i < props.length; i++){
|
|
26
|
+
var descriptor = props[i];
|
|
27
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
28
|
+
descriptor.configurable = true;
|
|
29
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
30
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
34
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
35
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
36
|
+
return Constructor;
|
|
37
|
+
}
|
|
38
|
+
function _get(target, property, receiver) {
|
|
39
|
+
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
40
|
+
_get = Reflect.get;
|
|
41
|
+
} else {
|
|
42
|
+
_get = function get(target, property, receiver) {
|
|
43
|
+
var base = _super_prop_base(target, property);
|
|
44
|
+
if (!base) return;
|
|
45
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
46
|
+
if (desc.get) {
|
|
47
|
+
return desc.get.call(receiver || target);
|
|
48
|
+
}
|
|
49
|
+
return desc.value;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return _get(target, property, receiver || target);
|
|
53
|
+
}
|
|
54
|
+
function _get_prototype_of(o) {
|
|
55
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
56
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
57
|
+
};
|
|
58
|
+
return _get_prototype_of(o);
|
|
59
|
+
}
|
|
60
|
+
function _inherits(subClass, superClass) {
|
|
61
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
62
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
63
|
+
}
|
|
64
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
65
|
+
constructor: {
|
|
66
|
+
value: subClass,
|
|
67
|
+
writable: true,
|
|
68
|
+
configurable: true
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
72
|
+
}
|
|
73
|
+
function _iterable_to_array(iter) {
|
|
74
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
75
|
+
}
|
|
76
|
+
function _non_iterable_spread() {
|
|
77
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
78
|
+
}
|
|
79
|
+
function _possible_constructor_return(self, call) {
|
|
80
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
81
|
+
return call;
|
|
82
|
+
}
|
|
83
|
+
return _assert_this_initialized(self);
|
|
84
|
+
}
|
|
85
|
+
function _set_prototype_of(o, p) {
|
|
86
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
87
|
+
o.__proto__ = p;
|
|
88
|
+
return o;
|
|
89
|
+
};
|
|
90
|
+
return _set_prototype_of(o, p);
|
|
91
|
+
}
|
|
92
|
+
function _super_prop_base(object, property) {
|
|
93
|
+
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
94
|
+
object = _get_prototype_of(object);
|
|
95
|
+
if (object === null) break;
|
|
96
|
+
}
|
|
97
|
+
return object;
|
|
98
|
+
}
|
|
99
|
+
function _to_consumable_array(arr) {
|
|
100
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
101
|
+
}
|
|
102
|
+
function _type_of(obj) {
|
|
103
|
+
"@swc/helpers - typeof";
|
|
104
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
105
|
+
}
|
|
106
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
107
|
+
if (!o) return;
|
|
108
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
109
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
110
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
111
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
112
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
113
|
+
}
|
|
114
|
+
function _is_native_reflect_construct() {
|
|
115
|
+
try {
|
|
116
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
117
|
+
} catch (_) {}
|
|
118
|
+
return (_is_native_reflect_construct = function() {
|
|
119
|
+
return !!result;
|
|
120
|
+
})();
|
|
121
|
+
}
|
|
122
|
+
import { nest } from "d3-collection";
|
|
123
|
+
import { hierarchy, pack } from "d3-hierarchy";
|
|
124
|
+
import { assign, elem } from "@d3plus/dom";
|
|
125
|
+
import { accessor, configPrep, constant } from "../utils/index.js";
|
|
126
|
+
import { Circle } from "../shapes/index.js";
|
|
127
|
+
import Viz from "./Viz.js";
|
|
128
|
+
var recursionCircles = function(d) {
|
|
129
|
+
var arr = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
130
|
+
if (d.values) {
|
|
131
|
+
d.values.forEach(function(h) {
|
|
132
|
+
arr.push(h);
|
|
133
|
+
recursionCircles(h, arr);
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
arr.push(d);
|
|
137
|
+
}
|
|
138
|
+
return arr;
|
|
139
|
+
};
|
|
140
|
+
var Pack = /*#__PURE__*/ function(Viz) {
|
|
141
|
+
"use strict";
|
|
142
|
+
_inherits(Pack, Viz);
|
|
143
|
+
function Pack() {
|
|
144
|
+
_class_call_check(this, Pack);
|
|
145
|
+
var _this;
|
|
146
|
+
_this = _call_super(this, Pack);
|
|
147
|
+
_this._layoutPadding = 1;
|
|
148
|
+
var defaultLegend = _this._legend;
|
|
149
|
+
_this._legend = function(config, arr) {
|
|
150
|
+
if (arr.length === _this._filteredData.length) return false;
|
|
151
|
+
return defaultLegend.bind(_this)(config, arr);
|
|
152
|
+
};
|
|
153
|
+
_this._on.mouseenter = function() {};
|
|
154
|
+
var defaultMouseMoveLegend = _this._on["mousemove.legend"];
|
|
155
|
+
_this._on["mousemove.legend"] = function(d, i, x, event) {
|
|
156
|
+
defaultMouseMoveLegend(d, i, x, event);
|
|
157
|
+
var ids = _this._ids(d, i);
|
|
158
|
+
var hoverData = recursionCircles(d);
|
|
159
|
+
_this.hover(function(h) {
|
|
160
|
+
var _hoverData;
|
|
161
|
+
var hover = Object.keys(h).filter(function(key) {
|
|
162
|
+
return key !== "value";
|
|
163
|
+
}).every(function(key) {
|
|
164
|
+
return d[key] && d[key].includes(h[key]);
|
|
165
|
+
});
|
|
166
|
+
if (hover) hoverData.push(h);
|
|
167
|
+
else if (ids.includes(h.key)) (_hoverData = hoverData).push.apply(_hoverData, _to_consumable_array(recursionCircles(h, [
|
|
168
|
+
h
|
|
169
|
+
])));
|
|
170
|
+
return hoverData.includes(h);
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
var defaultMouseMoveShape = _this._on["mousemove.shape"];
|
|
174
|
+
_this._on["mousemove.shape"] = function(d, i, x, event) {
|
|
175
|
+
if (d.__d3plusTooltip__) defaultMouseMoveShape(d, i, x, event);
|
|
176
|
+
_this.hover(function(h) {
|
|
177
|
+
return recursionCircles(d, [
|
|
178
|
+
d
|
|
179
|
+
]).includes(h);
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
_this._pack = pack();
|
|
183
|
+
_this._packOpacity = constant(0.25);
|
|
184
|
+
_this._shape = constant("Circle");
|
|
185
|
+
_this._shapeConfig = assign(_this._shapeConfig, {
|
|
186
|
+
Circle: {
|
|
187
|
+
label: function(d) {
|
|
188
|
+
return d.parent && !d.children ? d.id : false;
|
|
189
|
+
},
|
|
190
|
+
labelConfig: {
|
|
191
|
+
fontResize: true
|
|
192
|
+
},
|
|
193
|
+
opacity: function(d) {
|
|
194
|
+
return d.__d3plusOpacity__;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
_this._sort = function(a, b) {
|
|
199
|
+
return b.value - a.value;
|
|
200
|
+
};
|
|
201
|
+
_this._sum = accessor("value");
|
|
202
|
+
return _this;
|
|
203
|
+
}
|
|
204
|
+
_create_class(Pack, [
|
|
205
|
+
{
|
|
206
|
+
/**
|
|
207
|
+
Extends the draw behavior of the abstract Viz class.
|
|
208
|
+
@private
|
|
209
|
+
*/ key: "_draw",
|
|
210
|
+
value: function _draw(callback) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
_get(_get_prototype_of(Pack.prototype), "_draw", this).call(this, callback);
|
|
213
|
+
var height = this._height - this._margin.top - this._margin.bottom, width = this._width - this._margin.left - this._margin.right;
|
|
214
|
+
var diameter = Math.min(height, width);
|
|
215
|
+
var transform = "translate(".concat((width - diameter) / 2, ", ").concat((height - diameter) / 2, ")");
|
|
216
|
+
var nestedData = nest();
|
|
217
|
+
for(var i = 0; i <= this._drawDepth; i++)nestedData.key(this._groupBy[i]);
|
|
218
|
+
nestedData = nestedData.entries(this._filteredData);
|
|
219
|
+
var packData = this._pack.padding(this._layoutPadding).size([
|
|
220
|
+
diameter,
|
|
221
|
+
diameter
|
|
222
|
+
])(hierarchy({
|
|
223
|
+
key: nestedData.key,
|
|
224
|
+
values: nestedData
|
|
225
|
+
}, function(d) {
|
|
226
|
+
return d.values;
|
|
227
|
+
}).sum(this._sum).sort(this._sort)).descendants();
|
|
228
|
+
packData.forEach(function(d, i) {
|
|
229
|
+
d.__d3plus__ = true;
|
|
230
|
+
d.i = i;
|
|
231
|
+
d.id = d.parent ? d.parent.data.key : null;
|
|
232
|
+
d.data.__d3plusOpacity__ = d.height ? _this._packOpacity(d.data, i) : 1;
|
|
233
|
+
d.data.__d3plusTooltip__ = !d.height ? true : false;
|
|
234
|
+
});
|
|
235
|
+
this._shapes.push(new Circle().data(packData).select(elem("g.d3plus-Pack", {
|
|
236
|
+
parent: this._select,
|
|
237
|
+
enter: {
|
|
238
|
+
transform: transform
|
|
239
|
+
},
|
|
240
|
+
update: {
|
|
241
|
+
transform: transform
|
|
242
|
+
}
|
|
243
|
+
}).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).render());
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
/**
|
|
249
|
+
@memberof Pack
|
|
250
|
+
@desc If *value* is specified, sets the hover method to the specified function and returns the current class instance.
|
|
251
|
+
@param {Function} [*value*]
|
|
252
|
+
@chainable
|
|
253
|
+
*/ key: "hover",
|
|
254
|
+
value: function hover(_) {
|
|
255
|
+
this._hover = _;
|
|
256
|
+
this._shapes.forEach(function(s) {
|
|
257
|
+
return s.hover(_);
|
|
258
|
+
});
|
|
259
|
+
if (this._legend) this._legendClass.hover(_);
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
/**
|
|
265
|
+
@memberof Pack
|
|
266
|
+
@desc If *value* is specified, sets the opacity accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
|
|
267
|
+
@param {Function|Number} [*value*]
|
|
268
|
+
*/ key: "layoutPadding",
|
|
269
|
+
value: function layoutPadding(_) {
|
|
270
|
+
return arguments.length ? (this._layoutPadding = _, this) : this._layoutPadding;
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
/**
|
|
275
|
+
@memberof Pack
|
|
276
|
+
@desc If *value* is specified, sets the padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
|
|
277
|
+
@param {Function|Number} [*value*]
|
|
278
|
+
*/ key: "packOpacity",
|
|
279
|
+
value: function packOpacity(_) {
|
|
280
|
+
return arguments.length ? (this._packOpacity = typeof _ === "function" ? _ : constant(_), this) : this._packOpacity;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
/**
|
|
285
|
+
@memberof Pack
|
|
286
|
+
@desc If *comparator* is specified, sets the sort order for the pack using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
|
|
287
|
+
@param {Array} [*comparator*]
|
|
288
|
+
@example
|
|
289
|
+
function comparator(a, b) {
|
|
290
|
+
return b.value - a.value;
|
|
291
|
+
}
|
|
292
|
+
*/ key: "sort",
|
|
293
|
+
value: function sort(_) {
|
|
294
|
+
return arguments.length ? (this._sort = _, this) : this._sort;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
/**
|
|
299
|
+
@memberof Pack
|
|
300
|
+
@desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
|
|
301
|
+
@param {Function|Number} [*value*]
|
|
302
|
+
@example
|
|
303
|
+
function sum(d) {
|
|
304
|
+
return d.sum;
|
|
305
|
+
}
|
|
306
|
+
*/ key: "sum",
|
|
307
|
+
value: function sum(_) {
|
|
308
|
+
return arguments.length ? (this._sum = typeof _ === "function" ? _ : accessor(_), this) : this._sum;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
]);
|
|
312
|
+
return Pack;
|
|
313
|
+
}(Viz);
|
|
314
|
+
/**
|
|
315
|
+
@class Pack
|
|
316
|
+
@extends Viz
|
|
317
|
+
@desc Uses the [d3 pack layout](https://github.com/d3/d3-hierarchy#pack) to creates Circle Packing chart based on an array of data.
|
|
318
|
+
*/ export { Pack as default };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function _call_super(_this, derived, args) {
|
|
8
|
+
derived = _get_prototype_of(derived);
|
|
9
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
10
|
+
}
|
|
11
|
+
function _class_call_check(instance, Constructor) {
|
|
12
|
+
if (!(instance instanceof Constructor)) {
|
|
13
|
+
throw new TypeError("Cannot call a class as a function");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _defineProperties(target, props) {
|
|
17
|
+
for(var i = 0; i < props.length; i++){
|
|
18
|
+
var descriptor = props[i];
|
|
19
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
20
|
+
descriptor.configurable = true;
|
|
21
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
22
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
26
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
27
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
28
|
+
return Constructor;
|
|
29
|
+
}
|
|
30
|
+
function _get(target, property, receiver) {
|
|
31
|
+
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
32
|
+
_get = Reflect.get;
|
|
33
|
+
} else {
|
|
34
|
+
_get = function get(target, property, receiver) {
|
|
35
|
+
var base = _super_prop_base(target, property);
|
|
36
|
+
if (!base) return;
|
|
37
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
38
|
+
if (desc.get) {
|
|
39
|
+
return desc.get.call(receiver || target);
|
|
40
|
+
}
|
|
41
|
+
return desc.value;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return _get(target, property, receiver || target);
|
|
45
|
+
}
|
|
46
|
+
function _get_prototype_of(o) {
|
|
47
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
48
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
49
|
+
};
|
|
50
|
+
return _get_prototype_of(o);
|
|
51
|
+
}
|
|
52
|
+
function _inherits(subClass, superClass) {
|
|
53
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
54
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
55
|
+
}
|
|
56
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
57
|
+
constructor: {
|
|
58
|
+
value: subClass,
|
|
59
|
+
writable: true,
|
|
60
|
+
configurable: true
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
64
|
+
}
|
|
65
|
+
function _possible_constructor_return(self, call) {
|
|
66
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
67
|
+
return call;
|
|
68
|
+
}
|
|
69
|
+
return _assert_this_initialized(self);
|
|
70
|
+
}
|
|
71
|
+
function _set_prototype_of(o, p) {
|
|
72
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
73
|
+
o.__proto__ = p;
|
|
74
|
+
return o;
|
|
75
|
+
};
|
|
76
|
+
return _set_prototype_of(o, p);
|
|
77
|
+
}
|
|
78
|
+
function _super_prop_base(object, property) {
|
|
79
|
+
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
80
|
+
object = _get_prototype_of(object);
|
|
81
|
+
if (object === null) break;
|
|
82
|
+
}
|
|
83
|
+
return object;
|
|
84
|
+
}
|
|
85
|
+
function _type_of(obj) {
|
|
86
|
+
"@swc/helpers - typeof";
|
|
87
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
88
|
+
}
|
|
89
|
+
function _is_native_reflect_construct() {
|
|
90
|
+
try {
|
|
91
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
92
|
+
} catch (_) {}
|
|
93
|
+
return (_is_native_reflect_construct = function() {
|
|
94
|
+
return !!result;
|
|
95
|
+
})();
|
|
96
|
+
}
|
|
97
|
+
import { min } from "d3-array";
|
|
98
|
+
import { arc, pie } from "d3-shape";
|
|
99
|
+
import { Path } from "../shapes/index.js";
|
|
100
|
+
import { assign, elem } from "@d3plus/dom";
|
|
101
|
+
import { accessor, configPrep } from "../utils/index.js";
|
|
102
|
+
import Viz from "./Viz.js";
|
|
103
|
+
var Pie = /*#__PURE__*/ function(Viz) {
|
|
104
|
+
"use strict";
|
|
105
|
+
_inherits(Pie, Viz);
|
|
106
|
+
function Pie() {
|
|
107
|
+
_class_call_check(this, Pie);
|
|
108
|
+
var _this;
|
|
109
|
+
_this = _call_super(this, Pie);
|
|
110
|
+
var defaultLegend = _this._legend;
|
|
111
|
+
_this._legend = function(config, arr) {
|
|
112
|
+
if (arr.length === _this._filteredData.length) return false;
|
|
113
|
+
return defaultLegend.bind(_this)(config, arr);
|
|
114
|
+
};
|
|
115
|
+
_this._legendSort = function(a, b) {
|
|
116
|
+
return _this._value(b) - _this._value(a);
|
|
117
|
+
};
|
|
118
|
+
_this._shapeConfig = assign(_this._shapeConfig, {
|
|
119
|
+
ariaLabel: function(d, i) {
|
|
120
|
+
return _this._pieData ? "".concat(++_this._pieData[i].index, ". ").concat(_this._drawLabel(d, i), ", ").concat(_this._value(d, i), ".") : "";
|
|
121
|
+
},
|
|
122
|
+
Path: {
|
|
123
|
+
labelConfig: {
|
|
124
|
+
fontResize: true
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
_this._innerRadius = 0;
|
|
129
|
+
_this._legendSort = function(a, b) {
|
|
130
|
+
return _this._value(b) - _this._value(a);
|
|
131
|
+
};
|
|
132
|
+
_this._padPixel = 0;
|
|
133
|
+
_this._pie = pie();
|
|
134
|
+
_this._sort = function(a, b) {
|
|
135
|
+
return _this._value(b) - _this._value(a);
|
|
136
|
+
};
|
|
137
|
+
_this._value = accessor("value");
|
|
138
|
+
return _this;
|
|
139
|
+
}
|
|
140
|
+
_create_class(Pie, [
|
|
141
|
+
{
|
|
142
|
+
/**
|
|
143
|
+
Extends the draw behavior of the abstract Viz class.
|
|
144
|
+
@private
|
|
145
|
+
*/ key: "_draw",
|
|
146
|
+
value: function _draw(callback) {
|
|
147
|
+
var _this = this;
|
|
148
|
+
_get(_get_prototype_of(Pie.prototype), "_draw", this).call(this, callback);
|
|
149
|
+
var height = this._height - this._margin.top - this._margin.bottom, width = this._width - this._margin.left - this._margin.right;
|
|
150
|
+
var outerRadius = min([
|
|
151
|
+
width,
|
|
152
|
+
height
|
|
153
|
+
]) / 2;
|
|
154
|
+
var pieData = this._pieData = this._pie.padAngle(this._padAngle || this._padPixel / outerRadius).sort(this._sort).value(this._value)(this._filteredData);
|
|
155
|
+
pieData.forEach(function(d, i) {
|
|
156
|
+
d.__d3plus__ = true;
|
|
157
|
+
d.i = i;
|
|
158
|
+
});
|
|
159
|
+
var arcData = arc().innerRadius(this._innerRadius).outerRadius(outerRadius);
|
|
160
|
+
var transform = "translate(".concat(width / 2 + this._margin.left, ", ").concat(height / 2 + this._margin.top, ")");
|
|
161
|
+
this._shapes.push(new Path().data(pieData).d(arcData).select(elem("g.d3plus-Pie", {
|
|
162
|
+
parent: this._select,
|
|
163
|
+
enter: {
|
|
164
|
+
transform: transform
|
|
165
|
+
},
|
|
166
|
+
update: {
|
|
167
|
+
transform: transform
|
|
168
|
+
}
|
|
169
|
+
}).node()).config({
|
|
170
|
+
id: function(d) {
|
|
171
|
+
return _this._ids(d).join("-");
|
|
172
|
+
},
|
|
173
|
+
x: 0,
|
|
174
|
+
y: 0
|
|
175
|
+
}).label(this._drawLabel).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).render());
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
/**
|
|
181
|
+
@memberof Pie
|
|
182
|
+
@desc The pixel value, or function that returns a pixel value, that is used as the inner radius of the Pie (creating a Donut).
|
|
183
|
+
@param {Function|Number} [*value* = 0]
|
|
184
|
+
*/ key: "innerRadius",
|
|
185
|
+
value: function innerRadius(_) {
|
|
186
|
+
return arguments.length ? (this._innerRadius = _, this) : this._innerRadius;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
/**
|
|
191
|
+
@memberof Pie
|
|
192
|
+
@desc The padding between each arc, set as a radian value between \`0\` and \`1\`.
|
|
193
|
+
|
|
194
|
+
If set, this will override any previously set padPixel value.
|
|
195
|
+
@param {Number} [*value*]
|
|
196
|
+
*/ key: "padAngle",
|
|
197
|
+
value: function padAngle(_) {
|
|
198
|
+
return arguments.length ? (this._padAngle = _, this) : this._padAngle;
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
/**
|
|
203
|
+
@memberof Pie
|
|
204
|
+
@desc The padding between each arc, set as a pixel number value.
|
|
205
|
+
|
|
206
|
+
By default the value is \`0\`, which shows no padding between each arc.
|
|
207
|
+
|
|
208
|
+
If \`padAngle\` is defined, the \`padPixel\` value will not be considered.
|
|
209
|
+
@param {Number} [*value* = 0]
|
|
210
|
+
*/ key: "padPixel",
|
|
211
|
+
value: function padPixel(_) {
|
|
212
|
+
return arguments.length ? (this._padPixel = _, this) : this._padPixel;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
/**
|
|
217
|
+
@memberof Pie
|
|
218
|
+
@desc A comparator function that sorts the Pie slices.
|
|
219
|
+
@param {Function} [*comparator* = (a, b) => b.value - a.value]
|
|
220
|
+
*/ key: "sort",
|
|
221
|
+
value: function sort(_) {
|
|
222
|
+
return arguments.length ? (this._sort = _, this) : this._sort;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
/**
|
|
227
|
+
@memberof Pie
|
|
228
|
+
@desc The accessor key for each data point used to calculate the size of each Pie section.
|
|
229
|
+
@param {Function|String} *value* = d => d.value
|
|
230
|
+
*/ key: "value",
|
|
231
|
+
value: function value(_) {
|
|
232
|
+
return arguments.length ? (this._value = typeof _ === "function" ? _ : accessor(_), this) : this._value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
]);
|
|
236
|
+
return Pie;
|
|
237
|
+
}(Viz);
|
|
238
|
+
/**
|
|
239
|
+
@class Pie
|
|
240
|
+
@extends Viz
|
|
241
|
+
@desc Uses the [d3 pie layout](https://github.com/d3/d3-shape#pies) to creates SVG arcs based on an array of data.
|
|
242
|
+
*/ export { Pie as default };
|