@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,14 @@
1
+ import { select } from "d3-selection";
2
+ import { stylize } from "@d3plus/dom";
3
+ /**
4
+ @name _drawAttribution
5
+ @desc Draws absolute positioned attribution text.
6
+ @private
7
+ */ export default function() {
8
+ var attr = select(this._select.node().parentNode).selectAll("div.d3plus-attribution").data(this._attribution ? [
9
+ 0
10
+ ] : []);
11
+ var attrEnter = attr.enter().append("div").attr("class", "d3plus-attribution");
12
+ attr.exit().remove();
13
+ attr = attr.merge(attrEnter).style("position", "absolute").html(this._attribution).style("right", "".concat(this._margin.right, "px")).style("bottom", "".concat(this._margin.bottom, "px")).call(stylize, this._attributionStyle);
14
+ }
@@ -0,0 +1,23 @@
1
+ import { elem } from "@d3plus/dom";
2
+ /**
3
+ @function _drawBack
4
+ @desc Draws a back button if there are states in this._history.
5
+ @private
6
+ */ export default function() {
7
+ var visible = this._history.length;
8
+ var backGroup = elem("g.d3plus-viz-back", {
9
+ parent: this._select,
10
+ duration: this._duration,
11
+ update: {
12
+ transform: "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")")
13
+ }
14
+ }).node();
15
+ this._backClass.data(visible ? [
16
+ {
17
+ text: "← ".concat(this._translate("Back")),
18
+ x: 0,
19
+ y: 0
20
+ }
21
+ ] : []).select(backGroup).config(this._backConfig).render();
22
+ this._margin.top += visible ? this._backClass.fontSize()() + this._backClass.padding()() * 2 : 0;
23
+ }
@@ -0,0 +1,69 @@
1
+ import { min } from "d3-array";
2
+ import { elem } from "@d3plus/dom";
3
+ /**
4
+ @function _drawColorScale
5
+ @desc Renders the color scale if this._colorScale is not falsey.
6
+ @private
7
+ */ export default function() {
8
+ var _this = this;
9
+ var data = this._data;
10
+ var position = this._colorScalePosition.bind(this)(this.config());
11
+ if (![
12
+ false,
13
+ "top",
14
+ "bottom",
15
+ "left",
16
+ "right"
17
+ ].includes(position)) position = "bottom";
18
+ var wide = [
19
+ "top",
20
+ "bottom"
21
+ ].includes(position);
22
+ var showColorScale = this._colorScale && position;
23
+ var padding = this._colorScalePadding() ? this._padding : {
24
+ top: 0,
25
+ right: 0,
26
+ bottom: 0,
27
+ left: 0
28
+ };
29
+ var availableWidth = this._width - (this._margin.left + this._margin.right + padding.left + padding.right);
30
+ var width = wide ? min([
31
+ this._colorScaleMaxSize,
32
+ availableWidth
33
+ ]) : this._width - (this._margin.left + this._margin.right);
34
+ var availableHeight = this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top);
35
+ var height = !wide ? min([
36
+ this._colorScaleMaxSize,
37
+ availableHeight
38
+ ]) : this._height - (this._margin.bottom + this._margin.top);
39
+ var transform = {
40
+ opacity: position ? 1 : 0,
41
+ transform: "translate(".concat(wide ? this._margin.left + padding.left + (availableWidth - width) / 2 : this._margin.left, ", ").concat(wide ? this._margin.top : this._margin.top + padding.top + (availableHeight - height) / 2, ")")
42
+ };
43
+ var scaleGroup = elem("g.d3plus-viz-colorScale", {
44
+ condition: showColorScale && !this._colorScaleConfig.select,
45
+ enter: transform,
46
+ parent: this._select,
47
+ duration: this._duration,
48
+ update: transform
49
+ }).node();
50
+ if (this._colorScale) {
51
+ var scaleData = data.filter(function(d, i) {
52
+ var c = _this._colorScale(d, i);
53
+ return c !== undefined && c !== null;
54
+ });
55
+ this._colorScaleClass.align({
56
+ bottom: "end",
57
+ left: "start",
58
+ right: "end",
59
+ top: "start"
60
+ }[position] || "bottom").duration(this._duration).data(scaleData).height(height).locale(this._locale).orient(position).select(scaleGroup).value(this._colorScale).width(width).config(this._colorScaleConfig).render();
61
+ if (showColorScale) {
62
+ var scaleBounds = this._colorScaleClass.outerBounds();
63
+ if (!this._colorScaleConfig.select && scaleBounds.height) {
64
+ if (wide) this._margin[position] += scaleBounds.height + this._legendClass.padding() * 2;
65
+ else this._margin[position] += scaleBounds.width + this._legendClass.padding() * 2;
66
+ }
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,120 @@
1
+ function _instanceof(left, right) {
2
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
3
+ return !!right[Symbol.hasInstance](left);
4
+ } else {
5
+ return left instanceof right;
6
+ }
7
+ }
8
+ import { rollup } from "d3-array";
9
+ import { merge } from "@d3plus/data";
10
+ import { elem } from "@d3plus/dom";
11
+ import { configPrep } from "../../utils/index.js";
12
+ var legendAttrs = [
13
+ "fill",
14
+ "opacity",
15
+ "texture"
16
+ ];
17
+ /**
18
+ @function legendLabel
19
+ @desc Default label function for the legend.
20
+ @private
21
+ */ export function legendLabel(d, i) {
22
+ return this._drawLabel(d, i, this._legendDepth);
23
+ }
24
+ /**
25
+ @function _drawLegend
26
+ @desc Renders the legend if this._legend is not falsy.
27
+ @param {Array} data The filtered data array to be displayed.
28
+ @private
29
+ */ export default function() {
30
+ var _this, _loop = function(x) {
31
+ var values = labels.map(function(l) {
32
+ return l[x];
33
+ });
34
+ if (!values.some(function(v) {
35
+ return _instanceof(v, Array);
36
+ }) && Array.from(new Set(values)).length === legendData.length) {
37
+ _this._legendDepth = x;
38
+ return "break";
39
+ }
40
+ };
41
+ var _this1 = this;
42
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
43
+ var legendData = [];
44
+ var getAttr = function(d, i, attr) {
45
+ var shape = _this1._shape(d, i);
46
+ if (attr === "fill" && shape === "Line") attr = "stroke";
47
+ var value = _this1._shapeConfig[shape] && _this1._shapeConfig[shape][attr] ? _this1._shapeConfig[shape][attr] : _this1._shapeConfig[attr];
48
+ return typeof value === "function" ? value.bind(_this1)(d, i) : value;
49
+ };
50
+ var fill = function(d, i) {
51
+ return legendAttrs.map(function(a) {
52
+ return getAttr(d, i, a);
53
+ }).join("_");
54
+ };
55
+ var rollupData = this._colorScale ? data.filter(function(d, i) {
56
+ return _this1._colorScale(d, i) === undefined;
57
+ }) : data;
58
+ rollup(rollupData, function(leaves) {
59
+ return legendData.push(merge(leaves, _this1._aggs));
60
+ }, fill);
61
+ legendData.sort(this._legendSort);
62
+ var labels = legendData.map(function(d, i) {
63
+ return _this1._ids(d, i).slice(0, _this1._drawDepth + 1);
64
+ });
65
+ this._legendDepth = 0;
66
+ for(var x = 0; x <= this._drawDepth; x++){
67
+ var _ret = (_this = this, _loop(x));
68
+ if (_ret === "break") break;
69
+ }
70
+ var hidden = function(d, i) {
71
+ var id = _this1._id(d, i);
72
+ if (_instanceof(id, Array)) id = id[0];
73
+ return _this1._hidden.includes(id) || _this1._solo.length && !_this1._solo.includes(id);
74
+ };
75
+ var legendBounds = this._legendClass.outerBounds();
76
+ var config = this.config();
77
+ var position = this._legendPosition.bind(this)(config);
78
+ if (![
79
+ false,
80
+ "top",
81
+ "bottom",
82
+ "left",
83
+ "right"
84
+ ].includes(position)) position = "bottom";
85
+ var wide = [
86
+ "top",
87
+ "bottom"
88
+ ].includes(position);
89
+ var padding = this._legendPadding() ? this._padding : {
90
+ top: 0,
91
+ right: 0,
92
+ bottom: 0,
93
+ left: 0
94
+ };
95
+ var transform = {
96
+ transform: "translate(".concat(wide ? this._margin.left + padding.left : this._margin.left, ", ").concat(wide ? this._margin.top : this._margin.top + padding.top, ")")
97
+ };
98
+ var visible = this._legend.bind(this)(config, legendData);
99
+ var legendGroup = elem("g.d3plus-viz-legend", {
100
+ condition: visible && !this._legendConfig.select,
101
+ enter: transform,
102
+ parent: this._select,
103
+ duration: this._duration,
104
+ update: transform
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({
107
+ fill: function(d, i) {
108
+ return hidden(d, i) ? _this1._hiddenColor(d, i) : getAttr(d, i, "fill");
109
+ },
110
+ labelConfig: {
111
+ fontOpacity: function(d, i) {
112
+ return hidden(d, i) ? _this1._hiddenOpacity(d, i) : 1;
113
+ }
114
+ }
115
+ }).config(this._legendConfig).render();
116
+ if (!this._legendConfig.select && legendBounds.height) {
117
+ if (wide) this._margin[position] += legendBounds.height + this._legendClass.padding() * 2;
118
+ else this._margin[position] += legendBounds.width + this._legendClass.padding() * 2;
119
+ }
120
+ }
@@ -0,0 +1,31 @@
1
+ import { elem } from "@d3plus/dom";
2
+ /**
3
+ @function _drawSubtitle
4
+ @desc Draws a subtitle if this._subtitle is defined.
5
+ @param {Array} [*data*] The currently filtered dataset.
6
+ @private
7
+ */ export default function() {
8
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
9
+ var text = this._subtitle ? this._subtitle(data) : false;
10
+ var padding = this._subtitlePadding() ? this._padding : {
11
+ top: 0,
12
+ right: 0,
13
+ bottom: 0,
14
+ left: 0
15
+ };
16
+ var transform = {
17
+ transform: "translate(".concat(this._margin.left + padding.left, ", ").concat(this._margin.top, ")")
18
+ };
19
+ var group = elem("g.d3plus-viz-subtitle", {
20
+ enter: transform,
21
+ parent: this._select,
22
+ duration: 0,
23
+ update: transform
24
+ }).node();
25
+ this._subtitleClass.data(text ? [
26
+ {
27
+ text: text
28
+ }
29
+ ] : []).locale(this._locale).select(group).width(this._width - (this._margin.left + this._margin.right + padding.left + padding.right)).config(this._subtitleConfig).render();
30
+ this._margin.top += text ? group.getBBox().height + this._subtitleConfig.padding * 2 : 0;
31
+ }
@@ -0,0 +1,80 @@
1
+ function _instanceof(left, right) {
2
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
3
+ return !!right[Symbol.hasInstance](left);
4
+ } else {
5
+ return left instanceof right;
6
+ }
7
+ }
8
+ import { extent } from "d3-array";
9
+ import { unique } from "@d3plus/data";
10
+ import { date, elem } from "@d3plus/dom";
11
+ /**
12
+ @function setTimeFilter
13
+ @desc Determines whether or not to update the timeFilter method of the Viz.
14
+ @param {Array|Date} The timeline selection given from the d3 brush.
15
+ @private
16
+ */ function setTimeFilter(s) {
17
+ var _this = this;
18
+ if (!_instanceof(s, Array)) s = [
19
+ s,
20
+ s
21
+ ];
22
+ if (JSON.stringify(s) !== JSON.stringify(this._timelineSelection)) {
23
+ this._timelineSelection = s;
24
+ s = s.map(Number);
25
+ this.timeFilter(function(d) {
26
+ var ms = date(_this._time(d)).getTime();
27
+ return ms >= s[0] && ms <= s[1];
28
+ }).render();
29
+ }
30
+ }
31
+ /**
32
+ @function _drawTimeline
33
+ @desc Renders the timeline if this._time and this._timeline are not falsy and there are more than 1 tick available.
34
+ @param {Array} data The filtered data array to be displayed.
35
+ @private
36
+ */ export default function() {
37
+ var _this = this;
38
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
39
+ var timelinePossible = this._time && this._timeline;
40
+ var ticks = timelinePossible ? unique(this._data.map(this._time)).map(date) : [];
41
+ timelinePossible = timelinePossible && ticks.length > 1;
42
+ var padding = this._timelinePadding() ? this._padding : {
43
+ top: 0,
44
+ right: 0,
45
+ bottom: 0,
46
+ left: 0
47
+ };
48
+ var transform = {
49
+ transform: "translate(".concat(this._margin.left + padding.left, ", 0)")
50
+ };
51
+ var timelineGroup = elem("g.d3plus-viz-timeline", {
52
+ condition: timelinePossible,
53
+ enter: transform,
54
+ parent: this._select,
55
+ duration: this._duration,
56
+ update: transform
57
+ }).node();
58
+ if (timelinePossible) {
59
+ var timeline = this._timelineClass.domain(extent(ticks)).duration(this._duration).height(this._height - this._margin.bottom).locale(this._locale).select(timelineGroup).ticks(ticks.sort(function(a, b) {
60
+ return +a - +b;
61
+ })).width(this._width - (this._margin.left + this._margin.right + padding.left + padding.right));
62
+ var dataExtent = extent(data.map(this._time).map(date));
63
+ if (!this._timelineSelection) {
64
+ this._timelineSelection = this._timelineDefault || dataExtent;
65
+ } else {
66
+ if (this._timelineSelection[0] < dataExtent[0]) this._timelineSelection[0] = dataExtent[0];
67
+ if (this._timelineSelection[1] > dataExtent[1]) this._timelineSelection[1] = dataExtent[1];
68
+ }
69
+ timeline.selection(this._timelineSelection);
70
+ var config = this._timelineConfig;
71
+ timeline.config(config).on("brush", function(s) {
72
+ setTimeFilter.bind(_this)(s);
73
+ if (config.on && config.on.brush) config.on.brush(s);
74
+ }).on("end", function(s) {
75
+ setTimeFilter.bind(_this)(s);
76
+ if (config.on && config.on.end) config.on.end(s);
77
+ }).render();
78
+ this._margin.bottom += timeline.outerBounds().height + timeline.padding() * 2;
79
+ }
80
+ }
@@ -0,0 +1,31 @@
1
+ import { elem } from "@d3plus/dom";
2
+ /**
3
+ @function _drawTitle
4
+ @desc Draws a title if this._title is defined.
5
+ @param {Array} [*data*] The currently filtered dataset.
6
+ @private
7
+ */ export default function() {
8
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
9
+ var text = this._title ? this._title(data) : false;
10
+ var padding = this._titlePadding() ? this._padding : {
11
+ top: 0,
12
+ right: 0,
13
+ bottom: 0,
14
+ left: 0
15
+ };
16
+ var transform = {
17
+ transform: "translate(".concat(this._margin.left + padding.left, ", ").concat(this._margin.top, ")")
18
+ };
19
+ var group = elem("g.d3plus-viz-title", {
20
+ enter: transform,
21
+ parent: this._select,
22
+ duration: 0,
23
+ update: transform
24
+ }).node();
25
+ this._titleClass.data(text ? [
26
+ {
27
+ text: text
28
+ }
29
+ ] : []).locale(this._locale).select(group).width(this._width - (this._margin.left + this._margin.right + padding.left + padding.right)).config(this._titleConfig).render();
30
+ this._margin.top += text ? group.getBBox().height + this._titleConfig.padding * 2 : 0;
31
+ }
@@ -0,0 +1,32 @@
1
+ import { sum } from "d3-array";
2
+ import { elem } from "@d3plus/dom";
3
+ /**
4
+ @function _drawTotal
5
+ @desc Draws a total title if this._total is defined.
6
+ @param {Array} [*data*] The currently filtered dataset.
7
+ @private
8
+ */ export default function() {
9
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
10
+ var total = typeof this._total === "function" ? sum(data.map(this._total)) : this._total === true && this._size ? sum(data.map(this._size)) : false;
11
+ var padding = this._totalPadding() ? this._padding : {
12
+ top: 0,
13
+ right: 0,
14
+ bottom: 0,
15
+ left: 0
16
+ };
17
+ var transform = {
18
+ transform: "translate(".concat(this._margin.left + padding.left, ", ").concat(this._margin.top, ")")
19
+ };
20
+ var group = elem("g.d3plus-viz-total", {
21
+ enter: transform,
22
+ parent: this._select,
23
+ duration: 0,
24
+ update: transform
25
+ }).node();
26
+ this._totalClass.data(total ? [
27
+ {
28
+ text: this._totalFormat(total)
29
+ }
30
+ ] : []).locale(this._locale).select(group).width(this._width - (this._margin.left + this._margin.right + padding.left + padding.right)).config(this._totalConfig).render();
31
+ this._margin.top += total ? group.getBBox().height + this._totalConfig.padding * 2 : 0;
32
+ }
@@ -0,0 +1,254 @@
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_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ import { select } from "d3-selection";
48
+ import { zoomTransform } from "d3-zoom";
49
+ import { attrize, stylize } from "@d3plus/dom";
50
+ var brushing = false;
51
+ /**
52
+ @name zoomControls
53
+ @desc Sets up initial zoom events and controls.
54
+ @private
55
+ */ export default function() {
56
+ var _this = this;
57
+ if (!this._container || !this._zoomGroup) return;
58
+ var height = this._zoomHeight || this._height - this._margin.top - this._margin.bottom, that = this, width = this._zoomWidth || this._width - this._margin.left - this._margin.right;
59
+ this._zoomBehavior.extent([
60
+ [
61
+ 0,
62
+ 0
63
+ ],
64
+ [
65
+ width,
66
+ height
67
+ ]
68
+ ]).scaleExtent([
69
+ 1,
70
+ this._zoomMax
71
+ ]).translateExtent([
72
+ [
73
+ 0,
74
+ 0
75
+ ],
76
+ [
77
+ width,
78
+ height
79
+ ]
80
+ ]).on("zoom", function(event) {
81
+ return zoomed.bind(_this)(event.transform);
82
+ });
83
+ this._zoomToBounds = zoomToBounds.bind(this);
84
+ var control = select(this._select.node().parentNode).selectAll("div.d3plus-zoom-control").data(this._zoom ? [
85
+ 0
86
+ ] : []);
87
+ var controlEnter = control.enter().append("div").attr("class", "d3plus-zoom-control");
88
+ control.exit().remove();
89
+ control = control.merge(controlEnter).style("position", "absolute").style("top", "".concat(this._margin.top, "px")).style("left", "".concat(this._margin.left, "px"));
90
+ controlEnter.append("div").attr("class", "zoom-control zoom-in");
91
+ control.select(".zoom-in").on("click", zoomMath.bind(this, this._zoomFactor)).html("&#65291;");
92
+ controlEnter.append("div").attr("class", "zoom-control zoom-out");
93
+ control.select(".zoom-out").on("click", zoomMath.bind(this, 1 / this._zoomFactor)).html("&#65293;");
94
+ controlEnter.append("div").attr("class", "zoom-control zoom-reset");
95
+ control.select(".zoom-reset").on("click", zoomMath.bind(this, 0)).html("&#8634");
96
+ controlEnter.append("div").attr("class", "zoom-control zoom-brush");
97
+ control.select(".zoom-brush").on("click", function() {
98
+ select(this).classed("active", !brushing).call(stylize, brushing ? that._zoomControlStyle || {} : that._zoomControlStyleActive || {});
99
+ zoomEvents.bind(that)(!brushing);
100
+ }).html("&#164");
101
+ control.selectAll(".zoom-control").call(stylize, that._zoomControlStyle).on("mouseenter", function() {
102
+ select(this).call(stylize, that._zoomControlStyleHover || {});
103
+ }).on("mouseleave", function() {
104
+ select(this).call(stylize, select(this).classed("active") ? that._zoomControlStyleActive || {} : that._zoomControlStyle || {});
105
+ });
106
+ this._zoomBrush.extent([
107
+ [
108
+ 0,
109
+ 0
110
+ ],
111
+ [
112
+ width,
113
+ height
114
+ ]
115
+ ]).filter(function(event) {
116
+ return !event.button && event.detail < 2;
117
+ }).handleSize(this._zoomBrushHandleSize).on("start", brushStart.bind(this)).on("brush", brushBrush.bind(this)).on("end", brushEnd.bind(this));
118
+ var brushGroup = this._container.selectAll("g.brush").data([
119
+ 0
120
+ ]);
121
+ this._brushGroup = brushGroup.enter().append("g").attr("class", "brush").merge(brushGroup).call(this._zoomBrush);
122
+ zoomEvents.bind(this)();
123
+ if (this._renderTiles) this._renderTiles(zoomTransform(this._container.node()), 0);
124
+ }
125
+ /**
126
+ @name zoomEvents
127
+ @desc Handles adding/removing zoom event listeners.
128
+ @private
129
+ */ function zoomEvents() {
130
+ var brush = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
131
+ brushing = brush;
132
+ if (brushing) this._brushGroup.style("display", "inline");
133
+ else this._brushGroup.style("display", "none");
134
+ if (!brushing && this._zoom) {
135
+ this._container.call(this._zoomBehavior);
136
+ if (!this._zoomScroll) {
137
+ this._container.on("wheel.zoom", null);
138
+ }
139
+ if (!this._zoomPan) {
140
+ this._container.on("mousedown.zoom mousemove.zoom", null).on("touchstart.zoom touchmove.zoom touchend.zoom touchcancel.zoom", null);
141
+ }
142
+ } else {
143
+ this._container.on(".zoom", null);
144
+ }
145
+ }
146
+ /**
147
+ @name zoomed
148
+ @desc Handles events dispatched from this._zoomBehavior
149
+ @param {Object} [*transform* = event.transform]
150
+ @param {Number} [*duration* = 0]
151
+ @private
152
+ */ function zoomed() {
153
+ var transform = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false, duration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
154
+ if (this._zoomGroup) {
155
+ if (!duration) this._zoomGroup.attr("transform", transform);
156
+ else this._zoomGroup.transition().duration(duration).attr("transform", transform);
157
+ }
158
+ if (this._renderTiles) this._renderTiles(zoomTransform(this._container.node()), duration);
159
+ }
160
+ /**
161
+ @name zoomMath
162
+ @desc Zooms in or out based on the provided multiplier.
163
+ @param {Number} [*factor* = 0]
164
+ @private
165
+ */ function zoomMath() {
166
+ var factor = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
167
+ if (!this._container) return;
168
+ var center = this._zoomBehavior.extent().bind(document)()[1].map(function(d) {
169
+ return d / 2;
170
+ }), scaleExtent = this._zoomBehavior.scaleExtent(), t = zoomTransform(this._container.node());
171
+ if (!factor) {
172
+ t.k = scaleExtent[0];
173
+ t.x = 0;
174
+ t.y = 0;
175
+ } else {
176
+ var translate0 = [
177
+ (center[0] - t.x) / t.k,
178
+ (center[1] - t.y) / t.k
179
+ ];
180
+ t.k = Math.min(scaleExtent[1], t.k * factor);
181
+ if (t.k <= scaleExtent[0]) {
182
+ t.k = scaleExtent[0];
183
+ t.x = 0;
184
+ t.y = 0;
185
+ } else {
186
+ t.x += center[0] - (translate0[0] * t.k + t.x);
187
+ t.y += center[1] - (translate0[1] * t.k + t.y);
188
+ }
189
+ }
190
+ zoomed.bind(this)(t, this._duration);
191
+ }
192
+ /**
193
+ @name zoomToBounds
194
+ @desc Zooms to given bounds.
195
+ @param {Array} *bounds*
196
+ @param {Number} [*duration* = 0]
197
+ @private
198
+ */ function zoomToBounds(bounds) {
199
+ var duration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this._duration;
200
+ var scaleExtent = this._zoomBehavior.scaleExtent(), t = zoomTransform(this._container.node());
201
+ if (bounds) {
202
+ var _this__zoomBehavior_translateExtent_ = _sliced_to_array(this._zoomBehavior.translateExtent()[1], 2), width = _this__zoomBehavior_translateExtent_[0], height = _this__zoomBehavior_translateExtent_[1], dx = bounds[1][0] - bounds[0][0], dy = bounds[1][1] - bounds[0][1];
203
+ var k = Math.min(scaleExtent[1], 1 / Math.max(dx / width, dy / height));
204
+ var xMod, yMod;
205
+ if (dx / dy < width / height) {
206
+ k *= (height - this._zoomPadding * 2) / height;
207
+ xMod = (width - dx * k) / 2 / k;
208
+ yMod = this._zoomPadding / k;
209
+ } else {
210
+ k *= (width - this._zoomPadding * 2) / width;
211
+ yMod = (height - dy * k) / 2 / k;
212
+ xMod = this._zoomPadding / k;
213
+ }
214
+ t.x = (t.x - bounds[0][0] + xMod) * (t.k * k / t.k);
215
+ t.y = (t.y - bounds[0][1] + yMod) * (t.k * k / t.k);
216
+ t.k *= k;
217
+ if (t.x > 0) t.x = 0;
218
+ else if (t.x < width * -t.k + width) t.x = width * -t.k + width;
219
+ if (t.y > 0) t.y = 0;
220
+ else if (t.y < height * -t.k + height) t.y = height * -t.k + height;
221
+ } else {
222
+ t.k = scaleExtent[0];
223
+ t.x = 0;
224
+ t.y = 0;
225
+ }
226
+ zoomed.bind(this)(t, duration);
227
+ }
228
+ /**
229
+ @desc Triggered on brush "brush".
230
+ @private
231
+ */ function brushBrush() {
232
+ brushStyle.bind(this)();
233
+ }
234
+ /**
235
+ @desc Triggered on brush "end".
236
+ @private
237
+ */ function brushEnd(event) {
238
+ if (!event.selection) return; // Only transition after input.
239
+ this._brushGroup.call(this._zoomBrush.move, null);
240
+ zoomToBounds.bind(this)(event.selection);
241
+ }
242
+ /**
243
+ @desc Triggered on brush "start".
244
+ @private
245
+ */ function brushStart() {
246
+ brushStyle.bind(this)();
247
+ }
248
+ /**
249
+ @desc Overrides the default brush styles.
250
+ @private
251
+ */ function brushStyle() {
252
+ this._brushGroup.selectAll(".selection").call(attrize, this._zoomBrushSelectionStyle || {});
253
+ this._brushGroup.selectAll(".handle").call(attrize, this._zoomBrushHandleStyle || {});
254
+ }