@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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v3.0.0-alpha.1
2
+ @d3plus/core v3.0.0-alpha.3
3
3
  Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
4
4
  Copyright (c) 2025 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -5059,14 +5059,6 @@
5059
5059
  /**
5060
5060
  @namespace {Object} formatLocale
5061
5061
  @desc A set of default locale formatters used when assigning suffixes and currency in numbers.
5062
- *
5063
- * | Name | Default | Description |
5064
- * |---|---|---|
5065
- * | separator | "" | Separation between the number with the suffix. |
5066
- * | suffixes | [] | List of suffixes used to format numbers. |
5067
- * | grouping | [3] | The array of group sizes, |
5068
- * | delimiters | {thousands: ",", decimal: "."} | Decimal and group separators. |
5069
- * | currency | ["$", ""] | The currency prefix and suffix. |
5070
5062
  */ var formatLocale$2 = {
5071
5063
  "ar-SA": {
5072
5064
  separator: "",
@@ -20604,15 +20596,6 @@
20604
20596
  /**
20605
20597
  @namespace {Object} colorDefaults
20606
20598
  @desc A set of default color values used when assigning colors based on data.
20607
- *
20608
- * | Name | Default | Description |
20609
- * |---|---|---|
20610
- * | dark | gray-7 | Used in the [contrast](#contrast) function when the color given is very light. |
20611
- * | light | gray-0 | Used in the [contrast](#contrast) function when the color given is very dark. |
20612
- * | missing | gray-4 | Used in the [assign](#assign) function when the value passed is `null` or `undefined`. |
20613
- * | off | red-9 | Used in the [assign](#assign) function when the value passed is `false`. |
20614
- * | on | green-9 | Used in the [assign](#assign) function when the value passed is `true`. |
20615
- * | scale | [indigo-900, yellow-600, red-900, green-900, orange-600, grape-900, cyan-600, pink-600, lime-600, blue-300, pink-300, lime-300, violet-300, cyan-100, orange-100, green-100, grape-100, red-100] | An ordinal scale used in the [assign](#assign) function for non-valid color strings and numbers. |
20616
20599
  */ var defaults = {
20617
20600
  dark: openColor$2.colors.gray[700],
20618
20601
  light: openColor$2.colors.gray[50],
@@ -22155,7 +22138,7 @@
22155
22138
  var angleStep = 5; // step size for angles (in degrees); has linear impact on running time
22156
22139
  var polyCache = {};
22157
22140
  /**
22158
- @typedef {Object} LargestRect
22141
+ @typedef {Object} largestRect
22159
22142
  @desc The returned Object of the largestRect function.
22160
22143
  @property {Number} width The width of the rectangle
22161
22144
  @property {Number} height The height of the rectangle
@@ -22180,7 +22163,7 @@
22180
22163
  @param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
22181
22164
  @param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
22182
22165
  @param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
22183
- @return {LargestRect}
22166
+ @return {largestRect}
22184
22167
  */ function largestRect(poly) {
22185
22168
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
22186
22169
  if (poly.length < 3) {
@@ -23171,6 +23154,21 @@
23171
23154
  }
23172
23155
  }
23173
23156
 
23157
+ /**
23158
+ * @param {*} nodeList
23159
+ * @param {*} classNames
23160
+ * @private
23161
+ */ function findLastIndexWithClass(nodeList, classNames) {
23162
+ for(let x = 0; x < classNames.length; x++){
23163
+ const className = classNames[x];
23164
+ for(let i = nodeList.length - 1; i >= 0; i--){
23165
+ if (nodeList[i].classList.contains(className)) {
23166
+ return i; // Return the index if found
23167
+ }
23168
+ }
23169
+ }
23170
+ return 0; // Return -1 if no element is found with the class
23171
+ }
23174
23172
  class Shape extends BaseClass {
23175
23173
  /**
23176
23174
  @memberof Shape
@@ -23366,16 +23364,28 @@
23366
23364
  this._group.selectAll(`g.d3plus-${this._name}-shape, g.d3plus-${this._name}-image, g.d3plus-${this._name}-text, g.d3plus-${this._name}-hover`).selectAll(".d3plus-Shape, .d3plus-Image, .d3plus-textBox").each(function(d, i) {
23367
23365
  if (!d) d = {};
23368
23366
  if (!d.parentNode) d.parentNode = this.parentNode;
23367
+ if (!d.dataIndex) d.dataIndex = i;
23368
+ const dataIndex = d.dataIndex;
23369
23369
  const parent = d.parentNode;
23370
- if (select(this).classed("d3plus-textBox")) d = d.data;
23370
+ const d3plusType = select(this).classed("d3plus-textBox") ? "textBox" : select(this).classed("d3plus-Image") ? "Image" : "Shape";
23371
+ if (d3plusType === "textBox") d = d.data;
23371
23372
  if (d.__d3plusShape__ || d.__d3plus__) {
23372
23373
  while(d && (d.__d3plusShape__ || d.__d3plus__)){
23373
23374
  i = d.i;
23374
23375
  d = d.data;
23375
23376
  }
23376
23377
  } else i = that._data.indexOf(d);
23377
- const group = !that._hover || typeof that._hover !== "function" || !that._hover(d, i) ? parent : that._hoverGroup.node();
23378
- if (group !== this.parentNode) group.appendChild(this);
23378
+ const notHovering = !that._hover || typeof that._hover !== "function" || !that._hover(d, i);
23379
+ const group = notHovering ? parent : that._hoverGroup.node();
23380
+ if (group !== this.parentNode) {
23381
+ const offset = d3plusType === "textBox" ? findLastIndexWithClass(group.childNodes, [
23382
+ "d3plus-Image",
23383
+ "d3plus-Shape"
23384
+ ]) : d3plusType === "Image" ? findLastIndexWithClass(group.childNodes, [
23385
+ "d3plus-Shape"
23386
+ ]) : 0;
23387
+ group.insertBefore(this, group.childNodes[offset + dataIndex]);
23388
+ }
23379
23389
  if (this.className.baseVal.includes("d3plus-Shape")) {
23380
23390
  if (parent === group) select(this).call(that._applyStyle.bind(that));
23381
23391
  else select(this).call(that._updateStyle.bind(that, select(this), that._hoverStyle));
@@ -31577,7 +31587,7 @@
31577
31587
  /**
31578
31588
  * Creates a reference element for popper.
31579
31589
  * @param {Number[]} position
31580
- * @prrivate
31590
+ * @private
31581
31591
  */ function generateReference(position = [
31582
31592
  0,
31583
31593
  0
@@ -33604,11 +33614,13 @@
33604
33614
 
33605
33615
  /**
33606
33616
  * Default padding logic that will return false if the screen is less than 600 pixels wide.
33617
+ * @private
33607
33618
  */ function defaultPadding() {
33608
33619
  return typeof window !== "undefined" ? window.innerWidth > 600 : true;
33609
33620
  }
33610
33621
  /**
33611
33622
  * Turns an array of values into a list string.
33623
+ * @private
33612
33624
  */ function listify(n) {
33613
33625
  return n.reduce((str, item, i)=>{
33614
33626
  if (!i) str += item;
@@ -33806,6 +33818,7 @@
33806
33818
  /**
33807
33819
  * Applies the threshold algorithm according to the type of chart used.
33808
33820
  * @param {Array} data The data to process.
33821
+ * @private
33809
33822
  */ _thresholdFunction(data) {
33810
33823
  return data;
33811
33824
  }
@@ -35773,15 +35786,15 @@
35773
35786
  const defaultY2Config = y2Exists ? {
35774
35787
  data: y2Data
35775
35788
  } : defaultConfig;
35776
- const showX = this._discrete === "x" && this._width > this._discreteCutoff || this._width > this._xCutoff;
35777
- const showY = this._discrete === "y" && this._height > this._discreteCutoff || this._height > this._yCutoff;
35789
+ const showX = this._discrete === "x" ? this._width > this._discreteCutoff && this._width > this._xCutoff : this._width > this._xCutoff;
35790
+ const showY = this._discrete === "y" ? this._height > this._discreteCutoff && this._height > this._yCutoff : this._height > this._yCutoff;
35778
35791
  const yC = {
35779
35792
  data: yData,
35780
35793
  locale: this._locale,
35781
35794
  rounding: this._yDomain ? "none" : "outside",
35782
35795
  scalePadding: y.padding ? y.padding() : 0
35783
35796
  };
35784
- if (!showX) {
35797
+ if (!showX && showY) {
35785
35798
  yC.barConfig = {
35786
35799
  stroke: "transparent"
35787
35800
  };
@@ -35851,7 +35864,7 @@
35851
35864
  rounding: this._xDomain ? "none" : "outside",
35852
35865
  scalePadding: x.padding ? x.padding() : 0
35853
35866
  };
35854
- if (!showY) {
35867
+ if (!showY && showX) {
35855
35868
  xC.barConfig = {
35856
35869
  stroke: "transparent"
35857
35870
  };
@@ -35871,7 +35884,7 @@
35871
35884
  labelConfig: {
35872
35885
  padding: 0,
35873
35886
  rotate: 0,
35874
- textAnchor: (d)=>d.id === xTicks[0] ? "start" : "end"
35887
+ textAnchor: (d)=>xTicks && d.id === xTicks[0] ? "start" : "end"
35875
35888
  },
35876
35889
  labelRotation: false
35877
35890
  };
@@ -36044,14 +36057,15 @@
36044
36057
  });
36045
36058
  const transform = `translate(${this._margin.left}, ${this._margin.top + x2Height + topOffset})`;
36046
36059
  const x2Transform = `translate(${this._margin.left}, ${this._margin.top + topOffset})`;
36047
- const xGroup = showX && elem("g.d3plus-plot-x-axis", {
36060
+ const xGroup = elem("g.d3plus-plot-x-axis", {
36048
36061
  parent,
36049
36062
  transition,
36050
36063
  enter: {
36051
36064
  transform
36052
36065
  },
36053
36066
  update: {
36054
- transform
36067
+ transform,
36068
+ opacity: showX ? 1 : 0
36055
36069
  }
36056
36070
  });
36057
36071
  const x2Group = x2Exists && elem("g.d3plus-plot-x2-axis", {
@@ -36066,14 +36080,15 @@
36066
36080
  });
36067
36081
  const xTrans = xOffsetLeft > yWidth ? xOffsetLeft - yWidth : 0;
36068
36082
  const yTransform = `translate(${this._margin.left + xTrans}, ${this._margin.top + topOffset})`;
36069
- const yGroup = showY && elem("g.d3plus-plot-y-axis", {
36083
+ const yGroup = elem("g.d3plus-plot-y-axis", {
36070
36084
  parent,
36071
36085
  transition,
36072
36086
  enter: {
36073
36087
  transform: yTransform
36074
36088
  },
36075
36089
  update: {
36076
- transform: yTransform
36090
+ transform: yTransform,
36091
+ opacity: showY ? 1 : 0
36077
36092
  }
36078
36093
  });
36079
36094
  const y2Transform = `translate(-${this._margin.right}, ${this._margin.top + topOffset})`;
@@ -36087,7 +36102,7 @@
36087
36102
  transform: y2Transform
36088
36103
  }
36089
36104
  });
36090
- 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();
36105
+ 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();
36091
36106
  if (x2Exists) {
36092
36107
  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();
36093
36108
  }
@@ -36104,7 +36119,7 @@
36104
36119
  this._xAxis.outerBounds().y + x2Height,
36105
36120
  height - (xHeight + topOffset + verticalMargin)
36106
36121
  ];
36107
- 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();
36122
+ 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();
36108
36123
  if (y2Exists) {
36109
36124
  this._y2Axis.config(yC).domain(y2Exists ? y2Domain : yDomain).gridSize(0).height(height).range(yRange).select(y2Group.node()).width(width - max$5([
36110
36125
  0,
@@ -36150,6 +36165,8 @@
36150
36165
  return this._yAxis._getPosition.bind(this._yAxis)(d) - x2Height;
36151
36166
  }
36152
36167
  };
36168
+ let yOffset = this._xAxis.barConfig()["stroke-width"];
36169
+ if (yOffset) yOffset /= 2;
36153
36170
  new Rect().data([
36154
36171
  {}
36155
36172
  ]).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();
@@ -36229,8 +36246,6 @@
36229
36246
  });
36230
36247
  this._previousAnnotations[layer] = annotationShapes;
36231
36248
  });
36232
- let yOffset = this._xAxis.barConfig()["stroke-width"];
36233
- if (yOffset) yOffset /= 2;
36234
36249
  const discrete = this._discrete || "x";
36235
36250
  const shapeConfig = {
36236
36251
  discrete: this._discrete,
@@ -36469,14 +36484,6 @@
36469
36484
  */ confidenceConfig(_) {
36470
36485
  return arguments.length ? (this._confidenceConfig = assign(this._confidenceConfig, _), this) : this._confidenceConfig;
36471
36486
  }
36472
- /**
36473
- @memberof Plot
36474
- @desc Sets the discrete axis to the specified string. If *value* is not specified, returns the current discrete axis.
36475
- @param {String} *value*
36476
- @chainable
36477
- */ discrete(_) {
36478
- return arguments.length ? (this._discrete = _, this) : this._discrete;
36479
- }
36480
36487
  /**
36481
36488
  @memberof Plot
36482
36489
  @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.
@@ -36603,8 +36610,8 @@
36603
36610
  }
36604
36611
  /**
36605
36612
  @memberof Plot
36606
- @desc Sets the x accessor to the specified function or number. If *value* is not specified, returns the current x accessor.
36607
- @param {Function|Number} *value*
36613
+ @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.
36614
+ @param {Function|String} *value*
36608
36615
  @chainable
36609
36616
  */ x(_) {
36610
36617
  if (arguments.length) {
@@ -36618,8 +36625,8 @@
36618
36625
  }
36619
36626
  /**
36620
36627
  @memberof Plot
36621
- @desc Sets the x2 accessor to the specified function or number. If *value* is not specified, returns the current x2 accessor.
36622
- @param {Function|Number} *value*
36628
+ @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.
36629
+ @param {Function|String} *value*
36623
36630
  @chainable
36624
36631
  */ x2(_) {
36625
36632
  if (arguments.length) {
@@ -36689,8 +36696,8 @@
36689
36696
  }
36690
36697
  /**
36691
36698
  @memberof Plot
36692
- @desc Sets the y accessor to the specified function or number. If *value* is not specified, returns the current y accessor.
36693
- @param {Function|Number} *value*
36699
+ @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.
36700
+ @param {Function|String} *value*
36694
36701
  @chainable
36695
36702
  */ y(_) {
36696
36703
  if (arguments.length) {
@@ -36704,8 +36711,8 @@
36704
36711
  }
36705
36712
  /**
36706
36713
  @memberof Plot
36707
- @desc Sets the y2 accessor to the specified function or number. If *value* is not specified, returns the current y2 accessor.
36708
- @param {Function|Number} *value*
36714
+ @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.
36715
+ @param {Function|String} *value*
36709
36716
  @chainable
36710
36717
  */ y2(_) {
36711
36718
  if (arguments.length) {
@@ -36966,6 +36973,7 @@
36966
36973
  });
36967
36974
  this._x = accessor("x");
36968
36975
  this._xAxis = new AxisBottom().align("end");
36976
+ this._xKey = "x";
36969
36977
  this._xTest = new AxisBottom().align("end").gridSize(0);
36970
36978
  this._xConfig = {
36971
36979
  gridConfig: {
@@ -36986,6 +36994,7 @@
36986
36994
  };
36987
36995
  this._y = accessor("y");
36988
36996
  this._yAxis = new AxisLeft().align("start");
36997
+ this._yKey = "y";
36989
36998
  this._yTest = new AxisLeft().align("start").gridSize(0);
36990
36999
  this._yConfig = {
36991
37000
  gridConfig: {
@@ -37015,7 +37024,6 @@
37015
37024
  this._baseline = 0;
37016
37025
  this._discrete = "x";
37017
37026
  this._shape = constant$9("Area");
37018
- this.x("x");
37019
37027
  }
37020
37028
  }
37021
37029
 
@@ -37036,7 +37044,6 @@
37036
37044
  return defaultLegend.bind(this)(config, arr);
37037
37045
  };
37038
37046
  this._shape = constant$9("Bar");
37039
- this.x("x");
37040
37047
  }
37041
37048
  }
37042
37049
 
@@ -37049,7 +37056,6 @@
37049
37056
  super();
37050
37057
  this._discrete = "x";
37051
37058
  this._shape = constant$9("Box");
37052
- this.x("x");
37053
37059
  this._tooltipConfig = assign(this._tooltipConfig, {
37054
37060
  title: (d, i)=>{
37055
37061
  if (!d) return "";
@@ -37074,7 +37080,6 @@
37074
37080
  super();
37075
37081
  this._discrete = "x";
37076
37082
  this._shape = constant$9("Line");
37077
- this.x("x");
37078
37083
  this.y2((d)=>this._y(d));
37079
37084
  this.yConfig({
37080
37085
  tickFormat: (val)=>{
@@ -51771,7 +51776,6 @@
51771
51776
  super();
51772
51777
  this._discrete = "x";
51773
51778
  this._shape = constant$9("Line");
51774
- this.x("x");
51775
51779
  }
51776
51780
  }
51777
51781
 
@@ -54120,13 +54124,13 @@
54120
54124
  ])(hierarchy({
54121
54125
  key: nestedData.key,
54122
54126
  values: nestedData
54123
- }, (d)=>d.values).sum(this._sum).sort(this._sort)).descendants();
54124
- packData.forEach((d, i)=>{
54127
+ }, (d)=>d.values).sum(this._sum).sort(this._sort)).descendants().filter((d, i)=>{
54125
54128
  d.__d3plus__ = true;
54126
54129
  d.i = i;
54127
- d.id = d.parent ? d.parent.data.key : null;
54130
+ d.id = d.parent ? d.parent.data.key : "root";
54128
54131
  d.data.__d3plusOpacity__ = d.height ? this._packOpacity(d.data, i) : 1;
54129
54132
  d.data.__d3plusTooltip__ = !d.height ? true : false;
54133
+ return !d.children || d.children.length > 1;
54130
54134
  });
54131
54135
  this._shapes.push(new Circle().data(packData).select(elem("g.d3plus-Pack", {
54132
54136
  parent: this._select,
@@ -54216,9 +54220,10 @@
54216
54220
  const defaultMouseMoveShape = this._on["mousemove.shape"];
54217
54221
  this._on["mousemove.shape"] = (d, i, x, event)=>{
54218
54222
  if (d.__d3plusTooltip__) defaultMouseMoveShape(d, i, x, event);
54219
- this.hover((h)=>recursionCircles(d, [
54220
- d
54221
- ]).includes(h));
54223
+ const hoverData = recursionCircles(d, [
54224
+ d
54225
+ ]);
54226
+ this.hover((h)=>hoverData.includes(h));
54222
54227
  };
54223
54228
  this._pack = pack();
54224
54229
  this._packOpacity = constant$9(0.25);