dtable-utils 0.0.2 → 0.0.3-beta.1

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.
Files changed (150) hide show
  1. package/README.md +30 -2
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +227 -19
  4. package/es/cell-value-get/collaborator.js +9 -3
  5. package/es/cell-value-get/digital-sign.js +1 -1
  6. package/es/cell-value-get/geolocation.js +29 -5
  7. package/es/cell-value-get/long-text.js +1 -1
  8. package/es/cell-value-get/number.js +42 -18
  9. package/es/cell-value-get/option.js +17 -7
  10. package/es/cell-value-get/rate.js +6 -0
  11. package/es/cell-value-set/date.js +20 -0
  12. package/es/cell-value-set/number.js +53 -1
  13. package/es/color/gradient-color.js +100 -0
  14. package/es/column/color.js +415 -0
  15. package/es/column/{common.js → core.js} +3 -15
  16. package/es/column/date.js +2 -3
  17. package/es/column/number.js +3 -5
  18. package/es/column/option.js +115 -0
  19. package/es/common.js +10 -1
  20. package/es/constants/color.js +16 -0
  21. package/es/constants/column-permission.js +7 -0
  22. package/es/constants/column.js +127 -2
  23. package/es/constants/filter/index.js +5 -1
  24. package/es/constants/grid-header.js +6 -0
  25. package/es/constants/group.js +23 -0
  26. package/es/constants/limit.js +3 -0
  27. package/es/constants/reg.js +4 -0
  28. package/es/constants/row-color.js +11 -0
  29. package/es/constants/sort.js +11 -0
  30. package/es/date.js +1 -1
  31. package/es/filter/core.js +287 -0
  32. package/es/filter/filter-column/array.js +82 -0
  33. package/es/filter/filter-column/checkbox.js +8 -0
  34. package/es/filter/filter-column/collaborator.js +67 -0
  35. package/es/filter/filter-column/creator.js +50 -0
  36. package/es/filter/filter-column/date.js +59 -0
  37. package/es/filter/filter-column/digital-sign.js +26 -0
  38. package/es/filter/filter-column/file.js +24 -0
  39. package/es/filter/filter-column/formula.js +49 -0
  40. package/es/filter/filter-column/geolocation.js +53 -0
  41. package/es/filter/filter-column/link.js +12 -0
  42. package/es/filter/filter-column/long-text.js +25 -0
  43. package/es/filter/filter-column/multiple-select.js +60 -0
  44. package/es/filter/filter-column/number.js +93 -0
  45. package/es/filter/filter-column/single-select.js +41 -0
  46. package/es/filter/filter-column/text.js +55 -0
  47. package/es/filter/filter-row.js +198 -0
  48. package/es/group/core.js +107 -0
  49. package/es/group/group-row.js +366 -0
  50. package/es/index.js +62 -10
  51. package/es/link/core.js +78 -0
  52. package/es/number.js +13 -0
  53. package/es/row/color.js +278 -0
  54. package/es/row/core.js +161 -0
  55. package/es/sort/core.js +32 -0
  56. package/es/sort/sort-column/array.js +63 -0
  57. package/es/sort/sort-column/checkbox.js +15 -0
  58. package/es/sort/sort-column/collaborator.js +9 -0
  59. package/es/sort/sort-column/date.js +25 -0
  60. package/es/sort/sort-column/formula.js +40 -0
  61. package/es/sort/sort-column/link.js +23 -0
  62. package/es/sort/sort-column/multiple-select.js +45 -0
  63. package/es/sort/sort-column/number.js +18 -0
  64. package/es/sort/sort-column/single-select.js +22 -0
  65. package/es/sort/sort-column/text.js +47 -0
  66. package/es/sort/sort-row.js +126 -0
  67. package/es/table/column.js +27 -0
  68. package/es/table/core.js +14 -0
  69. package/es/table/index.js +14 -0
  70. package/es/table/row.js +25 -0
  71. package/es/validate/filter.js +1 -1
  72. package/es/validate/geolocation.js +5 -0
  73. package/es/view/core.js +135 -0
  74. package/es/view/formula.js +143 -0
  75. package/es/view/group.js +32 -0
  76. package/es/view/summaries.js +179 -0
  77. package/lib/cell-value-get/cell-value.js +231 -18
  78. package/lib/cell-value-get/collaborator.js +9 -2
  79. package/lib/cell-value-get/digital-sign.js +1 -1
  80. package/lib/cell-value-get/geolocation.js +30 -5
  81. package/lib/cell-value-get/long-text.js +1 -1
  82. package/lib/cell-value-get/number.js +42 -17
  83. package/lib/cell-value-get/option.js +18 -6
  84. package/lib/cell-value-get/rate.js +10 -0
  85. package/lib/cell-value-set/date.js +24 -0
  86. package/lib/cell-value-set/number.js +53 -0
  87. package/lib/color/gradient-color.js +110 -0
  88. package/lib/column/color.js +424 -0
  89. package/lib/column/{common.js → core.js} +3 -16
  90. package/lib/column/date.js +2 -3
  91. package/lib/column/number.js +3 -5
  92. package/lib/column/option.js +123 -0
  93. package/lib/common.js +14 -0
  94. package/lib/constants/color.js +20 -0
  95. package/lib/constants/column-permission.js +11 -0
  96. package/lib/constants/column.js +134 -1
  97. package/lib/constants/filter/index.js +5 -0
  98. package/lib/constants/grid-header.js +10 -0
  99. package/lib/constants/group.js +36 -0
  100. package/lib/constants/limit.js +7 -0
  101. package/lib/constants/reg.js +9 -0
  102. package/lib/constants/row-color.js +17 -0
  103. package/lib/constants/sort.js +18 -0
  104. package/lib/filter/core.js +301 -0
  105. package/lib/filter/filter-column/array.js +86 -0
  106. package/lib/filter/filter-column/checkbox.js +12 -0
  107. package/lib/filter/filter-column/collaborator.js +75 -0
  108. package/lib/filter/filter-column/creator.js +54 -0
  109. package/lib/filter/filter-column/date.js +63 -0
  110. package/lib/filter/filter-column/digital-sign.js +30 -0
  111. package/lib/filter/filter-column/file.js +28 -0
  112. package/lib/filter/filter-column/formula.js +53 -0
  113. package/lib/filter/filter-column/geolocation.js +57 -0
  114. package/lib/filter/filter-column/link.js +16 -0
  115. package/lib/filter/filter-column/long-text.js +29 -0
  116. package/lib/filter/filter-column/multiple-select.js +68 -0
  117. package/lib/filter/filter-column/number.js +97 -0
  118. package/lib/filter/filter-column/single-select.js +45 -0
  119. package/lib/filter/filter-column/text.js +59 -0
  120. package/lib/filter/filter-row.js +204 -0
  121. package/lib/group/core.js +117 -0
  122. package/lib/group/group-row.js +377 -0
  123. package/lib/index.js +176 -6
  124. package/lib/link/core.js +90 -0
  125. package/lib/number.js +18 -0
  126. package/lib/row/color.js +286 -0
  127. package/lib/row/core.js +170 -0
  128. package/lib/sort/core.js +37 -0
  129. package/lib/sort/sort-column/array.js +67 -0
  130. package/lib/sort/sort-column/checkbox.js +19 -0
  131. package/lib/sort/sort-column/collaborator.js +13 -0
  132. package/lib/sort/sort-column/date.js +29 -0
  133. package/lib/sort/sort-column/formula.js +44 -0
  134. package/lib/sort/sort-column/link.js +27 -0
  135. package/lib/sort/sort-column/multiple-select.js +50 -0
  136. package/lib/sort/sort-column/number.js +22 -0
  137. package/lib/sort/sort-column/single-select.js +26 -0
  138. package/lib/sort/sort-column/text.js +52 -0
  139. package/lib/sort/sort-row.js +136 -0
  140. package/lib/table/column.js +32 -0
  141. package/lib/table/core.js +18 -0
  142. package/lib/table/index.js +18 -0
  143. package/lib/table/row.js +30 -0
  144. package/lib/validate/filter.js +3 -3
  145. package/lib/validate/geolocation.js +9 -0
  146. package/lib/view/core.js +144 -0
  147. package/lib/view/formula.js +150 -0
  148. package/lib/view/group.js +36 -0
  149. package/lib/view/summaries.js +185 -0
  150. package/package.json +4 -2
