@evergis/charts 2.0.95 → 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.
@@ -1,2 +1,2 @@
1
1
  import { DrawTooltipProps } from './types';
2
- export declare const drawTooltip: ({ svg, node, data: argData, xScale, yScale, dynamicCircleRadius, formatDynamicTooltip, renderTooltip, stackedTooltipIndex, stackedTooltip, tooltipLineTop, tooltipRoot, tooltipClassName, }: DrawTooltipProps) => void;
2
+ export declare const drawTooltip: ({ svg, node, data: argData, xScale, yScale, dynamicCircleRadius, formatDynamicTooltip, renderTooltip, stackedTooltipIndex, stackedTooltip, tooltipLineTop, tooltipRoot, tooltipClassName, dotSnapping, lastIndex, }: DrawTooltipProps) => void;
@@ -5,4 +5,5 @@ export declare type DrawTooltipProps = {
5
5
  node: HTMLElement;
6
6
  yScale: d3.ScaleLinear<number, number>;
7
7
  xScale: d3.ScaleLinear<number, number>;
8
- } & Pick<LineChartProps, 'data' | 'dynamicCircleRadius' | 'formatDynamicTooltip' | 'renderTooltip' | 'stackedTooltipIndex' | 'stackedTooltip' | 'tooltipLineTop' | 'tooltipRoot' | 'tooltipClassName'>;
8
+ lastIndex: number;
9
+ } & Pick<LineChartProps, 'data' | 'dynamicCircleRadius' | 'formatDynamicTooltip' | 'renderTooltip' | 'stackedTooltipIndex' | 'stackedTooltip' | 'tooltipLineTop' | 'tooltipRoot' | 'tooltipClassName' | 'dotSnapping'>;
@@ -49,6 +49,7 @@ export declare type LineChartProps = {
49
49
  tooltipRoot?: Element;
50
50
  tooltipClassName?: string;
51
51
  xScaleItemWidth?: number;
52
+ dotSnapping?: boolean;
52
53
  };
53
54
  export declare type LineChartDot = {
54
55
  radius?: number;
@@ -1426,7 +1426,9 @@ const drawTooltip$1 = _ref => {
1426
1426
  stackedTooltip,
1427
1427
  tooltipLineTop,
1428
1428
  tooltipRoot,
1429
- tooltipClassName
1429
+ tooltipClassName,
1430
+ dotSnapping,
1431
+ lastIndex
1430
1432
  } = _ref;
1431
1433
  const container = tooltipRoot || document.querySelector('body');
1432
1434
  const format = d3.format(',');
@@ -1498,26 +1500,42 @@ const drawTooltip$1 = _ref => {
1498
1500
  return;
1499
1501
  }
1500
1502
 
1501
- let beginning = 0;
1502
- let end = line.getTotalLength();
1503
- let target = null;
1503
+ if (!dotSnapping) {
1504
+ let beginning = 0;
1505
+ let end = line.getTotalLength();
1506
+ let target = null;
1507
+
1508
+ while (true) {
1509
+ target = Math.floor((beginning + end) / 2);
1510
+ pos = line.getPointAtLength(target);
1504
1511
 
1505
- while (true) {
1506
- target = Math.floor((beginning + end) / 2);
1507
- pos = line.getPointAtLength(target);
1512
+ if ((target === end || target === beginning) && pos.x !== x) {
1513
+ break;
1514
+ }
1508
1515
 
1509
- if ((target === end || target === beginning) && pos.x !== x) {
1510
- break;
1516
+ if (pos.x > x) {
1517
+ end = target;
1518
+ } else if (pos.x < x) {
1519
+ beginning = target;
1520
+ } else {
1521
+ break;
1522
+ }
1511
1523
  }
1512
1524
 
1513
- if (pos.x > x) end = target;else if (pos.x < x) beginning = target;else break;
1525
+ positions[index] = pos;
1526
+ } else {
1527
+ const [x1, x2] = xScale.range();
1528
+ const chartWidth = x2 - x1;
1529
+ const step = chartWidth / lastIndex;
1530
+ positions[index] = {
1531
+ x: x1 + Math.round(currIndex) * step,
1532
+ y: typeof argData[index].values[Math.round(currIndex)] === "number" ? yScale(argData[index].values[Math.round(currIndex)]) : 0
1533
+ };
1514
1534
  }
1515
-
1516
- positions[index] = pos;
1517
1535
  });
1518
1536
  circles.attr('transform', (lineChartData, index) => {
1519
1537
  const value = getValue(lineChartData.values);
1520
- return positions[index] && value ? 'translate(' + x + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1538
+ return positions[index] && value ? 'translate(' + (!dotSnapping ? x : positions[index].x) + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1521
1539
  }).attr('style', _ref6 => {
1522
1540
  let {
1523
1541
  dynamicDotStyle
@@ -1556,14 +1574,20 @@ const drawTooltip$1 = _ref => {
1556
1574
  const dynamicDotOff = argData == null ? void 0 : argData[index].dynamicDotOff;
1557
1575
  return index === 0 || isVoid(value) || dynamicDotOff ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
1558
1576
  }, '0');
1559
- const labelTexts = labels && labels.style('left', left + "px").style('top', (_, i) => {
1577
+ const labelTexts = labels && labels.style('left', (_, i) => {
1578
+ var _positions$i$x, _positions$i;
1579
+
1580
+ return !dotSnapping ? left + "px" : ((_positions$i$x = (_positions$i = positions[i]) == null ? void 0 : _positions$i.x) != null ? _positions$i$x : 0) + "px";
1581
+ }).style('top', (_, i) => {
1582
+ var _positions$index$y, _positions$index, _positions$index$y2, _positions$index2;
1583
+
1560
1584
  const index = typeof stackedTooltipIndex === 'number' ? stackedTooltipIndex : stackedTooltip ? topIndex : i;
1561
- return (positions[index] && positions[index].y + (docY - nodeY)) + "px";
1585
+ 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";
1562
1586
  }).select("." + lineChartClassNames.lineChartLabel);
1563
1587
 
1564
1588
  if (renderTooltip && labels) {
1565
1589
  labels.html((_, index) => {
1566
- const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
1590
+ return ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
1567
1591
  className: lineChartClassNames.lineChartLabelFlex
1568
1592
  }, renderTooltip(datas, {
1569
1593
  indexX: Math.round(currIndex),
@@ -1571,7 +1595,6 @@ const drawTooltip$1 = _ref => {
1571
1595
  svg,
1572
1596
  event
1573
1597
  })));
1574
- return html;
1575
1598
  });
1576
1599
  } else {
1577
1600
  labelTexts && labelTexts.text((_, i) => {
@@ -1638,7 +1661,8 @@ const draw$3 = (node, props) => {
1638
1661
  customLine,
1639
1662
  tooltipClassName,
1640
1663
  xScaleItemWidth,
1641
- areaCurve
1664
+ areaCurve,
1665
+ dotSnapping
1642
1666
  } = props;
1643
1667
 
1644
1668
  if (node !== null && chartData.length) {
@@ -1831,7 +1855,9 @@ const draw$3 = (node, props) => {
1831
1855
  xScale,
1832
1856
  yScale,
1833
1857
  dynamicCircleRadius,
1834
- tooltipClassName
1858
+ tooltipClassName,
1859
+ dotSnapping,
1860
+ lastIndex
1835
1861
  });
1836
1862
  }
1837
1863