source: node_modules/recharts/lib/util/round.js

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

Added visualizations

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