@d3plus/core 3.0.0-alpha.2 → 3.0.0-alpha.4

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.2
2
+ @d3plus/core v3.0.0-alpha.4
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
@@ -574,6 +574,21 @@
574
574
  }
575
575
  }
576
576
 
577
+ /**
578
+ * @param {*} nodeList
579
+ * @param {*} classNames
580
+ * @private
581
+ */ function findLastIndexWithClass(nodeList, classNames) {
582
+ for(let x = 0; x < classNames.length; x++){
583
+ const className = classNames[x];
584
+ for(let i = nodeList.length - 1; i >= 0; i--){
585
+ if (nodeList[i].classList.contains(className)) {
586
+ return i; // Return the index if found
587
+ }
588
+ }
589
+ }
590
+ return 0; // Return -1 if no element is found with the class
591
+ }
577
592
  class Shape extends BaseClass {
578
593
  /**
579
594
  @memberof Shape
@@ -769,16 +784,28 @@
769
784
  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) {
770
785
  if (!d) d = {};
771
786
  if (!d.parentNode) d.parentNode = this.parentNode;
787
+ if (!d.dataIndex) d.dataIndex = i;
788
+ const dataIndex = d.dataIndex;
772
789
  const parent = d.parentNode;
773
- if (d3Selection.select(this).classed("d3plus-textBox")) d = d.data;
790
+ const d3plusType = d3Selection.select(this).classed("d3plus-textBox") ? "textBox" : d3Selection.select(this).classed("d3plus-Image") ? "Image" : "Shape";
791
+ if (d3plusType === "textBox") d = d.data;
774
792
  if (d.__d3plusShape__ || d.__d3plus__) {
775
793
  while(d && (d.__d3plusShape__ || d.__d3plus__)){
776
794
  i = d.i;
777
795
  d = d.data;
778
796
  }
779
797
  } else i = that._data.indexOf(d);
780
- const group = !that._hover || typeof that._hover !== "function" || !that._hover(d, i) ? parent : that._hoverGroup.node();
781
- if (group !== this.parentNode) group.appendChild(this);
798
+ const notHovering = !that._hover || typeof that._hover !== "function" || !that._hover(d, i);
799
+ const group = notHovering ? parent : that._hoverGroup.node();
800
+ if (group !== this.parentNode) {
801
+ const offset = d3plusType === "textBox" ? findLastIndexWithClass(group.childNodes, [
802
+ "d3plus-Image",
803
+ "d3plus-Shape"
804
+ ]) : d3plusType === "Image" ? findLastIndexWithClass(group.childNodes, [
805
+ "d3plus-Shape"
806
+ ]) : 0;
807
+ group.insertBefore(this, group.childNodes[offset + dataIndex]);
808
+ }
782
809
  if (this.className.baseVal.includes("d3plus-Shape")) {
783
810
  if (parent === group) d3Selection.select(this).call(that._applyStyle.bind(that));
784
811
  else d3Selection.select(this).call(that._updateStyle.bind(that, d3Selection.select(this), that._hoverStyle));
@@ -6128,7 +6155,7 @@
6128
6155
  /**
6129
6156
  * Creates a reference element for popper.
6130
6157
  * @param {Number[]} position
6131
- * @prrivate
6158
+ * @private
6132
6159
  */ function generateReference(position = [
6133
6160
  0,
6134
6161
  0
@@ -7426,11 +7453,13 @@
7426
7453
 
7427
7454
  /**
7428
7455
  * Default padding logic that will return false if the screen is less than 600 pixels wide.
7456
+ * @private
7429
7457
  */ function defaultPadding() {
7430
7458
  return typeof window !== "undefined" ? window.innerWidth > 600 : true;
7431
7459
  }
7432
7460
  /**
7433
7461
  * Turns an array of values into a list string.
7462
+ * @private
7434
7463
  */ function listify(n) {
7435
7464
  return n.reduce((str, item, i)=>{
7436
7465
  if (!i) str += item;
@@ -7628,6 +7657,7 @@
7628
7657
  /**
7629
7658
  * Applies the threshold algorithm according to the type of chart used.
7630
7659
  * @param {Array} data The data to process.
7660
+ * @private
7631
7661
  */ _thresholdFunction(data) {
7632
7662
  return data;
7633
7663
  }
@@ -9603,7 +9633,7 @@
9603
9633
  rounding: this._yDomain ? "none" : "outside",
9604
9634
  scalePadding: y.padding ? y.padding() : 0
9605
9635
  };
9606
- if (!showX) {
9636
+ if (!showX && showY) {
9607
9637
  yC.barConfig = {
9608
9638
  stroke: "transparent"
9609
9639
  };
@@ -9673,7 +9703,7 @@
9673
9703
  rounding: this._xDomain ? "none" : "outside",
9674
9704
  scalePadding: x.padding ? x.padding() : 0
9675
9705
  };
9676
- if (!showY) {
9706
+ if (!showY && showX) {
9677
9707
  xC.barConfig = {
9678
9708
  stroke: "transparent"
9679
9709
  };
@@ -10293,14 +10323,6 @@
10293
10323
  */ confidenceConfig(_) {
10294
10324
  return arguments.length ? (this._confidenceConfig = dom.assign(this._confidenceConfig, _), this) : this._confidenceConfig;
10295
10325
  }
10296
- /**
10297
- @memberof Plot
10298
- @desc Sets the discrete axis to the specified string. If *value* is not specified, returns the current discrete axis.
10299
- @param {String} *value*
10300
- @chainable
10301
- */ discrete(_) {
10302
- return arguments.length ? (this._discrete = _, this) : this._discrete;
10303
- }
10304
10326
  /**
10305
10327
  @memberof Plot
10306
10328
  @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.
@@ -10427,8 +10449,8 @@
10427
10449
  }
10428
10450
  /**
10429
10451
  @memberof Plot
10430
- @desc Sets the x accessor to the specified function or number. If *value* is not specified, returns the current x accessor.
10431
- @param {Function|Number} *value*
10452
+ @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.
10453
+ @param {Function|String} *value*
10432
10454
  @chainable
10433
10455
  */ x(_) {
10434
10456
  if (arguments.length) {
@@ -10442,8 +10464,8 @@
10442
10464
  }
10443
10465
  /**
10444
10466
  @memberof Plot
10445
- @desc Sets the x2 accessor to the specified function or number. If *value* is not specified, returns the current x2 accessor.
10446
- @param {Function|Number} *value*
10467
+ @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.
10468
+ @param {Function|String} *value*
10447
10469
  @chainable
10448
10470
  */ x2(_) {
10449
10471
  if (arguments.length) {
@@ -10513,8 +10535,8 @@
10513
10535
  }
10514
10536
  /**
10515
10537
  @memberof Plot
10516
- @desc Sets the y accessor to the specified function or number. If *value* is not specified, returns the current y accessor.
10517
- @param {Function|Number} *value*
10538
+ @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.
10539
+ @param {Function|String} *value*
10518
10540
  @chainable
10519
10541
  */ y(_) {
10520
10542
  if (arguments.length) {
@@ -10528,8 +10550,8 @@
10528
10550
  }
10529
10551
  /**
10530
10552
  @memberof Plot
10531
- @desc Sets the y2 accessor to the specified function or number. If *value* is not specified, returns the current y2 accessor.
10532
- @param {Function|Number} *value*
10553
+ @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.
10554
+ @param {Function|String} *value*
10533
10555
  @chainable
10534
10556
  */ y2(_) {
10535
10557
  if (arguments.length) {
@@ -10790,6 +10812,7 @@
10790
10812
  });
10791
10813
  this._x = accessor("x");
10792
10814
  this._xAxis = new AxisBottom().align("end");
10815
+ this._xKey = "x";
10793
10816
  this._xTest = new AxisBottom().align("end").gridSize(0);
10794
10817
  this._xConfig = {
10795
10818
  gridConfig: {
@@ -10810,6 +10833,7 @@
10810
10833
  };
10811
10834
  this._y = accessor("y");
10812
10835
  this._yAxis = new AxisLeft().align("start");
10836
+ this._yKey = "y";
10813
10837
  this._yTest = new AxisLeft().align("start").gridSize(0);
10814
10838
  this._yConfig = {
10815
10839
  gridConfig: {
@@ -10839,7 +10863,6 @@
10839
10863
  this._baseline = 0;
10840
10864
  this._discrete = "x";
10841
10865
  this._shape = constant("Area");
10842
- this.x("x");
10843
10866
  }
10844
10867
  }
10845
10868
 
@@ -10860,7 +10883,6 @@
10860
10883
  return defaultLegend.bind(this)(config, arr);
10861
10884
  };
10862
10885
  this._shape = constant("Bar");
10863
- this.x("x");
10864
10886
  }
10865
10887
  }
10866
10888
 
@@ -10873,7 +10895,6 @@
10873
10895
  super();
10874
10896
  this._discrete = "x";
10875
10897
  this._shape = constant("Box");
10876
- this.x("x");
10877
10898
  this._tooltipConfig = dom.assign(this._tooltipConfig, {
10878
10899
  title: (d, i)=>{
10879
10900
  if (!d) return "";
@@ -10898,7 +10919,6 @@
10898
10919
  super();
10899
10920
  this._discrete = "x";
10900
10921
  this._shape = constant("Line");
10901
- this.x("x");
10902
10922
  this.y2((d)=>this._y(d));
10903
10923
  this.yConfig({
10904
10924
  tickFormat: (val)=>{
@@ -11622,7 +11642,6 @@
11622
11642
  super();
11623
11643
  this._discrete = "x";
11624
11644
  this._shape = constant("Line");
11625
- this.x("x");
11626
11645
  }
11627
11646
  }
11628
11647
 
@@ -12467,13 +12486,13 @@
12467
12486
  ])(d3Hierarchy.hierarchy({
12468
12487
  key: nestedData.key,
12469
12488
  values: nestedData
12470
- }, (d)=>d.values).sum(this._sum).sort(this._sort)).descendants();
12471
- packData.forEach((d, i)=>{
12489
+ }, (d)=>d.values).sum(this._sum).sort(this._sort)).descendants().filter((d, i)=>{
12472
12490
  d.__d3plus__ = true;
12473
12491
  d.i = i;
12474
- d.id = d.parent ? d.parent.data.key : null;
12492
+ d.id = d.parent ? d.parent.data.key : "root";
12475
12493
  d.data.__d3plusOpacity__ = d.height ? this._packOpacity(d.data, i) : 1;
12476
12494
  d.data.__d3plusTooltip__ = !d.height ? true : false;
12495
+ return !d.children || d.children.length > 1;
12477
12496
  });
12478
12497
  this._shapes.push(new Circle().data(packData).select(dom.elem("g.d3plus-Pack", {
12479
12498
  parent: this._select,
@@ -12563,9 +12582,10 @@
12563
12582
  const defaultMouseMoveShape = this._on["mousemove.shape"];
12564
12583
  this._on["mousemove.shape"] = (d, i, x, event)=>{
12565
12584
  if (d.__d3plusTooltip__) defaultMouseMoveShape(d, i, x, event);
12566
- this.hover((h)=>recursionCircles(d, [
12567
- d
12568
- ]).includes(h));
12585
+ const hoverData = recursionCircles(d, [
12586
+ d
12587
+ ]);
12588
+ this.hover((h)=>hoverData.includes(h));
12569
12589
  };
12570
12590
  this._pack = d3Hierarchy.pack();
12571
12591
  this._packOpacity = constant(0.25);