@evergis/charts 2.0.96 → 2.0.97

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.
@@ -1418,7 +1418,9 @@ const drawTooltip$1 = _ref => {
1418
1418
  stackedTooltip,
1419
1419
  tooltipLineTop,
1420
1420
  tooltipRoot,
1421
- tooltipClassName
1421
+ tooltipClassName,
1422
+ dotSnapping,
1423
+ lastIndex
1422
1424
  } = _ref;
1423
1425
  const container = tooltipRoot || document.querySelector('body');
1424
1426
  const format$1 = format(',');
@@ -1490,26 +1492,42 @@ const drawTooltip$1 = _ref => {
1490
1492
  return;
1491
1493
  }
1492
1494
 
1493
- let beginning = 0;
1494
- let end = line.getTotalLength();
1495
- let target = null;
1495
+ if (!dotSnapping) {
1496
+ let beginning = 0;
1497
+ let end = line.getTotalLength();
1498
+ let target = null;
1499
+
1500
+ while (true) {
1501
+ target = Math.floor((beginning + end) / 2);
1502
+ pos = line.getPointAtLength(target);
1496
1503
 
1497
- while (true) {
1498
- target = Math.floor((beginning + end) / 2);
1499
- pos = line.getPointAtLength(target);
1504
+ if ((target === end || target === beginning) && pos.x !== x) {
1505
+ break;
1506
+ }
1500
1507
 
1501
- if ((target === end || target === beginning) && pos.x !== x) {
1502
- break;
1508
+ if (pos.x > x) {
1509
+ end = target;
1510
+ } else if (pos.x < x) {
1511
+ beginning = target;
1512
+ } else {
1513
+ break;
1514
+ }
1503
1515
  }
1504
1516
 
1505
- if (pos.x > x) end = target;else if (pos.x < x) beginning = target;else break;
1517
+ positions[index] = pos;
1518
+ } else {
1519
+ const [x1, x2] = xScale.range();
1520
+ const chartWidth = x2 - x1;
1521
+ const step = chartWidth / lastIndex;
1522
+ positions[index] = {
1523
+ x: x1 + Math.round(currIndex) * step,
1524
+ y: typeof argData[index].values[Math.round(currIndex)] === "number" ? yScale(argData[index].values[Math.round(currIndex)]) : 0
1525
+ };
1506
1526
  }
1507
-
1508
- positions[index] = pos;
1509
1527
  });
1510
1528
  circles.attr('transform', (lineChartData, index) => {
1511
1529
  const value = getValue(lineChartData.values);
1512
- return positions[index] && value ? 'translate(' + x + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1530
+ return positions[index] && value ? 'translate(' + (!dotSnapping ? x : positions[index].x) + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1513
1531
  }).attr('style', _ref6 => {
1514
1532
  let {
1515
1533
  dynamicDotStyle
@@ -1548,14 +1566,20 @@ const drawTooltip$1 = _ref => {
1548
1566
  const dynamicDotOff = argData == null ? void 0 : argData[index].dynamicDotOff;
1549
1567
  return index === 0 || isVoid(value) || dynamicDotOff ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
1550
1568
  }, '0');
1551
- const labelTexts = labels && labels.style('left', left + "px").style('top', (_, i) => {
1569
+ const labelTexts = labels && labels.style('left', (_, i) => {
1570
+ var _positions$i$x, _positions$i;
1571
+
1572
+ return !dotSnapping ? left + "px" : ((_positions$i$x = (_positions$i = positions[i]) == null ? void 0 : _positions$i.x) != null ? _positions$i$x : 0) + "px";
1573
+ }).style('top', (_, i) => {
1574
+ var _positions$index$y, _positions$index, _positions$index$y2, _positions$index2;
1575
+
1552
1576
  const index = typeof stackedTooltipIndex === 'number' ? stackedTooltipIndex : stackedTooltip ? topIndex : i;
1553
- return (positions[index] && positions[index].y + (docY - nodeY)) + "px";
1577
+ return !dotSnapping ? ((_positions$index$y = (_positions$index = positions[index]) == null ? void 0 : _positions$index.y) != null ? _positions$index$y : 0) + (docY - nodeY) + "px" : ((_positions$index$y2 = (_positions$index2 = positions[index]) == null ? void 0 : _positions$index2.y) != null ? _positions$index$y2 : 0) + "px";
1554
1578
  }).select("." + lineChartClassNames.lineChartLabel);
1555
1579
 
1556
1580
  if (renderTooltip && labels) {
1557
1581
  labels.html((_, index) => {
1558
- const html = ReactDOMServer.renderToString(React.createElement(LabelContainer$1, {
1582
+ return ReactDOMServer.renderToString(React.createElement(LabelContainer$1, {
1559
1583
  className: lineChartClassNames.lineChartLabelFlex
1560
1584
  }, renderTooltip(datas, {
1561
1585
  indexX: Math.round(currIndex),
@@ -1563,7 +1587,6 @@ const drawTooltip$1 = _ref => {
1563
1587
  svg,
1564
1588
  event
1565
1589
  })));
1566
- return html;
1567
1590
  });
1568
1591
  } else {
1569
1592
  labelTexts && labelTexts.text((_, i) => {
@@ -1630,7 +1653,8 @@ const draw$3 = (node, props) => {
1630
1653
  customLine,
1631
1654
  tooltipClassName,
1632
1655
  xScaleItemWidth,
1633
- areaCurve
1656
+ areaCurve,
1657
+ dotSnapping
1634
1658
  } = props;
1635
1659
 
1636
1660
  if (node !== null && chartData.length) {
@@ -1823,7 +1847,9 @@ const draw$3 = (node, props) => {
1823
1847
  xScale,
1824
1848
  yScale,
1825
1849
  dynamicCircleRadius,
1826
- tooltipClassName
1850
+ tooltipClassName,
1851
+ dotSnapping,
1852
+ lastIndex
1827
1853
  });
1828
1854
  }
1829
1855