@vizabi/bubblechart 3.13.2 → 3.14.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.13.2 build 1642697876953 Copyright 2022 Gapminder Foundation and contributors
1
+ // https://github.com/vizabi/bubblechart#readme v3.14.0 build 1642809388634 Copyright 2022 Gapminder Foundation and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('VizabiSharedComponents'), require('mobx')) :
4
4
  typeof define === 'function' && define.amd ? define(['VizabiSharedComponents', 'mobx'], factory) :
@@ -1026,7 +1026,8 @@
1026
1026
  zoomRect: this.element.select(".vzb-bc-zoom-rect"),
1027
1027
  eventArea: this.element.select(".vzb-bc-eventarea"),
1028
1028
  forecastOverlay: this.element.select(".vzb-bc-forecastoverlay"),
1029
- tooltipMobile: this.element.select(".vzb-tooltip-mobile")
1029
+ tooltipMobile: this.element.select(".vzb-tooltip-mobile"),
1030
+ defs: this.element.select("defs")
1030
1031
  };
1031
1032
  this.DOM.chartSvg.select(".vzb-bc-graph").call(graph =>
1032
1033
  Object.assign(this.DOM, {
@@ -1210,6 +1211,7 @@
1210
1211
  // this.addReaction(this._resetZoomMinMaxXReaction, this._resetZoomMinMaxX);
1211
1212
  // this.addReaction(this._resetZoomMinMaxYReaction, this._resetZoomMinMaxY);
1212
1213
  this.addReaction(this._updateOpacity);
1214
+ this.addReaction(this.updateColorPatterns);
1213
1215
  this.addReaction(this._updateShowYear);
1214
1216
  this.addReaction(this._updateYear);
1215
1217
  this.addReaction(this.drawData);
@@ -1230,6 +1232,41 @@
1230
1232
  //this.redrawData();
1231
1233
  }
1232
1234
 
1235
+ updateColorPatterns() {
1236
+ if (this.MDL.color.scale.isPattern) {
1237
+ const colorConcept = this.MDL.color.data.concept;
1238
+ this.DOM.defs.selectAll(".flag")
1239
+ .data(this.MDL.color.data.domainData, d => d[0])
1240
+ .enter()
1241
+ .append("pattern")
1242
+ .attr("id", d => `flag-${d[0]}-${this.id}`)
1243
+ .attr("class", "flag")
1244
+ .attr("width", "100%")
1245
+ .attr("height", "100%")
1246
+ .attr("patternContentUnits", "objectBoundingBox")
1247
+ .html(d => d[1][colorConcept])
1248
+ .each(function() {
1249
+ const svg = d3.select(this).select("svg");
1250
+ if (svg.empty()) return;
1251
+
1252
+ if (!svg.attr("viewBox"))
1253
+ svg.attr("viewBox", `0 0 ${svg.attr("width")} ${svg.attr("height")}`);
1254
+
1255
+ // xMidYMid: center the image in the circle
1256
+ // slice: scale the image to fill the circle
1257
+ if (!svg.attr("preserveAspectRatio"))
1258
+ svg.attr("preserveAspectRatio", "xMidYMid slice");
1259
+
1260
+ svg.attr("width", 1).attr("height", 1);
1261
+ });
1262
+ // .attr("xlink:href", function(d) {
1263
+ // return "flags/" + d.CountryCode + ".svg";
1264
+ // });
1265
+ } else {
1266
+ this.DOM.defs.selectAll(".flag").remove();
1267
+ }
1268
+ }
1269
+
1233
1270
  _updateShowYear() {
1234
1271
  this.DOM.date.classed("vzb-hidden", !this.ui.timeInBackground);
1235
1272
  }
@@ -1239,6 +1276,10 @@
1239
1276
  this._date.setText(this.MDL.frame.value, duration);
1240
1277
  }
1241
1278
 
1279
+ __getColor(key, valueC) {
1280
+ return valueC != null ? (this.MDL.color.scale.isPattern ? `url(#flag-${key}-${this.id})` : this.cScale(valueC)) : COLOR_WHITEISH;
1281
+ }
1282
+
1242
1283
  _createAndDeleteBubbles() {
1243
1284
  const _this = this;
1244
1285
  const duration = this._getDuration();
@@ -1310,7 +1351,7 @@
1310
1351
  d.r = VizabiSharedComponents.LegacyUtils.areaToRadius(_this.sScale(valueS || 0));
1311
1352
  const scaledX = _this.xScale(valueX);
1312
1353
  const scaledY = _this.yScale(valueY);
1313
- const scaledC = valueC != null ? _this.cScale(valueC) : COLOR_WHITEISH;
1354
+ const scaledC = _this.__getColor(d[Symbol.for(isTrail ? "trailHeadKey" : "key")], valueC);
1314
1355
 
1315
1356
  if (!duration || !headTrail) {
1316
1357
  circle
@@ -1340,10 +1381,10 @@
1340
1381
  .attr("x1", scaledX)
1341
1382
  .attr("y1", scaledY)
1342
1383
  .attr("x2", scaledX0)
1343
- .attr("y2", scaledY0)
1344
- .style("stroke", scaledC)
1384
+ .attr("y2", scaledY0)
1345
1385
  .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1346
- .attr("stroke-dashoffset", -d.r);
1386
+ .attr("stroke-dashoffset", -d.r)
1387
+ .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledC);
1347
1388
  }
1348
1389
  }
