@carbon/charts 0.30.21 → 0.30.25
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 +337 -1035
- package/README.md +3 -0
- package/axis-chart.js +8 -14
- package/axis-chart.js.map +1 -1
- package/build/demo/{data/create-codesandbox.d.ts → create-codesandbox.d.ts} +16 -13
- package/build/demo/data/bar.d.ts +175 -1
- package/build/demo/data/bubble.d.ts +41 -0
- package/build/demo/data/donut.d.ts +23 -0
- package/build/demo/data/line.d.ts +70 -0
- package/build/demo/data/pie.d.ts +13 -0
- package/build/demo/data/scatter.d.ts +31 -0
- package/build/demo/data/step.d.ts +4 -0
- package/build/demo/data/time-series-axis.d.ts +55 -3
- package/build/src/components/axes/grid.d.ts +3 -3
- package/build/src/components/axes/two-dimensional-axes.d.ts +3 -0
- package/build/src/components/essentials/threshold.d.ts +17 -0
- package/build/src/components/graphs/bar.d.ts +1 -1
- package/build/src/components/graphs/scatter.d.ts +1 -0
- package/build/src/components/graphs/skeleton.d.ts +22 -0
- package/build/src/components/index.d.ts +2 -0
- package/build/src/interfaces/axis-scales.d.ts +22 -11
- package/build/src/interfaces/charts.d.ts +5 -0
- package/build/src/interfaces/components.d.ts +21 -0
- package/build/src/interfaces/enums.d.ts +9 -0
- package/build/src/interfaces/events.d.ts +7 -0
- package/build/src/model.d.ts +1 -0
- package/build/src/services/scales-cartesian.d.ts +9 -1
- package/build/stories/tutorials/event-listeners.d.ts +1 -0
- package/build/stories/tutorials/index.d.ts +2 -1
- package/bundle.js +1 -1
- package/chart.js +15 -24
- package/chart.js.map +1 -1
- package/charts/bar-grouped.js +6 -2
- package/charts/bar-grouped.js.map +1 -1
- package/charts/bar-simple.js +6 -2
- package/charts/bar-simple.js.map +1 -1
- package/charts/bar-stacked.js +6 -2
- package/charts/bar-stacked.js.map +1 -1
- package/charts/bubble.js +6 -2
- package/charts/bubble.js.map +1 -1
- package/charts/donut.js +6 -2
- package/charts/donut.js.map +1 -1
- package/charts/line.js +6 -2
- package/charts/line.js.map +1 -1
- package/charts/pie.js +6 -2
- package/charts/pie.js.map +1 -1
- package/charts/radar.js +1 -3
- package/charts/radar.js.map +1 -1
- package/charts/scatter.js +6 -2
- package/charts/scatter.js.map +1 -1
- package/components/axes/axis.js +93 -43
- package/components/axes/axis.js.map +1 -1
- package/components/axes/grid.d.ts +3 -3
- package/components/axes/grid.js +46 -23
- package/components/axes/grid.js.map +1 -1
- package/components/axes/ruler.js +7 -5
- package/components/axes/ruler.js.map +1 -1
- package/components/axes/two-dimensional-axes.d.ts +3 -0
- package/components/axes/two-dimensional-axes.js +35 -2
- package/components/axes/two-dimensional-axes.js.map +1 -1
- package/components/axes/zero-line.js +16 -1
- package/components/axes/zero-line.js.map +1 -1
- package/components/component.js +2 -4
- package/components/component.js.map +1 -1
- package/components/essentials/legend.js +46 -23
- package/components/essentials/legend.js.map +1 -1
- package/components/essentials/threshold.d.ts +17 -0
- package/components/essentials/threshold.js +171 -0
- package/components/essentials/threshold.js.map +1 -0
- package/components/essentials/title.js +6 -4
- package/components/essentials/title.js.map +1 -1
- package/components/essentials/tooltip-bar.js +39 -20
- package/components/essentials/tooltip-bar.js.map +1 -1
- package/components/essentials/tooltip-pie.js +4 -3
- package/components/essentials/tooltip-pie.js.map +1 -1
- package/components/essentials/tooltip-radar.js +6 -3
- package/components/essentials/tooltip-radar.js.map +1 -1
- package/components/essentials/tooltip-scatter.js +3 -1
- package/components/essentials/tooltip-scatter.js.map +1 -1
- package/components/essentials/tooltip.js +35 -15
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/bar-grouped.js +48 -20
- package/components/graphs/bar-grouped.js.map +1 -1
- package/components/graphs/bar-simple.js +39 -19
- package/components/graphs/bar-simple.js.map +1 -1
- package/components/graphs/bar-stacked.js +50 -28
- package/components/graphs/bar-stacked.js.map +1 -1
- package/components/graphs/bar.d.ts +1 -1
- package/components/graphs/bar.js +1 -1
- package/components/graphs/bar.js.map +1 -1
- package/components/graphs/bubble.js +22 -8
- package/components/graphs/bubble.js.map +1 -1
- package/components/graphs/donut.js +17 -3
- package/components/graphs/donut.js.map +1 -1
- package/components/graphs/line.js +14 -7
- package/components/graphs/line.js.map +1 -1
- package/components/graphs/pie.js +80 -44
- package/components/graphs/pie.js.map +1 -1
- package/components/graphs/radar.js +271 -140
- package/components/graphs/radar.js.map +1 -1
- package/components/graphs/scatter.d.ts +1 -0
- package/components/graphs/scatter.js +80 -19
- package/components/graphs/scatter.js.map +1 -1
- package/components/graphs/skeleton.d.ts +22 -0
- package/components/graphs/skeleton.js +256 -0
- package/components/graphs/skeleton.js.map +1 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +2 -0
- package/components/index.js.map +1 -1
- package/components/layout/layout.js +38 -26
- package/components/layout/layout.js.map +1 -1
- package/components/layout/spacer.js +2 -1
- package/components/layout/spacer.js.map +1 -1
- package/configuration.js +17 -14
- package/configuration.js.map +1 -1
- package/demo/{data/create-codesandbox.d.ts → create-codesandbox.d.ts} +16 -13
- package/demo/{data/create-codesandbox.js → create-codesandbox.js} +24 -21
- package/demo/create-codesandbox.js.map +1 -0
- package/demo/data/bar.d.ts +175 -1
- package/demo/data/bar.js +189 -3
- package/demo/data/bar.js.map +1 -1
- package/demo/data/bubble.d.ts +41 -0
- package/demo/data/bubble.js +48 -3
- package/demo/data/bubble.js.map +1 -1
- package/demo/data/bundle.js +1 -1
- package/demo/data/donut.d.ts +23 -0
- package/demo/data/donut.js +25 -0
- package/demo/data/donut.js.map +1 -1
- package/demo/data/index.js +189 -7
- package/demo/data/index.js.map +1 -1
- package/demo/data/line.d.ts +70 -0
- package/demo/data/line.js +71 -0
- package/demo/data/line.js.map +1 -1
- package/demo/data/pie.d.ts +13 -0
- package/demo/data/pie.js +15 -0
- package/demo/data/pie.js.map +1 -1
- package/demo/data/radar.js.map +1 -1
- package/demo/data/scatter.d.ts +31 -0
- package/demo/data/scatter.js +33 -0
- package/demo/data/scatter.js.map +1 -1
- package/demo/data/step.d.ts +4 -0
- package/demo/data/step.js +15 -0
- package/demo/data/step.js.map +1 -1
- package/demo/data/time-series-axis.d.ts +55 -3
- package/demo/data/time-series-axis.js +62 -6
- package/demo/data/time-series-axis.js.map +1 -1
- package/demo/styles.css +342 -18
- package/demo/styles.css.map +1 -1
- package/demo/styles.min.css +1 -1
- package/demo/styles.min.css.map +1 -1
- package/demo/tsconfig.tsbuildinfo +232 -229
- package/index.js.map +1 -1
- package/interfaces/axis-scales.d.ts +22 -11
- package/interfaces/axis-scales.js.map +1 -1
- package/interfaces/charts.d.ts +5 -0
- package/interfaces/charts.js.map +1 -1
- package/interfaces/components.d.ts +21 -0
- package/interfaces/components.js.map +1 -1
- package/interfaces/enums.d.ts +9 -0
- package/interfaces/enums.js +10 -0
- package/interfaces/enums.js.map +1 -1
- package/interfaces/events.d.ts +7 -0
- package/interfaces/events.js +8 -0
- package/interfaces/events.js.map +1 -1
- package/model.d.ts +1 -0
- package/model.js +30 -16
- package/model.js.map +1 -1
- package/package.json +4 -2
- package/polyfills.js +7 -2
- package/polyfills.js.map +1 -1
- package/services/angle-utils.js +34 -9
- package/services/angle-utils.js.map +1 -1
- package/services/colors.js.map +1 -1
- package/services/curves.js +4 -2
- package/services/curves.js.map +1 -1
- package/services/essentials/dom-utils.js +4 -3
- package/services/essentials/dom-utils.js.map +1 -1
- package/services/essentials/transitions.js +3 -4
- package/services/essentials/transitions.js.map +1 -1
- package/services/scales-cartesian.d.ts +9 -1
- package/services/scales-cartesian.js +96 -23
- package/services/scales-cartesian.js.map +1 -1
- package/services/time-series.js +36 -19
- package/services/time-series.js.map +1 -1
- package/styles/components/_axis.scss +4 -0
- package/styles/components/_layout.scss +0 -1
- package/styles/components/_ruler.scss +5 -2
- package/styles/components/_skeleton.scss +56 -0
- package/styles/components/_threshold.scss +49 -0
- package/styles/components/_tooltip.scss +6 -5
- package/styles/components/index.scss +2 -0
- package/styles/graphs/_bubble.scss +1 -1
- package/styles/graphs/_radar.scss +4 -2
- package/styles/graphs/_scatter.scss +5 -1
- package/styles/mixins.scss +2 -2
- package/styles-g10.css +87 -4
- package/styles-g10.css.map +1 -1
- package/styles-g10.min.css +1 -1
- package/styles-g10.min.css.map +1 -1
- package/styles-g100.css +87 -4
- package/styles-g100.css.map +1 -1
- package/styles-g100.min.css +1 -1
- package/styles-g100.min.css.map +1 -1
- package/styles-g90.css +87 -4
- package/styles-g90.css.map +1 -1
- package/styles-g90.min.css +1 -1
- package/styles-g90.min.css.map +1 -1
- package/styles.css +87 -4
- package/styles.css.map +1 -1
- package/styles.min.css +1 -1
- package/styles.min.css.map +1 -1
- package/tools.js +25 -7
- package/tools.js.map +1 -1
- package/tsconfig.tsbuildinfo +169 -106
- package/demo/data/create-codesandbox.js.map +0 -1
package/tools.js
CHANGED
|
@@ -34,7 +34,8 @@ export var Tools;
|
|
|
34
34
|
for (var axisName in defaultOptions.axes) {
|
|
35
35
|
if (providedAxesNames.includes(axisName)) {
|
|
36
36
|
var providedAxisOptions = providedOptions.axes[axisName];
|
|
37
|
-
if (providedAxisOptions["primary"] ||
|
|
37
|
+
if (providedAxisOptions["primary"] ||
|
|
38
|
+
providedAxisOptions["secondary"]) {
|
|
38
39
|
console.warn("`primary` & `secondary` are no longer needed for axis configurations. Read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/tutorials--tabular-data-format");
|
|
39
40
|
}
|
|
40
41
|
var identifier = providedAxisOptions["mapsTo"];
|
|
@@ -82,12 +83,23 @@ export var Tools;
|
|
|
82
83
|
* @returns an object containing the translated x and y values or null
|
|
83
84
|
*/
|
|
84
85
|
function getTranslationValues(elementRef) {
|
|
86
|
+
if (!elementRef) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
85
89
|
// regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)
|
|
86
90
|
var translateRegex = /translate\([0-9]+\.?[0-9]*,[0-9]+\.?[0-9]*\)/;
|
|
87
|
-
var transformStr = elementRef
|
|
91
|
+
var transformStr = elementRef
|
|
92
|
+
.getAttribute("transform")
|
|
93
|
+
.match(translateRegex);
|
|
94
|
+
if (!transformStr) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
88
97
|
// check for the match
|
|
89
98
|
if (transformStr[0]) {
|
|
90
|
-
var transforms = transformStr[0]
|
|
99
|
+
var transforms = transformStr[0]
|
|
100
|
+
.replace(/translate\(/, "")
|
|
101
|
+
.replace(/\)/, "")
|
|
102
|
+
.split(",");
|
|
91
103
|
return {
|
|
92
104
|
tx: transforms[0],
|
|
93
105
|
ty: transforms[1]
|
|
@@ -150,9 +162,12 @@ export var Tools;
|
|
|
150
162
|
* @returns The percentage in the form of a number (1 significant digit if necessary)
|
|
151
163
|
*/
|
|
152
164
|
function convertValueToPercentage(item, fullData) {
|
|
153
|
-
var percentage = item / fullData.reduce(function (accum, val) { return accum + val.value; }, 0) *
|
|
165
|
+
var percentage = (item / fullData.reduce(function (accum, val) { return accum + val.value; }, 0)) *
|
|
166
|
+
100;
|
|
154
167
|
// if the value has any significant figures, keep 1
|
|
155
|
-
return percentage % 1 !== 0
|
|
168
|
+
return percentage % 1 !== 0
|
|
169
|
+
? parseFloat(percentage.toFixed(1))
|
|
170
|
+
: percentage;
|
|
156
171
|
}
|
|
157
172
|
Tools.convertValueToPercentage = convertValueToPercentage;
|
|
158
173
|
/**************************************
|
|
@@ -196,7 +211,8 @@ export var Tools;
|
|
|
196
211
|
var values = [];
|
|
197
212
|
var duplicateValues = [];
|
|
198
213
|
arr.forEach(function (value) {
|
|
199
|
-
if (values.indexOf(value) !== -1 &&
|
|
214
|
+
if (values.indexOf(value) !== -1 &&
|
|
215
|
+
duplicateValues.indexOf(value) === -1) {
|
|
200
216
|
duplicateValues.push(value);
|
|
201
217
|
}
|
|
202
218
|
values.push(value);
|
|
@@ -266,7 +282,9 @@ export var Tools;
|
|
|
266
282
|
return "M" + x0 + "," + y0 + "L" + x0 + "," + y1 + "L" + x1 + "," + y1 + "L" + x1 + "," + y0 + "L" + x0 + "," + y0;
|
|
267
283
|
};
|
|
268
284
|
function flipDomainAndRangeBasedOnOrientation(domain, range, orientation) {
|
|
269
|
-
return orientation === CartesianOrientations.VERTICAL
|
|
285
|
+
return orientation === CartesianOrientations.VERTICAL
|
|
286
|
+
? [domain, range]
|
|
287
|
+
: [range, domain];
|
|
270
288
|
}
|
|
271
289
|
Tools.flipDomainAndRangeBasedOnOrientation = flipDomainAndRangeBasedOnOrientation;
|
|
272
290
|
})(Tools || (Tools = {}));
|
package/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["tools.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAEN,qBAAqB,EACrB,UAAU,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,QAAQ,IAAI,cAAc,EAC1B,KAAK,IAAI,WAAW,EACpB,SAAS,IAAI,eAAe,EAC5B,IAAI,IAAI,YAAY,EACpB,KAAK,IAAI,WAAW,EACpB,OAAO,IAAI,aAAa,EACxB,WAAW,IAAI,iBAAiB,EAChC,SAAS,IAAI,eAAe,EAI5B,MAAM,WAAW,CAAC;AAEnB,YAAY;AACZ,MAAM,KAAW,KAAK,CAuSrB;AAvSD,WAAiB,KAAK;IACrB,qCAAqC;IACxB,cAAQ,GAAG,cAAc,CAAC;IAC1B,WAAK,GAAG,eAAe,CAAC;IACxB,WAAK,GAAG,WAAW,CAAC;IACpB,2BAAqB,GAAG,YAAY,CAAC;IACrC,WAAK,GAAG,WAAW,CAAC;IACpB,aAAO,GAAG,aAAa,CAAC;IACxB,iBAAW,GAAG,iBAAiB,CAAC;IAChC,eAAS,GAAG,eAAe,CAAC;IAEzC;;;;;;;;;OASG;IACH,SAAgB,wBAAwB,CAAC,cAAmB,EAAE,eAAoB;QACjF,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC7C,IAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,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oCAAoC,CAAO,MAAS,EAAE,KAAQ,EAAE,WAAmC;QAClH,OAAO,WAAW,KAAK,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3F,CAAC;IAFe,0CAAoC,uCAEnD,CAAA;AACF,CAAC,EAvSgB,KAAK,KAAL,KAAK,QAuSrB","sourcesContent":["// Internal imports\nimport {\n\tAxisChartOptions,\n\tCartesianOrientations,\n\tScaleTypes\n} from \"./interfaces\";\n\nimport {\n\tdebounce as lodashDebounce,\n\tmerge as lodashMerge,\n\tcloneDeep as lodashCloneDeep,\n\tuniq as lodashUnique,\n\tclamp as lodashClamp,\n\tisEqual as lodashIsEqual,\n\tflatMapDeep as lodashFlatMapDeep,\n\tkebabCase as lodashKebabCase,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tCancelable,\n\tDebounceSettings\n} from \"lodash-es\";\n\n// Functions\nexport namespace Tools {\n\t// Export these functions from lodash\n\texport const debounce = lodashDebounce;\n\texport const clone = lodashCloneDeep;\n\texport const merge = lodashMerge;\n\texport const removeArrayDuplicates = lodashUnique;\n\texport const clamp = lodashClamp;\n\texport const isEqual = lodashIsEqual;\n\texport const flatMapDeep = lodashFlatMapDeep;\n\texport const kebabCase = lodashKebabCase;\n\n\t/**\n\t * Returns default chart options merged with provided options,\n\t * with special cases for axes.\n\t * Axes object will not merge the not provided axes.\n\t *\n\t * @export\n\t * @param {AxisChartOptions} defaultOptions Configuration.options[chartType]\n\t * @param {AxisChartOptions} providedOptions user provided options\n\t * @returns merged options\n\t */\n\texport function mergeDefaultChartOptions(defaultOptions: any, providedOptions: any) {\n\t\tdefaultOptions = Tools.clone(defaultOptions);\n\t\tconst providedAxesNames = Object.keys(providedOptions.axes || {});\n\n\t\tif (providedAxesNames.length === 0) {\n\t\t\tdelete defaultOptions.axes;\n\t\t}\n\n\t\t// Update deprecated options to work with the tabular data format\n\t\t// Similar to the functionality in model.transformToTabularData()\n\t\tfor (const axisName in defaultOptions.axes) {\n\t\t\tif (providedAxesNames.includes(axisName)) {\n\t\t\t\tconst providedAxisOptions = providedOptions.axes[axisName];\n\n\t\t\t\tif (providedAxisOptions[\"primary\"] || providedAxisOptions[\"secondary\"]) {\n\t\t\t\t\tconsole.warn(\"`primary` & `secondary` are no longer needed for axis configurations. Read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/tutorials--tabular-data-format\");\n\t\t\t\t}\n\n\t\t\t\tconst identifier = providedAxisOptions[\"mapsTo\"];\n\t\t\t\tif (identifier === undefined || identifier === null) {\n\t\t\t\t\tconst scaleType = providedAxisOptions[\"scaleType\"];\n\n\t\t\t\t\tif (scaleType === undefined || scaleType === null) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"value\";\n\t\t\t\t\t} else if (scaleType === ScaleTypes.TIME) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"date\";\n\t\t\t\t\t} else if (scaleType === ScaleTypes.LABELS) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"key\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdelete defaultOptions.axes[axisName];\n\t\t\t}\n\t\t}\n\n\t\treturn Tools.merge(\n\t\t\tdefaultOptions,\n\t\t\tprovidedOptions\n\t\t);\n\t}\n\n\t/**************************************\n\t * DOM-related operations *\n\t *************************************/\n\n\t/**\n\t * Get width & height of an element\n\t *\n\t * @export\n\t * @param {any} el element to get dimensions from\n\t * @returns an object containing the width and height of el\n\t */\n\texport function getDimensions(el) {\n\t\treturn {\n\t\t\twidth: parseFloat(el.style.width.replace(\"px\", \"\") || el.offsetWidth),\n\t\t\theight: parseFloat(el.style.height.replace(\"px\", \"\") || el.offsetHeight)\n\t\t};\n\t}\n\n\t/**\n\t * Gets elements's x and y translations from transform attribute or returns null\n\t *\n\t * @param {HTMLElement} element\n\t * @returns an object containing the translated x and y values or null\n\t */\n\texport function getTranslationValues(elementRef: HTMLElement) {\n\t\t// regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)\n\t\tconst translateRegex = /translate\\([0-9]+\\.?[0-9]*,[0-9]+\\.?[0-9]*\\)/;\n\n\t\tconst transformStr = elementRef.getAttribute(\"transform\").match(translateRegex);\n\t\t// check for the match\n\t\tif (transformStr[0]) {\n\t\t\tconst transforms = transformStr[0].replace(/translate\\(/, \"\").replace(/\\)/, \"\").split(\",\");\n\n\t\t\treturn {\n\t\t\t\ttx: transforms[0],\n\t\t\t\tty: transforms[1]\n\t\t\t};\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**************************************\n\t * Formatting & calculations *\n\t *************************************/\n\n\t/**\n\t * Gets x and y coordinates from HTML transform attribute\n\t *\n\t * @export\n\t * @param {any} string the transform attribute string ie. transform(x,y)\n\t * @returns Returns an object with x and y offsets of the transform\n\t */\n\texport function getTranformOffsets(string) {\n\t\tconst regExp = /\\(([^)]+)\\)/;\n\t\tconst match = regExp.exec(string)[1];\n\t\tconst xyString = match.split(\",\");\n\n\t\treturn {\n\t\t\tx: parseFloat(xyString[0]),\n\t\t\ty: parseFloat(xyString[1])\n\t\t};\n\t}\n\n\t/**\n\t * Returns string value for height/width using pixels if there isn't a specified unit of measure\n\t *\n\t * @param value string or number value to be checked for unit of measure\n\t */\n\texport function formatWidthHeightValues(value) {\n\t\tconst stringValue = value.toString();\n\n\t\t// If the value provided contains any letters\n\t\t// Return it the same way\n\t\tif (stringValue.match(/[a-z]/i)) {\n\t\t\treturn stringValue;\n\t\t}\n\n\t\treturn stringValue + \"px\";\n\t}\n\n\t/**\n\t * Capitalizes first letter of a string\n\t *\n\t * @export\n\t * @param {any} string the input string to perform first letter capitalization with\n\t * @returns The transformed string after first letter is capitalized\n\t */\n\texport function capitalizeFirstLetter(string) {\n\t\treturn string[0].toUpperCase() + string.slice(1);\n\t}\n\n\t/**\n\t * Get the percentage of a datapoint compared to the entire dataset.\n\t * @export\n\t * @param {any} item\n\t * @param {any} fullData\n\t * @returns The percentage in the form of a number (1 significant digit if necessary)\n\t */\n\texport function convertValueToPercentage(item, fullData) {\n\t\tconst percentage = item / fullData.reduce((accum, val) => accum + val.value, 0) * 100;\n\t\t// if the value has any significant figures, keep 1\n\t\treturn percentage % 1 !== 0 ? parseFloat(percentage.toFixed(1)) : percentage;\n\t}\n\n\t/**************************************\n\t * Object/array related checks *\n\t *************************************/\n\n\t/**\n\t * Compares two arrays to return the difference between two arrays' items.\n\t *\n\t * @export\n\t * @param {any[]} oldArray the array to check for missing items\n\t * @param {any[]} newArray the array to check for newly added items\n\t * @returns An object containing items missing (existing in oldArray but not newArray)\n\t * and items added (existing in newArray but not in oldArray). Object is of the form { missing: [], added: [] }\n\t */\n\texport function arrayDifferences(oldArray: any[], newArray: any[]) {\n\t\tconst difference = {\n\t\t\tmissing: [],\n\t\t\tadded: []\n\t\t};\n\n\t\toldArray.forEach(element => {\n\t\t\tif (newArray.indexOf(element) === -1) {\n\t\t\t\tdifference.missing.push(element);\n\t\t\t}\n\t\t});\n\n\t\tnewArray.forEach(element => {\n\t\t\tif (oldArray.indexOf(element) === -1) {\n\t\t\t\tdifference.added.push(element);\n\t\t\t}\n\t\t});\n\n\t\treturn difference;\n\t}\n\n\t/**\n\t * Gets the duplicated keys from an array of data\n\t *\n\t * @export\n\t * @param {*} data - array of data\n\t * @returns A list of the duplicated keys in data\n\t */\n\texport function getDuplicateValues(arr: any) {\n\t\tconst values = [];\n\t\tconst duplicateValues = [];\n\n\t\tarr.forEach(value => {\n\t\t\tif (values.indexOf(value) !== -1 && duplicateValues.indexOf(value) === -1) {\n\t\t\t\tduplicateValues.push(value);\n\t\t\t}\n\n\t\t\tvalues.push(value);\n\t\t});\n\n\t\treturn duplicateValues;\n\t}\n\n\t// ================================================================================\n\t// D3 Extensions\n\t// ================================================================================\n\n\t/**\n\t * In D3, moves an element to the front of the canvas\n\t *\n\t * @export\n\t * @param {any} element input element to moved in front\n\t * @returns The function to be used by D3 to push element to the top of the canvas\n\t */\n\texport function moveToFront(element) {\n\t\treturn element.each(function() {\n\t\t\tthis.parentNode.appendChild(this);\n\t\t});\n\t}\n\n\t// ================================================================================\n\t// Style Helpers\n\t// ================================================================================\n\n\t/**\n\t * Gets a speicified property from within an object.\n\t *\n\t * @param object the object containing the property to retrieve\n\t * @param propPath nested properties used to extract the final property from within the object\n\t * (i.e \"style\", \"color\" would retrieve the color property from within an object that has \"color\" nested within \"style\")\n\t */\n\texport const getProperty = (object, ...propPath) => {\n\t\tlet position = object;\n\t\tif (position) {\n\t\t\tfor (const prop of propPath) {\n\t\t\t\tif (position[prop] !== null && position[prop] !== undefined) {\n\t\t\t\t\tposition = position[prop];\n\t\t\t\t} else {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn position;\n\t\t}\n\n\t\treturn null;\n\t};\n\n\tinterface SVGPathCoordinates {\n\t\tx0: number;\n\t\tx1: number;\n\t\ty0: number;\n\t\ty1: number;\n\t}\n\n\texport const flipSVGCoordinatesBasedOnOrientation = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tif (orientation === CartesianOrientations.HORIZONTAL) {\n\t\t\treturn {\n\t\t\t\ty0: verticalCoordinates.x0,\n\t\t\t\ty1: verticalCoordinates.x1,\n\t\t\t\tx0: verticalCoordinates.y0,\n\t\t\t\tx1: verticalCoordinates.y1\n\t\t\t};\n\t\t}\n\n\t\treturn verticalCoordinates;\n\t};\n\n\texport const generateSVGPathString = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tconst { x0, x1, y0, y1 } = flipSVGCoordinatesBasedOnOrientation(verticalCoordinates, orientation);\n\n\t\treturn `M${x0},${y0}L${x0},${y1}L${x1},${y1}L${x1},${y0}L${x0},${y0}`;\n\t};\n\n\texport function flipDomainAndRangeBasedOnOrientation<D, R>(domain: D, range: R, orientation?: CartesianOrientations): [D, R] | [R, D] {\n\t\treturn orientation === CartesianOrientations.VERTICAL ? [domain, range] : [range, domain];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["tools.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAEN,qBAAqB,EACrB,UAAU,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,QAAQ,IAAI,cAAc,EAC1B,KAAK,IAAI,WAAW,EACpB,SAAS,IAAI,eAAe,EAC5B,IAAI,IAAI,YAAY,EACpB,KAAK,IAAI,WAAW,EACpB,OAAO,IAAI,aAAa,EACxB,WAAW,IAAI,iBAAiB,EAChC,SAAS,IAAI,eAAe,EAI5B,MAAM,WAAW,CAAC;AAEnB,YAAY;AACZ,MAAM,KAAW,KAAK,CAmVrB;AAnVD,WAAiB,KAAK;IACrB,qCAAqC;IACxB,cAAQ,GAAG,cAAc,CAAC;IAC1B,WAAK,GAAG,eAAe,CAAC;IACxB,WAAK,GAAG,WAAW,CAAC;IACpB,2BAAqB,GAAG,YAAY,CAAC;IACrC,WAAK,GAAG,WAAW,CAAC;IACpB,aAAO,GAAG,aAAa,CAAC;IACxB,iBAAW,GAAG,iBAAiB,CAAC;IAChC,eAAS,GAAG,eAAe,CAAC;IAEzC;;;;;;;;;OASG;IACH,SAAgB,wBAAwB,CACvC,cAAmB,EACnB,eAAoB;QAEpB,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC7C,IAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAElE,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YACnC,OAAO,cAAc,CAAC,IAAI,CAAC;SAC3B;QAED,iEAAiE;QACjE,iEAAiE;QACjE,KAAK,IAAM,QAAQ,IAAI,cAAc,CAAC,IAAI,EAAE;YAC3C,IAAI,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,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B,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACpB,CAAC;IARe,0CAAoC,uCAQnD,CAAA;AACF,CAAC,EAnVgB,KAAK,KAAL,KAAK,QAmVrB","sourcesContent":["// Internal imports\nimport {\n\tAxisChartOptions,\n\tCartesianOrientations,\n\tScaleTypes\n} from \"./interfaces\";\n\nimport {\n\tdebounce as lodashDebounce,\n\tmerge as lodashMerge,\n\tcloneDeep as lodashCloneDeep,\n\tuniq as lodashUnique,\n\tclamp as lodashClamp,\n\tisEqual as lodashIsEqual,\n\tflatMapDeep as lodashFlatMapDeep,\n\tkebabCase as lodashKebabCase,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tCancelable,\n\tDebounceSettings\n} from \"lodash-es\";\n\n// Functions\nexport namespace Tools {\n\t// Export these functions from lodash\n\texport const debounce = lodashDebounce;\n\texport const clone = lodashCloneDeep;\n\texport const merge = lodashMerge;\n\texport const removeArrayDuplicates = lodashUnique;\n\texport const clamp = lodashClamp;\n\texport const isEqual = lodashIsEqual;\n\texport const flatMapDeep = lodashFlatMapDeep;\n\texport const kebabCase = lodashKebabCase;\n\n\t/**\n\t * Returns default chart options merged with provided options,\n\t * with special cases for axes.\n\t * Axes object will not merge the not provided axes.\n\t *\n\t * @export\n\t * @param {AxisChartOptions} defaultOptions Configuration.options[chartType]\n\t * @param {AxisChartOptions} providedOptions user provided options\n\t * @returns merged options\n\t */\n\texport function mergeDefaultChartOptions(\n\t\tdefaultOptions: any,\n\t\tprovidedOptions: any\n\t) {\n\t\tdefaultOptions = Tools.clone(defaultOptions);\n\t\tconst providedAxesNames = Object.keys(providedOptions.axes || {});\n\n\t\tif (providedAxesNames.length === 0) {\n\t\t\tdelete defaultOptions.axes;\n\t\t}\n\n\t\t// Update deprecated options to work with the tabular data format\n\t\t// Similar to the functionality in model.transformToTabularData()\n\t\tfor (const axisName in defaultOptions.axes) {\n\t\t\tif (providedAxesNames.includes(axisName)) {\n\t\t\t\tconst providedAxisOptions = providedOptions.axes[axisName];\n\n\t\t\t\tif (\n\t\t\t\t\tprovidedAxisOptions[\"primary\"] ||\n\t\t\t\t\tprovidedAxisOptions[\"secondary\"]\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\"`primary` & `secondary` are no longer needed for axis configurations. Read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/tutorials--tabular-data-format\"\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst identifier = providedAxisOptions[\"mapsTo\"];\n\t\t\t\tif (identifier === undefined || identifier === null) {\n\t\t\t\t\tconst scaleType = providedAxisOptions[\"scaleType\"];\n\n\t\t\t\t\tif (scaleType === undefined || scaleType === null) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"value\";\n\t\t\t\t\t} else if (scaleType === ScaleTypes.TIME) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"date\";\n\t\t\t\t\t} else if (scaleType === ScaleTypes.LABELS) {\n\t\t\t\t\t\tprovidedAxisOptions[\"mapsTo\"] = \"key\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdelete defaultOptions.axes[axisName];\n\t\t\t}\n\t\t}\n\n\t\treturn Tools.merge(defaultOptions, providedOptions);\n\t}\n\n\t/**************************************\n\t * DOM-related operations *\n\t *************************************/\n\n\t/**\n\t * Get width & height of an element\n\t *\n\t * @export\n\t * @param {any} el element to get dimensions from\n\t * @returns an object containing the width and height of el\n\t */\n\texport function getDimensions(el) {\n\t\treturn {\n\t\t\twidth: parseFloat(\n\t\t\t\tel.style.width.replace(\"px\", \"\") || el.offsetWidth\n\t\t\t),\n\t\t\theight: parseFloat(\n\t\t\t\tel.style.height.replace(\"px\", \"\") || el.offsetHeight\n\t\t\t)\n\t\t};\n\t}\n\n\t/**\n\t * Gets elements's x and y translations from transform attribute or returns null\n\t *\n\t * @param {HTMLElement} element\n\t * @returns an object containing the translated x and y values or null\n\t */\n\texport function getTranslationValues(elementRef: HTMLElement) {\n\t\tif (!elementRef) {\n\t\t\treturn;\n\t\t}\n\n\t\t// regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)\n\t\tconst translateRegex = /translate\\([0-9]+\\.?[0-9]*,[0-9]+\\.?[0-9]*\\)/;\n\n\t\tconst transformStr = elementRef\n\t\t\t.getAttribute(\"transform\")\n\t\t\t.match(translateRegex);\n\t\tif (!transformStr) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// check for the match\n\t\tif (transformStr[0]) {\n\t\t\tconst transforms = transformStr[0]\n\t\t\t\t.replace(/translate\\(/, \"\")\n\t\t\t\t.replace(/\\)/, \"\")\n\t\t\t\t.split(\",\");\n\n\t\t\treturn {\n\t\t\t\ttx: transforms[0],\n\t\t\t\tty: transforms[1]\n\t\t\t};\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**************************************\n\t * Formatting & calculations *\n\t *************************************/\n\n\t/**\n\t * Gets x and y coordinates from HTML transform attribute\n\t *\n\t * @export\n\t * @param {any} string the transform attribute string ie. transform(x,y)\n\t * @returns Returns an object with x and y offsets of the transform\n\t */\n\texport function getTranformOffsets(string) {\n\t\tconst regExp = /\\(([^)]+)\\)/;\n\t\tconst match = regExp.exec(string)[1];\n\t\tconst xyString = match.split(\",\");\n\n\t\treturn {\n\t\t\tx: parseFloat(xyString[0]),\n\t\t\ty: parseFloat(xyString[1])\n\t\t};\n\t}\n\n\t/**\n\t * Returns string value for height/width using pixels if there isn't a specified unit of measure\n\t *\n\t * @param value string or number value to be checked for unit of measure\n\t */\n\texport function formatWidthHeightValues(value) {\n\t\tconst stringValue = value.toString();\n\n\t\t// If the value provided contains any letters\n\t\t// Return it the same way\n\t\tif (stringValue.match(/[a-z]/i)) {\n\t\t\treturn stringValue;\n\t\t}\n\n\t\treturn stringValue + \"px\";\n\t}\n\n\t/**\n\t * Capitalizes first letter of a string\n\t *\n\t * @export\n\t * @param {any} string the input string to perform first letter capitalization with\n\t * @returns The transformed string after first letter is capitalized\n\t */\n\texport function capitalizeFirstLetter(string) {\n\t\treturn string[0].toUpperCase() + string.slice(1);\n\t}\n\n\t/**\n\t * Get the percentage of a datapoint compared to the entire dataset.\n\t * @export\n\t * @param {any} item\n\t * @param {any} fullData\n\t * @returns The percentage in the form of a number (1 significant digit if necessary)\n\t */\n\texport function convertValueToPercentage(item, fullData) {\n\t\tconst percentage =\n\t\t\t(item / fullData.reduce((accum, val) => accum + val.value, 0)) *\n\t\t\t100;\n\t\t// if the value has any significant figures, keep 1\n\t\treturn percentage % 1 !== 0\n\t\t\t? parseFloat(percentage.toFixed(1))\n\t\t\t: percentage;\n\t}\n\n\t/**************************************\n\t * Object/array related checks *\n\t *************************************/\n\n\t/**\n\t * Compares two arrays to return the difference between two arrays' items.\n\t *\n\t * @export\n\t * @param {any[]} oldArray the array to check for missing items\n\t * @param {any[]} newArray the array to check for newly added items\n\t * @returns An object containing items missing (existing in oldArray but not newArray)\n\t * and items added (existing in newArray but not in oldArray). Object is of the form { missing: [], added: [] }\n\t */\n\texport function arrayDifferences(oldArray: any[], newArray: any[]) {\n\t\tconst difference = {\n\t\t\tmissing: [],\n\t\t\tadded: []\n\t\t};\n\n\t\toldArray.forEach(element => {\n\t\t\tif (newArray.indexOf(element) === -1) {\n\t\t\t\tdifference.missing.push(element);\n\t\t\t}\n\t\t});\n\n\t\tnewArray.forEach(element => {\n\t\t\tif (oldArray.indexOf(element) === -1) {\n\t\t\t\tdifference.added.push(element);\n\t\t\t}\n\t\t});\n\n\t\treturn difference;\n\t}\n\n\t/**\n\t * Gets the duplicated keys from an array of data\n\t *\n\t * @export\n\t * @param {*} data - array of data\n\t * @returns A list of the duplicated keys in data\n\t */\n\texport function getDuplicateValues(arr: any) {\n\t\tconst values = [];\n\t\tconst duplicateValues = [];\n\n\t\tarr.forEach(value => {\n\t\t\tif (\n\t\t\t\tvalues.indexOf(value) !== -1 &&\n\t\t\t\tduplicateValues.indexOf(value) === -1\n\t\t\t) {\n\t\t\t\tduplicateValues.push(value);\n\t\t\t}\n\n\t\t\tvalues.push(value);\n\t\t});\n\n\t\treturn duplicateValues;\n\t}\n\n\t// ================================================================================\n\t// D3 Extensions\n\t// ================================================================================\n\n\t/**\n\t * In D3, moves an element to the front of the canvas\n\t *\n\t * @export\n\t * @param {any} element input element to moved in front\n\t * @returns The function to be used by D3 to push element to the top of the canvas\n\t */\n\texport function moveToFront(element) {\n\t\treturn element.each(function() {\n\t\t\tthis.parentNode.appendChild(this);\n\t\t});\n\t}\n\n\t// ================================================================================\n\t// Style Helpers\n\t// ================================================================================\n\n\t/**\n\t * Gets a speicified property from within an object.\n\t *\n\t * @param object the object containing the property to retrieve\n\t * @param propPath nested properties used to extract the final property from within the object\n\t * (i.e \"style\", \"color\" would retrieve the color property from within an object that has \"color\" nested within \"style\")\n\t */\n\texport const getProperty = (object, ...propPath) => {\n\t\tlet position = object;\n\t\tif (position) {\n\t\t\tfor (const prop of propPath) {\n\t\t\t\tif (position[prop] !== null && position[prop] !== undefined) {\n\t\t\t\t\tposition = position[prop];\n\t\t\t\t} else {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn position;\n\t\t}\n\n\t\treturn null;\n\t};\n\n\tinterface SVGPathCoordinates {\n\t\tx0: number;\n\t\tx1: number;\n\t\ty0: number;\n\t\ty1: number;\n\t}\n\n\texport const flipSVGCoordinatesBasedOnOrientation = (\n\t\tverticalCoordinates: SVGPathCoordinates,\n\t\torientation?: CartesianOrientations\n\t) => {\n\t\tif (orientation === CartesianOrientations.HORIZONTAL) {\n\t\t\treturn {\n\t\t\t\ty0: verticalCoordinates.x0,\n\t\t\t\ty1: verticalCoordinates.x1,\n\t\t\t\tx0: verticalCoordinates.y0,\n\t\t\t\tx1: verticalCoordinates.y1\n\t\t\t};\n\t\t}\n\n\t\treturn verticalCoordinates;\n\t};\n\n\texport const generateSVGPathString = (\n\t\tverticalCoordinates: SVGPathCoordinates,\n\t\torientation?: CartesianOrientations\n\t) => {\n\t\tconst { x0, x1, y0, y1 } = flipSVGCoordinatesBasedOnOrientation(\n\t\t\tverticalCoordinates,\n\t\t\torientation\n\t\t);\n\n\t\treturn `M${x0},${y0}L${x0},${y1}L${x1},${y1}L${x1},${y0}L${x0},${y0}`;\n\t};\n\n\texport function flipDomainAndRangeBasedOnOrientation<D, R>(\n\t\tdomain: D,\n\t\trange: R,\n\t\torientation?: CartesianOrientations\n\t): [D, R] | [R, D] {\n\t\treturn orientation === CartesianOrientations.VERTICAL\n\t\t\t? [domain, range]\n\t\t\t: [range, domain];\n\t}\n}\n"]}
|