@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.
Files changed (87) hide show
  1. package/README.md +6219 -0
  2. package/es/index.js +4 -0
  3. package/es/src/charts/AreaPlot.js +86 -0
  4. package/es/src/charts/BarChart.js +93 -0
  5. package/es/src/charts/BoxWhisker.js +97 -0
  6. package/es/src/charts/BumpChart.js +148 -0
  7. package/es/src/charts/Donut.js +84 -0
  8. package/es/src/charts/Geomap.js +833 -0
  9. package/es/src/charts/LinePlot.js +84 -0
  10. package/es/src/charts/Matrix.js +358 -0
  11. package/es/src/charts/Network.js +787 -0
  12. package/es/src/charts/Pack.js +318 -0
  13. package/es/src/charts/Pie.js +242 -0
  14. package/es/src/charts/Plot.js +2212 -0
  15. package/es/src/charts/Priestley.js +312 -0
  16. package/es/src/charts/Radar.js +365 -0
  17. package/es/src/charts/RadialMatrix.js +393 -0
  18. package/es/src/charts/Rings.js +777 -0
  19. package/es/src/charts/Sankey.js +413 -0
  20. package/es/src/charts/StackedArea.js +80 -0
  21. package/es/src/charts/Tree.js +312 -0
  22. package/es/src/charts/Treemap.js +406 -0
  23. package/es/src/charts/Viz.js +2017 -0
  24. package/es/src/charts/drawSteps/drawAttribution.js +14 -0
  25. package/es/src/charts/drawSteps/drawBack.js +23 -0
  26. package/es/src/charts/drawSteps/drawColorScale.js +69 -0
  27. package/es/src/charts/drawSteps/drawLegend.js +120 -0
  28. package/es/src/charts/drawSteps/drawSubtitle.js +31 -0
  29. package/es/src/charts/drawSteps/drawTimeline.js +80 -0
  30. package/es/src/charts/drawSteps/drawTitle.js +31 -0
  31. package/es/src/charts/drawSteps/drawTotal.js +32 -0
  32. package/es/src/charts/drawSteps/zoomControls.js +254 -0
  33. package/es/src/charts/events/click.legend.js +76 -0
  34. package/es/src/charts/events/click.shape.js +26 -0
  35. package/es/src/charts/events/mouseenter.js +31 -0
  36. package/es/src/charts/events/mouseleave.js +21 -0
  37. package/es/src/charts/events/mousemove.legend.js +64 -0
  38. package/es/src/charts/events/mousemove.shape.js +42 -0
  39. package/es/src/charts/events/touchstart.body.js +7 -0
  40. package/es/src/charts/helpers/matrixData.js +104 -0
  41. package/es/src/charts/helpers/tileAttributions.js +34 -0
  42. package/es/src/charts/index.js +21 -0
  43. package/es/src/charts/plotBuffers/Bar.js +65 -0
  44. package/es/src/charts/plotBuffers/Box.js +60 -0
  45. package/es/src/charts/plotBuffers/Circle.js +39 -0
  46. package/es/src/charts/plotBuffers/Line.js +30 -0
  47. package/es/src/charts/plotBuffers/Rect.js +40 -0
  48. package/es/src/charts/plotBuffers/discreteBuffer.js +24 -0
  49. package/es/src/charts/plotBuffers/numericBuffer.js +111 -0
  50. package/es/src/components/Axis.js +1567 -0
  51. package/es/src/components/AxisBottom.js +77 -0
  52. package/es/src/components/AxisLeft.js +77 -0
  53. package/es/src/components/AxisRight.js +77 -0
  54. package/es/src/components/AxisTop.js +77 -0
  55. package/es/src/components/ColorScale.js +958 -0
  56. package/es/src/components/Legend.js +673 -0
  57. package/es/src/components/Message.js +95 -0
  58. package/es/src/components/TextBox.js +752 -0
  59. package/es/src/components/Timeline.js +760 -0
  60. package/es/src/components/Tooltip.js +726 -0
  61. package/es/src/components/index.js +11 -0
  62. package/es/src/shapes/Area.js +361 -0
  63. package/es/src/shapes/Bar.js +342 -0
  64. package/es/src/shapes/Box.js +482 -0
  65. package/es/src/shapes/Circle.js +201 -0
  66. package/es/src/shapes/Image.js +255 -0
  67. package/es/src/shapes/Line.js +289 -0
  68. package/es/src/shapes/Path.js +186 -0
  69. package/es/src/shapes/Rect.js +215 -0
  70. package/es/src/shapes/Shape.js +1156 -0
  71. package/es/src/shapes/Whisker.js +330 -0
  72. package/es/src/shapes/index.js +10 -0
  73. package/es/src/utils/BaseClass.js +204 -0
  74. package/es/src/utils/RESET.js +4 -0
  75. package/es/src/utils/accessor.js +19 -0
  76. package/es/src/utils/configPrep.js +76 -0
  77. package/es/src/utils/constant.js +15 -0
  78. package/es/src/utils/getProp.js +9 -0
  79. package/es/src/utils/index.js +7 -0
  80. package/es/src/utils/uuid.js +13 -0
  81. package/package.json +68 -0
  82. package/umd/d3plus-core.full.js +56459 -0
  83. package/umd/d3plus-core.full.js.map +1 -0
  84. package/umd/d3plus-core.full.min.js +7241 -0
  85. package/umd/d3plus-core.js +14422 -0
  86. package/umd/d3plus-core.js.map +1 -0
  87. package/umd/d3plus-core.min.js +4564 -0