@@ -1,7 +1,13 @@
1
+ var getCollaborator = function getCollaborator(collaborators, collaboratorEmail) {
2
+ return collaborators.find(function (collaborator) {
3
+ return collaborator.email === collaboratorEmail;
4
+ });
5
+ };
6
+
1
7
  /**
2
8
  * Get collaborators name list of given emails
3
9
  * @param {array} emails e.g. ['email', ...]
4
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
10
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
5
11
  * @returns name list, array. e.g. ['name1', 'name2']
6
12
  */
7
13
  var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
@@ -20,7 +26,7 @@ var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators
20
26
 
21
27
  /**
22
28
  * Get concatenated collaborators names of given emails.
23
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
29
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
24
30
  * @param {array} emails e.g. ['email', ...]
25
31
  * @returns concatenated collaborators names, string. e.g. 'name1, name2'
26
32
  */
@@ -30,4 +36,4 @@ var getCollaboratorsName = function getCollaboratorsName(collaborators, emails)
30
36
  return collaboratorsNames.join(', ');
31
37
  };
32
38
 
33
- export { getCollaboratorsName, getCollaboratorsNames };
39
+ export { getCollaborator, getCollaboratorsName, getCollaboratorsNames };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Get signature image url to display
3
- * @param {object} digitalSign object, e.g. { sign_image_url: 'xxx' }
3
+ * @param {object} digitalSign object, e.g. { sign_image_url, ... }
4
4
  * @returns signature image url, string
