source: node_modules/recharts/es6/util/round.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
Line 
1// if you go lower than 3, wild wild things happen during rendering
2var defaultRoundPrecision = 4;
3export function round(num) {
4 var roundPrecision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultRoundPrecision;
5 var factor = 10 ** roundPrecision;
6 var rounded = Math.round(num * factor) / factor;
7 if (Object.is(rounded, -0)) {
8 return 0;
9 }
10 return rounded;
11}
12
13/**
14 * This function will accept a string template literal and for each
15 * variable placeholder, it will round the value to avoid long float numbers in
16 * the SVG path which might cause rendering issues in some browsers.
17 */
18export function roundTemplateLiteral(strings) {
19 for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20 values[_key - 1] = arguments[_key];
21 }
22 return strings.reduce((result, string, i) => {
23 var value = values[i - 1];
24 if (typeof value === 'string') {
25 return result + value + string;
26 }
27 if (value !== undefined) {
28 return result + round(value) + string;
29 }
30 return result + string;
31 }, '');
32}
Note: See TracBrowser for help on using the repository browser.