@carbon/charts 1.7.5 → 1.8.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 +26 -0
- package/build/demo/data/CHART_TYPES.d.ts +5 -0
- package/build/demo/data/choropleth.d.ts +738 -0
- package/build/demo/data/index.d.ts +1 -0
- package/build/demo/data/topojson-110.d.ts +360 -0
- package/build/src/charts/choropleth.d.ts +10 -0
- package/build/src/charts/index.d.ts +1 -0
- package/build/src/components/essentials/color-scale-legend.d.ts +3 -0
- package/build/src/components/essentials/geo-projection.d.ts +16 -0
- package/build/src/components/graphs/choropleth.d.ts +6 -0
- package/build/src/components/index.d.ts +2 -0
- package/build/src/configuration.d.ts +3 -1
- package/build/src/interfaces/charts.d.ts +28 -1
- package/build/src/interfaces/enums.d.ts +12 -0
- package/build/src/interfaces/events.d.ts +9 -0
- package/build/src/model/choropleth.d.ts +29 -0
- package/build/src/model/heatmap.d.ts +0 -5
- package/build/src/services/color-scale-utils.d.ts +10 -0
- package/build/src/services/index.d.ts +1 -0
- package/build/src/services/scales-cartesian.d.ts +1 -1
- package/bundle.js +2 -2
- package/charts/choropleth.d.ts +10 -0
- package/charts/choropleth.js +141 -0
- package/charts/choropleth.js.map +1 -0
- package/charts/heatmap.js +5 -1
- package/charts/heatmap.js.map +1 -1
- package/charts/index.d.ts +1 -0
- package/charts/index.js +1 -0
- package/charts/index.js.map +1 -1
- package/components/axes/chart-clip.js +7 -5
- package/components/axes/chart-clip.js.map +1 -1
- package/components/axes/grid-brush.js +12 -9
- package/components/axes/grid-brush.js.map +1 -1
- package/components/essentials/color-scale-legend.d.ts +3 -0
- package/components/essentials/color-scale-legend.js +18 -11
- package/components/essentials/color-scale-legend.js.map +1 -1
- package/components/essentials/geo-projection.d.ts +16 -0
- package/components/essentials/geo-projection.js +160 -0
- package/components/essentials/geo-projection.js.map +1 -0
- package/components/essentials/title-meter.js +1 -1
- package/components/essentials/title-meter.js.map +1 -1
- package/components/graphs/choropleth.d.ts +6 -0
- package/components/graphs/choropleth.js +106 -0
- package/components/graphs/choropleth.js.map +1 -0
- package/components/graphs/radar.js +1 -1
- package/components/graphs/radar.js.map +1 -1
- package/components/index.d.ts +2 -0
- package/components/index.js +2 -0
- package/components/index.js.map +1 -1
- package/configuration.d.ts +3 -1
- package/configuration.js +18 -1
- package/configuration.js.map +1 -1
- package/demo/create-codesandbox.js +20 -2
- package/demo/create-codesandbox.js.map +1 -1
- package/demo/data/CHART_TYPES.d.ts +5 -0
- package/demo/data/CHART_TYPES.js +5 -0
- package/demo/data/CHART_TYPES.js.map +1 -1
- package/demo/data/bundle.js +1 -1
- package/demo/data/choropleth.d.ts +738 -0
- package/demo/data/choropleth.js +1684 -0
- package/demo/data/choropleth.js.map +1 -0
- package/demo/data/index.d.ts +1 -0
- package/demo/data/index.js +45 -5
- package/demo/data/index.js.map +1 -1
- package/demo/data/topojson-110.d.ts +360 -0
- package/demo/data/topojson-110.js +40724 -0
- package/demo/data/topojson-110.js.map +1 -0
- package/demo/styles.css +410 -185
- 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 +25 -6
- package/demo/utils.js +29 -1
- package/demo/utils.js.map +1 -1
- package/interfaces/charts.d.ts +28 -1
- package/interfaces/charts.js.map +1 -1
- package/interfaces/enums.d.ts +12 -0
- package/interfaces/enums.js +16 -0
- package/interfaces/enums.js.map +1 -1
- package/interfaces/events.d.ts +9 -0
- package/interfaces/events.js +10 -0
- package/interfaces/events.js.map +1 -1
- package/model/choropleth.d.ts +29 -0
- package/model/choropleth.js +105 -0
- package/model/choropleth.js.map +1 -0
- package/model/heatmap.d.ts +0 -5
- package/model/heatmap.js +3 -64
- package/model/heatmap.js.map +1 -1
- package/package.json +4 -3
- package/services/color-scale-utils.d.ts +2 -0
- package/services/color-scale-utils.js +64 -0
- package/services/color-scale-utils.js.map +1 -0
- package/services/index.d.ts +1 -0
- package/services/index.js +1 -0
- package/services/index.js.map +1 -1
- package/styles/color-palatte.scss +96 -0
- package/styles/colors.scss +23 -8
- package/styles/graphs/_choropleth.scss +18 -0
- package/styles/graphs/index.scss +1 -0
- package/styles.css +156 -144
- package/styles.css.map +1 -1
- package/styles.min.css +1 -1
- package/styles.min.css.map +1 -1
- package/tsconfig.tsbuildinfo +419 -47
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
15
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
16
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
17
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
18
|
+
r[k] = a[j];
|
|
19
|
+
return r;
|
|
20
|
+
};
|
|
21
|
+
// Internal Imports
|
|
22
|
+
import { ChartModel } from './model';
|
|
23
|
+
import * as Tools from '../tools';
|
|
24
|
+
import { getColorScale } from '../services';
|
|
25
|
+
/**
|
|
26
|
+
* Base thematic maps chart model layer
|
|
27
|
+
*/
|
|
28
|
+
var ChoroplethModel = /** @class */ (function (_super) {
|
|
29
|
+
__extends(ChoroplethModel, _super);
|
|
30
|
+
function ChoroplethModel(services) {
|
|
31
|
+
var _this = _super.call(this, services) || this;
|
|
32
|
+
_this._colorScale = undefined;
|
|
33
|
+
// Holds a mapping of geometry objects to data objects
|
|
34
|
+
// Allows us to access data faster
|
|
35
|
+
_this._matrix = {};
|
|
36
|
+
return _this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @override
|
|
40
|
+
* @param value
|
|
41
|
+
* @returns string
|
|
42
|
+
*/
|
|
43
|
+
ChoroplethModel.prototype.getFillColor = function (value) {
|
|
44
|
+
return this._colorScale(value);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Helper function that will generate a dictionary
|
|
48
|
+
*/
|
|
49
|
+
ChoroplethModel.prototype.getCombinedData = function () {
|
|
50
|
+
var _this = this;
|
|
51
|
+
if (Tools.isEmpty(this._matrix)) {
|
|
52
|
+
var options = this.getOptions();
|
|
53
|
+
var data = this.getDisplayData();
|
|
54
|
+
if (!Tools.isEmpty(data) &&
|
|
55
|
+
!Tools.isEmpty(options.geoData.objects.countries)) {
|
|
56
|
+
/**
|
|
57
|
+
* @todo
|
|
58
|
+
* We can either use name or id by default to generate this dictionary
|
|
59
|
+
* Curently id & name are standard in geoJSON. Unfortunately, topojson does not have any standard
|
|
60
|
+
* so feature objects can have any key. We suggest that they include name or id at the very least
|
|
61
|
+
*
|
|
62
|
+
* May need to provide users with the option to pass in keys to create dictionary with
|
|
63
|
+
*/
|
|
64
|
+
options.geoData.objects.countries.geometries.forEach(function (country) {
|
|
65
|
+
_this._matrix[country.properties.NAME] = country;
|
|
66
|
+
});
|
|
67
|
+
data.forEach(function (value) {
|
|
68
|
+
if (_this._matrix[value.name]) {
|
|
69
|
+
_this._matrix[value.name]['value'] = value.value || null;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.warn("Data point " + value + " is missing geographical data.");
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return this._matrix;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Generate tabular data from display data
|
|
81
|
+
* @returns Array<Object>
|
|
82
|
+
*/
|
|
83
|
+
ChoroplethModel.prototype.getTabularDataArray = function () {
|
|
84
|
+
var displayData = this.getDisplayData();
|
|
85
|
+
var result = __spreadArrays([
|
|
86
|
+
['Country ID', 'Country Name', 'Value']
|
|
87
|
+
], displayData.map(function (datum) { return [
|
|
88
|
+
datum['id'] === null ? '–' : datum['id'],
|
|
89
|
+
datum['name'],
|
|
90
|
+
datum['value'],
|
|
91
|
+
]; }));
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
// Uses quantize scale to return class names
|
|
95
|
+
ChoroplethModel.prototype.getColorClassName = function (configs) {
|
|
96
|
+
return configs.originalClassName + " " + this._colorScale(configs.value);
|
|
97
|
+
};
|
|
98
|
+
ChoroplethModel.prototype.setColorClassNames = function () {
|
|
99
|
+
var colorOptions = Tools.getProperty(this.getOptions(), 'color');
|
|
100
|
+
this._colorScale = getColorScale(this.getDisplayData(), colorOptions);
|
|
101
|
+
};
|
|
102
|
+
return ChoroplethModel;
|
|
103
|
+
}(ChartModel));
|
|
104
|
+
export { ChoroplethModel };
|
|
105
|
+
//# sourceMappingURL=../../src/model/choropleth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choropleth.js","sourceRoot":"","sources":["choropleth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;GAEG;AACH;IAAqC,mCAAU;IAO9C,yBAAY,QAAa;QAAzB,YACC,kBAAM,QAAQ,CAAC,SACf;QARO,iBAAW,GAAQ,SAAS,CAAC;QAErC,sDAAsD;QACtD,kCAAkC;QAC1B,aAAO,GAAG,EAAE,CAAC;;IAIrB,CAAC;IAED;;;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WACpC,WAAW,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA;YAC7B,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;YAC9C,KAAK,CAAC,MAAM,CAAC;YACb,KAAK,CAAC,OAAO,CAAC;SACd,EAJ6B,CAI7B,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC;IAED,4CAA4C;IAC5C,2CAAiB,GAAjB,UAAkB,OAAuD;QACxE,OAAU,OAAO,CAAC,iBAAiB,SAAI,IAAI,CAAC,WAAW,CACtD,OAAO,CAAC,KAAe,CACrB,CAAC;IACL,CAAC;IAES,4CAAkB,GAA5B;QACC,IAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,CAAC;IACvE,CAAC;IACF,sBAAC;AAAD,CAAC,AA1FD,CAAqC,UAAU,GA0F9C","sourcesContent":["// Internal Imports\nimport { ChartModel } from './model';\nimport * as Tools from '../tools';\nimport { getColorScale } from '../services';\n\n/**\n * Base thematic maps chart model layer\n */\nexport class ChoroplethModel extends ChartModel {\n\tprivate _colorScale: any = undefined;\n\n\t// Holds a mapping of geometry objects to data objects\n\t// Allows us to access data faster\n\tprivate _matrix = {};\n\n\tconstructor(services: any) {\n\t\tsuper(services);\n\t}\n\n\t/**\n\t * @override\n\t * @param value\n\t * @returns string\n\t */\n\tgetFillColor(value: number) {\n\t\treturn this._colorScale(value);\n\t}\n\n\t/**\n\t * Helper function that will generate a dictionary\n\t */\n\tgetCombinedData() {\n\t\tif (Tools.isEmpty(this._matrix)) {\n\t\t\tconst options = this.getOptions();\n\t\t\tconst data = this.getDisplayData();\n\t\t\tif (\n\t\t\t\t!Tools.isEmpty(data) &&\n\t\t\t\t!Tools.isEmpty(options.geoData.objects.countries)\n\t\t\t) {\n\t\t\t\t/**\n\t\t\t\t * @todo\n\t\t\t\t * We can either use name or id by default to generate this dictionary\n\t\t\t\t * Curently id & name are standard in geoJSON. Unfortunately, topojson does not have any standard\n\t\t\t\t * so feature objects can have any key. We suggest that they include name or id at the very least\n\t\t\t\t *\n\t\t\t\t * May need to provide users with the option to pass in keys to create dictionary with\n\t\t\t\t */\n\t\t\t\toptions.geoData.objects.countries.geometries.forEach(\n\t\t\t\t\t(country) => {\n\t\t\t\t\t\tthis._matrix[country.properties.NAME] = country;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tdata.forEach((value) => {\n\t\t\t\t\tif (this._matrix[value.name]) {\n\t\t\t\t\t\tthis._matrix[value.name]['value'] = value.value || null;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Data point ${value} is missing geographical data.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn this._matrix;\n\t}\n\n\t/**\n\t * Generate tabular data from display data\n\t * @returns Array<Object>\n\t */\n\tgetTabularDataArray() {\n\t\tconst displayData = this.getDisplayData();\n\n\t\tconst result = [\n\t\t\t['Country ID', 'Country Name', 'Value'],\n\t\t\t...displayData.map((datum) => [\n\t\t\t\tdatum['id'] === null ? '–' : datum['id'],\n\t\t\t\tdatum['name'],\n\t\t\t\tdatum['value'],\n\t\t\t]),\n\t\t];\n\n\t\treturn result;\n\t}\n\n\t// Uses quantize scale to return class names\n\tgetColorClassName(configs: { value?: number; originalClassName?: string }) {\n\t\treturn `${configs.originalClassName} ${this._colorScale(\n\t\t\tconfigs.value as number\n\t\t)}`;\n\t}\n\n\tprotected setColorClassNames() {\n\t\tconst colorOptions = Tools.getProperty(this.getOptions(), 'color');\n\t\tthis._colorScale = getColorScale(this.getDisplayData(), colorOptions);\n\t}\n}\n"]}
|
package/model/heatmap.d.ts
CHANGED
|
@@ -8,11 +8,6 @@ export declare class HeatmapModel extends ChartModelCartesian {
|
|
|
8
8
|
private _ranges;
|
|
9
9
|
private _matrix;
|
|
10
10
|
constructor(services: any);
|
|
11
|
-
/**
|
|
12
|
-
* Get min and maximum value of the display data
|
|
13
|
-
* @returns Array consisting of smallest and largest values in data
|
|
14
|
-
*/
|
|
15
|
-
getValueDomain(): number[];
|
|
16
11
|
/**
|
|
17
12
|
* @override
|
|
18
13
|
* @param value
|
package/model/heatmap.js
CHANGED
|
@@ -21,10 +21,8 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
21
21
|
// Internal Imports
|
|
22
22
|
import { AxisFlavor, ScaleTypes } from '../interfaces';
|
|
23
23
|
import { ChartModelCartesian } from './cartesian-charts';
|
|
24
|
+
import { getColorScale } from '../services';
|
|
24
25
|
import * as Tools from '../tools';
|
|
25
|
-
// d3 imports
|
|
26
|
-
import { extent } from 'd3-array';
|
|
27
|
-
import { scaleQuantize, scaleLinear } from 'd3-scale';
|
|
28
26
|
/** The gauge chart model layer */
|
|
29
27
|
var HeatmapModel = /** @class */ (function (_super) {
|
|
30
28
|
__extends(HeatmapModel, _super);
|
|
@@ -55,35 +53,6 @@ var HeatmapModel = /** @class */ (function (_super) {
|
|
|
55
53
|
}
|
|
56
54
|
return _this;
|
|
57
55
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Get min and maximum value of the display data
|
|
60
|
-
* @returns Array consisting of smallest and largest values in data
|
|
61
|
-
*/
|
|
62
|
-
HeatmapModel.prototype.getValueDomain = function () {
|
|
63
|
-
var limits = extent(this.getDisplayData(), function (d) { return d.value; });
|
|
64
|
-
var domain = scaleLinear()
|
|
65
|
-
.domain(limits)
|
|
66
|
-
.nice()
|
|
67
|
-
.domain();
|
|
68
|
-
// Ensuring limits start at 0 to make scale look more `nicer`
|
|
69
|
-
if (domain[0] > 0) {
|
|
70
|
-
domain[0] = 0;
|
|
71
|
-
}
|
|
72
|
-
else if (domain[0] === 0 && domain[1] === 0) {
|
|
73
|
-
// Range cannot be between 0 and 0 (itself)
|
|
74
|
-
return [0, 1];
|
|
75
|
-
}
|
|
76
|
-
// Ensure the median of the range is 0 if domain extends into both negative & positive
|
|
77
|
-
if (domain[0] < 0 && domain[1] > 0) {
|
|
78
|
-
if (Math.abs(domain[0]) > domain[1]) {
|
|
79
|
-
domain[1] = Math.abs(domain[0]);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
domain[0] = -domain[1];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return domain;
|
|
86
|
-
};
|
|
87
56
|
/**
|
|
88
57
|
* @override
|
|
89
58
|
* @param value
|
|
@@ -242,38 +211,8 @@ var HeatmapModel = /** @class */ (function (_super) {
|
|
|
242
211
|
return configs.originalClassName + " " + this._colorScale(configs.value);
|
|
243
212
|
};
|
|
244
213
|
HeatmapModel.prototype.setColorClassNames = function () {
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
var customColorsEnabled = !Tools.isEmpty(customColors);
|
|
248
|
-
var colorPairingOption = Tools.getProperty(options, 'color', 'pairing', 'option');
|
|
249
|
-
// If domain consists of negative and positive values, use diverging palettes
|
|
250
|
-
var domain = this.getValueDomain();
|
|
251
|
-
var colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';
|
|
252
|
-
// Use default color pairing options if not in defined range
|
|
253
|
-
if (colorPairingOption < 1 &&
|
|
254
|
-
colorPairingOption > 4 &&
|
|
255
|
-
colorScheme === 'mono') {
|
|
256
|
-
colorPairingOption = 1;
|
|
257
|
-
}
|
|
258
|
-
else if (colorPairingOption < 1 &&
|
|
259
|
-
colorPairingOption > 2 &&
|
|
260
|
-
colorScheme === 'diverge') {
|
|
261
|
-
colorPairingOption = 1;
|
|
262
|
-
}
|
|
263
|
-
// Uses css classes for fill
|
|
264
|
-
var colorPairing = customColorsEnabled ? customColors : [];
|
|
265
|
-
if (!customColorsEnabled) {
|
|
266
|
-
// Add class names to list and the amount based on the color scheme
|
|
267
|
-
// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette
|
|
268
|
-
var colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;
|
|
269
|
-
for (var i = 1; i < colorGroupingLength + 1; i++) {
|
|
270
|
-
colorPairing.push("fill-" + colorScheme + "-" + colorPairingOption + "-" + i);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
// Save scale type
|
|
274
|
-
this._colorScale = scaleQuantize()
|
|
275
|
-
.domain(domain)
|
|
276
|
-
.range(colorPairing);
|
|
214
|
+
var colorOptions = Tools.getProperty(this.getOptions(), 'color');
|
|
215
|
+
this._colorScale = getColorScale(this.getDisplayData(), colorOptions);
|
|
277
216
|
};
|
|
278
217
|
return HeatmapModel;
|
|
279
218
|
}(ChartModelCartesian));
|
package/model/heatmap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heatmap.js","sourceRoot":"","sources":["heatmap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAElC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,kCAAkC;AAClC;IAAkC,gCAAmB;IAUpD,sBAAY,QAAa;QAAzB,YACC,kBAAM,QAAQ,CAAC,SAsBf;QAhCS,gBAAU,GAAG,UAAU,CAAC,SAAS,CAAC;QACpC,iBAAW,GAAQ,SAAS,CAAC;QAErC,oCAAoC;QAC5B,cAAQ,GAAG,EAAE,CAAC;QACd,aAAO,GAAG,EAAE,CAAC;QAEb,aAAO,GAAG,EAAE,CAAC;QA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R,CAAC;QAEF,6EAA6E;QAC7E,IAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,IAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;QAExE,4DAA4D;QAC5D,IACC,kBAAkB,GAAG,CAAC;YACtB,kBAAkB,GAAG,CAAC;YACtB,WAAW,KAAK,MAAM,EACrB;YACD,kBAAkB,GAAG,CAAC,CAAC;SACvB;aAAM,IACN,kBAAkB,GAAG,CAAC;YACtB,kBAAkB,GAAG,CAAC;YACtB,WAAW,KAAK,SAAS,EACxB;YACD,kBAAkB,GAAG,CAAC,CAAC;SACvB;QAED,4BAA4B;QAC5B,IAAM,YAAY,GAAG,mBAAmB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;QAE7D,IAAI,CAAC,mBAAmB,EAAE;YACzB,mEAAmE;YACnE,8FAA8F;YAC9F,IAAM,mBAAmB,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBACjD,YAAY,CAAC,IAAI,CAChB,UAAQ,WAAW,SAAI,kBAAkB,SAAI,CAAG,CAChD,CAAC;aACF;SACD;QAED,kBAAkB;QAClB,IAAI,CAAC,WAAW,GAAG,aAAa,EAAE;aAChC,MAAM,CAAC,MAA0B,CAAC;aAClC,KAAK,CAAC,YAAY,CAAC,CAAC;IACvB,CAAC;IACF,mBAAC;AAAD,CAAC,AApUD,CAAkC,mBAAmB,GAoUpD","sourcesContent":["// Internal Imports\nimport { AxisFlavor, ScaleTypes } from '../interfaces';\nimport { ChartModelCartesian } from './cartesian-charts';\nimport * as Tools from '../tools';\n\n// d3 imports\nimport { extent } from 'd3-array';\nimport { scaleQuantize, scaleLinear } from 'd3-scale';\n\n/** The gauge chart model layer */\nexport class HeatmapModel extends ChartModelCartesian {\n\tprotected axisFlavor = AxisFlavor.HOVERABLE;\n\tprivate _colorScale: any = undefined;\n\n\t// List of unique ranges and domains\n\tprivate _domains = [];\n\tprivate _ranges = [];\n\n\tprivate _matrix = {};\n\n\tconstructor(services: any) {\n\t\tsuper(services);\n\n\t\t// Check which scale types are being used\n\t\tconst axis = Tools.getProperty(this.getOptions(), 'axes');\n\n\t\t// Need to check options since scale service hasn't been instantiated\n\t\tif (\n\t\t\t(!!Tools.getProperty(axis, 'left', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'left', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'right', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'right', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'top', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'top', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'bottom', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'bottom', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS)\n\t\t) {\n\t\t\tthrow Error('Heatmap only supports label scaletypes.');\n\t\t}\n\t}\n\n\t/**\n\t * Get min and maximum value of the display data\n\t * @returns Array consisting of smallest and largest values in data\n\t */\n\tgetValueDomain() {\n\t\tconst limits = extent(this.getDisplayData(), (d: any) => d.value);\n\t\tconst domain = scaleLinear()\n\t\t\t.domain(limits as [number, number])\n\t\t\t.nice()\n\t\t\t.domain();\n\n\t\t// Ensuring limits start at 0 to make scale look more `nicer`\n\t\tif (domain[0] > 0) {\n\t\t\tdomain[0] = 0;\n\t\t} else if (domain[0] === 0 && domain[1] === 0) {\n\t\t\t// Range cannot be between 0 and 0 (itself)\n\t\t\treturn [0, 1];\n\t\t}\n\n\t\t// Ensure the median of the range is 0 if domain extends into both negative & positive\n\t\tif (domain[0] < 0 && domain[1] > 0) {\n\t\t\tif (Math.abs(domain[0]) > domain[1]) {\n\t\t\t\tdomain[1] = Math.abs(domain[0]);\n\t\t\t} else {\n\t\t\t\tdomain[0] = -domain[1];\n\t\t\t}\n\t\t}\n\n\t\treturn domain;\n\t}\n\n\t/**\n\t * @override\n\t * @param value\n\t * @returns string\n\t */\n\tgetFillColor(value: number) {\n\t\treturn this._colorScale(value);\n\t}\n\n\t/**\n\t * Generate a list of all unique domains\n\t * @returns String[]\n\t */\n\tgetUniqueDomain(): string[] {\n\t\tif (Tools.isEmpty(this._domains)) {\n\t\t\tconst displayData = this.getDisplayData();\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\tconst domainIdentifier = cartesianScales.getDomainIdentifier();\n\t\t\tconst mainXAxisPosition = cartesianScales.getMainXAxisPosition();\n\t\t\tconst customDomain = cartesianScales.getCustomDomainValuesByposition(\n\t\t\t\tmainXAxisPosition\n\t\t\t);\n\n\t\t\t// Use user defined domain if specified\n\t\t\tif (!!customDomain) {\n\t\t\t\treturn customDomain;\n\t\t\t}\n\n\t\t\t// Get unique axis values & create a matrix\n\t\t\tthis._domains = Array.from(\n\t\t\t\tnew Set(\n\t\t\t\t\tdisplayData.map((d) => {\n\t\t\t\t\t\treturn d[domainIdentifier];\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn this._domains;\n\t}\n\n\t/**\n\t * Generates a list of all unique ranges\n\t * @returns String[]\n\t */\n\tgetUniqueRanges(): string[] {\n\t\tif (Tools.isEmpty(this._ranges)) {\n\t\t\tconst displayData = this.getDisplayData();\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\tconst rangeIdentifier = cartesianScales.getRangeIdentifier();\n\t\t\tconst mainYAxisPosition = cartesianScales.getMainYAxisPosition();\n\t\t\tconst customDomain = cartesianScales.getCustomDomainValuesByposition(\n\t\t\t\tmainYAxisPosition\n\t\t\t);\n\n\t\t\t// Use user defined domain if specified\n\t\t\tif (!!customDomain) {\n\t\t\t\treturn customDomain;\n\t\t\t}\n\n\t\t\t// Get unique axis values & create a matrix\n\t\t\tthis._ranges = Array.from(\n\t\t\t\tnew Set(\n\t\t\t\t\tdisplayData.map((d) => {\n\t\t\t\t\t\treturn d[rangeIdentifier];\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn this._ranges;\n\t}\n\n\t/**\n\t * Generates a matrix (If doesn't exist) and returns it\n\t * @returns Object\n\t */\n\tgetMatrix() {\n\t\tif (Tools.isEmpty(this._matrix)) {\n\t\t\tconst uniqueDomain = this.getUniqueDomain();\n\t\t\tconst uniqueRange = this.getUniqueRanges();\n\n\t\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t// Create a column\n\t\t\tconst range = {};\n\t\t\tuniqueRange.forEach((ran: any) => {\n\t\t\t\t// Initialize matrix to empty state\n\t\t\t\trange[ran] = {\n\t\t\t\t\tvalue: null,\n\t\t\t\t\tindex: -1,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\t// Complete the matrix by cloning the column to all domains\n\t\t\tuniqueDomain.forEach((dom: any) => {\n\t\t\t\tthis._matrix[dom] = Tools.clone(range);\n\t\t\t});\n\n\t\t\t// Fill in user passed data\n\t\t\tthis.getDisplayData().forEach((d, i) => {\n\t\t\t\tthis._matrix[d[domainIdentifier]][d[rangeIdentifier]] = {\n\t\t\t\t\tvalue: d['value'],\n\t\t\t\t\tindex: i,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\n\t\treturn this._matrix;\n\t}\n\n\t/**\n\t *\n\t * @param newData The new raw data to be set\n\t */\n\tsetData(newData) {\n\t\tconst sanitizedData = this.sanitize(Tools.clone(newData));\n\t\tconst dataGroups = this.generateDataGroups(sanitizedData);\n\n\t\tthis.set({\n\t\t\tdata: sanitizedData,\n\t\t\tdataGroups,\n\t\t});\n\n\t\t// Set attributes to empty\n\t\tthis._domains = [];\n\t\tthis._ranges = [];\n\t\tthis._matrix = {};\n\n\t\treturn sanitizedData;\n\t}\n\n\t/**\n\t * Converts Object matrix into a single array\n\t * @returns Object[]\n\t */\n\tgetMatrixAsArray(): Object[] {\n\t\tif (Tools.isEmpty(this._matrix)) {\n\t\t\tthis.getMatrix();\n\t\t}\n\n\t\tconst uniqueDomain = this.getUniqueDomain();\n\t\tconst uniqueRange = this.getUniqueRanges();\n\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst arr = [];\n\t\tuniqueDomain.forEach((domain) => {\n\t\t\tuniqueRange.forEach((range) => {\n\t\t\t\tconst element = {\n\t\t\t\t\tvalue: this._matrix[domain][range].value,\n\t\t\t\t\tindex: this._matrix[domain][range].index,\n\t\t\t\t};\n\t\t\t\telement[domainIdentifier] = domain;\n\t\t\t\telement[rangeIdentifier] = range;\n\t\t\t\tarr.push(element);\n\t\t\t});\n\t\t});\n\n\t\treturn arr;\n\t}\n\n\t/**\n\t * Generate tabular data from display data\n\t * @returns Array<Object>\n\t */\n\tgetTabularDataArray() {\n\t\tconst displayData = this.getDisplayData();\n\n\t\tconst { primaryDomain, primaryRange } = this.assignRangeAndDomains();\n\n\t\tlet domainValueFormatter;\n\n\t\tconst result = [\n\t\t\t[primaryDomain.label, primaryRange.label, 'Value'],\n\t\t\t...displayData.map((datum) => [\n\t\t\t\tdatum[primaryDomain.identifier] === null\n\t\t\t\t\t? '–'\n\t\t\t\t\t: domainValueFormatter\n\t\t\t\t\t? domainValueFormatter(datum[primaryDomain.identifier])\n\t\t\t\t\t: datum[primaryDomain.identifier],\n\t\t\t\tdatum[primaryRange.identifier] === null\n\t\t\t\t\t? '–'\n\t\t\t\t\t: datum[primaryRange.identifier].toLocaleString(),\n\t\t\t\tdatum['value'],\n\t\t\t]),\n\t\t];\n\n\t\treturn result;\n\t}\n\n\t// Uses quantize scale to return class names\n\tgetColorClassName(configs: { value?: number; originalClassName?: string }) {\n\t\treturn `${configs.originalClassName} ${this._colorScale(\n\t\t\tconfigs.value as number\n\t\t)}`;\n\t}\n\n\tprotected setColorClassNames() {\n\t\tconst options = this.getOptions();\n\n\t\tconst customColors = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'gradient',\n\t\t\t'colors'\n\t\t);\n\t\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\n\t\tlet colorPairingOption = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'pairing',\n\t\t\t'option'\n\t\t);\n\n\t\t// If domain consists of negative and positive values, use diverging palettes\n\t\tconst domain = this.getValueDomain();\n\t\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t\t// Use default color pairing options if not in defined range\n\t\tif (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 4 &&\n\t\t\tcolorScheme === 'mono'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t} else if (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 2 &&\n\t\t\tcolorScheme === 'diverge'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t}\n\n\t\t// Uses css classes for fill\n\t\tconst colorPairing = customColorsEnabled ? customColors : [];\n\n\t\tif (!customColorsEnabled) {\n\t\t\t// Add class names to list and the amount based on the color scheme\n\t\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\t\tconst colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\t\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\t\tcolorPairing.push(\n\t\t\t\t\t`fill-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Save scale type\n\t\tthis._colorScale = scaleQuantize()\n\t\t\t.domain(domain as [number, number])\n\t\t\t.range(colorPairing);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"heatmap.js","sourceRoot":"","sources":["heatmap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAElC,kCAAkC;AAClC;IAAkC,gCAAmB;IAUpD,sBAAY,QAAa;QAAzB,YACC,kBAAM,QAAQ,CAAC,SAsBf;QAhCS,gBAAU,GAAG,UAAU,CAAC,SAAS,CAAC;QACpC,iBAAW,GAAQ,SAAS,CAAC;QAErC,oCAAoC;QAC5B,cAAQ,GAAG,EAAE,CAAC;QACd,aAAO,GAAG,EAAE,CAAC;QAEb,aAAO,GAAG,EAAE,CAAC;QAKpB,yCAAyC;QACzC,IAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,KAAI,CAAC,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;QAE1D,qEAAqE;QACrE,IACC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC;YAC9C,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC;gBAC3C,UAAU,CAAC,MAAM,CAAC;YACpB,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC;gBAC/C,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC;oBAC5C,UAAU,CAAC,MAAM,CAAC;YACpB,CAAC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,UAAU,CAAC,KAAK,IAAI;gBACvC,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,oBAAoB;oBACtB,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;oBACvD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC;YAClC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,IAAI;gBACtC,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,cAAc,EAAE;YAClD,KAAK,CAAC,OAAO,CAAC;SACd,EAV6B,CAU7B,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC;IAED,4CAA4C;IAC5C,wCAAiB,GAAjB,UAAkB,OAAuD;QACxE,OAAU,OAAO,CAAC,iBAAiB,SAAI,IAAI,CAAC,WAAW,CACtD,OAAO,CAAC,KAAe,CACrB,CAAC;IACL,CAAC;IAES,yCAAkB,GAA5B;QACC,IAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,CAAC;IACvE,CAAC;IACF,mBAAC;AAAD,CAAC,AAjPD,CAAkC,mBAAmB,GAiPpD","sourcesContent":["// Internal Imports\nimport { AxisFlavor, ScaleTypes } from '../interfaces';\nimport { ChartModelCartesian } from './cartesian-charts';\nimport { getColorScale } from '../services';\nimport * as Tools from '../tools';\n\n/** The gauge chart model layer */\nexport class HeatmapModel extends ChartModelCartesian {\n\tprotected axisFlavor = AxisFlavor.HOVERABLE;\n\tprivate _colorScale: any = undefined;\n\n\t// List of unique ranges and domains\n\tprivate _domains = [];\n\tprivate _ranges = [];\n\n\tprivate _matrix = {};\n\n\tconstructor(services: any) {\n\t\tsuper(services);\n\n\t\t// Check which scale types are being used\n\t\tconst axis = Tools.getProperty(this.getOptions(), 'axes');\n\n\t\t// Need to check options since scale service hasn't been instantiated\n\t\tif (\n\t\t\t(!!Tools.getProperty(axis, 'left', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'left', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'right', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'right', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'top', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'top', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS) ||\n\t\t\t(!!Tools.getProperty(axis, 'bottom', 'scaleType') &&\n\t\t\t\tTools.getProperty(axis, 'bottom', 'scaleType') !==\n\t\t\t\t\tScaleTypes.LABELS)\n\t\t) {\n\t\t\tthrow Error('Heatmap only supports label scaletypes.');\n\t\t}\n\t}\n\n\t/**\n\t * @override\n\t * @param value\n\t * @returns string\n\t */\n\tgetFillColor(value: number) {\n\t\treturn this._colorScale(value);\n\t}\n\n\t/**\n\t * Generate a list of all unique domains\n\t * @returns String[]\n\t */\n\tgetUniqueDomain(): string[] {\n\t\tif (Tools.isEmpty(this._domains)) {\n\t\t\tconst displayData = this.getDisplayData();\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\tconst domainIdentifier = cartesianScales.getDomainIdentifier();\n\t\t\tconst mainXAxisPosition = cartesianScales.getMainXAxisPosition();\n\t\t\tconst customDomain = cartesianScales.getCustomDomainValuesByposition(\n\t\t\t\tmainXAxisPosition\n\t\t\t);\n\n\t\t\t// Use user defined domain if specified\n\t\t\tif (!!customDomain) {\n\t\t\t\treturn customDomain;\n\t\t\t}\n\n\t\t\t// Get unique axis values & create a matrix\n\t\t\tthis._domains = Array.from(\n\t\t\t\tnew Set(\n\t\t\t\t\tdisplayData.map((d) => {\n\t\t\t\t\t\treturn d[domainIdentifier];\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn this._domains;\n\t}\n\n\t/**\n\t * Generates a list of all unique ranges\n\t * @returns String[]\n\t */\n\tgetUniqueRanges(): string[] {\n\t\tif (Tools.isEmpty(this._ranges)) {\n\t\t\tconst displayData = this.getDisplayData();\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\tconst rangeIdentifier = cartesianScales.getRangeIdentifier();\n\t\t\tconst mainYAxisPosition = cartesianScales.getMainYAxisPosition();\n\t\t\tconst customDomain = cartesianScales.getCustomDomainValuesByposition(\n\t\t\t\tmainYAxisPosition\n\t\t\t);\n\n\t\t\t// Use user defined domain if specified\n\t\t\tif (!!customDomain) {\n\t\t\t\treturn customDomain;\n\t\t\t}\n\n\t\t\t// Get unique axis values & create a matrix\n\t\t\tthis._ranges = Array.from(\n\t\t\t\tnew Set(\n\t\t\t\t\tdisplayData.map((d) => {\n\t\t\t\t\t\treturn d[rangeIdentifier];\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn this._ranges;\n\t}\n\n\t/**\n\t * Generates a matrix (If doesn't exist) and returns it\n\t * @returns Object\n\t */\n\tgetMatrix() {\n\t\tif (Tools.isEmpty(this._matrix)) {\n\t\t\tconst uniqueDomain = this.getUniqueDomain();\n\t\t\tconst uniqueRange = this.getUniqueRanges();\n\n\t\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t// Create a column\n\t\t\tconst range = {};\n\t\t\tuniqueRange.forEach((ran: any) => {\n\t\t\t\t// Initialize matrix to empty state\n\t\t\t\trange[ran] = {\n\t\t\t\t\tvalue: null,\n\t\t\t\t\tindex: -1,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\t// Complete the matrix by cloning the column to all domains\n\t\t\tuniqueDomain.forEach((dom: any) => {\n\t\t\t\tthis._matrix[dom] = Tools.clone(range);\n\t\t\t});\n\n\t\t\t// Fill in user passed data\n\t\t\tthis.getDisplayData().forEach((d, i) => {\n\t\t\t\tthis._matrix[d[domainIdentifier]][d[rangeIdentifier]] = {\n\t\t\t\t\tvalue: d['value'],\n\t\t\t\t\tindex: i,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\n\t\treturn this._matrix;\n\t}\n\n\t/**\n\t *\n\t * @param newData The new raw data to be set\n\t */\n\tsetData(newData) {\n\t\tconst sanitizedData = this.sanitize(Tools.clone(newData));\n\t\tconst dataGroups = this.generateDataGroups(sanitizedData);\n\n\t\tthis.set({\n\t\t\tdata: sanitizedData,\n\t\t\tdataGroups,\n\t\t});\n\n\t\t// Set attributes to empty\n\t\tthis._domains = [];\n\t\tthis._ranges = [];\n\t\tthis._matrix = {};\n\n\t\treturn sanitizedData;\n\t}\n\n\t/**\n\t * Converts Object matrix into a single array\n\t * @returns Object[]\n\t */\n\tgetMatrixAsArray(): Object[] {\n\t\tif (Tools.isEmpty(this._matrix)) {\n\t\t\tthis.getMatrix();\n\t\t}\n\n\t\tconst uniqueDomain = this.getUniqueDomain();\n\t\tconst uniqueRange = this.getUniqueRanges();\n\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst arr = [];\n\t\tuniqueDomain.forEach((domain) => {\n\t\t\tuniqueRange.forEach((range) => {\n\t\t\t\tconst element = {\n\t\t\t\t\tvalue: this._matrix[domain][range].value,\n\t\t\t\t\tindex: this._matrix[domain][range].index,\n\t\t\t\t};\n\t\t\t\telement[domainIdentifier] = domain;\n\t\t\t\telement[rangeIdentifier] = range;\n\t\t\t\tarr.push(element);\n\t\t\t});\n\t\t});\n\n\t\treturn arr;\n\t}\n\n\t/**\n\t * Generate tabular data from display data\n\t * @returns Array<Object>\n\t */\n\tgetTabularDataArray() {\n\t\tconst displayData = this.getDisplayData();\n\n\t\tconst { primaryDomain, primaryRange } = this.assignRangeAndDomains();\n\n\t\tlet domainValueFormatter;\n\n\t\tconst result = [\n\t\t\t[primaryDomain.label, primaryRange.label, 'Value'],\n\t\t\t...displayData.map((datum) => [\n\t\t\t\tdatum[primaryDomain.identifier] === null\n\t\t\t\t\t? '–'\n\t\t\t\t\t: domainValueFormatter\n\t\t\t\t\t? domainValueFormatter(datum[primaryDomain.identifier])\n\t\t\t\t\t: datum[primaryDomain.identifier],\n\t\t\t\tdatum[primaryRange.identifier] === null\n\t\t\t\t\t? '–'\n\t\t\t\t\t: datum[primaryRange.identifier].toLocaleString(),\n\t\t\t\tdatum['value'],\n\t\t\t]),\n\t\t];\n\n\t\treturn result;\n\t}\n\n\t// Uses quantize scale to return class names\n\tgetColorClassName(configs: { value?: number; originalClassName?: string }) {\n\t\treturn `${configs.originalClassName} ${this._colorScale(\n\t\t\tconfigs.value as number\n\t\t)}`;\n\t}\n\n\tprotected setColorClassNames() {\n\t\tconst colorOptions = Tools.getProperty(this.getOptions(), 'color');\n\t\tthis._colorScale = getColorScale(this.getDisplayData(), colorOptions);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/charts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Carbon charting components",
|
|
5
5
|
"main": "./bundle.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"author": "IBM",
|
|
49
49
|
"license": "Apache-2.0",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@carbon/styles": "^1.
|
|
51
|
+
"@carbon/styles": "^1.4.0",
|
|
52
52
|
"@carbon/telemetry": "^0.1.0",
|
|
53
53
|
"@carbon/utils-position": "^1.1.4",
|
|
54
54
|
"carbon-components": "^10.58.3",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"date-fns": "2.8.1",
|
|
58
58
|
"dom-to-image-more": "^3.1.6",
|
|
59
59
|
"lodash-es": "4.17.21",
|
|
60
|
-
"resize-observer-polyfill": "1.5.0"
|
|
60
|
+
"resize-observer-polyfill": "1.5.0",
|
|
61
|
+
"topojson-client": "3.1.0"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
64
|
"d3": "7.x"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Internal Imports
|
|
2
|
+
import * as Tools from '../tools';
|
|
3
|
+
// d3 imports
|
|
4
|
+
import { extent } from 'd3-array';
|
|
5
|
+
import { scaleQuantize, scaleLinear } from 'd3-scale';
|
|
6
|
+
export function getDomain(data) {
|
|
7
|
+
var limits = extent(data, function (d) { return d.value; });
|
|
8
|
+
var domain = scaleLinear()
|
|
9
|
+
.domain(limits)
|
|
10
|
+
.nice()
|
|
11
|
+
.domain();
|
|
12
|
+
// Ensuring limits start at 0 to make scale look more `nicer`
|
|
13
|
+
if (domain[0] > 0) {
|
|
14
|
+
domain[0] = 0;
|
|
15
|
+
}
|
|
16
|
+
else if (domain[0] === 0 && domain[1] === 0) {
|
|
17
|
+
// Range cannot be between 0 and 0 (itself)
|
|
18
|
+
return [0, 1];
|
|
19
|
+
}
|
|
20
|
+
// Ensure the median of the range is 0 if domain extends into both negative & positive
|
|
21
|
+
if (domain[0] < 0 && domain[1] > 0) {
|
|
22
|
+
if (Math.abs(domain[0]) > domain[1]) {
|
|
23
|
+
domain[1] = Math.abs(domain[0]);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
domain[0] = -domain[1];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return domain;
|
|
30
|
+
}
|
|
31
|
+
export function getColorScale(displayData, colorOptions) {
|
|
32
|
+
var customColors = Tools.getProperty(colorOptions, 'gradient', 'colors');
|
|
33
|
+
var customColorsEnabled = !Tools.isEmpty(customColors);
|
|
34
|
+
var colorPairingOption = Tools.getProperty(colorOptions, 'pairing', 'option');
|
|
35
|
+
// If domain consists of negative and positive values, use diverging palettes
|
|
36
|
+
var domain = getDomain(displayData);
|
|
37
|
+
var colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';
|
|
38
|
+
// Use default color pairing options if not in defined range
|
|
39
|
+
if (colorPairingOption < 1 &&
|
|
40
|
+
colorPairingOption > 4 &&
|
|
41
|
+
colorScheme === 'mono') {
|
|
42
|
+
colorPairingOption = 1;
|
|
43
|
+
}
|
|
44
|
+
else if (colorPairingOption < 1 &&
|
|
45
|
+
colorPairingOption > 2 &&
|
|
46
|
+
colorScheme === 'diverge') {
|
|
47
|
+
colorPairingOption = 1;
|
|
48
|
+
}
|
|
49
|
+
// Uses css classes for fill
|
|
50
|
+
var colorPairing = customColorsEnabled ? customColors : [];
|
|
51
|
+
if (!customColorsEnabled) {
|
|
52
|
+
// Add class names to list and the amount based on the color scheme
|
|
53
|
+
// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette
|
|
54
|
+
var colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;
|
|
55
|
+
for (var i = 1; i < colorGroupingLength + 1; i++) {
|
|
56
|
+
colorPairing.push("fill-" + colorScheme + "-" + colorPairingOption + "-" + i);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Return generated color scale
|
|
60
|
+
return scaleQuantize()
|
|
61
|
+
.domain(domain)
|
|
62
|
+
.range(colorPairing);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=../../src/services/color-scale-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scale-utils.js","sourceRoot":"","sources":["color-scale-utils.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAElC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,UAAU,SAAS,CAAC,IAAI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S,EACT,QAAQ,CACR,CAAC;IAEF,6EAA6E;IAC7E,IAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IACtC,IAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IAExE,4DAA4D;IAC5D,IACC,kBAAkB,GAAG,CAAC;QACtB,kBAAkB,GAAG,CAAC;QACtB,WAAW,KAAK,MAAM,EACrB;QACD,kBAAkB,GAAG,CAAC,CAAC;KACvB;SAAM,IACN,kBAAkB,GAAG,CAAC;QACtB,kBAAkB,GAAG,CAAC;QACtB,WAAW,KAAK,SAAS,EACxB;QACD,kBAAkB,GAAG,CAAC,CAAC;KACvB;IAED,4BAA4B;IAC5B,IAAM,YAAY,GAAG,mBAAmB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAE7D,IAAI,CAAC,mBAAmB,EAAE;QACzB,mEAAmE;QACnE,8FAA8F;QAC9F,IAAM,mBAAmB,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YACjD,YAAY,CAAC,IAAI,CAAC,UAAQ,WAAW,SAAI,kBAAkB,SAAI,CAAG,CAAC,CAAC;SACpE;KACD;IAED,+BAA+B;IAC/B,OAAO,aAAa,EAAE;SACpB,MAAM,CAAC,MAA0B,CAAC;SAClC,KAAK,CAAC,YAAY,CAAC,CAAC;AACvB,CAAC","sourcesContent":["// Internal Imports\nimport * as Tools from '../tools';\n\n// d3 imports\nimport { extent } from 'd3-array';\nimport { scaleQuantize, scaleLinear } from 'd3-scale';\n\nexport function getDomain(data) {\n\tconst limits = extent(data, (d: any) => d.value);\n\tconst domain = scaleLinear()\n\t\t.domain(limits as [number, number])\n\t\t.nice()\n\t\t.domain();\n\n\t// Ensuring limits start at 0 to make scale look more `nicer`\n\tif (domain[0] > 0) {\n\t\tdomain[0] = 0;\n\t} else if (domain[0] === 0 && domain[1] === 0) {\n\t\t// Range cannot be between 0 and 0 (itself)\n\t\treturn [0, 1];\n\t}\n\n\t// Ensure the median of the range is 0 if domain extends into both negative & positive\n\tif (domain[0] < 0 && domain[1] > 0) {\n\t\tif (Math.abs(domain[0]) > domain[1]) {\n\t\t\tdomain[1] = Math.abs(domain[0]);\n\t\t} else {\n\t\t\tdomain[0] = -domain[1];\n\t\t}\n\t}\n\n\treturn domain;\n}\n\nexport function getColorScale(displayData, colorOptions) {\n\tconst customColors = Tools.getProperty(colorOptions, 'gradient', 'colors');\n\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\n\tlet colorPairingOption = Tools.getProperty(\n\t\tcolorOptions,\n\t\t'pairing',\n\t\t'option'\n\t);\n\n\t// If domain consists of negative and positive values, use diverging palettes\n\tconst domain = getDomain(displayData);\n\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t// Use default color pairing options if not in defined range\n\tif (\n\t\tcolorPairingOption < 1 &&\n\t\tcolorPairingOption > 4 &&\n\t\tcolorScheme === 'mono'\n\t) {\n\t\tcolorPairingOption = 1;\n\t} else if (\n\t\tcolorPairingOption < 1 &&\n\t\tcolorPairingOption > 2 &&\n\t\tcolorScheme === 'diverge'\n\t) {\n\t\tcolorPairingOption = 1;\n\t}\n\n\t// Uses css classes for fill\n\tconst colorPairing = customColorsEnabled ? customColors : [];\n\n\tif (!customColorsEnabled) {\n\t\t// Add class names to list and the amount based on the color scheme\n\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\tconst colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\tcolorPairing.push(`fill-${colorScheme}-${colorPairingOption}-${i}`);\n\t\t}\n\t}\n\n\t// Return generated color scale\n\treturn scaleQuantize()\n\t\t.domain(domain as [number, number])\n\t\t.range(colorPairing);\n}\n"]}
|
package/services/index.d.ts
CHANGED
package/services/index.js
CHANGED
package/services/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAE5C,OAAO;AACP,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC","sourcesContent":["// Essentials\nexport * from './essentials/dom-utils';\nexport * from './essentials/events';\nexport * from './essentials/files';\nexport * from './essentials/transitions';\nexport * from './essentials/gradient-utils';\n\n// MISC\nexport * from './scales-cartesian';\nexport * from './curves';\nexport * from './zoom';\nexport * from './canvas-zoom';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAE5C,OAAO;AACP,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["// Essentials\nexport * from './essentials/dom-utils';\nexport * from './essentials/events';\nexport * from './essentials/files';\nexport * from './essentials/transitions';\nexport * from './essentials/gradient-utils';\n\n// MISC\nexport * from './scales-cartesian';\nexport * from './curves';\nexport * from './zoom';\nexport * from './canvas-zoom';\nexport * from './color-scale-utils';\n"]}
|
|
@@ -320,6 +320,61 @@ $monochrome-quantize-colors: (
|
|
|
320
320
|
),
|
|
321
321
|
);
|
|
322
322
|
|
|
323
|
+
$dark-monochrome-quantize-colors: (
|
|
324
|
+
'mono-1': (
|
|
325
|
+
'1': getColorValue(purple, 100),
|
|
326
|
+
'2': getColorValue(purple, 90),
|
|
327
|
+
'3': getColorValue(purple, 80),
|
|
328
|
+
'4': getColorValue(purple, 70),
|
|
329
|
+
'5': getColorValue(purple, 60),
|
|
330
|
+
'6': getColorValue(purple, 50),
|
|
331
|
+
'7': getColorValue(purple, 40),
|
|
332
|
+
'8': getColorValue(purple, 30),
|
|
333
|
+
'9': getColorValue(purple, 20),
|
|
334
|
+
'10': getColorValue(purple, 10),
|
|
335
|
+
'11': #ffffff,
|
|
336
|
+
),
|
|
337
|
+
'mono-2': (
|
|
338
|
+
'1': getColorValue(blue, 100),
|
|
339
|
+
'2': getColorValue(blue, 90),
|
|
340
|
+
'3': getColorValue(blue, 80),
|
|
341
|
+
'4': getColorValue(blue, 70),
|
|
342
|
+
'5': getColorValue(blue, 60),
|
|
343
|
+
'6': getColorValue(blue, 50),
|
|
344
|
+
'7': getColorValue(blue, 40),
|
|
345
|
+
'8': getColorValue(blue, 30),
|
|
346
|
+
'9': getColorValue(blue, 20),
|
|
347
|
+
'10': getColorValue(blue, 10),
|
|
348
|
+
'11': #ffffff,
|
|
349
|
+
),
|
|
350
|
+
'mono-3': (
|
|
351
|
+
'1': getColorValue(cyan, 100),
|
|
352
|
+
'2': getColorValue(cyan, 90),
|
|
353
|
+
'3': getColorValue(cyan, 80),
|
|
354
|
+
'4': getColorValue(cyan, 70),
|
|
355
|
+
'5': getColorValue(cyan, 60),
|
|
356
|
+
'6': getColorValue(cyan, 50),
|
|
357
|
+
'7': getColorValue(cyan, 40),
|
|
358
|
+
'8': getColorValue(cyan, 30),
|
|
359
|
+
'9': getColorValue(cyan, 20),
|
|
360
|
+
'10': getColorValue(cyan, 10),
|
|
361
|
+
'11': #ffffff,
|
|
362
|
+
),
|
|
363
|
+
'mono-4': (
|
|
364
|
+
'1': getColorValue(teal, 100),
|
|
365
|
+
'2': getColorValue(teal, 90),
|
|
366
|
+
'3': getColorValue(teal, 80),
|
|
367
|
+
'4': getColorValue(teal, 70),
|
|
368
|
+
'5': getColorValue(teal, 60),
|
|
369
|
+
'6': getColorValue(teal, 50),
|
|
370
|
+
'7': getColorValue(teal, 40),
|
|
371
|
+
'8': getColorValue(teal, 30),
|
|
372
|
+
'9': getColorValue(teal, 20),
|
|
373
|
+
'10': getColorValue(teal, 10),
|
|
374
|
+
'11': #ffffff,
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
|
|
323
378
|
$divergent-quantize-colors: (
|
|
324
379
|
'diverge-1': (
|
|
325
380
|
'1': getColorValue(red, 80),
|
|
@@ -360,3 +415,44 @@ $divergent-quantize-colors: (
|
|
|
360
415
|
'17': getColorValue(teal, 80),
|
|
361
416
|
),
|
|
362
417
|
);
|
|
418
|
+
|
|
419
|
+
$dark-divergent-quantize-colors: (
|
|
420
|
+
'diverge-1': (
|
|
421
|
+
'1': getColorValue(red, 10),
|
|
422
|
+
'2': getColorValue(red, 20),
|
|
423
|
+
'3': getColorValue(red, 30),
|
|
424
|
+
'4': getColorValue(red, 40),
|
|
425
|
+
'5': getColorValue(red, 50),
|
|
426
|
+
'6': getColorValue(red, 60),
|
|
427
|
+
'7': getColorValue(red, 70),
|
|
428
|
+
'8': getColorValue(red, 80),
|
|
429
|
+
'9': #ffffff,
|
|
430
|
+
'10': getColorValue(cyan, 80),
|
|
431
|
+
'11': getColorValue(cyan, 70),
|
|
432
|
+
'12': getColorValue(cyan, 60),
|
|
433
|
+
'13': getColorValue(cyan, 50),
|
|
434
|
+
'14': getColorValue(cyan, 40),
|
|
435
|
+
'15': getColorValue(cyan, 30),
|
|
436
|
+
'16': getColorValue(cyan, 20),
|
|
437
|
+
'17': getColorValue(cyan, 10),
|
|
438
|
+
),
|
|
439
|
+
'diverge-2': (
|
|
440
|
+
'1': getColorValue(purple, 10),
|
|
441
|
+
'2': getColorValue(purple, 20),
|
|
442
|
+
'3': getColorValue(purple, 30),
|
|
443
|
+
'4': getColorValue(purple, 40),
|
|
444
|
+
'5': getColorValue(purple, 50),
|
|
445
|
+
'6': getColorValue(purple, 60),
|
|
446
|
+
'7': getColorValue(purple, 70),
|
|
447
|
+
'8': getColorValue(purple, 80),
|
|
448
|
+
'9': #ffffff,
|
|
449
|
+
'10': getColorValue(teal, 80),
|
|
450
|
+
'11': getColorValue(teal, 70),
|
|
451
|
+
'12': getColorValue(teal, 60),
|
|
452
|
+
'13': getColorValue(teal, 50),
|
|
453
|
+
'14': getColorValue(teal, 40),
|
|
454
|
+
'15': getColorValue(teal, 30),
|
|
455
|
+
'16': getColorValue(teal, 20),
|
|
456
|
+
'17': getColorValue(teal, 10),
|
|
457
|
+
),
|
|
458
|
+
);
|
package/styles/colors.scss
CHANGED
|
@@ -18,9 +18,17 @@
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
@function getGradientColors() {
|
|
22
|
-
$monochrome:
|
|
23
|
-
$divergent:
|
|
21
|
+
@function getGradientColors($theme_type) {
|
|
22
|
+
$monochrome: ();
|
|
23
|
+
$divergent: ();
|
|
24
|
+
|
|
25
|
+
@if $theme_type == 'dark' {
|
|
26
|
+
$monochrome: color-property(null, $dark-monochrome-quantize-colors);
|
|
27
|
+
$divergent: color-property(null, $dark-divergent-quantize-colors);
|
|
28
|
+
} @else {
|
|
29
|
+
$monochrome: color-property(null, $monochrome-quantize-colors);
|
|
30
|
+
$divergent: color-property(null, $divergent-quantize-colors);
|
|
31
|
+
}
|
|
24
32
|
|
|
25
33
|
@return map-merge($monochrome, $divergent);
|
|
26
34
|
}
|
|
@@ -28,9 +36,9 @@
|
|
|
28
36
|
@function color-property($name, $theme-colors) {
|
|
29
37
|
$color-items: ();
|
|
30
38
|
|
|
31
|
-
@if type-of($theme-colors) ==
|
|
39
|
+
@if type-of($theme-colors) ==map {
|
|
32
40
|
@each $category, $value in $theme-colors {
|
|
33
|
-
@if $name ==
|
|
41
|
+
@if $name ==null {
|
|
34
42
|
$color-items: map-merge(
|
|
35
43
|
$color-items,
|
|
36
44
|
color-property('#{$category}', $value)
|
|
@@ -42,13 +50,18 @@
|
|
|
42
50
|
);
|
|
43
51
|
}
|
|
44
52
|
}
|
|
53
|
+
|
|
45
54
|
@return $color-items;
|
|
46
55
|
} @else {
|
|
47
56
|
@return (#{$name}: $theme-colors);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
$color-map-light: map-merge(
|
|
60
|
+
$color-map-light: map-merge(
|
|
61
|
+
getThemeColors('light'),
|
|
62
|
+
getGradientColors('light')
|
|
63
|
+
);
|
|
64
|
+
|
|
52
65
|
.#{$prefix}--chart-holder {
|
|
53
66
|
@each $token, $color in $color-map-light {
|
|
54
67
|
--cds-charts-#{$token}: #{$color};
|
|
@@ -56,7 +69,8 @@ $color-map-light: map-merge(getThemeColors('light'), getGradientColors());
|
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
|
|
59
|
-
$color-map-dark: map-merge(getThemeColors('dark'), getGradientColors());
|
|
72
|
+
$color-map-dark: map-merge(getThemeColors('dark'), getGradientColors('dark'));
|
|
73
|
+
|
|
60
74
|
.#{$prefix}--chart-holder[data-carbon-theme='g90'],
|
|
61
75
|
.#{$prefix}--chart-holder[data-carbon-theme='g100'] {
|
|
62
76
|
@each $token, $color in $color-map-dark {
|
|
@@ -65,7 +79,8 @@ $color-map-dark: map-merge(getThemeColors('dark'), getGradientColors());
|
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
|
|
68
|
-
$color-map: map-merge(getThemeColors('light'), getGradientColors());
|
|
82
|
+
$color-map: map-merge(getThemeColors('light'), getGradientColors('light'));
|
|
83
|
+
|
|
69
84
|
.#{$prefix}--#{$charts-prefix}--chart-wrapper {
|
|
70
85
|
@each $token, $color in $color-map {
|
|
71
86
|
.fill-#{$token} {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@use "@carbon/styles/scss/themes";
|
|
2
|
+
@use "@carbon/styles/scss/theme" as *;
|
|
3
|
+
|
|
4
|
+
.#{$prefix}--#{$charts-prefix}--choropleth {
|
|
5
|
+
path.border {
|
|
6
|
+
stroke: $border-subtle-selected-01;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
g.missing-data path {
|
|
10
|
+
stroke: $border-subtle-selected-01;
|
|
11
|
+
fill: $background;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
pattern path.pattern-fill {
|
|
15
|
+
stroke: $border-strong-01;
|
|
16
|
+
stroke-width: 0.5px;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/styles/graphs/index.scss
CHANGED