@carbon/charts 1.6.13 → 1.7.0

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 (190) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/axis-chart.js +1 -1
  3. package/axis-chart.js.map +1 -1
  4. package/build/src/interfaces/charts.d.ts +6 -0
  5. package/build/src/tools.d.ts +2420 -151
  6. package/bundle.js +1 -1
  7. package/chart.js +1 -1
  8. package/chart.js.map +1 -1
  9. package/charts/alluvial.js +1 -1
  10. package/charts/alluvial.js.map +1 -1
  11. package/charts/area-stacked.js +1 -1
  12. package/charts/area-stacked.js.map +1 -1
  13. package/charts/area.js +1 -1
  14. package/charts/area.js.map +1 -1
  15. package/charts/bar-grouped.js +1 -1
  16. package/charts/bar-grouped.js.map +1 -1
  17. package/charts/bar-simple.js +1 -1
  18. package/charts/bar-simple.js.map +1 -1
  19. package/charts/bar-stacked.js +1 -1
  20. package/charts/bar-stacked.js.map +1 -1
  21. package/charts/boxplot.js +1 -1
  22. package/charts/boxplot.js.map +1 -1
  23. package/charts/bubble.js +1 -1
  24. package/charts/bubble.js.map +1 -1
  25. package/charts/bullet.js +1 -1
  26. package/charts/bullet.js.map +1 -1
  27. package/charts/circle-pack.js +1 -1
  28. package/charts/circle-pack.js.map +1 -1
  29. package/charts/combo.js +1 -1
  30. package/charts/combo.js.map +1 -1
  31. package/charts/donut.js +1 -1
  32. package/charts/donut.js.map +1 -1
  33. package/charts/gauge.js +1 -1
  34. package/charts/gauge.js.map +1 -1
  35. package/charts/heatmap.js +1 -1
  36. package/charts/heatmap.js.map +1 -1
  37. package/charts/histogram.js +1 -1
  38. package/charts/histogram.js.map +1 -1
  39. package/charts/line.js +1 -1
  40. package/charts/line.js.map +1 -1
  41. package/charts/lollipop.js +1 -1
  42. package/charts/lollipop.js.map +1 -1
  43. package/charts/meter.js +1 -1
  44. package/charts/meter.js.map +1 -1
  45. package/charts/pie.js +1 -1
  46. package/charts/pie.js.map +1 -1
  47. package/charts/radar.js +1 -1
  48. package/charts/radar.js.map +1 -1
  49. package/charts/scatter.js +1 -1
  50. package/charts/scatter.js.map +1 -1
  51. package/charts/tree.js +1 -1
  52. package/charts/tree.js.map +1 -1
  53. package/charts/treemap.js +1 -1
  54. package/charts/treemap.js.map +1 -1
  55. package/charts/wordcloud.js +1 -1
  56. package/charts/wordcloud.js.map +1 -1
  57. package/components/axes/axis.js +1 -1
  58. package/components/axes/axis.js.map +1 -1
  59. package/components/axes/grid.js +1 -1
  60. package/components/axes/grid.js.map +1 -1
  61. package/components/axes/hover-axis.js +1 -1
  62. package/components/axes/hover-axis.js.map +1 -1
  63. package/components/axes/ruler-binned.js +1 -1
  64. package/components/axes/ruler-binned.js.map +1 -1
  65. package/components/axes/ruler.js +1 -1
  66. package/components/axes/ruler.js.map +1 -1
  67. package/components/axes/toolbar.js +1 -1
  68. package/components/axes/toolbar.js.map +1 -1
  69. package/components/axes/two-dimensional-axes.js +1 -1
  70. package/components/axes/two-dimensional-axes.js.map +1 -1
  71. package/components/axes/zero-line.js +1 -1
  72. package/components/axes/zero-line.js.map +1 -1
  73. package/components/axes/zoom-bar.js +1 -1
  74. package/components/axes/zoom-bar.js.map +1 -1
  75. package/components/component.js +1 -1
  76. package/components/component.js.map +1 -1
  77. package/components/essentials/color-scale-legend.js +1 -1
  78. package/components/essentials/color-scale-legend.js.map +1 -1
  79. package/components/essentials/highlights.js +1 -1
  80. package/components/essentials/highlights.js.map +1 -1
  81. package/components/essentials/legend.js +1 -1
  82. package/components/essentials/legend.js.map +1 -1
  83. package/components/essentials/modal.js +1 -1
  84. package/components/essentials/modal.js.map +1 -1
  85. package/components/essentials/threshold.js +1 -1
  86. package/components/essentials/threshold.js.map +1 -1
  87. package/components/essentials/title-meter.js +1 -1
  88. package/components/essentials/title-meter.js.map +1 -1
  89. package/components/essentials/title.js +1 -1
  90. package/components/essentials/title.js.map +1 -1
  91. package/components/essentials/tooltip-axis.js +1 -1
  92. package/components/essentials/tooltip-axis.js.map +1 -1
  93. package/components/essentials/tooltip.js +1 -1
  94. package/components/essentials/tooltip.js.map +1 -1
  95. package/components/graphs/alluvial.js +1 -1
  96. package/components/graphs/alluvial.js.map +1 -1
  97. package/components/graphs/area-stacked.js +1 -1
  98. package/components/graphs/area-stacked.js.map +1 -1
  99. package/components/graphs/area.js +1 -1
  100. package/components/graphs/area.js.map +1 -1
  101. package/components/graphs/bar-grouped.js +1 -1
  102. package/components/graphs/bar-grouped.js.map +1 -1
  103. package/components/graphs/bar-simple.js +1 -1
  104. package/components/graphs/bar-simple.js.map +1 -1
  105. package/components/graphs/bar-stacked.js +1 -1
  106. package/components/graphs/bar-stacked.js.map +1 -1
  107. package/components/graphs/bar.js +1 -1
  108. package/components/graphs/bar.js.map +1 -1
  109. package/components/graphs/boxplot.js +1 -1
  110. package/components/graphs/boxplot.js.map +1 -1
  111. package/components/graphs/bubble.js +1 -1
  112. package/components/graphs/bubble.js.map +1 -1
  113. package/components/graphs/bullet.js +1 -1
  114. package/components/graphs/bullet.js.map +1 -1
  115. package/components/graphs/circle-pack.js +1 -1
  116. package/components/graphs/circle-pack.js.map +1 -1
  117. package/components/graphs/donut.js +1 -1
  118. package/components/graphs/donut.js.map +1 -1
  119. package/components/graphs/gauge.js +1 -1
  120. package/components/graphs/gauge.js.map +1 -1
  121. package/components/graphs/heatmap.js +1 -1
  122. package/components/graphs/heatmap.js.map +1 -1
  123. package/components/graphs/histogram.js +1 -1
  124. package/components/graphs/histogram.js.map +1 -1
  125. package/components/graphs/line.js +1 -1
  126. package/components/graphs/line.js.map +1 -1
  127. package/components/graphs/lollipop.js +1 -1
  128. package/components/graphs/lollipop.js.map +1 -1
  129. package/components/graphs/meter.js +1 -1
  130. package/components/graphs/meter.js.map +1 -1
  131. package/components/graphs/pie.js +1 -1
  132. package/components/graphs/pie.js.map +1 -1
  133. package/components/graphs/radar.js +1 -1
  134. package/components/graphs/radar.js.map +1 -1
  135. package/components/graphs/scatter-stacked.js +1 -1
  136. package/components/graphs/scatter-stacked.js.map +1 -1
  137. package/components/graphs/scatter.js +1 -1
  138. package/components/graphs/scatter.js.map +1 -1
  139. package/components/graphs/skeleton-lines.js +1 -1
  140. package/components/graphs/skeleton-lines.js.map +1 -1
  141. package/components/graphs/skeleton.js +1 -1
  142. package/components/graphs/skeleton.js.map +1 -1
  143. package/components/graphs/tree.js +1 -1
  144. package/components/graphs/tree.js.map +1 -1
  145. package/components/graphs/treemap.js +1 -1
  146. package/components/graphs/treemap.js.map +1 -1
  147. package/components/graphs/wordcloud.js +1 -1
  148. package/components/graphs/wordcloud.js.map +1 -1
  149. package/components/layout/layout.js +1 -1
  150. package/components/layout/layout.js.map +1 -1
  151. package/configuration.js +1 -1
  152. package/configuration.js.map +1 -1
  153. package/demo/data/bar.js +60 -12
  154. package/demo/data/bar.js.map +1 -1
  155. package/demo/tsconfig.tsbuildinfo +1 -1
  156. package/interfaces/charts.d.ts +6 -0
  157. package/interfaces/charts.js.map +1 -1
  158. package/model/boxplot.js +1 -1
  159. package/model/boxplot.js.map +1 -1
  160. package/model/bullet.js +1 -1
  161. package/model/bullet.js.map +1 -1
  162. package/model/cartesian-charts.js +1 -1
  163. package/model/cartesian-charts.js.map +1 -1
  164. package/model/circle-pack.js +1 -1
  165. package/model/circle-pack.js.map +1 -1
  166. package/model/heatmap.js +1 -1
  167. package/model/heatmap.js.map +1 -1
  168. package/model/meter.js +1 -1
  169. package/model/meter.js.map +1 -1
  170. package/model/model.js +8 -2
  171. package/model/model.js.map +1 -1
  172. package/model/radar.js +1 -1
  173. package/model/radar.js.map +1 -1
  174. package/model/treemap.js +1 -1
  175. package/model/treemap.js.map +1 -1
  176. package/package.json +1 -1
  177. package/services/essentials/dom-utils.js +15 -3
  178. package/services/essentials/dom-utils.js.map +1 -1
  179. package/services/essentials/transitions.js +1 -1
  180. package/services/essentials/transitions.js.map +1 -1
  181. package/services/scales-cartesian.js +1 -1
  182. package/services/scales-cartesian.js.map +1 -1
  183. package/services/time-series.js +1 -1
  184. package/services/time-series.js.map +1 -1
  185. package/services/zoom.js +1 -1
  186. package/services/zoom.js.map +1 -1
  187. package/tools.d.ts +141 -155
  188. package/tools.js +315 -344
  189. package/tools.js.map +1 -1
  190. package/tsconfig.tsbuildinfo +92 -92
