@oliasoft-open-source/charts-library 2.11.1 → 2.11.3

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.1",
3
+ "version": "2.11.3",
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",
@@ -50,8 +49,8 @@
50
49
  "@babel/eslint-parser": "^7.18.9",
51
50
  "@babel/preset-env": "^7.18.10",
52
51
  "@babel/preset-react": "^7.18.6",
53
- "@oliasoft-open-source/react-ui-library": "3.3.11-beta-1",
54
- "@oliasoft-open-source/units": "^2",
52
+ "@oliasoft-open-source/react-ui-library": "3.3.12",
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,21 @@
1
1
  # Charts Library Release Notes
2
2
 
3
+ ## 2.11.3
4
+
5
+ - Submit Axes option on keyboard Enter ([OW-10995](https://oliasoft.atlassian.net/browse/OW-10995))
6
+
7
+ ## 2.11.2
8
+
9
+ - remove number handling functions that were duplicated from units package
10
+ ([OW-11062](https://oliasoft.atlassian.net/browse/OW-11062))
11
+
3
12
  ## 2.11.1
4
13
 
5
14
  - updated icon import
6
15
 
7
16
  ## 2.11.0
8
17
 
9
- - added dragData feature(plugin-https://github.com/chrispahm/chartjs-plugin-dragData)
18
+ - added `dragData` feature ([chartjs-plugin-dragdata](https://github.com/chrispahm/chartjs-plugin-dragdata))
10
19
 
11
20
  ## 2.10.2
12
21
 
@@ -15,7 +24,7 @@
15
24
  ## 2.10.1
16
25
 
17
26
  - Use `peerDependencies` for common versions of shared packages like `units` and `react-ui-library` so reduce double
18
- installs and conflicting versions in parent apps ([OW-10974](https://oliasoft.atlassian.net/browse/OW-10974))
27
+ installs and conflicting versions in parent apps ([OW-10974](https://oliasoft.atlassian.net/browse/OW-10974))
19
28
 
20
29
  ## 2.10.0
21
30
 
@@ -45,7 +45,8 @@ const AxesOptionsPopover = ({
45
45
  });
46
46
  };
47
47
 
48
- const onDone = () => {
48
+ const onDone = (e) => {
49
+ e.preventDefault();
49
50
  if (valid) {
50
51
  const sanitizedFormState = formState.map((axis) => ({
51
52
  ...axis,
@@ -72,7 +73,7 @@ const AxesOptionsPopover = ({
72
73
  const isCustomValue = axes.filter((axis) => axis.max || axis.min).length > 0;
73
74
  const handleInputFocus = (e) => e.target.select();
74
75
  return (
75
- <>
76
+ <form onSubmit={onDone}>
76
77
  {axes.map((axis, i) => {
77
78
  const axisLabel = controlsAxesLabels.find(
78
79
  (el) => el.id === axis.id,
@@ -121,7 +122,7 @@ const AxesOptionsPopover = ({
121
122
  );
122
123
  })}
123
124
  <Flex gap="8px" alignItems="center">
124
- <Button small colored label="Done" onClick={onDone} disabled={!valid} />
125
+ <Button type="submit" small colored label="Done" disabled={!valid} />
125
126
  <Button
126
127
  small
127
128
  name="resetAxes"
@@ -133,7 +134,7 @@ const AxesOptionsPopover = ({
133
134
  or double click on canvas
134
135
  </Text>
135
136
  </Flex>
136
- </>
137
+ </form>
137
138
  );
138
139
  };
139
140
 
@@ -1,142 +1,8 @@
1
- import Fraction from 'fraction.js';
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 charCount = (chr, str) => {
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);