@vizabi/bubblechart 3.16.3 → 3.17.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.
@@ -1,4 +1,4 @@
1
- // https://github.com/vizabi/bubblechart#readme v3.16.3 build 1684270566053 Copyright 2023 Gapminder Foundation and contributors
1
+ // https://github.com/vizabi/bubblechart#readme v3.17.0 build 1684329878518 Copyright 2023 Gapminder Foundation and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@vizabi/shared-components'), require('d3'), require('mobx')) :
4
4
  typeof define === 'function' && define.amd ? define(['@vizabi/shared-components', 'd3', 'mobx'], factory) :
@@ -861,6 +861,7 @@
861
861
  const {ICON_QUESTION} = sharedComponents.Icons;
862
862
  const COLOR_WHITEISH = "rgb(253, 253, 253)";
863
863
  const COLOR_BLACKISH = "rgb(51, 51, 51)";
864
+ const THICK_LINE_THRESHOLD_FOR_DARKER_COLOR = 3;
864
865
 
865
866
  const marginScaleH = (marginMin, ratio = 0) => height => marginMin + height * ratio;
866
867
  const marginScaleW = (marginMin, ratio = 0) => width => marginMin + width * ratio;
@@ -878,6 +879,8 @@
878
879
  padding: 2,
879
880
  minRadiusPx: 0.5,
880
881
  maxRadiusPx: Math.max(0.5, MAX_RADIUS_EM * sharedComponents.LegacyUtils.hypotenuse(width, height)),
882
+ minTrailThicknessPx: 1,
883
+ maxTrailThicknessPx: 4,
881
884
  infoElHeight: 16,
882
885
  yAxisTitleBottomMargin: 6,
883
886
  xAxisTitleBottomMargin: 4
@@ -888,6 +891,8 @@
888
891
  padding: 2,
889
892
  minRadiusPx: 1,
890
893
  maxRadiusPx: Math.max(0.5, MAX_RADIUS_EM * sharedComponents.LegacyUtils.hypotenuse(width, height)),
894
+ minTrailThicknessPx: 2,
895
+ maxTrailThicknessPx: 6,
891
896
  infoElHeight: 20,
892
897
  yAxisTitleBottomMargin: 3,
893
898
  xAxisTitleBottomMargin: 4
@@ -898,6 +903,8 @@
898
903
  padding: 2,
899
904
  minRadiusPx: 1,
900
905
  maxRadiusPx: Math.max(0.5, MAX_RADIUS_EM * sharedComponents.LegacyUtils.hypotenuse(width, height)),
906
+ minTrailThicknessPx: 2,
907
+ maxTrailThicknessPx: 8,
901
908
  infoElHeight: 22,
902
909
  yAxisTitleBottomMargin: 3,//marginScaleH(4, 0.01)(height),
903
910
  xAxisTitleBottomMargin: marginScaleH(0, 0.01)(height),
@@ -1194,6 +1201,7 @@
1194
1201
  //this.MDL.trail.config.show = false;
1195
1202
  //this.ui.cursorMode = "plus";
1196
1203
  this.sScale = this.MDL.size.scale.d3Scale;
1204
+ this.trailSizeScale = this.MDL.size.scale.d3Scale.copy();
1197
1205
 
1198
1206
  this.TIMEDIM = this.MDL.frame.data.concept;
1199
1207
  this.KEYS = this.model.data.space.filter(dim => dim !== this.TIMEDIM);
@@ -1271,10 +1279,14 @@
1271
1279
  }
1272
1280
 
1273
1281
  __getColor(key, valueC) {
1274
- return valueC != null && !sharedComponents.LegacyUtils.isNaN(valueC) ? (this.MDL.color.scale.isPattern ? `url(#flag-${key}-${this.id})` : this.cScale(valueC)) : COLOR_WHITEISH;
1282
+ return valueC != null && !sharedComponents.LegacyUtils.isNaN(valueC)
1283
+ ? (this.MDL.color.scale.isPattern ? `url(#flag-${key}-${this.id})` : this.cScale(valueC))
1284
+ : COLOR_WHITEISH;
1275
1285
  }
1276
- __getColorForTrail(key, valueC) {
1277
- return valueC != null && !sharedComponents.LegacyUtils.isNaN(valueC) ? (this.MDL.color.scale.isPattern ? `url(#flag-${key}-${this.id})` : this.cScale(valueC)) : COLOR_BLACKISH;
1286
+ __getColorForTrail(valueC, valueS) {
1287
+ if(valueC == null || sharedComponents.LegacyUtils.isNaN(valueC) || this.MDL.color.scale.isPattern) return COLOR_BLACKISH;
1288
+ if(this.trailSizeScale(valueS) > THICK_LINE_THRESHOLD_FOR_DARKER_COLOR) return this.cScale(valueC);
1289
+ return this.MDL.color.scale.palette.getColorShade({colorID: valueC}) || COLOR_BLACKISH;
1278
1290
  }
1279
1291
 
1280
1292
  _createAndDeleteBubbles() {
@@ -1378,16 +1390,19 @@
1378
1390
 
1379
1391
  const scaledX0 = _this.xScale(dataNext[_this._alias("x")]);
1380
1392
  const scaledY0 = _this.yScale(dataNext[_this._alias("y")]);
1381
- const scaledCT = _this.__getColorForTrail(dataNext[Symbol.for(isTrail ? "trailHeadKey" : "key")], dataNext.color);
1393
+ const scaledCT = _this.__getColorForTrail(dataNext.color, dataNext.size);
1394
+
1395
+ const nextR = sharedComponents.LegacyUtils.areaToRadius(_this.sScale(dataNext.size || 0));
1396
+ const length = Math.sqrt( (scaledX - scaledX0)**2 + (scaledY - scaledY0)**2 ) - d.r - nextR;
1382
1397
 
1383
1398
  trailLine
1384
1399
  .attr("x1", scaledX)
1385
1400
  .attr("y1", scaledY)
1386
1401
  .attr("x2", scaledX0)
1387
1402
  .attr("y2", scaledY0)
1388
- .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1389
- .attr("stroke-dashoffset", -d.r)
1390
- .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledCT);
1403
+ .attr("stroke-dasharray", `0 ${d.r} ${length > 0 ? length : 0} ${nextR}`)
1404
+ .style("stroke-width", _this.trailSizeScale(dataNext.size))
1405
+ .style("stroke", scaledCT);
1391
1406
  }