1349
1390
 
@@ -1382,7 +1423,7 @@
1382
1423
  //view.classed("vzb-hidden", d.hidden);
1383
1424
  const scaledX = _this.xScale(valueX);
1384
1425
  const scaledY = _this.yScale(valueY);
1385
- const scaledC = valueC != null ? _this.cScale(valueC) : COLOR_WHITEISH;
1426
+ const scaledC = _this.__getColor(d[Symbol.for(isTrail ? "trailHeadKey" : "key")], valueC);
1386
1427
 
1387
1428
  if (!duration || !headTrail) {
1388
1429
  const view = duration && !isTrail ?
@@ -1438,7 +1479,7 @@
1438
1479
  }
1439
1480
 
1440
1481
  trailLine
1441
- .style("stroke", scaledC)
1482
+ .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledC)
1442
1483
  .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1443
1484
  .attr("stroke-dashoffset", -d.r);
1444
1485
  }
@@ -1494,7 +1535,7 @@
1494
1535
  d.r = VizabiSharedComponents.LegacyUtils.areaToRadius(_this.sScale(valueS || 0));
1495
1536
  const scaledX = _this.xScale(valueX);
1496
1537
  const scaledY = _this.yScale(valueY);
1497
- const scaledC = valueC != null ? _this.cScale(valueC) : COLOR_WHITEISH;
1538
+ const scaledC = _this.__getColor(d[Symbol.for(isTrail ? "trailHeadKey" : "key")], valueC);
1498
1539
 
1499
1540
  const view = duration ?
1500
1541
  d3.select(this)
@@ -1544,7 +1585,7 @@
1544
1585
  .attr("y1", scaledY)
1545
1586
  .attr("x2", scaledX0)
1546
1587
  .attr("y2", scaledY0)
1547
- .style("stroke", scaledC)
1588
+ .style("stroke", _this.MDL.color.scale.isPattern ? null : scaledC)
1548
1589
  .attr("stroke-dasharray", Math.abs(scaledX - scaledX0) + Math.abs(scaledY - scaledY0))
1549
1590
  .attr("stroke-dashoffset", -d.r);
1550
1591
  }
@@ -2263,10 +2304,12 @@
2263
2304
  if (highlightedFilter.markers.size === 1) {
2264
2305
  const highlightedKey = highlightedFilter.markers.keys().next().value;
2265
2306
  const d = Object.assign(this.model.dataMap.getByStr(highlightedKey));
2307
+ const selectedKey = d[Symbol.for("trailHeadKey")] || d[Symbol.for("key")];
2308
+
2266
2309
  const x = _this.xScale(d[_this._alias("x")]);
2267
2310
  const y = _this.yScale(d[_this._alias("y")]);
2268
2311
  const s = d.r;
2269
- const c = d.color != null ? this.cScale(d.color) : COLOR_WHITEISH;
2312
+ const c = _this.__getColor(selectedKey, d.color);
2270
2313
  let entityOutOfView = false;
2271
2314
 
2272
2315
  ////const titles = _this._formatSTitleValues(values.size[utils.getKey(d, dataKeys.size)], values.color[utils.getKey(d, dataKeys.color)]);
@@ -2276,7 +2319,6 @@
2276
2319
  }
2277
2320
 
2278
2321
  //show tooltip
2279
- const selectedKey = d[Symbol.for("trailHeadKey")] || d[Symbol.for("key")];
2280
2322
  // const trailShow = this.MDL.trail.show;
2281
2323
  // const trailStarts = this.MDL.trail.starts;
2282
2324
  // const trailGroupDim = this.MDL.trail.groupDim;
@@ -2681,7 +2723,7 @@
2681
2723
  }
2682
2724
  });
2683
2725
 
2684
- BubbleChart.versionInfo = { version: "3.13.2", build: 1642697876953, package: {"homepage":"https://github.com/vizabi/bubblechart#readme","name":"@vizabi/bubblechart","description":"Vizabi bubble chart"}, sharedComponents: VizabiSharedComponents.versionInfo};
2726
+ BubbleChart.versionInfo = { version: "3.14.0", build: 1642809388634, package: {"homepage":"https://github.com/vizabi/bubblechart#readme","name":"@vizabi/bubblechart","description":"Vizabi bubble chart"}, sharedComponents: VizabiSharedComponents.versionInfo};
2685
2727
 
2686
2728
  return BubbleChart;
2687
2729