@operato/chart 7.0.4 → 7.0.6
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/CHANGELOG.md +19 -0
- package/dist/src/chartjs/config-converter.js +1 -1
- package/dist/src/chartjs/config-converter.js.map +1 -1
- package/dist/src/chartjs/ox-chart-js.js +1 -1
- package/dist/src/chartjs/ox-chart-js.js.map +1 -1
- package/dist/src/editors/input-chart-abstract.d.ts +1 -1
- package/dist/src/editors/input-chart-abstract.js +5 -8
- package/dist/src/editors/input-chart-abstract.js.map +1 -1
- package/dist/src/editors/input-chart-multi-series-abstract.js +1 -1
- package/dist/src/editors/input-chart-multi-series-abstract.js.map +1 -1
- package/dist/src/editors/input-chart-styles.js +1 -1
- package/dist/src/editors/input-chart-styles.js.map +1 -1
- package/dist/src/editors/ox-input-chart-hbar.js +1 -1
- package/dist/src/editors/ox-input-chart-hbar.js.map +1 -1
- package/dist/src/editors/ox-property-editor-chart.js +1 -1
- package/dist/src/editors/ox-property-editor-chart.js.map +1 -1
- package/dist/src/progress/ox-progress-circle.d.ts +1 -1
- package/dist/src/progress/ox-progress-circle.js +1 -1
- package/dist/src/progress/ox-progress-circle.js.map +1 -1
- package/dist/src/scichart/ox-scichart.d.ts +0 -2
- package/dist/src/scichart/ox-scichart.js +3 -11
- package/dist/src/scichart/ox-scichart.js.map +1 -1
- package/dist/src/scichart/scichart-builder.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -4
- package/src/chartjs/config-converter.ts +1 -1
- package/src/chartjs/ox-chart-js.ts +1 -1
- package/src/editors/input-chart-abstract.ts +6 -9
- package/src/editors/input-chart-multi-series-abstract.ts +1 -1
- package/src/editors/input-chart-styles.ts +1 -1
- package/src/editors/ox-input-chart-hbar.ts +1 -1
- package/src/editors/ox-property-editor-chart.ts +1 -1
- package/src/progress/ox-progress-circle.ts +1 -1
- package/src/scichart/ox-scichart.ts +3 -5
- package/src/scichart/scichart-builder.ts +1 -1
- package/dist/src/utils/text-formatter.d.ts +0 -1
- package/dist/src/utils/text-formatter.js +0 -78
- package/dist/src/utils/text-formatter.js.map +0 -1
- package/src/utils/text-formatter.ts +0 -106
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export function format(mask, value) {
|
|
2
|
-
if (!mask || isNaN(+value)) {
|
|
3
|
-
return value.toString(); // return as it is.
|
|
4
|
-
}
|
|
5
|
-
let isNegative, result, decimal, group, posLeadZero, posTrailZero, posSeparator, part, szSep, integer,
|
|
6
|
-
// find prefix/suffix
|
|
7
|
-
len = mask.length, start = mask.search(/[0-9\-\+#]/), prefix = start > 0 ? mask.substring(0, start) : '',
|
|
8
|
-
// reverse string: not an ideal method if there are surrogate pairs
|
|
9
|
-
str = mask.split('').reverse().join(''), end = str.search(/[0-9\-\+#]/), offset = len - end, substr = mask.substring(offset, offset + 1), indx = offset + (substr === '.' || substr === ',' ? 1 : 0), suffix = end > 0 ? mask.substring(indx, len) : '', splittedMask, splittedValue, stringValue;
|
|
10
|
-
// mask with prefix & suffix removed
|
|
11
|
-
mask = mask.substring(start, indx);
|
|
12
|
-
// convert any string to number according to formation sign.
|
|
13
|
-
value = mask.charAt(0) === '-' ? -value : +value;
|
|
14
|
-
isNegative = value < 0 ? ((value = -value), true) : false; // process only abs(), and turn on flag.
|
|
15
|
-
// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
|
|
16
|
-
result = mask.match(/[^\d\-\+#]/g);
|
|
17
|
-
decimal = '.'; // ( result && result[ result.length - 1 ] ) || '.'; // ','는 소수점이 되지 않게 함
|
|
18
|
-
group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator
|
|
19
|
-
// split the decimal for the format string if any.
|
|
20
|
-
splittedMask = mask.split(decimal);
|
|
21
|
-
// Fix the decimal first, toFixed will auto fill trailing zero.
|
|
22
|
-
value = parseFloat(value.toFixed((splittedMask[1] && splittedMask[1].length) || 0));
|
|
23
|
-
stringValue = +value + ''; // convert number to string to trim off *all* trailing decimal zero(es)
|
|
24
|
-
// fill back any trailing zero according to format
|
|
25
|
-
posTrailZero = (splittedMask[1] && splittedMask[1].lastIndexOf('0')) || 0; // look for last zero in format
|
|
26
|
-
part = stringValue.split('.');
|
|
27
|
-
// integer will get !part[1]
|
|
28
|
-
if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {
|
|
29
|
-
stringValue = (+value).toFixed(posTrailZero + 1);
|
|
30
|
-
}
|
|
31
|
-
szSep = splittedMask[0].split(group); // look for separator
|
|
32
|
-
splittedMask[0] = szSep.join(''); // join back without separator for counting the pos of any leading 0.
|
|
33
|
-
posLeadZero = (splittedMask[0] && splittedMask[0].indexOf('0')) || 0;
|
|
34
|
-
if (posLeadZero > -1) {
|
|
35
|
-
while (part[0].length < splittedMask[0].length - posLeadZero) {
|
|
36
|
-
part[0] = '0' + part[0];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (+part[0] === 0) {
|
|
40
|
-
part[0] = '';
|
|
41
|
-
}
|
|
42
|
-
splittedValue = stringValue.split('.');
|
|
43
|
-
splittedValue[0] = part[0];
|
|
44
|
-
// process the first group separator from decimal (.) only, the rest ignore.
|
|
45
|
-
// get the length of the last slice of split result.
|
|
46
|
-
posSeparator = (szSep[1] && szSep[szSep.length - 1].length) || 0;
|
|
47
|
-
if (posSeparator) {
|
|
48
|
-
integer = splittedValue[0];
|
|
49
|
-
str = '';
|
|
50
|
-
offset = integer.length % posSeparator;
|
|
51
|
-
len = integer.length;
|
|
52
|
-
for (indx = 0; indx < len; indx++) {
|
|
53
|
-
str += integer.charAt(indx); // ie6 only support charAt for sz.
|
|
54
|
-
// -posSeparator so that won't trail separator on full length
|
|
55
|
-
/* jshint -W018 */
|
|
56
|
-
if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {
|
|
57
|
-
str += group;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
splittedValue[0] = str;
|
|
61
|
-
}
|
|
62
|
-
splittedValue[1] = splittedMask[1] && splittedValue[1] ? decimal + splittedValue[1] : '';
|
|
63
|
-
// remove negative sign if result is zero
|
|
64
|
-
result = splittedValue.join('');
|
|
65
|
-
if (result === '0' || result === '') {
|
|
66
|
-
// remove negative sign if result is zero
|
|
67
|
-
isNegative = false;
|
|
68
|
-
}
|
|
69
|
-
// 앞에 +가 붙는다면 양수일 경우에도 +를 표기해줌
|
|
70
|
-
let fixedPlusSign;
|
|
71
|
-
if (splittedMask[0].substring(0, 1) === '+')
|
|
72
|
-
fixedPlusSign = isNegative ? '-' : '+';
|
|
73
|
-
else
|
|
74
|
-
fixedPlusSign = isNegative ? '-' : '';
|
|
75
|
-
// put back any negation, combine integer and fraction, and add back prefix & suffix
|
|
76
|
-
return prefix + (fixedPlusSign + result) + suffix;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=text-formatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text-formatter.js","sourceRoot":"","sources":["../../../src/utils/text-formatter.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,KAAa;IAChD,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA,CAAC,mBAAmB;IAC7C,CAAC;IAED,IAAI,UAAmB,EACrB,MAAwC,EACxC,OAAe,EACf,KAAa,EACb,WAAmB,EACnB,YAAoB,EACpB,YAAoB,EACpB,IAAc,EACd,KAAe,EACf,OAAe;IACf,qBAAqB;IACrB,GAAG,GAAG,IAAI,CAAC,MAAM,EACjB,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EACjC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;IAClD,mEAAmE;IACnE,GAAG,GAAG,IAAI,CA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C,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAExF,yCAAyC;IACzC,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC/B,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QACpC,yCAAyC;QACzC,UAAU,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,8BAA8B;IAC9B,IAAI,aAAqB,CAAA;IAEzB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG;QAAE,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;;QAC9E,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAE1C,oFAAoF;IACpF,OAAO,MAAM,GAAG,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAA;AACnD,CAAC","sourcesContent":["export function format(mask: string, value: number): string {\n if (!mask || isNaN(+value)) {\n return value.toString() // return as it is.\n }\n\n let isNegative: boolean,\n result: string | RegExpMatchArray | null,\n decimal: string,\n group: string,\n posLeadZero: number,\n posTrailZero: number,\n posSeparator: number,\n part: string[],\n szSep: string[],\n integer: string,\n // find prefix/suffix\n len = mask.length,\n start = mask.search(/[0-9\\-\\+#]/),\n prefix = start > 0 ? mask.substring(0, start) : '',\n // reverse string: not an ideal method if there are surrogate pairs\n str = mask.split('').reverse().join(''),\n end = str.search(/[0-9\\-\\+#]/),\n offset = len - end,\n substr = mask.substring(offset, offset + 1),\n indx = offset + (substr === '.' || substr === ',' ? 1 : 0),\n suffix = end > 0 ? mask.substring(indx, len) : '',\n splittedMask: string[],\n splittedValue: string[],\n stringValue: string\n\n // mask with prefix & suffix removed\n mask = mask.substring(start, indx)\n\n // convert any string to number according to formation sign.\n value = mask.charAt(0) === '-' ? -value : +value\n isNegative = value < 0 ? ((value = -value), true) : false // process only abs(), and turn on flag.\n\n // search for separator for grp & decimal, anything not digit, not +/- sign, not #.\n result = mask.match(/[^\\d\\-\\+#]/g)\n decimal = '.' // ( result && result[ result.length - 1 ] ) || '.'; // ','는 소수점이 되지 않게 함\n group = (result && result[1] && result[0]) || ',' // treat the left most symbol as group separator\n\n // split the decimal for the format string if any.\n splittedMask = mask.split(decimal)\n // Fix the decimal first, toFixed will auto fill trailing zero.\n value = parseFloat(value.toFixed((splittedMask[1] && splittedMask[1].length) || 0))\n stringValue = +value + '' // convert number to string to trim off *all* trailing decimal zero(es)\n\n // fill back any trailing zero according to format\n posTrailZero = (splittedMask[1] && splittedMask[1].lastIndexOf('0')) || 0 // look for last zero in format\n part = stringValue.split('.')\n // integer will get !part[1]\n if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {\n stringValue = (+value).toFixed(posTrailZero + 1)\n }\n szSep = splittedMask[0].split(group) // look for separator\n splittedMask[0] = szSep.join('') // join back without separator for counting the pos of any leading 0.\n\n posLeadZero = (splittedMask[0] && splittedMask[0].indexOf('0')) || 0\n if (posLeadZero > -1) {\n while (part[0].length < splittedMask[0].length - posLeadZero) {\n part[0] = '0' + part[0]\n }\n } else if (+part[0] === 0) {\n part[0] = ''\n }\n\n splittedValue = stringValue.split('.')\n splittedValue[0] = part[0]\n\n // process the first group separator from decimal (.) only, the rest ignore.\n // get the length of the last slice of split result.\n posSeparator = (szSep[1] && szSep[szSep.length - 1].length) || 0\n if (posSeparator) {\n integer = splittedValue[0]\n str = ''\n offset = integer.length % posSeparator\n len = integer.length\n for (indx = 0; indx < len; indx++) {\n str += integer.charAt(indx) // ie6 only support charAt for sz.\n // -posSeparator so that won't trail separator on full length\n /* jshint -W018 */\n if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {\n str += group\n }\n }\n splittedValue[0] = str\n }\n splittedValue[1] = splittedMask[1] && splittedValue[1] ? decimal + splittedValue[1] : ''\n\n // remove negative sign if result is zero\n result = splittedValue.join('')\n if (result === '0' || result === '') {\n // remove negative sign if result is zero\n isNegative = false\n }\n\n // 앞에 +가 붙는다면 양수일 경우에도 +를 표기해줌\n let fixedPlusSign: string\n\n if (splittedMask[0].substring(0, 1) === '+') fixedPlusSign = isNegative ? '-' : '+'\n else fixedPlusSign = isNegative ? '-' : ''\n\n // put back any negation, combine integer and fraction, and add back prefix & suffix\n return prefix + (fixedPlusSign + result) + suffix\n}\n"]}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export function format(mask: string, value: number): string {
|
|
2
|
-
if (!mask || isNaN(+value)) {
|
|
3
|
-
return value.toString() // return as it is.
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
let isNegative: boolean,
|
|
7
|
-
result: string | RegExpMatchArray | null,
|
|
8
|
-
decimal: string,
|
|
9
|
-
group: string,
|
|
10
|
-
posLeadZero: number,
|
|
11
|
-
posTrailZero: number,
|
|
12
|
-
posSeparator: number,
|
|
13
|
-
part: string[],
|
|
14
|
-
szSep: string[],
|
|
15
|
-
integer: string,
|
|
16
|
-
// find prefix/suffix
|
|
17
|
-
len = mask.length,
|
|
18
|
-
start = mask.search(/[0-9\-\+#]/),
|
|
19
|
-
prefix = start > 0 ? mask.substring(0, start) : '',
|
|
20
|
-
// reverse string: not an ideal method if there are surrogate pairs
|
|
21
|
-
str = mask.split('').reverse().join(''),
|
|
22
|
-
end = str.search(/[0-9\-\+#]/),
|
|
23
|
-
offset = len - end,
|
|
24
|
-
substr = mask.substring(offset, offset + 1),
|
|
25
|
-
indx = offset + (substr === '.' || substr === ',' ? 1 : 0),
|
|
26
|
-
suffix = end > 0 ? mask.substring(indx, len) : '',
|
|
27
|
-
splittedMask: string[],
|
|
28
|
-
splittedValue: string[],
|
|
29
|
-
stringValue: string
|
|
30
|
-
|
|
31
|
-
// mask with prefix & suffix removed
|
|
32
|
-
mask = mask.substring(start, indx)
|
|
33
|
-
|
|
34
|
-
// convert any string to number according to formation sign.
|
|
35
|
-
value = mask.charAt(0) === '-' ? -value : +value
|
|
36
|
-
isNegative = value < 0 ? ((value = -value), true) : false // process only abs(), and turn on flag.
|
|
37
|
-
|
|
38
|
-
// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
|
|
39
|
-
result = mask.match(/[^\d\-\+#]/g)
|
|
40
|
-
decimal = '.' // ( result && result[ result.length - 1 ] ) || '.'; // ','는 소수점이 되지 않게 함
|
|
41
|
-
group = (result && result[1] && result[0]) || ',' // treat the left most symbol as group separator
|
|
42
|
-
|
|
43
|
-
// split the decimal for the format string if any.
|
|
44
|
-
splittedMask = mask.split(decimal)
|
|
45
|
-
// Fix the decimal first, toFixed will auto fill trailing zero.
|
|
46
|
-
value = parseFloat(value.toFixed((splittedMask[1] && splittedMask[1].length) || 0))
|
|
47
|
-
stringValue = +value + '' // convert number to string to trim off *all* trailing decimal zero(es)
|
|
48
|
-
|
|
49
|
-
// fill back any trailing zero according to format
|
|
50
|
-
posTrailZero = (splittedMask[1] && splittedMask[1].lastIndexOf('0')) || 0 // look for last zero in format
|
|
51
|
-
part = stringValue.split('.')
|
|
52
|
-
// integer will get !part[1]
|
|
53
|
-
if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {
|
|
54
|
-
stringValue = (+value).toFixed(posTrailZero + 1)
|
|
55
|
-
}
|
|
56
|
-
szSep = splittedMask[0].split(group) // look for separator
|
|
57
|
-
splittedMask[0] = szSep.join('') // join back without separator for counting the pos of any leading 0.
|
|
58
|
-
|
|
59
|
-
posLeadZero = (splittedMask[0] && splittedMask[0].indexOf('0')) || 0
|
|
60
|
-
if (posLeadZero > -1) {
|
|
61
|
-
while (part[0].length < splittedMask[0].length - posLeadZero) {
|
|
62
|
-
part[0] = '0' + part[0]
|
|
63
|
-
}
|
|
64
|
-
} else if (+part[0] === 0) {
|
|
65
|
-
part[0] = ''
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
splittedValue = stringValue.split('.')
|
|
69
|
-
splittedValue[0] = part[0]
|
|
70
|
-
|
|
71
|
-
// process the first group separator from decimal (.) only, the rest ignore.
|
|
72
|
-
// get the length of the last slice of split result.
|
|
73
|
-
posSeparator = (szSep[1] && szSep[szSep.length - 1].length) || 0
|
|
74
|
-
if (posSeparator) {
|
|
75
|
-
integer = splittedValue[0]
|
|
76
|
-
str = ''
|
|
77
|
-
offset = integer.length % posSeparator
|
|
78
|
-
len = integer.length
|
|
79
|
-
for (indx = 0; indx < len; indx++) {
|
|
80
|
-
str += integer.charAt(indx) // ie6 only support charAt for sz.
|
|
81
|
-
// -posSeparator so that won't trail separator on full length
|
|
82
|
-
/* jshint -W018 */
|
|
83
|
-
if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {
|
|
84
|
-
str += group
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
splittedValue[0] = str
|
|
88
|
-
}
|
|
89
|
-
splittedValue[1] = splittedMask[1] && splittedValue[1] ? decimal + splittedValue[1] : ''
|
|
90
|
-
|
|
91
|
-
// remove negative sign if result is zero
|
|
92
|
-
result = splittedValue.join('')
|
|
93
|
-
if (result === '0' || result === '') {
|
|
94
|
-
// remove negative sign if result is zero
|
|
95
|
-
isNegative = false
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 앞에 +가 붙는다면 양수일 경우에도 +를 표기해줌
|
|
99
|
-
let fixedPlusSign: string
|
|
100
|
-
|
|
101
|
-
if (splittedMask[0].substring(0, 1) === '+') fixedPlusSign = isNegative ? '-' : '+'
|
|
102
|
-
else fixedPlusSign = isNegative ? '-' : ''
|
|
103
|
-
|
|
104
|
-
// put back any negation, combine integer and fraction, and add back prefix & suffix
|
|
105
|
-
return prefix + (fixedPlusSign + result) + suffix
|
|
106
|
-
}
|