1392
1407
  }
1393
1408
 
@@ -1467,7 +1482,7 @@
1467
1482
  const trailLine = group.select(".vzb-trail-line");
1468
1483
  const scaledX0 = _this.xScale(dataNext[_this._alias("x")]);
1469
1484
  const scaledY0 = _this.yScale(dataNext[_this._alias("y")]);
1470
- const scaledCT = _this.__getColorForTrail(dataNext[Symbol.for(isTrail ? "trailHeadKey" : "key")], dataNext.color);
1485
+ const scaledCT = _this.__getColorForTrail(dataNext.color, dataNext.size);
1471
1486
 
1472
1487
  trailLine
1473
1488
  .attr("x1", scaledX)
@@ -1485,10 +1500,13 @@
1485
1500
  .attr("y2", scaledY0);
1486
1501
  }
1487
1502
 
1503
+ const nextR = sharedComponents.LegacyUtils.areaToRadius(_this.sScale(dataNext.size || 0));
1504
+ const length = Math.sqrt( (scaledX - scaledX0)**2 + (scaledY - scaledY0)**2 ) - d.r - nextR;
1505
+
1488
1506
  trailLine
1489
- .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledCT)
1490
- .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1491
- .attr("stroke-dashoffset", -d.r);
1507
+ .style("stroke", scaledCT)
1508
+ .style("stroke-width", _this.trailSizeScale(dataNext.size))
1509
+ .attr("stroke-dasharray", `0 ${d.r} ${length > 0 ? length : 0} ${nextR}`);
1492
1510
  }
1493
1511
  }
1494
1512
 
@@ -1599,16 +1617,19 @@
1599
1617
  const dataNext = data[index + 1];
1600
1618
  const scaledX0 = _this.xScale(dataNext[_this._alias("x")]);
1601
1619
  const scaledY0 = _this.yScale(dataNext[_this._alias("y")]);
1602
- const scaledCT = _this.__getColorForTrail(dataNext[Symbol.for(isTrail ? "trailHeadKey" : "key")], dataNext.color);
1620
+ const scaledCT = _this.__getColorForTrail(dataNext.color, dataNext.size);
1621
+
1622
+ const nextR = sharedComponents.LegacyUtils.areaToRadius(_this.sScale(dataNext.size || 0));
1623
+ const length = Math.sqrt( (scaledX - scaledX0)**2 + (scaledY - scaledY0)**2 ) - d.r - nextR;
1603
1624
 
1604
1625
  trailLine
1605
1626
  .attr("x1", scaledX)
1606
1627
  .attr("y1", scaledY)
1607
1628
  .attr("x2", scaledX0)
1608
1629
  .attr("y2", scaledY0)
1609
- .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledCT)
1610
- .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1611
- .attr("stroke-dashoffset", -d.r);
1630
+ .style("stroke", scaledCT)
1631
+ .style("stroke-width", _this.trailSizeScale(dataNext.size))
1632
+ .attr("stroke-dasharray", `0 ${d.r} ${length > 0 ? length : 0} ${nextR}`);
1612
1633
  }
1613
1634
  });
1614
1635
 
@@ -2155,7 +2176,9 @@
2155
2176
 
2156
2177
  const {
2157
2178
  minRadiusPx,
2158
- maxRadiusPx
2179
+ maxRadiusPx,
2180
+ minTrailThicknessPx,
2181
+ maxTrailThicknessPx,
2159
2182
  } = this.profileConstants;
2160
2183
 
2161
2184
  //transfer min max radius to size dialog via root ui observable (probably a cleaner way is possible)
@@ -2170,6 +2193,7 @@
2170
2193
  d3.range(minArea, maxArea, (maxArea - minArea)/(this.sScale.domain().length - 1)).concat(maxArea);
2171
2194
 
2172
2195
  this.sScale.range(range);
2196
+ this.trailSizeScale.domain(this.MDL.size.scale.domain).range([minTrailThicknessPx, maxTrailThicknessPx]);
2173
2197
  }
2174
2198
 
2175
2199
  _setTooltip(tooltipText, x, y, s, c, d) {
@@ -2752,7 +2776,7 @@
2752
2776
  }
2753
2777
  });
2754
2778
 
2755
- BubbleChart.versionInfo = { version: "3.16.3", build: 1684270566053, package: {"homepage":"https://github.com/vizabi/bubblechart#readme","name":"@vizabi/bubblechart","description":"Vizabi bubble chart"}, sharedComponents: sharedComponents.versionInfo};
2779
+ BubbleChart.versionInfo = { version: "3.17.0", build: 1684329878518, package: {"homepage":"https://github.com/vizabi/bubblechart#readme","name":"@vizabi/bubblechart","description":"Vizabi bubble chart"}, sharedComponents: sharedComponents.versionInfo};
2756
2780
 
2757
2781
  return BubbleChart;
2758
2782