package/tools.js CHANGED
@@ -1,377 +1,348 @@
1
1
  // Internal imports
2
2
  import { CartesianOrientations, ScaleTypes, TruncationTypes, } from './interfaces';
3
3
  import { defaultLegendAdditionalItems } from './configuration-non-customizable';
4
- import { debounce as lodashDebounce, merge as lodashMerge, cloneDeep as lodashCloneDeep, unionBy as lodashUnionBy, uniq as lodashUnique, clamp as lodashClamp, flatten as lodashFlatten, groupBy as lodashGroupBy, camelCase as lodashCamelCase, isEmpty as lodashIsEmpty, isEqual as lodashIsEqual, flatMapDeep as lodashFlatMapDeep, kebabCase as lodashKebabCase, fromPairs as lodashFromPairs, some as lodashSome, } from 'lodash-es';
4
+ import { debounce, merge, cloneDeep, unionBy, uniq, clamp, flatten, groupBy, camelCase, isEmpty, isEqual, flatMapDeep, kebabCase, fromPairs, some, } from 'lodash-es';
5
5
  // D3 Imports
6
6
  // @ts-ignore
7
7
  // ts-ignore is needed because `@types/d3`
8
8
  // is missing the `pointer` function
9
9
  import { pointer } from 'd3-selection';
