@d3plus/core 3.0.0-alpha.1 → 3.0.0-alpha.3

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.
@@ -69,7 +69,6 @@ var AreaPlot = /*#__PURE__*/ function(Plot) {
69
69
  _this._baseline = 0;
70
70
  _this._discrete = "x";
71
71
  _this._shape = constant("Area");
72
- _this.x("x");
73
72
  return _this;
74
73
  }
75
74
  return AreaPlot;
@@ -76,7 +76,6 @@ var BarChart = /*#__PURE__*/ function(Plot) {
76
76
  return defaultLegend.bind(_this)(config, arr);
77
77
  };
78
78
  _this._shape = constant("Bar");
79
- _this.x("x");
80
79
  return _this;
81
80
  }
82
81
  return BarChart;
@@ -69,7 +69,6 @@ var BoxWhisker = /*#__PURE__*/ function(Plot) {
69
69
  _this = _call_super(this, BoxWhisker);
70
70
  _this._discrete = "x";
71
71
  _this._shape = constant("Box");
72
- _this.x("x");
73
72
  _this._tooltipConfig = assign(_this._tooltipConfig, {
74
73
  title: function(d, i) {
75
74
  if (!d) return "";
@@ -75,7 +75,6 @@ var BumpChart = /*#__PURE__*/ function(Plot) {
75
75
  _this = _call_super(this, BumpChart);
76
76
  _this._discrete = "x";
77
77
  _this._shape = constant("Line");
78
- _this.x("x");
79
78
  _this.y2(function(d) {
80
79
  return _this._y(d);
81
80
  });
@@ -123,7 +122,6 @@ var BumpChart = /*#__PURE__*/ function(Plot) {
123
122
  new d3plus.Plot()
124
123
  .discrete("x")
125
124
  .shape("Line")
126
- .x("x")
127
125
  .y2(d => this._y(d))
128
126
  .yConfig({
129
127
  tickFormat: val => {
@@ -68,7 +68,6 @@ var LinePlot = /*#__PURE__*/ function(Plot) {
68
68
  _this = _call_super(this, LinePlot);
69
69
  _this._discrete = "x";
70
70
  _this._shape = constant("Line");
71
- _this.x("x");
72
71
  return _this;
73
72
  }
74
73
  return LinePlot;
@@ -173,10 +173,11 @@ var Pack = /*#__PURE__*/ function(Viz) {
173
173
  var defaultMouseMoveShape = _this._on["mousemove.shape"];
174
174
  _this._on["mousemove.shape"] = function(d, i, x, event) {
175
175
  if (d.__d3plusTooltip__) defaultMouseMoveShape(d, i, x, event);
176
+ var hoverData = recursionCircles(d, [
177
+ d
178
+ ]);
176
179
  _this.hover(function(h) {
177
- return recursionCircles(d, [
178
- d
179
- ]).includes(h);
180
+ return hoverData.includes(h);
180
181
  });
181
182
  };
182
183
  _this._pack = pack();
@@ -224,13 +225,13 @@ var Pack = /*#__PURE__*/ function(Viz) {
224
225
  values: nestedData
225
226
  }, function(d) {
226
227
  return d.values;
227
- }).sum(this._sum).sort(this._sort)).descendants();
228
- packData.forEach(function(d, i) {
228
+ }).sum(this._sum).sort(this._sort)).descendants().filter(function(d, i) {
229
229
  d.__d3plus__ = true;
230
230
  d.i = i;
231
- d.id = d.parent ? d.parent.data.key : null;
231
+ d.id = d.parent ? d.parent.data.key : "root";
232
232
  d.data.__d3plusOpacity__ = d.height ? _this._packOpacity(d.data, i) : 1;
233
233
  d.data.__d3plusTooltip__ = !d.height ? true : false;
234
+ return !d.children || d.children.length > 1;
234
235
  });
235
236
  this._shapes.push(new Circle().data(packData).select(elem("g.d3plus-Pack", {
236
237
  parent: this._select,
@@ -461,6 +461,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
461
461
  });
462
462
  _this._x = accessor("x");
463
463
  _this._xAxis = new AxisBottom().align("end");
464
+ _this._xKey = "x";
464
465
  _this._xTest = new AxisBottom().align("end").gridSize(0);
465
466
  _this._xConfig = {
466
467
  gridConfig: {
@@ -481,6 +482,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
481
482
  };
482
483
  _this._y = accessor("y");
483
484
  _this._yAxis = new AxisLeft().align("start");
485
+ _this._yKey = "y";
484
486
  _this._yTest = new AxisLeft().align("start").gridSize(0);
485
487
  _this._yConfig = {
486
488
  gridConfig: {
@@ -904,15 +906,15 @@ var Plot = /*#__PURE__*/ function(Viz) {
904
906
  var defaultY2Config = y2Exists ? {
905
907
  data: y2Data
906
908
  } : defaultConfig;
907
- var showX = this._discrete === "x" && this._width > this._discreteCutoff || this._width > this._xCutoff;
908
- var showY = this._discrete === "y" && this._height > this._discreteCutoff || this._height > this._yCutoff;
909
+ var showX = this._discrete === "x" ? this._width > this._discreteCutoff && this._width > this._xCutoff : this._width > this._xCutoff;
910
+ var showY = this._discrete === "y" ? this._height > this._discreteCutoff && this._height > this._yCutoff : this._height > this._yCutoff;
909
911
  var yC = {
910
912
  data: yData,
911
913
  locale: this._locale,
912
914
  rounding: this._yDomain ? "none" : "outside",
913
915
  scalePadding: y.padding ? y.padding() : 0
914
916
  };
915
- if (!showX) {
917
+ if (!showX && showY) {
916
918
  yC.barConfig = {
917
919
  stroke: "transparent"
918
920
  };
@@ -1002,7 +1004,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
1002
1004
  rounding: this._xDomain ? "none" : "outside",
1003
1005
  scalePadding: x.padding ? x.padding() : 0
1004
1006
  };
1005
- if (!showY) {
1007
+ if (!showY && showX) {
1006
1008
  xC.barConfig = {
1007
1009
  stroke: "transparent"
1008
1010
  };
@@ -1023,7 +1025,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
1023
1025
  padding: 0,
1024
1026
  rotate: 0,
1025
1027
  textAnchor: function(d) {
1026
- return d.id === xTicks[0] ? "start" : "end";
1028
+ return xTicks && d.id === xTicks[0] ? "start" : "end";
1027
1029
  }
1028
1030
  },
1029
1031
  labelRotation: false
@@ -1223,14 +1225,15 @@ var Plot = /*#__PURE__*/ function(Viz) {
1223
1225
  });
1224
1226
  var transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top + x2Height + topOffset, ")");
1225
1227
  var x2Transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top + topOffset, ")");
1226
- var xGroup = showX && elem("g.d3plus-plot-x-axis", {
1228
+ var xGroup = elem("g.d3plus-plot-x-axis", {
1227
1229
  parent: parent,
1228
1230
  transition: transition,
1229
1231
  enter: {
1230
1232
  transform: transform
1231
1233
  },
1232
1234
  update: {
1233
- transform: transform
1235
+ transform: transform,
1236
+ opacity: showX ? 1 : 0
1234
1237
  }
1235
1238
  });
1236
1239
  var x2Group = x2Exists && elem("g.d3plus-plot-x2-axis", {
@@ -1245,14 +1248,15 @@ var Plot = /*#__PURE__*/ function(Viz) {
1245
1248
  });
1246
1249
  var xTrans = xOffsetLeft > yWidth ? xOffsetLeft - yWidth : 0;
1247
1250
  var yTransform = "translate(".concat(this._margin.left + xTrans, ", ").concat(this._margin.top + topOffset, ")");
1248
- var yGroup = showY && elem("g.d3plus-plot-y-axis", {
1251
+ var yGroup = elem("g.d3plus-plot-y-axis", {
1249
1252
  parent: parent,
1250
1253
  transition: transition,
1251
1254
  enter: {
1252
1255
  transform: yTransform
1253
1256
  },
1254
1257
  update: {
1255
- transform: yTransform
1258
+ transform: yTransform,
1259
+ opacity: showY ? 1 : 0
1256
1260
  }
1257
1261
  });
1258
1262
  var y2Transform = "translate(-".concat(this._margin.right, ", ").concat(this._margin.top + topOffset, ")");
@@ -1266,7 +1270,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
1266
1270
  transform: y2Transform
1267
1271
  }
1268
1272
  });
1269
- this._xAxis.domain(xDomain).height(height - (x2Height + topOffset + verticalMargin)).maxSize(height / 2).range(xRange).select(showX ? xGroup.node() : undefined).ticks(xTicks).width(width).config(xC).config(this._xConfig).scale(xConfigScale).render();
1273
+ this._xAxis.domain(xDomain).height(height - (x2Height + topOffset + verticalMargin)).maxSize(height / 2).range(xRange).select(xGroup.node()).ticks(xTicks).width(width).config(xC).config(this._xConfig).scale(xConfigScale).render();
1270
1274
  if (x2Exists) {
1271
1275
  this._x2Axis.domain(x2Domain).height(height - (xHeight + topOffset + verticalMargin)).range(xRange).select(x2Group.node()).ticks(x2Ticks).width(width).config(xC).config(defaultX2Config).config(this._x2Config).scale(x2ConfigScale).render();
1272
1276
  }
@@ -1283,7 +1287,7 @@ var Plot = /*#__PURE__*/ function(Viz) {
1283
1287
  this._xAxis.outerBounds().y + x2Height,
1284
1288
  height - (xHeight + topOffset + verticalMargin)
1285
1289
  ];
1286
- this._yAxis.domain(yDomain).height(height).maxSize(width / 2).range(yRange).select(showY ? yGroup.node() : undefined).ticks(yTicks).width(xRange[xRange.length - 1]).config(yC).config(this._yConfig).scale(yConfigScale).render();
1290
+ this._yAxis.domain(yDomain).height(height).maxSize(width / 2).range(yRange).select(yGroup.node()).ticks(yTicks).width(xRange[xRange.length - 1]).config(yC).config(this._yConfig).scale(yConfigScale).render();
1287
1291
  if (y2Exists) {
1288
1292
  this._y2Axis.config(yC).domain(y2Exists ? y2Domain : yDomain).gridSize(0).height(height).range(yRange).select(y2Group.node()).width(width - max([
1289
1293
  0,
@@ -1336,6 +1340,8 @@ var Plot = /*#__PURE__*/ function(Viz) {
1336
1340
  return _this._yAxis._getPosition.bind(_this._yAxis)(d) - x2Height;
1337
1341
  }
1338
1342
  };
1343
+ var yOffset = this._xAxis.barConfig()["stroke-width"];
1344
+ if (yOffset) yOffset /= 2;
1339
1345
  new shapes.Rect().data([
1340
1346
  {}
1341
1347
  ]).select(rectGroup.node()).x(xRange[0] + (xRange[1] - xRange[0]) / 2).width(xRange[1] - xRange[0]).y(this._margin.top + topOffset + yRange[0] + (yRange[1] - yRange[0]) / 2).height(yRange[1] - yRange[0]).config(this._backgroundConfig).render();
@@ -1445,8 +1451,6 @@ var Plot = /*#__PURE__*/ function(Viz) {
1445
1451
  });
1446
1452
  _this._previousAnnotations[layer] = annotationShapes;
1447
1453
  });
1448
- var yOffset = this._xAxis.barConfig()["stroke-width"];
1449
- if (yOffset) yOffset /= 2;
1450
1454
  var discrete1 = this._discrete || "x";
1451
1455
  var shapeConfig = {
1452
1456
  discrete: this._discrete,
@@ -1789,17 +1793,6 @@ Additionally, each config object can also contain an optional "layer" key, which
1789
1793
  {
1790
1794
  /**
1791
1795
  @memberof Plot
1792
- @desc Sets the discrete axis to the specified string. If *value* is not specified, returns the current discrete axis.
1793
- @param {String} *value*
1794
- @chainable
1795
- */ key: "discrete",
1796
- value: function discrete(_) {
1797
- return arguments.length ? (this._discrete = _, this) : this._discrete;
1798
- }
1799
- },
1800
- {
1801
- /**
1802
- @memberof Plot
1803
1796
  @desc When the width or height of the chart is less than or equal to this pixel value, the discrete axis will not be shown. This helps produce slick sparklines. Set this value to `0` to disable the behavior entirely.
1804
1797
  @param {Number} *value*
1805
1798
  @chainable
@@ -1969,8 +1962,8 @@ Additionally, each config object can also contain an optional "layer" key, which
1969
1962
  {
1970
1963
  /**
1971
1964
  @memberof Plot
1972
- @desc Sets the x accessor to the specified function or number. If *value* is not specified, returns the current x accessor.
1973
- @param {Function|Number} *value*
1965
+ @desc Sets the x accessor to the specified accessor Function or String representing which key in the data to reference. If *value* is not specified, returns the current x accessor.
1966
+ @param {Function|String} *value*
1974
1967
  @chainable
1975
1968
  */ key: "x",
1976
1969
  value: function x(_) {
@@ -1987,8 +1980,8 @@ Additionally, each config object can also contain an optional "layer" key, which
1987
1980
  {
1988
1981
  /**
1989
1982
  @memberof Plot
1990
- @desc Sets the x2 accessor to the specified function or number. If *value* is not specified, returns the current x2 accessor.
1991
- @param {Function|Number} *value*
1983
+ @desc Sets the x2 accessor to the specified accessor Function or String representing which key in the data to reference. If *value* is not specified, returns the current x2 accessor.
1984
+ @param {Function|String} *value*
1992
1985
  @chainable
1993
1986
  */ key: "x2",
1994
1987
  value: function x2(_) {
@@ -2082,8 +2075,8 @@ Additionally, each config object can also contain an optional "layer" key, which
2082
2075
  {
2083
2076
  /**
2084
2077
  @memberof Plot
2085
- @desc Sets the y accessor to the specified function or number. If *value* is not specified, returns the current y accessor.
2086
- @param {Function|Number} *value*
2078
+ @desc Sets the y accessor to the specified accessor Function or String representing which key in the data to reference. If *value* is not specified, returns the current y accessor.
2079
+ @param {Function|String} *value*
2087
2080
  @chainable
2088
2081
  */ key: "y",
2089
2082
  value: function y(_) {
@@ -2100,8 +2093,8 @@ Additionally, each config object can also contain an optional "layer" key, which
2100
2093
  {
2101
2094
  /**
2102
2095
  @memberof Plot
2103
- @desc Sets the y2 accessor to the specified function or number. If *value* is not specified, returns the current y2 accessor.
2104
- @param {Function|Number} *value*
2096
+ @desc Sets the y2 accessor to the specified accessor Function or String representing which key in the data to reference. If *value* is not specified, returns the current y2 accessor.
2097
+ @param {Function|String} *value*
2105
2098
  @chainable
2106
2099
  */ key: "y2",
2107
2100
  value: function y2(_) {
@@ -223,11 +223,13 @@ import mousemoveShape from "./events/mousemove.shape.js";
223
223
  import touchstartBody from "./events/touchstart.body.js";
224
224
  /**
225
225
  * Default padding logic that will return false if the screen is less than 600 pixels wide.
226
+ * @private
226
227
  */ function defaultPadding() {
227
228
  return typeof window !== "undefined" ? window.innerWidth > 600 : true;
228
229
  }
229
230
  /**
230
231
  * Turns an array of values into a list string.
232
+ * @private
231
233
  */ function listify(n) {
232
234
  return n.reduce(function(str, item, i) {
233
235
  if (!i) str += item;
@@ -707,6 +709,7 @@ var Viz = /*#__PURE__*/ function(BaseClass) {
707
709
  /**
708
710
  * Applies the threshold algorithm according to the type of chart used.
709
711
  * @param {Array} data The data to process.
712
+ * @private
710
713
  */ key: "_thresholdFunction",
711
714
  value: function _thresholdFunction(data) {
712
715
  return data;
@@ -80,7 +80,7 @@ import { accessor, BaseClass, constant } from "../utils/index.js";
80
80
  /**
81
81
  * Creates a reference element for popper.
82
82
  * @param {Number[]} position
83
- * @prrivate
83
+ * @private
84
84
  */ function generateReference() {
85
85
  var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [
86
86
  0,
@@ -91,6 +91,21 @@ import { pointDistance } from "@d3plus/math";
91
91
  import { strip } from "@d3plus/text";
92
92
  import { TextBox } from "../components/index.js";
93
93
  import { accessor, BaseClass, configPrep, constant } from "../utils/index.js";
94
+ /**
95
+ * @param {*} nodeList
96
+ * @param {*} classNames
97
+ * @private
98
+ */ function findLastIndexWithClass(nodeList, classNames) {
99
+ for(var x = 0; x < classNames.length; x++){
100
+ var className = classNames[x];
101
+ for(var i = nodeList.length - 1; i >= 0; i--){
102
+ if (nodeList[i].classList.contains(className)) {
103
+ return i; // Return the index if found
104
+ }
105
+ }
106
+ }
107
+ return 0; // Return -1 if no element is found with the class
108
+ }
94
109
  import Image from "./Image.js";
95
110
  var Shape = /*#__PURE__*/ function(BaseClass) {
96
111
  "use strict";
@@ -405,16 +420,28 @@ var Shape = /*#__PURE__*/ function(BaseClass) {
405
420
  this._group.selectAll("g.d3plus-".concat(this._name, "-shape, g.d3plus-").concat(this._name, "-image, g.d3plus-").concat(this._name, "-text, g.d3plus-").concat(this._name, "-hover")).selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(d, i) {
406
421
  if (!d) d = {};
407
422
  if (!d.parentNode) d.parentNode = this.parentNode;
423
+ if (!d.dataIndex) d.dataIndex = i;
424
+ var dataIndex = d.dataIndex;
408
425
  var parent = d.parentNode;
409
- if (select(this).classed("d3plus-textBox")) d = d.data;
426
+ var d3plusType = select(this).classed("d3plus-textBox") ? "textBox" : select(this).classed("d3plus-Image") ? "Image" : "Shape";
427
+ if (d3plusType === "textBox") d = d.data;
410
428
  if (d.__d3plusShape__ || d.__d3plus__) {
411
429
  while(d && (d.__d3plusShape__ || d.__d3plus__)){
412
430
  i = d.i;
413
431
  d = d.data;
414
432
  }
415
433
  } else i = that._data.indexOf(d);
416
- var group = !that._hover || typeof that._hover !== "function" || !that._hover(d, i) ? parent : that._hoverGroup.node();
417
- if (group !== this.parentNode) group.appendChild(this);
434
+ var notHovering = !that._hover || typeof that._hover !== "function" || !that._hover(d, i);
435
+ var group = notHovering ? parent : that._hoverGroup.node();
436
+ if (group !== this.parentNode) {
437
+ var offset = d3plusType === "textBox" ? findLastIndexWithClass(group.childNodes, [
438
+ "d3plus-Image",
439
+ "d3plus-Shape"
440
+ ]) : d3plusType === "Image" ? findLastIndexWithClass(group.childNodes, [
441
+ "d3plus-Shape"
442
+ ]) : 0;
443
+ group.insertBefore(this, group.childNodes[offset + dataIndex]);
444
+ }
418
445
  if (this.className.baseVal.includes("d3plus-Shape")) {
419
446
  if (parent === group) select(this).call(that._applyStyle.bind(that));
420
447
  else select(this).call(that._updateStyle.bind(that, select(this), that._hoverStyle));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3plus/core",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.3",
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.0-alpha.1",
38
- "@d3plus/data": "3.0.0-alpha.1",
39
- "@d3plus/dom": "3.0.0-alpha.1",
40
- "@d3plus/format": "3.0.0-alpha.1",
41
- "@d3plus/locales": "3.0.0-alpha.1",
42
- "@d3plus/math": "3.0.0-alpha.1",
43
- "@d3plus/text": "3.0.0-alpha.1",
37
+ "@d3plus/color": "3.0.0-alpha.3",
38
+ "@d3plus/data": "3.0.0-alpha.3",
39
+ "@d3plus/dom": "3.0.0-alpha.3",
40
+ "@d3plus/format": "3.0.0-alpha.3",
41
+ "@d3plus/locales": "3.0.0-alpha.3",
42
+ "@d3plus/math": "3.0.0-alpha.3",
43
+ "@d3plus/text": "3.0.0-alpha.3",
44
44
  "@popperjs/core": "^2.11.8",
45
45
  "d3-array": "^3.2.4",
46
46
  "d3-brush": "^3.0.0",