5
5
  */
6
6
  var getDigitalSignImageUrl = function getDigitalSignImageUrl(digitalSign) {
@@ -1,11 +1,10 @@
1
- var isValidPosition = function isValidPosition(lng, lat) {
2
- return (lng || lng === 0) && (lat || lat === 0);
3
- };
1
+ import { GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
2
+ import { isValidPosition } from '../validate/geolocation.js';
4
3
 
5
4
  /**
6
5
  * Get formatted geolocation
7
6
  * @param {object} loc
8
- * @param {object} formats , e.g. { geo_format: 'xxx' }
7
+ * @param {object} formats , e.g. { geo_format, ... }
9
8
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
10
9
  * @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
11
10
  * @returns formatted geolocation, string
@@ -77,5 +76,30 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
77
76
  }
78
77
  }
79
78
  };
79
+ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
80
+ if (!geolocation) return '';
81
+ var province = geolocation.province,
82
+ city = geolocation.city,
83
+ district = geolocation.district,
84
+ country_region = geolocation.country_region;
85
+ switch (granularity) {
86
+ case GROUP_GEOLOCATION_GRANULARITY.CITY:
87
+ {
88
+ return city || '';
89
+ }
90
+ case GROUP_GEOLOCATION_GRANULARITY.DISTRICT:
91
+ {
92
+ return district || '';
93
+ }
94
+ case GROUP_GEOLOCATION_GRANULARITY.COUNTRY:
95
+ {
96
+ return country_region || '';
97
+ }
98
+ default:
99
+ {
100
+ return province || '';
101
+ }
102
+ }
103
+ };
80
104
 
81
- export { getGeolocationDisplayString };
105
+ export { getGeolocationByGranularity, getGeolocationDisplayString };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Get text from long-text to display.
3
- * @param {object} longText e.g. { text: 'xxx' }
3
+ * @param {object} longText e.g. { text, ... }
4
4
  * @returns text from long-text, string
5
5
  */
6
6
  var getLongtextDisplayString = function getLongtextDisplayString(longText) {
@@ -1,6 +1,6 @@
1
1
  import { NPminus as minus } from '../helper/number-precision/index.js';
2
- import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
3
2
  import { getDurationDisplayString } from './duration.js';
3
+ import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
4
4
 
5
5
  var separatorMap = {
6
6
  comma: ',',
@@ -8,6 +8,30 @@ var separatorMap = {
8
8
  no: '',
9
9
  space: ' '
10
10
  };
11
+ var _getDecimalDigits = function _getDecimalDigits(num) {
12
+ if (Number.isInteger(num)) {
13
+ return 0;
14
+ }
15
+ var valueArr = (num + '').split('.');
16
+ var digitsLength = valueArr[1] ? valueArr[1].length : 8;
17
+ return digitsLength > 8 ? 8 : digitsLength;
18
+ };
19
+ var getPrecisionNumber = function getPrecisionNumber(num, formatData) {
20
+ var _ref = formatData || {},
21
+ _ref$precision = _ref.precision,
22
+ precision = _ref$precision === void 0 ? 2 : _ref$precision,
23
+ _ref$enable_precision = _ref.enable_precision,
24
+ enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
25
+ var type = Object.prototype.toString.call(num);
26
+ if (type !== '[object Number]') {
27
+ if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(num)) {
28
+ return num;
29
+ }
30
+ return null;
31
+ }
32
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(num);
33
+ return num.toFixed(decimalDigits);
34
+ };
11
35
 
12
36
  /**
13
37
  * removeZerosFromEnd('0.0100') // '0.01'
@@ -34,19 +58,19 @@ var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
34
58
  var digitsLength = decimalPart ? decimalPart.length : 8;
35
59
  return digitsLength > 8 ? 8 : digitsLength;
36
60
  };
37
- var toThousands = function toThousands(number, _ref) {
38
- var formats = _ref.formats,
39
- _ref$isCurrency = _ref.isCurrency,
40
- isCurrency = _ref$isCurrency === void 0 ? true : _ref$isCurrency;
41
- var _ref2 = formats || {},
42
- _ref2$decimal = _ref2.decimal,
43
- decimal = _ref2$decimal === void 0 ? 'dot' : _ref2$decimal,
44
- _ref2$thousands = _ref2.thousands,
45
- thousands = _ref2$thousands === void 0 ? 'no' : _ref2$thousands,
46
- _ref2$precision = _ref2.precision,
47
- precision = _ref2$precision === void 0 ? 2 : _ref2$precision,
48
- _ref2$enable_precisio = _ref2.enable_precision,
49
- enable_precision = _ref2$enable_precisio === void 0 ? false : _ref2$enable_precisio;
61
+ var toThousands = function toThousands(number, _ref2) {
62
+ var formats = _ref2.formats,
63
+ _ref2$isCurrency = _ref2.isCurrency,
64
+ isCurrency = _ref2$isCurrency === void 0 ? true : _ref2$isCurrency;
65
+ var _ref3 = formats || {},
66
+ _ref3$decimal = _ref3.decimal,
67
+ decimal = _ref3$decimal === void 0 ? 'dot' : _ref3$decimal,
68
+ _ref3$thousands = _ref3.thousands,
69
+ thousands = _ref3$thousands === void 0 ? 'no' : _ref3$thousands,
70
+ _ref3$precision = _ref3.precision,
71
+ precision = _ref3$precision === void 0 ? 2 : _ref3$precision,
72
+ _ref3$enable_precisio = _ref3.enable_precision,
73
+ enable_precision = _ref3$enable_precisio === void 0 ? false : _ref3$enable_precisio;
50
74
 
51
75
  // handle numbers in scientific notation
52
76
  if (String(number).includes('e')) {
@@ -118,9 +142,9 @@ var getNumberDisplayString = function getNumberDisplayString(number, formats) {
118
142
  if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
119
143
 
120
144
  // formats: old version maybe 'null'
121
- var _ref3 = formats || {},
122
- _ref3$format = _ref3.format,
123
- format = _ref3$format === void 0 ? DEFAULT_NUMBER_FORMAT : _ref3$format;
145
+ var _ref4 = formats || {},
146
+ _ref4$format = _ref4.format,
147
+ format = _ref4$format === void 0 ? DEFAULT_NUMBER_FORMAT : _ref4$format;
124
148
  switch (format) {
125
149
  case 'number':
126
150
  {
@@ -219,4 +243,4 @@ var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, forma
219
243
  }
220
244
  };
221
245
 
222
- export { getNumberDisplayString, replaceNumberNotAllowInput };
246
+ export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput };
@@ -1,16 +1,26 @@
1
+ import { getColumnOptions } from '../column/option.js';
2
+
3
+ var getOption = function getOption(options, optionId) {
4
+ return options.find(function (o) {
5
+ return o.id === optionId;
6
+ });
7
+ };
8
+
1
9
  /**
2
10
  * Get option name of the given id
3
11
  * @param {array} options e.g. [ { id: '', color: '', name: '' } ]
4
- * @param {string} targetOptionID option id
12
+ * @param {string} targetOptionId option id
5
13
  * @returns option name, string
6
14
  */
7
- var getOptionName = function getOptionName(options, targetOptionID) {
8
- if (!targetOptionID || !Array.isArray(options)) return '';
9
- var targetOption = options.find(function (option) {
10
- return option.id === targetOptionID;
11
- });
15
+ var getOptionName = function getOptionName(options, targetOptionId) {
16
+ if (!targetOptionId || !Array.isArray(options)) return '';
17
+ var targetOption = getOption(options, targetOptionId);
12
18
  return targetOption ? targetOption.name : '';
13
19
  };
20
+ var getColumnOptionNameById = function getColumnOptionNameById(column, optionId) {
21
+ var options = getColumnOptions(column);
22
+ return getOptionName(options, optionId);
23
+ };
14
24
 
15
25
  /**
16
26
  * Get concatenated options names of given ids.
@@ -29,4 +39,4 @@ var getMultipleOptionName = function getMultipleOptionName(options, targetOption
29
39
  }).join(', ');
30
40
  };
31
41
 
32
- export { getMultipleOptionName, getOptionName };
42
+ export { getColumnOptionNameById, getMultipleOptionName, getOption, getOptionName };
@@ -0,0 +1,6 @@
1
+ var getRateDisplayString = function getRateDisplayString(value) {
2
+ if (!value) return '';
3
+ return String(value);
4
+ };
5
+
6
+ export { getRateDisplayString };
@@ -0,0 +1,20 @@
1
+ import { DateUtils } from '../date.js';
2
+ import { getFloatNumber } from './number.js';
3
+
4
+ var formatTextToDate = function formatTextToDate(text) {
5
+ var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
6
+ if (typeof text !== 'string' || !text.trim()) return null;
7
+ var isAllNumber = /^[0-9]+$/.test(text);
8
+ var dateObj = {};
9
+ if (isAllNumber) {
10
+ dateObj = new Date(getFloatNumber(text));
11
+ } else {
12
+ dateObj = DateUtils.parseDateWithFormat(text, dateFormat);
13
+ }
14
+ if (dateFormat.indexOf('HH:mm') < 0) {
15
+ return DateUtils.format(dateObj, 'YYYY-MM-DD') || null;
16
+ }
17
+ return DateUtils.format(dateObj, 'YYYY-MM-DD HH:MM') || null;
18
+ };
19
+
20
+ export { formatTextToDate };
@@ -1,4 +1,6 @@
1
1
  import { NPdivide as divide } from '../helper/number-precision/index.js';
2
+ import { isNumber } from '../number.js';
3
+ import { DURATION_FORMATS_MAP, DURATION_FORMATS } from '../constants/column.js';
2
4
 
3
5
  /**
4
6
  * @param {string} sNumber e.g. '1.23'
@@ -50,4 +52,54 @@ var formatStringToNumber = function formatStringToNumber(sNum, formats) {
50
52
  return value;
51
53
  };
52
54
 
53
- export { formatStringToNumber, getFloatNumber };
55
+ /**
56
+ * parse duration to seconds depend on formats
57
+ * @param {string} duration
58
+ * @param {object} data { duration_format: '' }
59
+ * @returns number
60
+ */
61
+ var formatDurationToNumber = function formatDurationToNumber(duration, data) {
62
+ if (duration === 0) return 0;
63
+ if (!duration) return null;
64
+ var _ref2 = data || {},
65
+ duration_format = _ref2.duration_format;
66
+ duration_format = duration_format || DURATION_FORMATS_MAP.H_MM;
67
+ if (DURATION_FORMATS.findIndex(function (format) {
68
+ return format.type === duration_format;
69
+ }) < 0) {
70
+ return null;
71
+ }
72
+ var numericDuration = duration - 0;
73
+ if (isNumber(numericDuration)) {
74
+ return duration_format === DURATION_FORMATS_MAP.H_MM ? numericDuration * 60 : numericDuration;
75
+ }
76
+ var stringifyDuration = String(duration);
77
+ var isNegative = stringifyDuration[0] === '-';
78
+ if (isNegative) {
79
+ stringifyDuration = stringifyDuration.substring(1);
80
+ }
81
+ var timeParts = stringifyDuration.split(/[::]/); // support ':' and ':'.
82
+ var timePartsLen = timeParts.length;
83
+ var hoursIndex;
84
+ var minutesIndex;
85
+ var secondsIndex;
86
+ if (duration_format === DURATION_FORMATS_MAP.H_MM) {
87
+ hoursIndex = timePartsLen - 2;
88
+ minutesIndex = timePartsLen - 1;
89
+ } else {
90
+ hoursIndex = timePartsLen - 3;
91
+ minutesIndex = timePartsLen - 2;
92
+ secondsIndex = timePartsLen - 1;
93
+ }
94
+ var hours = timeParts[hoursIndex] - 0;
95
+ var minutes = timeParts[minutesIndex] - 0;
96
+ var seconds = timeParts[secondsIndex] - 0;
97
+ if (!isNumber(hours) && !isNumber(minutes) && !isNumber(seconds)) return null;
98
+ hours = isNumber(hours) ? hours : 0;
99
+ minutes = isNumber(minutes) ? minutes : 0;
100
+ seconds = isNumber(seconds) ? seconds : 0;
101
+ var result = hours * 3600 + minutes * 60 + seconds;
102
+ return isNegative ? -result : result;
103
+ };
104
+
105
+ export { formatDurationToNumber, formatStringToNumber, getFloatNumber };
@@ -0,0 +1,100 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
3
+ import _createClass from '@babel/runtime/helpers/createClass';
4
+ import { COLOR_GRADATION_OPTIONS } from '../constants/color.js';
5
+
6
+ var GradientColorUtils = /*#__PURE__*/function () {
7
+ function GradientColorUtils(_ref) {
8
+ var colorType = _ref.colorType,
9
+ max = _ref.max,
10
+ min = _ref.min;
11
+ _classCallCheck(this, GradientColorUtils);
12
+ var newColorType = colorType || 'color_gradation_1';
13
+ var colors = COLOR_GRADATION_OPTIONS[newColorType];
14
+ this.startColor = this.hexToRgb(colors[0]);
15
+ this.endColor = this.hexToRgb(colors[4]);
16
+ this.min = min;
17
+ this.max = max;
18
+ this.computeMap = {};
19
+ }
20
+ _createClass(GradientColorUtils, [{
21
+ key: "hexToRgb",
22
+ value: function hexToRgb(hexCode) {
23
+ var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
24
+ var nextHexCode = hexCode.toLowerCase();
25
+ if (nextHexCode && reg.test(nextHexCode)) {
26
+ if (nextHexCode.length === 4) {
27
+ var newHexCode = '#';
28
+ for (var i = 1; i < 4; i += 1) {
29
+ newHexCode += nextHexCode.slice(i, i + 1).concat(nextHexCode.slice(i, i + 1));
30
+ }
31
+ nextHexCode = newHexCode;
32
+ }
33
+ var hexCodeChange = [];
34
+ for (var _i = 1; _i < 7; _i += 2) {
35
+ hexCodeChange.push(parseInt("0x".concat(nextHexCode.slice(_i, _i + 2))));
36
+ }
37
+ return "RGB(".concat(hexCodeChange.join(','), ")");
38
+ }
39
+ return nextHexCode;
40
+ }
41
+ }, {
42
+ key: "getColorGradation",
43
+ value: function getColorGradation(color1, color2, value1, value2, value) {
44
+ var rgb1 = color1.split(',');
45
+ var r1 = parseInt(rgb1[0].split('(')[1]);
46
+ var g1 = parseInt(rgb1[1]);
47
+ var b1 = parseInt(rgb1[2].split(')')[0]);
48
+ var rgb2 = color2.split(',');
49
+ var r2 = parseInt(rgb2[0].split('(')[1]);
50
+ var g2 = parseInt(rgb2[1]);
51
+ var b2 = parseInt(rgb2[2].split(')')[0]);
52
+ var r = Math.round(r1 - (r1 - r2) / (value1 - value2) * (value1 - value));
53
+ var g = Math.round(g1 - (g1 - g2) / (value1 - value2) * (value1 - value));
54
+ var b = Math.round(b1 - (b1 - b2) / (value1 - value2) * (value1 - value));
55
+ return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
56
+ }
57
+ }, {
58
+ key: "getCellColor",
59
+ value: function getCellColor(value) {
60
+ if (this.computeMap[value]) {
61
+ return this.computeMap[value];
62
+ }
63
+
64
+ // eslint-disable-next-line
65
+ if (value == this.min) {
66
+ if (this.computeMap[value]) {
67
+ this.computeMap[value] = this.startColor;
68
+ } else {
69
+ this.computeMap = _defineProperty({}, value, this.startColor);
70
+ }
71
+ return this.computeMap[value];
72
+ }
73
+
74
+ // eslint-disable-next-line
75
+ if (value == this.max) {
76
+ if (this.computeMap[value]) {
77
+ this.computeMap[value] = this.endColor;
78
+ } else {
79
+ this.computeMap = _defineProperty({}, value, this.endColor);
80
+ }
81
+ return this.computeMap[value];
82
+ }
83
+ if (value > this.min && value < this.max) {
84
+ var color1 = this.startColor,
85
+ color2 = this.endColor,
86
+ value1 = this.min,
87
+ value2 = this.max;
88
+ var color = this.getColorGradation(color1, color2, value1, value2, value);
89
+ this.computeMap[value] = color;
90
+ return this.computeMap[value];
91
+ }
92
+
93
+ // value < min || value > max
94
+ return null;
95
+ }
96
+ }]);
97
+ return GradientColorUtils;
98
+ }();
99
+
100
+ export { GradientColorUtils as default };