@@ -0,0 +1,312 @@
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, max, range } from "d3-array";
98
+ import { nest } from "d3-collection";
99
+ import { scaleBand } from "d3-scale";
100
+ import { Axis } from "../components/index.js";
101
+ import { assign, date, elem } from "@d3plus/dom";
102
+ import { Rect } from "../shapes/index.js";
103
+ import { accessor, configPrep } from "../utils/index.js";
104
+ import Viz from "./Viz.js";
105
+ var Priestley = /*#__PURE__*/ function(Viz) {
106
+ "use strict";
107
+ _inherits(Priestley, Viz);
108
+ function Priestley() {
109
+ _class_call_check(this, Priestley);
110
+ var _this;
111
+ _this = _call_super(this, Priestley);
112
+ _this._axis = new Axis().align("end").orient("bottom");
113
+ _this._axisConfig = {
114
+ scale: "time"
115
+ };
116
+ _this._axisTest = new Axis().align("end").gridSize(0).orient("bottom");
117
+ _this.end("end");
118
+ _this._paddingInner = 0.05;
119
+ _this._paddingOuter = 0.05;
120
+ _this._shapeConfig = assign({}, _this._shapeConfig, {
121
+ ariaLabel: function(d, i) {
122
+ return "".concat(_this._drawLabel(d, i), ", ").concat(_this._start(d, i), " - ").concat(_this._end(d, i), ".");
123
+ }
124
+ });
125
+ _this.start("start");
126
+ return _this;
127
+ }
128
+ _create_class(Priestley, [
129
+ {
130
+ /**
131
+ @memberof Priestley
132
+ @desc Extends the render behavior of the abstract Viz class.
133
+ @private
134
+ */ key: "_draw",
135
+ value: function _draw(callback) {
136
+ var _this = this;
137
+ _get(_get_prototype_of(Priestley.prototype), "_draw", this).call(this, callback);
138
+ if (!this._filteredData) return this;
139
+ var data = this._filteredData.map(function(data, i) {
140
+ return {
141
+ __d3plus__: true,
142
+ data: data,
143
+ end: _this._axisConfig.scale === "time" ? date(_this._end(data, i)) : _this._end(data, i),
144
+ i: i,
145
+ id: _this._id(data, i),
146
+ start: _this._axisConfig.scale === "time" ? date(_this._start(data, i)) : _this._start(data, i)
147
+ };
148
+ }).filter(function(d) {
149
+ return d.end - d.start > 0;
150
+ }).sort(function(a, b) {
151
+ return a.start - b.start;
152
+ });
153
+ var nestedData;
154
+ if (this._groupBy.length > 1 && this._drawDepth > 0) {
155
+ var _loop = function(i) {
156
+ dataNest.key(function(d) {
157
+ return _this._groupBy[i](d.data, d.i);
158
+ });
159
+ };
160
+ var dataNest = nest();
161
+ for(var i = 0; i < this._drawDepth; i++)_loop(i);
162
+ nestedData = dataNest.entries(data);
163
+ } else nestedData = [
164
+ {
165
+ values: data
166
+ }
167
+ ];
168
+ var maxLane = 0;
169
+ nestedData.forEach(function(g) {
170
+ var track = [];
171
+ g.values.forEach(function(d) {
172
+ track = track.map(function(t) {
173
+ return t <= d.start ? false : t;
174
+ });
175
+ var i = track.indexOf(false);
176
+ if (i < 0) {
177
+ d.lane = maxLane + track.length;
178
+ track.push(d.end);
179
+ } else {
180
+ track[i] = d.end;
181
+ d.lane = maxLane + i;
182
+ }
183
+ });
184
+ maxLane += track.length;
185
+ });
186
+ var axisConfig = {
187
+ domain: [
188
+ min(data, function(d) {
189
+ return d.start;
190
+ }) || 0,
191
+ max(data, function(d) {
192
+ return d.end;
193
+ }) || 0
194
+ ],
195
+ height: this._height - this._margin.top - this._margin.bottom,
196
+ width: this._width - this._margin.left - this._margin.right
197
+ };
198
+ var transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")");
199
+ this._axisTest.config(axisConfig).config(this._axisConfig).select(elem("g.d3plus-priestley-axis-test", {
200
+ parent: this._select,
201
+ enter: {
202
+ opacity: 0
203
+ }
204
+ }).node()).render();
205
+ this._axis.config(axisConfig).config(this._axisConfig).select(elem("g.d3plus-priestley-axis", {
206
+ parent: this._select,
207
+ enter: {
208
+ transform: transform
209
+ },
210
+ update: {
211
+ transform: transform
212
+ }
213
+ }).node()).render();
214
+ var axisPad = this._axisTest._padding;
215
+ var xScale = this._axis._d3Scale;
216
+ var yScale = scaleBand().domain(range(0, maxLane, 1)).paddingInner(this._paddingInner).paddingOuter(this._paddingOuter).rangeRound([
217
+ this._height - this._margin.bottom - this._axisTest.outerBounds().height - axisPad,
218
+ this._margin.top + axisPad
219
+ ]);
220
+ var bandWidth = yScale.bandwidth();
221
+ this._shapes.push(new Rect().data(data).duration(this._duration).height(bandWidth).label(function(d, i) {
222
+ return _this._drawLabel(d.data, i);
223
+ }).select(elem("g.d3plus-priestley-shapes", {
224
+ parent: this._select
225
+ }).node()).width(function(d) {
226
+ var w = Math.abs(xScale(d.end) - xScale(d.start));
227
+ return w > 2 ? w - 2 : w;
228
+ }).x(function(d) {
229
+ return xScale(d.start) + (xScale(d.end) - xScale(d.start)) / 2;
230
+ }).y(function(d) {
231
+ return yScale(d.lane) + bandWidth / 2;
232
+ }).config(configPrep.bind(this)(this._shapeConfig, "shape", "Rect")).render());
233
+ return this;
234
+ }
235
+ },
236
+ {
237
+ /**
238
+ @memberof Priestley
239
+ @desc If *value* is specified, sets the config method for the axis and returns the current class instance. If *value* is not specified, returns the current axis configuration.
240
+ @param {Object} [*value*]
241
+ @chainable
242
+ */ key: "axisConfig",
243
+ value: function axisConfig(_) {
244
+ return arguments.length ? (this._axisConfig = assign(this._axisConfig, _), this) : this._axisConfig;
245
+ }
246
+ },
247
+ {
248
+ /**
249
+ @memberof Priestley
250
+ @desc If *value* is specified, sets the end accessor to the specified function or key and returns the current class instance. If *value* is not specified, returns the current end accessor.
251
+ @param {Function|String} [*value*]
252
+ @chainable
253
+ */ key: "end",
254
+ value: function end(_) {
255
+ if (arguments.length) {
256
+ if (typeof _ === "function") this._end = _;
257
+ else {
258
+ this._end = accessor(_);
259
+ if (!this._aggs[_]) this._aggs[_] = max;
260
+ }
261
+ return this;
262
+ } else return this._end;
263
+ }
264
+ },
265
+ {
266
+ /**
267
+ @memberof Priestley
268
+ @desc Sets the [paddingInner](https://github.com/d3/d3-scale#band_paddingInner) value of the underlining [Band Scale](https://github.com/d3/d3-scale#band-scales) used to determine the height of each bar. Values should be a ratio between 0 and 1 representing the space in between each rectangle.
269
+ @param {Number} [*value* = 0.05]
270
+ @chainable
271
+ */ key: "paddingInner",
272
+ value: function paddingInner(_) {
273
+ return arguments.length ? (this._paddingInner = _, this) : this._paddingInner;
274
+ }
275
+ },
276
+ {
277
+ /**
278
+ @memberof Priestley
279
+ @desc Sets the [paddingOuter](https://github.com/d3/d3-scale#band_paddingOuter) value of the underlining [Band Scale](https://github.com/d3/d3-scale#band-scales) used to determine the height of each bar. Values should be a ratio between 0 and 1 representing the space around the outer rectangles.
280
+ @param {Number} [*value* = 0.05]
281
+ @chainable
282
+ */ key: "paddingOuter",
283
+ value: function paddingOuter(_) {
284
+ return arguments.length ? (this._paddingOuter = _, this) : this._paddingOuter;
285
+ }
286
+ },
287
+ {
288
+ /**
289
+ @memberof Priestley
290
+ @desc If *value* is specified, sets the start accessor to the specified function or key and returns the current class instance. If *value* is not specified, returns the current start accessor.
291
+ @param {Function|String} [*value*]
292
+ @chainable
293
+ */ key: "start",
294
+ value: function start(_) {
295
+ if (arguments.length) {
296
+ if (typeof _ === "function") this._start = _;
297
+ else {
298
+ this._start = accessor(_);
299
+ if (!this._aggs[_]) this._aggs[_] = min;
300
+ }
301
+ return this;
302
+ } else return this._start;
303
+ }
304
+ }
305
+ ]);
306
+ return Priestley;
307
+ }(Viz);
308
+ /**
309
+ @class Priestley
310
+ @extends Viz
311
+ @desc Creates a priestley timeline based on an array of data.
312
+ */ export { Priestley as default };
@@ -0,0 +1,365 @@
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, max, sum } from "d3-array";
98
+ import { nest } from "d3-collection";
99
+ import { pointer } from "d3-selection";
100
+ import { merge } from "@d3plus/data";
101
+ import { assign, elem } from "@d3plus/dom";
102
+ import { accessor, configPrep, constant } from "../utils/index.js";
103
+ import { Circle, Path, Rect } from "../shapes/index.js";
104
+ import Viz from "./Viz.js";
105
+ var tau = Math.PI * 2;
106
+ var Radar = /*#__PURE__*/ function(Viz) {
107
+ "use strict";
108
+ _inherits(Radar, Viz);
109
+ function Radar() {
110
+ _class_call_check(this, Radar);
111
+ var _this;
112
+ _this = _call_super(this, Radar);
113
+ _this._axisConfig = {
114
+ shapeConfig: {
115
+ fill: constant("none"),
116
+ labelConfig: {
117
+ fontColor: "#999",
118
+ padding: 0,
119
+ textAnchor: function(d, i, x) {
120
+ return x.textAnchor;
121
+ },
122
+ verticalAlign: "middle"
123
+ },
124
+ stroke: "#eee",
125
+ strokeWidth: constant(1)
126
+ }
127
+ };
128
+ _this._discrete = "metric";
129
+ _this._levels = 6;
130
+ _this._metric = accessor("metric");
131
+ _this._outerPadding = 100;
132
+ _this._shape = constant("Path");
133
+ _this._value = accessor("value");
134
+ return _this;
135
+ }
136
+ _create_class(Radar, [
137
+ {
138
+ /**
139
+ Extends the draw behavior of the abstract Viz class.
140
+ @private
141
+ */ key: "_draw",
142
+ value: function _draw(callback) {
143
+ var _loop = function(e) {
144
+ var event = events[e];
145
+ pathConfig.on[event] = function(d, i, s, e) {
146
+ var x = d.points.map(function(p) {
147
+ return p.x + width / 2;
148
+ });
149
+ var y = d.points.map(function(p) {
150
+ return p.y + height / 2;
151
+ });
152
+ var cursor = pointer(e, _this._select.node());
153
+ var xDist = x.map(function(p) {
154
+ return Math.abs(p - cursor[0]);
155
+ });
156
+ var yDist = y.map(function(p) {
157
+ return Math.abs(p - cursor[1]);
158
+ });
159
+ var dists = xDist.map(function(d, i) {
160
+ return d + yDist[i];
161
+ });
162
+ _this._on[event].bind(_this)(d.arr[dists.indexOf(min(dists))], i, s, e);
163
+ };
164
+ };
165
+ var _this = this;
166
+ _get(_get_prototype_of(Radar.prototype), "_draw", this).call(this, callback);
167
+ var height = this._height - this._margin.top - this._margin.bottom, width = this._width - this._margin.left - this._margin.right;
168
+ var radius = min([
169
+ height,
170
+ width
171
+ ]) / 2 - this._outerPadding, transform = "translate(".concat(width / 2, ", ").concat(height / 2, ")");
172
+ var nestedAxisData = nest().key(this._metric).entries(this._filteredData), nestedGroupData = nest().key(this._id).key(this._metric).entries(this._filteredData);
173
+ var maxValue = max(nestedGroupData.map(function(h) {
174
+ return h.values.map(function(d) {
175
+ return sum(d.values, function(x, i) {
176
+ return _this._value(x, i);
177
+ });
178
+ });
179
+ }).flat());
180
+ var circularAxis = Array.from(Array(this._levels).keys()).map(function(d) {
181
+ return {
182
+ id: d,
183
+ r: radius * ((d + 1) / _this._levels)
184
+ };
185
+ });
186
+ var circleConfig = configPrep.bind(this)(this._axisConfig.shapeConfig, "shape", "Circle");
187
+ delete circleConfig.label;
188
+ new Circle().data(circularAxis).select(elem("g.d3plus-Radar-radial-circles", {
189
+ parent: this._select,
190
+ enter: {
191
+ transform: transform
192
+ },
193
+ update: {
194
+ transform: transform
195
+ }
196
+ }).node()).config(circleConfig).render();
197
+ var totalAxis = nestedAxisData.length;
198
+ var polarAxis = nestedAxisData.map(function(d, i) {
199
+ var width = _this._outerPadding;
200
+ var fontSize = _this._shapeConfig.labelConfig.fontSize && _this._shapeConfig.labelConfig.fontSize(d, i) || 11;
201
+ var lineHeight = fontSize * 1.4;
202
+ var height = lineHeight * 2;
203
+ var padding = 10, quadrant = parseInt(360 - 360 / totalAxis * i / 90, 10) % 4 + 1, radians = tau / totalAxis * i;
204
+ var angle = 360 / totalAxis * i;
205
+ var textAnchor = "start";
206
+ var x = padding;
207
+ if (quadrant === 2 || quadrant === 3) {
208
+ x = -width - padding;
209
+ textAnchor = "end";
210
+ angle += 180;
211
+ }
212
+ var labelBounds = {
213
+ x: x,
214
+ y: -height / 2,
215
+ width: width,
216
+ height: height
217
+ };
218
+ return {
219
+ __d3plus__: true,
220
+ data: merge(d.values, _this._aggs),
221
+ i: i,
222
+ id: d.key,
223
+ angle: angle,
224
+ textAnchor: textAnchor,
225
+ labelBounds: labelBounds,
226
+ rotateAnchor: [
227
+ -x,
228
+ height / 2
229
+ ],
230
+ x: radius * Math.cos(radians),
231
+ y: radius * Math.sin(radians)
232
+ };
233
+ }).sort(function(a, b) {
234
+ return a.key - b.key;
235
+ });
236
+ new Rect().data(polarAxis).rotate(function(d) {
237
+ return d.angle || 0;
238
+ }).width(0).height(0).x(function(d) {
239
+ return d.x;
240
+ }).y(function(d) {
241
+ return d.y;
242
+ }).label(function(d) {
243
+ return d.id;
244
+ }).labelBounds(function(d) {
245
+ return d.labelBounds;
246
+ }).labelConfig(this._axisConfig.shapeConfig.labelConfig).select(elem("g.d3plus-Radar-text", {
247
+ parent: this._select,
248
+ enter: {
249
+ transform: transform
250
+ },
251
+ update: {
252
+ transform: transform
253
+ }
254
+ }).node()).render();
255
+ new Path().data(polarAxis).d(function(d) {
256
+ return "M".concat(0, ",", 0, " ").concat(-d.x, ",").concat(-d.y);
257
+ }).select(elem("g.d3plus-Radar-axis", {
258
+ parent: this._select,
259
+ enter: {
260
+ transform: transform
261
+ },
262
+ update: {
263
+ transform: transform
264
+ }
265
+ }).node()).config(configPrep.bind(this)(this._axisConfig.shapeConfig, "shape", "Path")).render();
266
+ var groupData = nestedGroupData.map(function(h) {
267
+ var q = h.values.map(function(d, i) {
268
+ var value = sum(d.values, function(x, i) {
269
+ return _this._value(x, i);
270
+ });
271
+ var r = value / maxValue * radius, radians = tau / totalAxis * i;
272
+ return {
273
+ x: r * Math.cos(radians),
274
+ y: r * Math.sin(radians)
275
+ };
276
+ });
277
+ var d = "M ".concat(q[0].x, " ").concat(q[0].y, " ").concat(q.map(function(l) {
278
+ return "L ".concat(l.x, " ").concat(l.y);
279
+ }).join(" "), " L ").concat(q[0].x, " ").concat(q[0].y);
280
+ return {
281
+ arr: h.values.map(function(d) {
282
+ return merge(d.values, _this._aggs);
283
+ }),
284
+ id: h.key,
285
+ points: q,
286
+ d: d,
287
+ __d3plus__: true,
288
+ data: merge(h.values.map(function(d) {
289
+ return merge(d.values, _this._aggs);
290
+ }), _this._aggs)
291
+ };
292
+ });
293
+ var pathConfig = configPrep.bind(this)(this._shapeConfig, "shape", "Path");
294
+ var events = Object.keys(pathConfig.on);
295
+ pathConfig.on = {};
296
+ for(var e = 0; e < events.length; e++)_loop(e);
297
+ this._shapes.push(new Path().data(groupData).d(function(d) {
298
+ return d.d;
299
+ }).select(elem("g.d3plus-Radar-items", {
300
+ parent: this._select,
301
+ enter: {
302
+ transform: transform
303
+ },
304
+ update: {
305
+ transform: transform
306
+ }
307
+ }).node()).config(pathConfig).render());
308
+ return this;
309
+ }
310
+ },
311
+ {
312
+ /**
313
+ @memberof Radar
314
+ @desc Sets the config method used for the radial spokes, circles, and labels.
315
+ @param {Object} *value*
316
+ @chainable
317
+ */ key: "axisConfig",
318
+ value: function axisConfig(_) {
319
+ return arguments.length ? (this._axisConfig = assign(this._axisConfig, _), this) : this._axisConfig;
320
+ }
321
+ },
322
+ {
323
+ /**
324
+ @memberof Radar
325
+ @desc Defines the value used as axis. If *value* is specified, sets the accessor to the specified metric function. If *value* is not specified, returns the current metric accessor.
326
+ @param {Function|String} *value*
327
+ @chainable
328
+ */ key: "metric",
329
+ value: function metric(_) {
330
+ return arguments.length ? (this._metric = typeof _ === "function" ? _ : accessor(_), this) : this._metric;
331
+ }
332
+ },
333
+ {
334
+ /**
335
+ @memberof Radar
336
+ @desc Determines how much pixel spaces to give the outer labels.
337
+ @param {Number} [*value* = 100]
338
+ @chainable
339
+ */ key: "outerPadding",
340
+ value: function outerPadding(_) {
341
+ return arguments.length ? (this._outerPadding = _, this) : this._outerPadding;
342
+ }
343
+ },
344
+ {
345
+ /**
346
+ @memberof Radar
347
+ @desc If *value* is specified, sets the value accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current value accessor.
348
+ @param {Function|String} *value*
349
+ @example
350
+ function value(d) {
351
+ return d.value;
352
+ }
353
+ */ key: "value",
354
+ value: function value(_) {
355
+ return arguments.length ? (this._value = typeof _ === "function" ? _ : accessor(_), this) : this._value;
356
+ }
357
+ }
358
+ ]);
359
+ return Radar;
360
+ }(Viz);
361
+ /**
362
+ @class Radar
363
+ @extends Viz
364
+ @desc Creates a radar visualization based on an array of data.
365
+ */ export { Radar as default };