@oliasoft-open-source/charts-library 2.11.1 → 2.11.2
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.2",
|
|
4
4
|
"description": "React Chart Library (based on Chart.js and react-chart-js-2)",
|
|
5
5
|
"homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
|
|
6
6
|
"bugs": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"chartjs-plugin-dragdata": "^2.2.5",
|
|
40
40
|
"chartjs-plugin-zoom": "^1.2.1",
|
|
41
41
|
"classnames": "^2.3.1",
|
|
42
|
-
"fraction.js": "^4.2.0",
|
|
43
42
|
"lodash": "^4",
|
|
44
43
|
"react-base64-downloader": "^2.1.7",
|
|
45
44
|
"react-chartjs-2": "^4.3.1",
|
|
@@ -51,7 +50,7 @@
|
|
|
51
50
|
"@babel/preset-env": "^7.18.10",
|
|
52
51
|
"@babel/preset-react": "^7.18.6",
|
|
53
52
|
"@oliasoft-open-source/react-ui-library": "3.3.11-beta-1",
|
|
54
|
-
"@oliasoft-open-source/units": "
|
|
53
|
+
"@oliasoft-open-source/units": "2.1.0",
|
|
55
54
|
"@storybook/addon-actions": "^6.5.10",
|
|
56
55
|
"@storybook/addon-docs": "^6.5.10",
|
|
57
56
|
"@storybook/addon-links": "^6.5.10",
|
|
@@ -97,7 +96,7 @@
|
|
|
97
96
|
},
|
|
98
97
|
"peerDependencies": {
|
|
99
98
|
"@oliasoft-open-source/react-ui-library": "^3",
|
|
100
|
-
"@oliasoft-open-source/units": "^2",
|
|
99
|
+
"@oliasoft-open-source/units": "^2.1",
|
|
101
100
|
"immer": "^9",
|
|
102
101
|
"prop-types": "^15",
|
|
103
102
|
"react": "^17",
|
package/release-notes.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# Charts Library Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.11.2
|
|
4
|
+
|
|
5
|
+
- remove number handling functions that were duplicated from units package
|
|
6
|
+
([OW-11062](https://oliasoft.atlassian.net/browse/OW-11062))
|
|
7
|
+
|
|
3
8
|
## 2.11.1
|
|
4
9
|
|
|
5
10
|
- updated icon import
|
|
6
11
|
|
|
7
12
|
## 2.11.0
|
|
8
13
|
|
|
9
|
-
- added dragData feature(plugin-https://github.com/chrispahm/chartjs-plugin-
|
|
14
|
+
- added `dragData` feature ([chartjs-plugin-dragdata](https://github.com/chrispahm/chartjs-plugin-dragdata))
|
|
10
15
|
|
|
11
16
|
## 2.10.2
|
|
12
17
|
|
|
@@ -1,142 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toNum as toNumber, isValidNum } from '@oliasoft-open-source/units';
|
|
2
2
|
|
|
3
|
-
const isNull = (str) => str === null;
|
|
4
|
-
const isUndefined = (str) => str === undefined;
|
|
5
|
-
const isArray = (str) => str && str.constructor === Array;
|
|
6
|
-
const isObject = (str) => str && str.constructor === Object;
|
|
7
|
-
const hasDivisor = (str) =>
|
|
8
|
-
str && typeof str.includes === 'function' && str.includes('/');
|
|
9
|
-
export const isEmptyString = (str) => str === '';
|
|
10
|
-
const isTrailingPeriodSeparator = (str) => str && str[str.length - 1] === '.';
|
|
11
|
-
const isTrailingCommaSeparator = (str) => str && str[str.length - 1] === ',';
|
|
12
3
|
const isOnlyNumbers = (str) => /^-?\d*\.?\d+$/.test(str);
|
|
13
4
|
|
|
14
|
-
export const
|
|
15
|
-
let total = 0,
|
|
16
|
-
last_location = 0,
|
|
17
|
-
single_char = (chr + '')[0];
|
|
18
|
-
while ((last_location = str.indexOf(single_char, last_location) + 1)) {
|
|
19
|
-
total += 1;
|
|
20
|
-
}
|
|
21
|
-
return total;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const cleanNumStr = (str) => {
|
|
25
|
-
str += '';
|
|
26
|
-
let slashCount = charCount('/', str);
|
|
27
|
-
let spaceCount = charCount(' ', str) + charCount(' ', str);
|
|
28
|
-
let dotcount = charCount('.', str);
|
|
29
|
-
let commacount = charCount(',', str);
|
|
30
|
-
if (slashCount === 0 && spaceCount > 0) str = str.replace(/\s/g, '');
|
|
31
|
-
if (commacount > 1) str = str.replace(/,/g, '');
|
|
32
|
-
if (dotcount > 1) str = str.replace(/\./g, '');
|
|
33
|
-
commacount = charCount(',', str);
|
|
34
|
-
dotcount = charCount('.', str);
|
|
35
|
-
if (dotcount === 1 && commacount === 1) {
|
|
36
|
-
// One of each, make the rightmost act as decimal separator
|
|
37
|
-
if (str.indexOf(',') > str.indexOf('.')) {
|
|
38
|
-
str = str.replace('.', '');
|
|
39
|
-
str = str.replace(',', '.');
|
|
40
|
-
} else {
|
|
41
|
-
str = str.replace(',', '');
|
|
42
|
-
}
|
|
43
|
-
if (str.indexOf('.') === 0) {
|
|
44
|
-
str = 0 + str;
|
|
45
|
-
}
|
|
46
|
-
return str;
|
|
47
|
-
}
|
|
48
|
-
if (dotcount === 1 && commacount) str = str.replace(',', '');
|
|
49
|
-
if (!dotcount && commacount) str = str.replace(',', '.');
|
|
50
|
-
if (str.indexOf('.') === 0) {
|
|
51
|
-
str = 0 + str;
|
|
52
|
-
}
|
|
53
|
-
return str;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const numFraction = (str) => {
|
|
57
|
-
if (str instanceof Array || str === null || str === undefined) {
|
|
58
|
-
return str;
|
|
59
|
-
}
|
|
60
|
-
if (typeof str === 'string') {
|
|
61
|
-
str = str.trim(); //trailing whitespace causes InvalidParameter error in fraction.js
|
|
62
|
-
}
|
|
63
|
-
let result = str;
|
|
64
|
-
try {
|
|
65
|
-
result = Fraction(str);
|
|
66
|
-
} catch (e) {
|
|
67
|
-
//do nothing
|
|
68
|
-
}
|
|
69
|
-
return result.valueOf();
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const isValidNum = (input) => {
|
|
73
|
-
let result = false;
|
|
74
|
-
if (isEmptyString(input)) {
|
|
75
|
-
result = true;
|
|
76
|
-
} else {
|
|
77
|
-
if (
|
|
78
|
-
!(
|
|
79
|
-
isNull(input) ||
|
|
80
|
-
isUndefined(input) ||
|
|
81
|
-
isTrailingPeriodSeparator(input) ||
|
|
82
|
-
isTrailingCommaSeparator(input) ||
|
|
83
|
-
isArray(input) ||
|
|
84
|
-
isObject(input) ||
|
|
85
|
-
!isOnlyNumbers(input)
|
|
86
|
-
)
|
|
87
|
-
) {
|
|
88
|
-
let number;
|
|
89
|
-
const cleaned = cleanNumStr(input);
|
|
90
|
-
if (hasDivisor(cleaned)) {
|
|
91
|
-
//numFraction is slow, so only call it if needed
|
|
92
|
-
number = numFraction(cleaned);
|
|
93
|
-
} else {
|
|
94
|
-
number = parseFloat(cleaned);
|
|
95
|
-
}
|
|
96
|
-
if (!isNaN(number)) {
|
|
97
|
-
result = true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const toNumber = (input, defaultValue, minimum) => {
|
|
105
|
-
let result;
|
|
106
|
-
defaultValue = defaultValue === undefined ? input : defaultValue;
|
|
107
|
-
if (
|
|
108
|
-
isNull(input) ||
|
|
109
|
-
isUndefined(input) ||
|
|
110
|
-
isEmptyString(input) ||
|
|
111
|
-
isTrailingPeriodSeparator(input) ||
|
|
112
|
-
isTrailingCommaSeparator(input) ||
|
|
113
|
-
isArray(input) ||
|
|
114
|
-
isObject(input)
|
|
115
|
-
) {
|
|
116
|
-
result = defaultValue;
|
|
117
|
-
} else {
|
|
118
|
-
let number;
|
|
119
|
-
const cleaned = cleanNumStr(input);
|
|
120
|
-
if (hasDivisor(cleaned)) {
|
|
121
|
-
//numFraction is slow, so only call it if needed
|
|
122
|
-
number = numFraction(cleaned);
|
|
123
|
-
} else {
|
|
124
|
-
number = parseFloat(cleaned);
|
|
125
|
-
}
|
|
126
|
-
if (isNaN(number)) {
|
|
127
|
-
result = defaultValue;
|
|
128
|
-
} else if (minimum && number < minimum) {
|
|
129
|
-
result = minimum;
|
|
130
|
-
} else {
|
|
131
|
-
result = number;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const validNumber = (value) => {
|
|
138
|
-
return isValidNum(value);
|
|
139
|
-
};
|
|
5
|
+
export const validNumber = (input) => isValidNum(input) && isOnlyNumbers(input);
|
|
140
6
|
|
|
141
7
|
export const toNum = (value) => {
|
|
142
8
|
const asNumber = toNumber(value);
|