@evergis/charts 2.0.12 → 2.0.17

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,3 +1,3 @@
1
1
  import { HorizontalBarChartProps } from '../../types';
2
2
  import { UseTooltip } from './types';
3
- export declare const useTooltip: ({ renderTooltip, tooltipBind, tooltipStyle, tooltipRoot, tooltipClassName, }: Pick<HorizontalBarChartProps, 'renderTooltip' | 'tooltipBind' | 'tooltipStyle' | 'tooltipRoot' | 'tooltipClassName'>) => UseTooltip;
3
+ export declare const useTooltip: ({ renderTooltip, tooltipBind, tooltipStyle, tooltipRoot, tooltipClassName, hideTooltip, }: Pick<HorizontalBarChartProps, 'renderTooltip' | 'tooltipBind' | 'tooltipStyle' | 'tooltipRoot' | 'tooltipClassName' | 'hideTooltip'>) => UseTooltip;
@@ -13,6 +13,7 @@ export declare type HorizontalBarChartProps = {
13
13
  maxValue?: number | undefined;
14
14
  formatNativeTitle?: (bar: HorizontalBarChartMarshalingData) => string;
15
15
  renderTooltip?: (bar: HorizontalBarChartMarshalingData[]) => ReactNode;
16
+ hideTooltip?: () => void;
16
17
  withTooltip?: boolean;
17
18
  fullooltip?: boolean;
18
19
  stackedTooltip?: boolean;
@@ -51,7 +51,7 @@ export declare type LineChartProps = {
51
51
  xScaleItemWidth?: number;
52
52
  };
53
53
  export declare type LineChartDot = {
54
- radius: number;
54
+ radius?: number;
55
55
  style?: string;
56
56
  filter?: (value: LineChartData, index: number, circles: (d3.BaseType | SVGCircleElement)[] | ArrayLike<d3.BaseType | SVGCircleElement>) => boolean;
57
57
  };
@@ -65,7 +65,9 @@ export declare type LineChartData = {
65
65
  style?: string;
66
66
  dot?: LineChartDot;
67
67
  dynamicDotStyle?: string;
68
+ dynamicDotOff?: boolean;
68
69
  areaStyle?: string;
70
+ tooltipOrder?: number;
69
71
  };
70
72
  export declare type LineChartDatas = Omit<LineChartData, 'values'> & {
71
73
  value: number | null;
@@ -1,2 +1,2 @@
1
1
  import { DrawTooltipProps } from './types';
2
- export declare const drawTooltip: ({ fullChartTooltip, global, tooltipRoot, data, tooltipClassName, tooltipBind, renderTooltip, arc, allSlices, tooltipStyle, }: DrawTooltipProps) => void;
2
+ export declare const drawTooltip: ({ fullChartTooltip, global, tooltipRoot, data, tooltipClassName, tooltipBind, renderTooltip, arc, allSlices, tooltipStyle, width, height, radius, }: DrawTooltipProps) => void;
@@ -1,7 +1,8 @@
1
1
  import * as d3 from 'd3';
2
2
  import { PieChartProps, PieChartDatum } from '../types';
3
- export declare type DrawTooltipProps = Pick<PieChartProps, 'fullChartTooltip' | 'tooltipRoot' | 'data' | 'tooltipClassName' | 'tooltipBind' | 'renderTooltip' | 'tooltipStyle'> & {
3
+ export declare type DrawTooltipProps = Pick<PieChartProps, 'fullChartTooltip' | 'tooltipRoot' | 'data' | 'tooltipClassName' | 'tooltipBind' | 'renderTooltip' | 'tooltipStyle' | 'width' | 'height'> & {
4
4
  global: d3.Selection<SVGGElement, unknown, null, undefined>;
5
5
  allSlices: d3.Selection<SVGPathElement, PieChartDatum, SVGGElement, unknown>;
6
6
  arc: d3.Arc<any, d3.DefaultArcObject>;
7
+ radius: number;
7
8
  };
@@ -13,5 +13,6 @@ export declare const pieChartclassNames: {
13
13
  pieTooltipName: string;
14
14
  pieTooltipValue: string;
15
15
  pieTooltipColorBox: string;
16
+ pieFullChartTooltipCircle: string;
16
17
  };
17
18
  export declare const SvgWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -65,6 +65,42 @@ function _templateObject() {
65
65
  }
66
66
  const Wrapper = /*#__PURE__*/styled__default.div( /*#__PURE__*/_templateObject());
67
67
 
68
+ function useNode() {
69
+ const [node, onSetNode] = React.useState(null);
70
+ const ref = React.useCallback(onSetNode, [onSetNode]);
71
+ return [ref, node];
72
+ }
73
+
74
+ function throttle(fn, wait) {
75
+ let isCalled = false;
76
+ return function () {
77
+ if (!isCalled) {
78
+ fn(...arguments);
79
+ isCalled = true;
80
+ setTimeout(function () {
81
+ isCalled = false;
82
+ }, wait);
83
+ }
84
+ };
85
+ }
86
+
87
+ const THROTTLE_DELAY = 44;
88
+ const useResize = (width, callback, delay) => {
89
+ const throttledCallback = React.useMemo(() => {
90
+ return callback ? throttle(callback, delay || THROTTLE_DELAY) : undefined;
91
+ }, [callback, delay]);
92
+ React.useEffect(() => {
93
+ throttledCallback && typeof width !== 'number' && window.addEventListener('resize', throttledCallback);
94
+ return () => throttledCallback && window.removeEventListener('resize', throttledCallback);
95
+ }, [width, throttledCallback]);
96
+ };
97
+
98
+ const appendSvg = (node, width, height) => {
99
+ d3.select(node).select('svg').remove();
100
+ const svg = d3.select(node).append('svg').attr('width', width).attr('height', height);
101
+ return svg;
102
+ };
103
+
68
104
  function _templateObject$1() {
69
105
  const data = _taggedTemplateLiteralLoose(["\n width: 100%;\n overflow: hidden;\n user-select: none;\n"]);
70
106
 
@@ -76,12 +112,6 @@ function _templateObject$1() {
76
112
  }
77
113
  const SwipeScrollContainer = /*#__PURE__*/styled__default.div( /*#__PURE__*/_templateObject$1());
78
114
 
79
- function useNode() {
80
- const [node, onSetNode] = React.useState(null);
81
- const ref = React.useCallback(onSetNode, [onSetNode]);
82
- return [ref, node];
83
- }
84
-
85
115
  function animate(_ref) {
86
116
  let {
87
117
  duration,
@@ -248,36 +278,6 @@ SwipeScroll.defaultProps = {
248
278
  duration: 1400
249
279
  };
250
280
 
251
- function throttle(fn, wait) {
252
- let isCalled = false;
253
- return function () {
254
- if (!isCalled) {
255
- fn(...arguments);
256
- isCalled = true;
257
- setTimeout(function () {
258
- isCalled = false;
259
- }, wait);
260
- }
261
- };
262
- }
263
-
264
- const THROTTLE_DELAY = 44;
265
- const useResize = (width, callback) => {
266
- const throttledCallback = React.useMemo(() => {
267
- return callback ? throttle(callback, THROTTLE_DELAY) : undefined;
268
- }, [callback]);
269
- React.useEffect(() => {
270
- throttledCallback && typeof width !== 'number' && window.addEventListener('resize', throttledCallback);
271
- return () => throttledCallback && window.removeEventListener('resize', throttledCallback);
272
- }, [width, throttledCallback]);
273
- };
274
-
275
- const appendSvg = (node, width, height) => {
276
- d3.select(node).select('svg').remove();
277
- const svg = d3.select(node).append('svg').attr('width', width).attr('height', height);
278
- return svg;
279
- };
280
-
281
281
  const degByIndex = (index, count) => {
282
282
  const degs = 360;
283
283
  const deg = degs / count * index;
@@ -726,7 +726,7 @@ function degreesToRadians(degrees) {
726
726
  }
727
727
 
728
728
  function _templateObject$5() {
729
- const data = _taggedTemplateLiteralLoose(["\n .", " {\n fill: #4a4a4a;\n }\n .", " {\n position: absolute;\n max-width: 128px;\n }\n .", " {\n stroke: #000;\n }\n"]);
729
+ const data = _taggedTemplateLiteralLoose(["\n .", " {\n fill: #4a4a4a;\n }\n .", " {\n position: absolute;\n max-width: 128px;\n }\n .", " {\n stroke: #000;\n }\n .", " {\n fill: transparent;\n cursor: pointer;\n }\n"]);
730
730
 
731
731
  _templateObject$5 = function _templateObject() {
732
732
  return data;
@@ -748,9 +748,10 @@ const pieChartclassNames = {
748
748
  pieTooltipItem: 'pieTooltipItem',
749
749
  pieTooltipName: 'pieTooltipName',
750
750
  pieTooltipValue: 'pieTooltipValue',
751
- pieTooltipColorBox: 'pieTooltipColorBox'
751
+ pieTooltipColorBox: 'pieTooltipColorBox',
752
+ pieFullChartTooltipCircle: 'pieFullChartTooltipCircle'
752
753
  };
753
- const SvgWrapper$1 = /*#__PURE__*/styled__default(Wrapper)( /*#__PURE__*/_templateObject$5(), pieChartclassNames.pieSliceLabel, pieChartclassNames.pieRadialLabel, pieChartclassNames.pieRadialLink);
754
+ const SvgWrapper$1 = /*#__PURE__*/styled__default(Wrapper)( /*#__PURE__*/_templateObject$5(), pieChartclassNames.pieSliceLabel, pieChartclassNames.pieRadialLabel, pieChartclassNames.pieRadialLink, pieChartclassNames.pieFullChartTooltipCircle);
754
755
 
755
756
  const getMidFactor = d => d.startAngle + (d.endAngle - d.startAngle) / 2 < Math.PI ? 1 : -1;
756
757
  const getAlign = d => {
@@ -979,7 +980,10 @@ const drawTooltip = (_ref) => {
979
980
  renderTooltip,
980
981
  arc,
981
982
  allSlices,
982
- tooltipStyle
983
+ tooltipStyle,
984
+ width,
985
+ height,
986
+ radius
983
987
  } = _ref;
984
988
  const container = tooltipRoot || document.querySelector('body');
985
989
  const format = d3.format(',');
@@ -1066,11 +1070,15 @@ const drawTooltip = (_ref) => {
1066
1070
 
1067
1071
  if (fullChartTooltip) {
1068
1072
  global.on('mouseover.fulltooltip', event => setTooltip(event));
1069
- global.on('mouseoutfulltooltip', () => {
1073
+ global.on('mouseout.fulltooltip', () => {
1070
1074
  tooltipContainer.html('');
1071
1075
  setVisible();
1072
1076
  });
1073
1077
 
1078
+ if (width && height) {
1079
+ global.append('circle').attr('class', pieChartclassNames.pieFullChartTooltipCircle).attr('r', radius).attr('cx', 0).attr('cy', 0);
1080
+ }
1081
+
1074
1082
  if (!tooltipBind) {
1075
1083
  global.on('touchmove.tooltipBind mousemove.tooltipBind', event => setPosition(event));
1076
1084
  }
@@ -1215,7 +1223,10 @@ const draw$1 = (node, props) => {
1215
1223
  renderTooltip,
1216
1224
  allSlices,
1217
1225
  arc,
1218
- tooltipStyle
1226
+ tooltipStyle,
1227
+ width,
1228
+ height,
1229
+ radius
1219
1230
  });
1220
1231
  }
1221
1232
 
@@ -1710,16 +1721,21 @@ const drawTooltip$1 = (_ref) => {
1710
1721
  const mouseRect = mouseGlobal.append('rect').attr('width', x2 - x1).attr('height', Math.abs(y1 - y2)).attr('class', lineChartClassNames.lineChartMouseRect).attr('transform', "translate(" + x1 + ", " + y2 + ")");
1711
1722
  const mouseLine = mouseGlobal.append('path').attr('class', lineChartClassNames.lineChartMouseLine).style('opacity', '0');
1712
1723
  const lines = svg.selectAll("." + lineChartClassNames.lineChartLine).nodes();
1713
- const circles = mouseGlobal.selectAll('circle').data(chartData).join('circle').attr('class', lineChartClassNames.lineChartMouseCircle).attr('r', dynamicCircleRadius).attr('fill', (_ref3) => {
1724
+ const circles = mouseGlobal.selectAll('circle').data(chartData.filter((_ref3) => {
1714
1725
  let {
1715
- stroke
1726
+ dynamicDotOff
1716
1727
  } = _ref3;
1717
- return stroke || 'none';
1718
- }).attr('stroke', (_ref4) => {
1728
+ return !dynamicDotOff;
1729
+ })).join('circle').attr('class', lineChartClassNames.lineChartMouseCircle).attr('r', dynamicCircleRadius).attr('fill', (_ref4) => {
1719
1730
  let {
1720
1731
  stroke
1721
1732
  } = _ref4;
1722
1733
  return stroke || 'none';
1734
+ }).attr('stroke', (_ref5) => {
1735
+ let {
1736
+ stroke
1737
+ } = _ref5;
1738
+ return stroke || 'none';
1723
1739
  }).style('opacity', '0');
1724
1740
  let labelContainer = d3.select("." + lineChartClassNames.lineChartMouseLabelContainer);
1725
1741
 
@@ -1780,27 +1796,27 @@ const drawTooltip$1 = (_ref) => {
1780
1796
  circles.attr('transform', (lineChartData, index) => {
1781
1797
  const value = getValue(lineChartData.values);
1782
1798
  return positions[index] && value ? 'translate(' + x + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1783
- }).attr('style', (_ref5) => {
1799
+ }).attr('style', (_ref6) => {
1784
1800
  let {
1785
1801
  dynamicDotStyle
1786
- } = _ref5;
1802
+ } = _ref6;
1787
1803
  return dynamicDotStyle || '';
1788
1804
  });
1789
- const datas = chartData.map((_ref6, i) => {
1805
+ const datas = chartData.map((_ref7, i) => {
1790
1806
  let {
1791
1807
  values
1792
- } = _ref6,
1793
- rest = _objectWithoutPropertiesLoose(_ref6, ["values"]);
1808
+ } = _ref7,
1809
+ rest = _objectWithoutPropertiesLoose(_ref7, ["values"]);
1794
1810
 
1795
1811
  return _extends({}, rest, {
1796
1812
  value: getValue(values),
1797
1813
  invertValue: positions[i] ? yScale.invert(positions[i].y) : 0
1798
1814
  });
1799
1815
  });
1800
- const noHasData = datas.every((_ref7) => {
1816
+ const noHasData = datas.every((_ref8) => {
1801
1817
  let {
1802
1818
  value
1803
- } = _ref7;
1819
+ } = _ref8;
1804
1820
  return isVoid(value);
1805
1821
  });
1806
1822
 
@@ -1815,7 +1831,8 @@ const drawTooltip$1 = (_ref) => {
1815
1831
 
1816
1832
  const prevValue = (_datas$Number = datas[Number(acc)]) == null ? void 0 : _datas$Number.value;
1817
1833
  const value = (_datas$Number2 = datas[Number(key)]) == null ? void 0 : _datas$Number2.value;
1818
- return index === 0 || isVoid(value) ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
1834
+ const dynamicDotOff = argData == null ? void 0 : argData[index].dynamicDotOff;
1835
+ return index === 0 || isVoid(value) || dynamicDotOff ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
1819
1836
  }, '0');
1820
1837
  const labelTexts = labels && labels.style('left', left + "px").style('top', (_, i) => {
1821
1838
  const index = typeof stackedTooltipIndex === 'number' ? stackedTooltipIndex : stackedTooltip ? topIndex : i;
@@ -2061,7 +2078,7 @@ const draw$3 = (node, props) => {
2061
2078
  filter
2062
2079
  } = dot;
2063
2080
  const dotsGroup = dotsGlobal.append('g').attr('class', lineChartClassNames.lineChartDotsGlobal);
2064
- dotsGroup.selectAll('circle').data(values).join('circle').attr('cx', (_, index) => xScale(index)).attr('class', lineChartClassNames.lineChartDot).attr('cy', d => yScale(d)).attr('r', radius).attr('style', style || '');
2081
+ dotsGroup.selectAll('circle').data(values).join('circle').attr('cx', (_, index) => xScale(index)).attr('class', lineChartClassNames.lineChartDot).attr('cy', d => yScale(d)).attr('r', radius || 0).attr('style', style || '');
2065
2082
 
2066
2083
  if (filter) {
2067
2084
  dotsGroup.selectAll('circle').select((_, i, g) => filter(item, i, g) ? g[i] : null).remove();
@@ -3155,7 +3172,7 @@ const Tooltip = (_ref) => {
3155
3172
  }
3156
3173
  }), name && React__default.createElement(Name$1, {
3157
3174
  className: horizontalBarChartClassNames.horizontalBarChartTooltipName
3158
- }, "name"), React__default.createElement(Value, {
3175
+ }, name), React__default.createElement(Value, {
3159
3176
  className: horizontalBarChartClassNames.horizontalBarChartTooltipValue
3160
3177
  }, format(value)));
3161
3178
  })));
@@ -3168,7 +3185,8 @@ const useTooltip = (_ref) => {
3168
3185
  tooltipBind,
3169
3186
  tooltipStyle,
3170
3187
  tooltipRoot,
3171
- tooltipClassName
3188
+ tooltipClassName,
3189
+ hideTooltip
3172
3190
  } = _ref;
3173
3191
  React.useEffect(() => {
3174
3192
  const container = tooltipRoot || document.querySelector('body');
@@ -3207,8 +3225,9 @@ const useTooltip = (_ref) => {
3207
3225
  const onMouseLeave = React.useCallback(() => {
3208
3226
  if (rootElement) {
3209
3227
  rootElement.style.visibility = 'hidden';
3228
+ hideTooltip && hideTooltip();
3210
3229
  }
3211
- }, []);
3230
+ }, [hideTooltip]);
3212
3231
  return [onMouseMove, onMouseLeave];
3213
3232
  };
3214
3233
 
@@ -3388,7 +3407,8 @@ const HorizontalBarChart = (_ref) => {
3388
3407
  thead,
3389
3408
  withoutXScale,
3390
3409
  stackedTooltip,
3391
- fullChartTooltip
3410
+ fullChartTooltip,
3411
+ hideTooltip
3392
3412
  } = _ref;
3393
3413
  const {
3394
3414
  fullMax,
@@ -3403,7 +3423,8 @@ const HorizontalBarChart = (_ref) => {
3403
3423
  renderTooltip,
3404
3424
  tooltipBind,
3405
3425
  tooltipStyle,
3406
- tooltipClassName
3426
+ tooltipClassName,
3427
+ hideTooltip
3407
3428
  });
3408
3429
  const Stack = useStackWrapper(stackedTooltip);
3409
3430
  return React__default.createElement(Table, {
@@ -3829,6 +3850,7 @@ exports.LineChart = LineChart;
3829
3850
  exports.PieChart = PieChart;
3830
3851
  exports.RadarChart = RadarChart;
3831
3852
  exports.SwipeScroll = SwipeScroll;
3853
+ exports.appendSvg = appendSvg;
3832
3854
  exports.barChartClassNames = barChartClassNames;
3833
3855
  exports.bubbleChartClassNames = bubbleChartClassNames;
3834
3856
  exports.calendarChartClassNames = calendarChartClassNames;
@@ -3836,4 +3858,6 @@ exports.horizontalBarChartClassNames = horizontalBarChartClassNames;
3836
3858
  exports.lineChartClassNames = lineChartClassNames;
3837
3859
  exports.pieChartclassNames = pieChartclassNames;
3838
3860
  exports.radarChartclassNames = radarChartclassNames;
3861
+ exports.useNode = useNode;
3862
+ exports.useResize = useResize;
3839
3863
  //# sourceMappingURL=charts.cjs.development.js.map