@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.
- package/CHANGELOG.md +19 -0
- package/axis-chart.js +1 -1
- package/axis-chart.js.map +1 -1
- package/build/src/interfaces/charts.d.ts +6 -0
- package/build/src/tools.d.ts +2420 -151
- package/bundle.js +1 -1
- package/chart.js +1 -1
- package/chart.js.map +1 -1
- package/charts/alluvial.js +1 -1
- package/charts/alluvial.js.map +1 -1
- package/charts/area-stacked.js +1 -1
- package/charts/area-stacked.js.map +1 -1
- package/charts/area.js +1 -1
- package/charts/area.js.map +1 -1
- package/charts/bar-grouped.js +1 -1
- package/charts/bar-grouped.js.map +1 -1
- package/charts/bar-simple.js +1 -1
- package/charts/bar-simple.js.map +1 -1
- package/charts/bar-stacked.js +1 -1
- package/charts/bar-stacked.js.map +1 -1
- package/charts/boxplot.js +1 -1
- package/charts/boxplot.js.map +1 -1
- package/charts/bubble.js +1 -1
- package/charts/bubble.js.map +1 -1
- package/charts/bullet.js +1 -1
- package/charts/bullet.js.map +1 -1
- package/charts/circle-pack.js +1 -1
- package/charts/circle-pack.js.map +1 -1
- package/charts/combo.js +1 -1
- package/charts/combo.js.map +1 -1
- package/charts/donut.js +1 -1
- package/charts/donut.js.map +1 -1
- package/charts/gauge.js +1 -1
- package/charts/gauge.js.map +1 -1
- package/charts/heatmap.js +1 -1
- package/charts/heatmap.js.map +1 -1
- package/charts/histogram.js +1 -1
- package/charts/histogram.js.map +1 -1
- package/charts/line.js +1 -1
- package/charts/line.js.map +1 -1
- package/charts/lollipop.js +1 -1
- package/charts/lollipop.js.map +1 -1
- package/charts/meter.js +1 -1
- package/charts/meter.js.map +1 -1
- package/charts/pie.js +1 -1
- package/charts/pie.js.map +1 -1
- package/charts/radar.js +1 -1
- package/charts/radar.js.map +1 -1
- package/charts/scatter.js +1 -1
- package/charts/scatter.js.map +1 -1
- package/charts/tree.js +1 -1
- package/charts/tree.js.map +1 -1
- package/charts/treemap.js +1 -1
- package/charts/treemap.js.map +1 -1
- package/charts/wordcloud.js +1 -1
- package/charts/wordcloud.js.map +1 -1
- package/components/axes/axis.js +1 -1
- package/components/axes/axis.js.map +1 -1
- package/components/axes/grid.js +1 -1
- package/components/axes/grid.js.map +1 -1
- package/components/axes/hover-axis.js +1 -1
- package/components/axes/hover-axis.js.map +1 -1
- package/components/axes/ruler-binned.js +1 -1
- package/components/axes/ruler-binned.js.map +1 -1
- package/components/axes/ruler.js +1 -1
- package/components/axes/ruler.js.map +1 -1
- package/components/axes/toolbar.js +1 -1
- package/components/axes/toolbar.js.map +1 -1
- package/components/axes/two-dimensional-axes.js +1 -1
- package/components/axes/two-dimensional-axes.js.map +1 -1
- package/components/axes/zero-line.js +1 -1
- package/components/axes/zero-line.js.map +1 -1
- package/components/axes/zoom-bar.js +1 -1
- package/components/axes/zoom-bar.js.map +1 -1
- package/components/component.js +1 -1
- package/components/component.js.map +1 -1
- package/components/essentials/color-scale-legend.js +1 -1
- package/components/essentials/color-scale-legend.js.map +1 -1
- package/components/essentials/highlights.js +1 -1
- package/components/essentials/highlights.js.map +1 -1
- package/components/essentials/legend.js +1 -1
- package/components/essentials/legend.js.map +1 -1
- package/components/essentials/modal.js +1 -1
- package/components/essentials/modal.js.map +1 -1
- package/components/essentials/threshold.js +1 -1
- package/components/essentials/threshold.js.map +1 -1
- package/components/essentials/title-meter.js +1 -1
- package/components/essentials/title-meter.js.map +1 -1
- package/components/essentials/title.js +1 -1
- package/components/essentials/title.js.map +1 -1
- package/components/essentials/tooltip-axis.js +1 -1
- package/components/essentials/tooltip-axis.js.map +1 -1
- package/components/essentials/tooltip.js +1 -1
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/alluvial.js +1 -1
- package/components/graphs/alluvial.js.map +1 -1
- package/components/graphs/area-stacked.js +1 -1
- package/components/graphs/area-stacked.js.map +1 -1
- package/components/graphs/area.js +1 -1
- package/components/graphs/area.js.map +1 -1
- package/components/graphs/bar-grouped.js +1 -1
- package/components/graphs/bar-grouped.js.map +1 -1
- package/components/graphs/bar-simple.js +1 -1
- package/components/graphs/bar-simple.js.map +1 -1
- package/components/graphs/bar-stacked.js +1 -1
- package/components/graphs/bar-stacked.js.map +1 -1
- package/components/graphs/bar.js +1 -1
- package/components/graphs/bar.js.map +1 -1
- package/components/graphs/boxplot.js +1 -1
- package/components/graphs/boxplot.js.map +1 -1
- package/components/graphs/bubble.js +1 -1
- package/components/graphs/bubble.js.map +1 -1
- package/components/graphs/bullet.js +1 -1
- package/components/graphs/bullet.js.map +1 -1
- package/components/graphs/circle-pack.js +1 -1
- package/components/graphs/circle-pack.js.map +1 -1
- package/components/graphs/donut.js +1 -1
- package/components/graphs/donut.js.map +1 -1
- package/components/graphs/gauge.js +1 -1
- package/components/graphs/gauge.js.map +1 -1
- package/components/graphs/heatmap.js +1 -1
- package/components/graphs/heatmap.js.map +1 -1
- package/components/graphs/histogram.js +1 -1
- package/components/graphs/histogram.js.map +1 -1
- package/components/graphs/line.js +1 -1
- package/components/graphs/line.js.map +1 -1
- package/components/graphs/lollipop.js +1 -1
- package/components/graphs/lollipop.js.map +1 -1
- package/components/graphs/meter.js +1 -1
- package/components/graphs/meter.js.map +1 -1
- package/components/graphs/pie.js +1 -1
- package/components/graphs/pie.js.map +1 -1
- package/components/graphs/radar.js +1 -1
- package/components/graphs/radar.js.map +1 -1
- package/components/graphs/scatter-stacked.js +1 -1
- package/components/graphs/scatter-stacked.js.map +1 -1
- package/components/graphs/scatter.js +1 -1
- package/components/graphs/scatter.js.map +1 -1
- package/components/graphs/skeleton-lines.js +1 -1
- package/components/graphs/skeleton-lines.js.map +1 -1
- package/components/graphs/skeleton.js +1 -1
- package/components/graphs/skeleton.js.map +1 -1
- package/components/graphs/tree.js +1 -1
- package/components/graphs/tree.js.map +1 -1
- package/components/graphs/treemap.js +1 -1
- package/components/graphs/treemap.js.map +1 -1
- package/components/graphs/wordcloud.js +1 -1
- package/components/graphs/wordcloud.js.map +1 -1
- package/components/layout/layout.js +1 -1
- package/components/layout/layout.js.map +1 -1
- package/configuration.js +1 -1
- package/configuration.js.map +1 -1
- package/demo/data/bar.js +60 -12
- package/demo/data/bar.js.map +1 -1
- package/demo/tsconfig.tsbuildinfo +1 -1
- package/interfaces/charts.d.ts +6 -0
- package/interfaces/charts.js.map +1 -1
- package/model/boxplot.js +1 -1
- package/model/boxplot.js.map +1 -1
- package/model/bullet.js +1 -1
- package/model/bullet.js.map +1 -1
- package/model/cartesian-charts.js +1 -1
- package/model/cartesian-charts.js.map +1 -1
- package/model/circle-pack.js +1 -1
- package/model/circle-pack.js.map +1 -1
- package/model/heatmap.js +1 -1
- package/model/heatmap.js.map +1 -1
- package/model/meter.js +1 -1
- package/model/meter.js.map +1 -1
- package/model/model.js +8 -2
- package/model/model.js.map +1 -1
- package/model/radar.js +1 -1
- package/model/radar.js.map +1 -1
- package/model/treemap.js +1 -1
- package/model/treemap.js.map +1 -1
- package/package.json +1 -1
- package/services/essentials/dom-utils.js +15 -3
- package/services/essentials/dom-utils.js.map +1 -1
- package/services/essentials/transitions.js +1 -1
- package/services/essentials/transitions.js.map +1 -1
- package/services/scales-cartesian.js +1 -1
- package/services/scales-cartesian.js.map +1 -1
- package/services/time-series.js +1 -1
- package/services/time-series.js.map +1 -1
- package/services/zoom.js +1 -1
- package/services/zoom.js.map +1 -1
- package/tools.d.ts +141 -155
- package/tools.js +315 -344
- package/tools.js.map +1 -1
- 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
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
94
|
-
|
|
74
|
+
else {
|
|
75
|
+
delete clonedDefaultOptions.axes[axisName];
|
|
76
|
+
}
|
|
95
77
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
162
|
-
|
|
122
|
+
tx: transforms[0],
|
|
123
|
+
ty: transforms[1],
|
|
163
124
|
};
|
|
164
125
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|