10
10
  // Functions
11
- export var Tools;
12
- (function (Tools) {
13
- // Export these functions from lodash
14
- Tools.debounce = lodashDebounce;
15
- Tools.clone = lodashCloneDeep;
16
- Tools.merge = lodashMerge;
17
- Tools.unionBy = lodashUnionBy;
18
- Tools.removeArrayDuplicates = lodashUnique;
19
- Tools.clamp = lodashClamp;
20
- Tools.flatten = lodashFlatten;
21
- Tools.groupBy = lodashGroupBy;
22
- Tools.camelCase = lodashCamelCase;
23
- Tools.isEmpty = lodashIsEmpty;
24
- Tools.isEqual = lodashIsEqual;
25
- Tools.flatMapDeep = lodashFlatMapDeep;
26
- Tools.kebabCase = lodashKebabCase;
27
- Tools.fromPairs = lodashFromPairs;
28
- Tools.some = lodashSome;
29
- function debounceWithD3MousePosition(fn, delay, holder) {
30
- var timer = null;
31
- return function () {
32
- var context = this;
33
- var args = arguments;
34
- //we get the D3 event here
35
- context.mousePosition = pointer(args[0], holder);
36
- clearTimeout(timer);
37
- timer = setTimeout(function () {
38
- // and use the reference here
39
- fn.apply(context, args);
40
- }, delay);
41
- };
11
+ // Export these functions from lodash
12
+ export { debounce, merge, unionBy, clamp, flatten, groupBy, camelCase, isEmpty, isEqual, flatMapDeep, kebabCase, fromPairs, some, };
13
+ export var clone = cloneDeep;
14
+ export var removeArrayDuplicates = uniq;
15
+ export function debounceWithD3MousePosition(fn, delay, holder) {
16
+ var timer = null;
17
+ return function () {
18
+ var context = this;
19
+ var args = arguments;
20
+ //we get the D3 event here
21
+ context.mousePosition = pointer(args[0], holder);
22
+ clearTimeout(timer);
23
+ timer = setTimeout(function () {
24
+ // and use the reference here
25
+ fn.apply(context, args);
26
+ }, delay);
27
+ };
28
+ }
29
+ /**
30
+ * Returns default chart options merged with provided options,
31
+ * with special cases for axes.
32
+ * Axes object will not merge the not provided axes.
33
+ *
34
+ * @export
35
+ * @param {AxisChartOptions} defaultOptions Configuration.options[chartType]
36
+ * @param {AxisChartOptions} providedOptions user provided options
37
+ * @returns merged options
38
+ */
39
+ export function mergeDefaultChartOptions(defaultOptions, providedOptions) {
40
+ var _a, _b;
41
+ var clonedDefaultOptions = clone(defaultOptions);
42
+ var providedAxesNames = Object.keys(providedOptions.axes || {});
43
+ // Use provide controls list if it exists
44
+ // Prevents merging and element overriding of the two lists
45
+ if ((_b = (_a = providedOptions) === null || _a === void 0 ? void 0 : _a.toolbar) === null || _b === void 0 ? void 0 : _b.controls) {
46
+ delete clonedDefaultOptions.toolbar.controls;
42
47
  }
43
- Tools.debounceWithD3MousePosition = debounceWithD3MousePosition;
44
- /**
45
- * Returns default chart options merged with provided options,
46
- * with special cases for axes.
47
- * Axes object will not merge the not provided axes.
48
- *
49
- * @export
50
- * @param {AxisChartOptions} defaultOptions Configuration.options[chartType]
51
- * @param {AxisChartOptions} providedOptions user provided options
52
- * @returns merged options
53
- */
54
- function mergeDefaultChartOptions(defaultOptions, providedOptions) {
55
- var _a, _b;
56
- var clonedDefaultOptions = Tools.clone(defaultOptions);
57
- var providedAxesNames = Object.keys(providedOptions.axes || {});
58
- // Use provide controls list if it exists
59
- // Prevents merging and element overriding of the two lists
60
- if ((_b = (_a = providedOptions) === null || _a === void 0 ? void 0 : _a.toolbar) === null || _b === void 0 ? void 0 : _b.controls) {
61
- delete clonedDefaultOptions.toolbar.controls;
62
- }
63
- if (providedAxesNames.length === 0) {
64
- delete clonedDefaultOptions.axes;
65
- }
66
- // Update deprecated options to work with the tabular data format
67
- // Similar to the functionality in model.transformToTabularData()
68
- for (var axisName in clonedDefaultOptions.axes) {
69
- if (providedAxesNames.includes(axisName)) {
70
- var providedAxisOptions = providedOptions.axes[axisName];
71
- if (providedAxisOptions['primary'] ||
72
- providedAxisOptions['secondary']) {
73
- console.warn('`primary` & `secondary` are no longer needed for axis configurations. Read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/docs-tutorials--tabular-data-format');
48
+ if (providedAxesNames.length === 0) {
49
+ delete clonedDefaultOptions.axes;
50
+ }
51
+ // Update deprecated options to work with the tabular data format
52
+ // Similar to the functionality in model.transformToTabularData()
53
+ for (var axisName in clonedDefaultOptions.axes) {
54
+ if (providedAxesNames.includes(axisName)) {
55
+ var providedAxisOptions = providedOptions.axes[axisName];
56
+ if (providedAxisOptions['primary'] ||
57
+ providedAxisOptions['secondary']) {
58
+ console.warn('`primary` & `secondary` are no longer needed for axis configurations. Read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/docs-tutorials--tabular-data-format');
59
+ }
60
+ var identifier = providedAxisOptions['mapsTo'];
61
+ if (identifier === undefined || identifier === null) {
62
+ var scaleType = providedAxisOptions['scaleType'];
63
+ if (scaleType === undefined || scaleType === null) {
64
+ providedAxisOptions['mapsTo'] = 'value';
74
65
  }
75
- var identifier = providedAxisOptions['mapsTo'];
76
- if (identifier === undefined || identifier === null) {
77
- var scaleType = providedAxisOptions['scaleType'];
78
- if (scaleType === undefined || scaleType === null) {
79
- providedAxisOptions['mapsTo'] = 'value';
80
- }
81
- else if (scaleType === ScaleTypes.TIME) {
82
- providedAxisOptions['mapsTo'] = 'date';
83
- }
84
- else if (scaleType === ScaleTypes.LABELS) {
85
- providedAxisOptions['mapsTo'] = 'key';
86
- }
66
+ else if (scaleType === ScaleTypes.TIME) {
67
+ providedAxisOptions['mapsTo'] = 'date';
68
+ }
69
+ else if (scaleType === ScaleTypes.LABELS) {
70
+ providedAxisOptions['mapsTo'] = 'key';
87
71
  }
88
72
  }
89
- else {
90
- delete clonedDefaultOptions.axes[axisName];
91
- }
92
73
  }
93
- updateLegendAdditionalItems(clonedDefaultOptions, providedOptions);
94
- return Tools.merge(clonedDefaultOptions, providedOptions);
74
+ else {
75
+ delete clonedDefaultOptions.axes[axisName];
76
+ }
95
77
  }
96
- Tools.mergeDefaultChartOptions = mergeDefaultChartOptions;
97
- /**************************************
98
- * DOM-related operations *
99
- *************************************/
100
- /**
101
- * Get width & height of an element
102
- *
103
- * @export
104
- * @param {any} el element to get dimensions from
105
- * @returns an object containing the width and height of el
106
- */
107
- function getDimensions(el) {
108
- return {
109
- width: parseFloat(el.style.width.replace('px', '') || el.offsetWidth),
110
- height: parseFloat(el.style.height.replace('px', '') || el.offsetHeight),
111
- };
78
+ updateLegendAdditionalItems(clonedDefaultOptions, providedOptions);
79
+ return merge(clonedDefaultOptions, providedOptions);
80
+ }
81
+ /**************************************
82
+ * DOM-related operations *
83
+ *************************************/
84
+ /**
85
+ * Get width & height of an element
86
+ *
87
+ * @export
88
+ * @param {any} el element to get dimensions from
89
+ * @returns an object containing the width and height of el
90
+ */
91
+ export function getDimensions(el) {
92
+ return {
93
+ width: parseFloat(el.style.width.replace('px', '') || el.offsetWidth),
94
+ height: parseFloat(el.style.height.replace('px', '') || el.offsetHeight),
95
+ };
96
+ }
97
+ /**
98
+ * Gets elements's x and y translations from transform attribute or returns null
99
+ *
100
+ * @param {HTMLElement} element
101
+ * @returns an object containing the translated x and y values or null
102
+ */
103
+ export function getTranslationValues(elementRef) {
104
+ if (!elementRef) {
105
+ return;
112
106
  }
113
- Tools.getDimensions = getDimensions;
114
- /**
115
- * Gets elements's x and y translations from transform attribute or returns null
116
- *
117
- * @param {HTMLElement} element
118
- * @returns an object containing the translated x and y values or null
119
- */
120
- function getTranslationValues(elementRef) {
121
- if (!elementRef) {
122
- return;
123
- }
124
- // regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)
125
- var translateRegex = /translate\([0-9]+\.?[0-9]*,[0-9]+\.?[0-9]*\)/;
126
- var transformStr = elementRef
127
- .getAttribute('transform')
128
- .match(translateRegex);
129
- if (!transformStr) {
130
- return null;
131
- }
132
- // check for the match
133
- if (transformStr[0]) {
134
- var transforms = transformStr[0]
135
- .replace(/translate\(/, '')
136
- .replace(/\)/, '')
137
- .split(',');
138
- return {
139
- tx: transforms[0],
140
- ty: transforms[1],
141
- };
142
- }
107
+ // regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)
108
+ var translateRegex = /translate\([0-9]+\.?[0-9]*,[0-9]+\.?[0-9]*\)/;
109
+ var transformStr = elementRef
110
+ .getAttribute('transform')
111
+ .match(translateRegex);
112
+ if (!transformStr) {
143
113
  return null;
144
114
  }
145
- Tools.getTranslationValues = getTranslationValues;
146
- /**************************************
147
- * Formatting & calculations *
148
- *************************************/
149
- /**
150
- * Gets x and y coordinates from HTML transform attribute
151
- *
152
- * @export
153
- * @param {any} string the transform attribute string ie. transform(x,y)
154
- * @returns Returns an object with x and y offsets of the transform
155
- */
156
- function getTranformOffsets(string) {
157
- var regExp = /\(([^)]+)\)/;
158
- var match = regExp.exec(string)[1];
159
- var xyString = match.split(',');
115
+ // check for the match
116
+ if (transformStr[0]) {
117
+ var transforms = transformStr[0]
118
+ .replace(/translate\(/, '')
119
+ .replace(/\)/, '')
120
+ .split(',');
160
121
  return {
161
- x: parseFloat(xyString[0]),
162
- y: parseFloat(xyString[1]),
122
+ tx: transforms[0],
123
+ ty: transforms[1],
163
124
  };
164
125
  }
165
- Tools.getTranformOffsets = getTranformOffsets;
166
- /**
167
- * Returns string value for height/width using pixels if there isn't a specified unit of measure
168
- *
169
- * @param value string or number value to be checked for unit of measure
170
- */
171
- function formatWidthHeightValues(value) {
172
- var stringValue = value.toString();
173
- // If the value provided contains any letters
174
- // Return it the same way
175
- if (stringValue.match(/[a-z]/i)) {
176
- return stringValue;
177
- }
178
- return stringValue + 'px';
126
+ return null;
127
+ }
128
+ /**************************************
129
+ * Formatting & calculations *
130
+ *************************************/
131
+ /**
132
+ * Gets x and y coordinates from HTML transform attribute
133
+ *
134
+ * @export
135
+ * @param {any} string the transform attribute string ie. transform(x,y)
136
+ * @returns Returns an object with x and y offsets of the transform
137
+ */
138
+ export function getTranformOffsets(string) {
139
+ var regExp = /\(([^)]+)\)/;
140
+ var match = regExp.exec(string)[1];
141
+ var xyString = match.split(',');
142
+ return {
143
+ x: parseFloat(xyString[0]),
144
+ y: parseFloat(xyString[1]),
145
+ };
146
+ }
147
+ /**
148
+ * Returns string value for height/width using pixels if there isn't a specified unit of measure
149
+ *
150
+ * @param value string or number value to be checked for unit of measure
151
+ */
152
+ export function formatWidthHeightValues(value) {
153
+ var stringValue = value.toString();
154
+ // If the value provided contains any letters
155
+ // Return it the same way
156
+ if (stringValue.match(/[a-z]/i)) {
157
+ return stringValue;
179
158
  }
180
- Tools.formatWidthHeightValues = formatWidthHeightValues;
181
- /**
182
- * Capitalizes first letter of a string
183
- *
184
- * @export
185
- * @param {any} string the input string to perform first letter capitalization with
186
- * @returns The transformed string after first letter is capitalized
187
- */
188
- function capitalizeFirstLetter(string) {
189
- return string[0].toUpperCase() + string.slice(1);
159
+ return stringValue + 'px';
160
+ }
161
+ /**
162
+ * Capitalizes first letter of a string
163
+ *
164
+ * @export
165
+ * @param {any} string the input string to perform first letter capitalization with
166
+ * @returns The transformed string after first letter is capitalized
167
+ */
168
+ export function capitalizeFirstLetter(string) {
169
+ return string[0].toUpperCase() + string.slice(1);
170
+ }
171
+ /**
172
+ * Get the percentage of a datapoint compared to the entire dataset.
173
+ * @export
174
+ * @param {any} item
175
+ * @param {any} fullData
176
+ * @param {string} key
177
+ * @returns The percentage in the form of a number (1 significant digit if necessary)
178
+ */
179
+ export function convertValueToPercentage(item, fullData, key) {
180
+ if (key === void 0) { key = 'value'; }
181
+ var percentage = (item / fullData.reduce(function (accum, val) { return accum + val[key]; }, 0)) * 100;
182
+ // if the value has any significant figures, keep 1
183
+ return percentage % 1 !== 0
184
+ ? parseFloat(percentage.toFixed(1))
185
+ : percentage;
186
+ }
187
+ /**
188
+ * Truncate the labels
189
+ * @export
190
+ * @param {any} fullText
191
+ * @param {any} truncationType
192
+ * @param {any} numCharacter
193
+ * @returns Truncated text
194
+ */
195
+ export function truncateLabel(fullText, truncationType, numCharacter) {
196
+ if (numCharacter > fullText.length) {
197
+ return fullText;
190
198
  }
191
- Tools.capitalizeFirstLetter = capitalizeFirstLetter;
192
- /**
193
- * Get the percentage of a datapoint compared to the entire dataset.
194
- * @export
195
- * @param {any} item
196
- * @param {any} fullData
197
- * @param {string} key
198
- * @returns The percentage in the form of a number (1 significant digit if necessary)
199
- */
200
- function convertValueToPercentage(item, fullData, key) {
201
- if (key === void 0) { key = 'value'; }
202
- var percentage = (item / fullData.reduce(function (accum, val) { return accum + val[key]; }, 0)) * 100;
203
- // if the value has any significant figures, keep 1
204
- return percentage % 1 !== 0
205
- ? parseFloat(percentage.toFixed(1))
206
- : percentage;
199
+ if (truncationType === TruncationTypes.MID_LINE) {
200
+ return (fullText.substr(0, numCharacter / 2) +
201
+ '...' +
202
+ fullText.substr(-numCharacter / 2));
207
203
  }
208
- Tools.convertValueToPercentage = convertValueToPercentage;
209
- /**
210
- * Truncate the labels
211
- * @export
212
- * @param {any} fullText
213
- * @param {any} truncationType
214
- * @param {any} numCharacter
215
- * @returns Truncated text
216
- */
217
- function truncateLabel(fullText, truncationType, numCharacter) {
218
- if (numCharacter > fullText.length) {
219
- return fullText;
220
- }
221
- if (truncationType === TruncationTypes.MID_LINE) {
222
- return (fullText.substr(0, numCharacter / 2) +
223
- '...' +
224
- fullText.substr(-numCharacter / 2));
225
- }
226
- else if (truncationType === TruncationTypes.FRONT_LINE) {
227
- return '...' + fullText.substr(-numCharacter);
228
- }
229
- else if (truncationType === TruncationTypes.END_LINE) {
230
- return fullText.substr(0, numCharacter) + '...';
231
- }
204
+ else if (truncationType === TruncationTypes.FRONT_LINE) {
205
+ return '...' + fullText.substr(-numCharacter);
232
206
  }
233
- Tools.truncateLabel = truncateLabel;
234
- /**
235
- * Update legend additional items
236
- * @param {any} defaultOptions
237
- * @param {any} providedOptions
238
- */
239
- function updateLegendAdditionalItems(defaultOptions, providedOptions) {
240
- var defaultAdditionalItems = Tools.getProperty(defaultOptions, 'legend', 'additionalItems');
241
- var userProvidedAdditionalItems = Tools.getProperty(providedOptions, 'legend', 'additionalItems');
242
- // Retain default legend additional items
243
- if (defaultAdditionalItems && userProvidedAdditionalItems) {
244
- var providedTypes_1 = userProvidedAdditionalItems.map(function (item) { return item.type; });
245
- var defaultTypes_1 = defaultAdditionalItems.map(function (item) { return item.type; });
246
- // Get default items in default options but not in provided options
247
- var updatedDefaultItems = defaultLegendAdditionalItems.filter(function (item) {
248
- return defaultTypes_1.includes(item.type) &&
249
- !providedTypes_1.includes(item.type);
250
- });
251
- defaultOptions.legend.additionalItems = updatedDefaultItems;
252
- providedOptions.legend.additionalItems = Tools.unionBy(updatedDefaultItems, userProvidedAdditionalItems, 'name');
253
- }
207
+ else if (truncationType === TruncationTypes.END_LINE) {
208
+ return fullText.substr(0, numCharacter) + '...';
254
209
  }
255
- Tools.updateLegendAdditionalItems = updateLegendAdditionalItems;
256
- /**************************************
257
- * Object/array related checks *
258
- *************************************/
259
- /**
260
- * Compares two arrays to return the difference between two arrays' items.
261
- *
262
- * @export
263
- * @param {any[]} oldArray the array to check for missing items
264
- * @param {any[]} newArray the array to check for newly added items
265
- * @returns An object containing items missing (existing in oldArray but not newArray)
266
- * and items added (existing in newArray but not in oldArray). Object is of the form { missing: [], added: [] }
267
- */
268
- function arrayDifferences(oldArray, newArray) {
269
- var difference = {
270
- missing: [],
271
- added: [],
272
- };
273
- oldArray.forEach(function (element) {
274
- if (newArray.indexOf(element) === -1) {
275
- difference.missing.push(element);
276
- }
277
- });
278
- newArray.forEach(function (element) {
279
- if (oldArray.indexOf(element) === -1) {
280
- difference.added.push(element);
281
- }
282
- });
283
- return difference;
284
- }
285
- Tools.arrayDifferences = arrayDifferences;
286
- /**
287
- * Gets the duplicated keys from an array of data
288
- *
289
- * @export
290
- * @param {*} data - array of data
291
- * @returns A list of the duplicated keys in data
292
- */
293
- function getDuplicateValues(arr) {
294
- var values = [];
295
- var duplicateValues = [];
296
- arr.forEach(function (value) {
297
- if (values.indexOf(value) !== -1 &&
298
- duplicateValues.indexOf(value) === -1) {
299
- duplicateValues.push(value);
300
- }
301
- values.push(value);
302
- });
303
- return duplicateValues;
304
- }
305
- Tools.getDuplicateValues = getDuplicateValues;
306
- // ================================================================================
307
- // D3 Extensions
308
- // ================================================================================
309
- /**
310
- * In D3, moves an element to the front of the canvas
311
- *
312
- * @export
313
- * @param {any} element input element to moved in front
314
- * @returns The function to be used by D3 to push element to the top of the canvas
315
- */
316
- function moveToFront(element) {
317
- return element.each(function () {
318
- this.parentNode.appendChild(this);
210
+ }
211
+ /**
212
+ * Update legend additional items
213
+ * @param {any} defaultOptions
214
+ * @param {any} providedOptions
215
+ */
216
+ export function updateLegendAdditionalItems(defaultOptions, providedOptions) {
217
+ var defaultAdditionalItems = getProperty(defaultOptions, 'legend', 'additionalItems');
218
+ var userProvidedAdditionalItems = getProperty(providedOptions, 'legend', 'additionalItems');
219
+ // Retain default legend additional items
220
+ if (defaultAdditionalItems && userProvidedAdditionalItems) {
221
+ var providedTypes_1 = userProvidedAdditionalItems.map(function (item) { return item.type; });
222
+ var defaultTypes_1 = defaultAdditionalItems.map(function (item) { return item.type; });
223
+ // Get default items in default options but not in provided options
224
+ var updatedDefaultItems = defaultLegendAdditionalItems.filter(function (item) {
225
+ return defaultTypes_1.includes(item.type) &&
226
+ !providedTypes_1.includes(item.type);
319
227
  });
228
+ defaultOptions.legend.additionalItems = updatedDefaultItems;
229
+ providedOptions.legend.additionalItems = unionBy(updatedDefaultItems, userProvidedAdditionalItems, 'name');
320
230
  }
321
- Tools.moveToFront = moveToFront;
322
- // ================================================================================
323
- // Style Helpers
324
- // ================================================================================
325
- /**
326
- * Gets a speicified property from within an object.
327
- *
328
- * @param object the object containing the property to retrieve
329
- * @param propPath nested properties used to extract the final property from within the object
330
- * (i.e "style", "color" would retrieve the color property from within an object that has "color" nested within "style")
331
- */
332
- Tools.getProperty = function (object) {
333
- var propPath = [];
334
- for (var _i = 1; _i < arguments.length; _i++) {
335
- propPath[_i - 1] = arguments[_i];
231
+ }
232
+ /**************************************
233
+ * Object/array related checks *
234
+ *************************************/
235
+ /**
236
+ * Compares two arrays to return the difference between two arrays' items.
237
+ *
238
+ * @export
239
+ * @param {any[]} oldArray the array to check for missing items
240
+ * @param {any[]} newArray the array to check for newly added items
241
+ * @returns An object containing items missing (existing in oldArray but not newArray)
242
+ * and items added (existing in newArray but not in oldArray). Object is of the form { missing: [], added: [] }
243
+ */
244
+ export function arrayDifferences(oldArray, newArray) {
245
+ var difference = {
246
+ missing: [],
247
+ added: [],
248
+ };
249
+ oldArray.forEach(function (element) {
250
+ if (newArray.indexOf(element) === -1) {
251
+ difference.missing.push(element);
336
252
  }
337
- var position = object;
338
- if (position) {
339
- for (var _a = 0, propPath_1 = propPath; _a < propPath_1.length; _a++) {
340
- var prop = propPath_1[_a];
341
- if (position[prop] !== null && position[prop] !== undefined) {
342
- position = position[prop];
343
- }
344
- else {
345
- return null;
346
- }
347
- }
348
- return position;
253
+ });
254
+ newArray.forEach(function (element) {
255
+ if (oldArray.indexOf(element) === -1) {
256
+ difference.added.push(element);
349
257
  }
350
- return null;
351
- };
352
- Tools.flipSVGCoordinatesBasedOnOrientation = function (verticalCoordinates, orientation) {
353
- if (orientation === CartesianOrientations.HORIZONTAL) {
354
- return {
355
- y0: verticalCoordinates.x0,
356
- y1: verticalCoordinates.x1,
357
- x0: verticalCoordinates.y0,
358
- x1: verticalCoordinates.y1,
359
- };
258
+ });
259
+ return difference;
260
+ }
261
+ /**
262
+ * Gets the duplicated keys from an array of data
263
+ *
264
+ * @export
265
+ * @param {*} data - array of data
266
+ * @returns A list of the duplicated keys in data
267
+ */
268
+ export function getDuplicateValues(arr) {
269
+ var values = [];
270
+ var duplicateValues = [];
271
+ arr.forEach(function (value) {
272
+ if (values.indexOf(value) !== -1 &&
273
+ duplicateValues.indexOf(value) === -1) {
274
+ duplicateValues.push(value);
360
275
  }
361
- return verticalCoordinates;
362
- };
363
- Tools.generateSVGPathString = function (verticalCoordinates, orientation) {
364
- var _a = Tools.flipSVGCoordinatesBasedOnOrientation(verticalCoordinates, orientation), x0 = _a.x0, x1 = _a.x1, y0 = _a.y0, y1 = _a.y1;
365
- return "M" + x0 + "," + y0 + "L" + x0 + "," + y1 + "L" + x1 + "," + y1 + "L" + x1 + "," + y0 + "L" + x0 + "," + y0;
366
- };
367
- function flipDomainAndRangeBasedOnOrientation(domain, range, orientation) {
368
- return orientation === CartesianOrientations.VERTICAL
369
- ? [domain, range]
370
- : [range, domain];
276
+ values.push(value);
277
+ });
278
+ return duplicateValues;
279
+ }
280
+ // ================================================================================
281
+ // D3 Extensions
282
+ // ================================================================================
283
+ /**
284
+ * In D3, moves an element to the front of the canvas
285
+ *
286
+ * @export
287
+ * @param {any} element input element to moved in front
288
+ * @returns The function to be used by D3 to push element to the top of the canvas
289
+ */
290
+ export function moveToFront(element) {
291
+ return element.each(function () {
292
+ this.parentNode.appendChild(this);
293
+ });
294
+ }
295
+ // ================================================================================
296
+ // Style Helpers
297
+ // ================================================================================
298
+ /**
299
+ * Gets a speicified property from within an object.
300
+ *
301
+ * @param object the object containing the property to retrieve
302
+ * @param propPath nested properties used to extract the final property from within the object
303
+ * (i.e "style", "color" would retrieve the color property from within an object that has "color" nested within "style")
304
+ */
305
+ export var getProperty = function (object) {
306
+ var propPath = [];
307
+ for (var _i = 1; _i < arguments.length; _i++) {
308
+ propPath[_i - 1] = arguments[_i];
371
309
  }
372
- Tools.flipDomainAndRangeBasedOnOrientation = flipDomainAndRangeBasedOnOrientation;
373
- Tools.compareNumeric = function (a, b) {
374
- return Number(a) === Number(b);
375
- };
376
- })(Tools || (Tools = {}));
310
+ var position = object;
311
+ if (position) {
312
+ for (var _a = 0, propPath_1 = propPath; _a < propPath_1.length; _a++) {
313
+ var prop = propPath_1[_a];
314
+ if (position[prop] !== null && position[prop] !== undefined) {
315
+ position = position[prop];
316
+ }
317
+ else {
318
+ return null;
319
+ }
320
+ }
321
+ return position;
322
+ }
323
+ return null;
324
+ };
325
+ export var flipSVGCoordinatesBasedOnOrientation = function (verticalCoordinates, orientation) {
326
+ if (orientation === CartesianOrientations.HORIZONTAL) {
327
+ return {
328
+ y0: verticalCoordinates.x0,
329
+ y1: verticalCoordinates.x1,
330
+ x0: verticalCoordinates.y0,
331
+ x1: verticalCoordinates.y1,
332
+ };
333
+ }
334
+ return verticalCoordinates;
335
+ };
336
+ export var generateSVGPathString = function (verticalCoordinates, orientation) {
337
+ var _a = flipSVGCoordinatesBasedOnOrientation(verticalCoordinates, orientation), x0 = _a.x0, x1 = _a.x1, y0 = _a.y0, y1 = _a.y1;
338
+ return "M" + x0 + "," + y0 + "L" + x0 + "," + y1 + "L" + x1 + "," + y1 + "L" + x1 + "," + y0 + "L" + x0 + "," + y0;
339
+ };
340
+ export function flipDomainAndRangeBasedOnOrientation(domain, range, orientation) {
341
+ return orientation === CartesianOrientations.VERTICAL
342
+ ? [domain, range]
343
+ : [range, domain];
344
+ }
345
+ export var compareNumeric = function (a, b) {
346
+ return Number(a) === Number(b);
347
+ };
377
348
  //# sourceMappingURL=../src/tools.js.map