@carbon/charts 0.53.2 → 0.54.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 +44 -0
- package/build/demo/data/CHART_TYPES.d.ts +5 -0
- package/build/demo/data/heatmap.d.ts +96 -0
- package/build/demo/data/index.d.ts +1 -0
- package/build/src/charts/heatmap.d.ts +10 -0
- package/build/src/charts/index.d.ts +1 -0
- package/build/src/components/axes/axis.d.ts +7 -1
- package/build/src/components/axes/hover-axis.d.ts +10 -0
- package/build/src/components/axes/toolbar.d.ts +5 -1
- package/build/src/components/essentials/color-scale-legend.d.ts +11 -0
- package/build/src/components/graphs/heatmap.d.ts +25 -0
- package/build/src/components/index.d.ts +2 -0
- package/build/src/configuration-non-customizable.d.ts +12 -0
- package/build/src/configuration.d.ts +2 -1
- package/build/src/interfaces/charts.d.ts +35 -2
- package/build/src/interfaces/components.d.ts +19 -0
- package/build/src/interfaces/enums.d.ts +24 -1
- package/build/src/interfaces/events.d.ts +15 -2
- package/build/src/model/cartesian-charts.d.ts +8 -1
- package/build/src/model/heatmap.d.ts +57 -0
- package/build/src/services/scales-cartesian.d.ts +1 -0
- package/bundle.js +1 -1
- package/charts/heatmap.d.ts +10 -0
- package/charts/heatmap.js +138 -0
- package/charts/heatmap.js.map +1 -0
- package/charts/index.d.ts +1 -0
- package/charts/index.js +1 -0
- package/charts/index.js.map +1 -1
- package/components/axes/axis.d.ts +7 -1
- package/components/axes/axis.js +9 -2
- package/components/axes/axis.js.map +1 -1
- package/components/axes/hover-axis.d.ts +10 -0
- package/components/axes/hover-axis.js +235 -0
- package/components/axes/hover-axis.js.map +1 -0
- package/components/axes/toolbar.d.ts +5 -1
- package/components/axes/toolbar.js +100 -34
- package/components/axes/toolbar.js.map +1 -1
- package/components/axes/two-dimensional-axes.js +8 -3
- package/components/axes/two-dimensional-axes.js.map +1 -1
- package/components/essentials/color-scale-legend.d.ts +11 -0
- package/components/essentials/color-scale-legend.js +236 -0
- package/components/essentials/color-scale-legend.js.map +1 -0
- package/components/graphs/heatmap.d.ts +25 -0
- package/components/graphs/heatmap.js +369 -0
- package/components/graphs/heatmap.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/configuration-non-customizable.d.ts +12 -0
- package/configuration-non-customizable.js +13 -0
- package/configuration-non-customizable.js.map +1 -1
- package/configuration.d.ts +2 -1
- package/configuration.js +13 -1
- package/configuration.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/heatmap.d.ts +96 -0
- package/demo/data/heatmap.js +1135 -0
- package/demo/data/heatmap.js.map +1 -0
- package/demo/data/index.d.ts +1 -0
- package/demo/data/index.js +30 -0
- package/demo/data/index.js.map +1 -1
- package/demo/data/toolbar.js +12 -0
- package/demo/data/toolbar.js.map +1 -1
- package/demo/styles.css +16458 -9179
- 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 +19 -5
- package/interfaces/charts.d.ts +35 -2
- package/interfaces/charts.js.map +1 -1
- package/interfaces/components.d.ts +19 -0
- package/interfaces/components.js.map +1 -1
- package/interfaces/enums.d.ts +24 -1
- package/interfaces/enums.js +26 -0
- package/interfaces/enums.js.map +1 -1
- package/interfaces/events.d.ts +15 -2
- package/interfaces/events.js +14 -0
- package/interfaces/events.js.map +1 -1
- package/model/cartesian-charts.d.ts +8 -1
- package/model/cartesian-charts.js +4 -2
- package/model/cartesian-charts.js.map +1 -1
- package/model/heatmap.d.ts +57 -0
- package/model/heatmap.js +289 -0
- package/model/heatmap.js.map +1 -0
- package/package.json +1 -1
- package/services/scales-cartesian.d.ts +1 -0
- package/services/scales-cartesian.js +16 -0
- package/services/scales-cartesian.js.map +1 -1
- package/services/zoom.js +5 -0
- package/services/zoom.js.map +1 -1
- package/styles/color-palatte.scss +96 -0
- package/styles/colors.scss +35 -1
- package/styles/components/_axis.scss +41 -0
- package/styles/components/_color-legend.scss +24 -0
- package/styles/components/index.scss +1 -0
- package/styles/graphs/_heatmap.scss +70 -0
- package/styles/graphs/index.scss +1 -0
- package/styles-g10.css +2000 -179
- 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 +2003 -182
- 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 +2004 -180
- 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 +2000 -179
- package/styles.css.map +1 -1
- package/styles.min.css +1 -1
- package/styles.min.css.map +1 -1
- package/tsconfig.tsbuildinfo +182 -59
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AxisFlavor } from '../interfaces';
|
|
2
|
+
import { ChartModelCartesian } from './cartesian-charts';
|
|
3
|
+
/** The gauge chart model layer */
|
|
4
|
+
export declare class HeatmapModel extends ChartModelCartesian {
|
|
5
|
+
protected axisFlavor: AxisFlavor;
|
|
6
|
+
private _colorScale;
|
|
7
|
+
private _domains;
|
|
8
|
+
private _ranges;
|
|
9
|
+
private _matrix;
|
|
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(): any[];
|
|
16
|
+
/**
|
|
17
|
+
* @override
|
|
18
|
+
* @param value
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getFillColor(value: number): any;
|
|
22
|
+
/**
|
|
23
|
+
* Generate a list of all unique domains
|
|
24
|
+
* @returns String[]
|
|
25
|
+
*/
|
|
26
|
+
getUniqueDomain(): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Generates a list of all unique ranges
|
|
29
|
+
* @returns String[]
|
|
30
|
+
*/
|
|
31
|
+
getUniqueRanges(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Generates a matrix (If doesn't exist) and returns it
|
|
34
|
+
* @returns Object
|
|
35
|
+
*/
|
|
36
|
+
getMatrix(): {};
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param newData The new raw data to be set
|
|
40
|
+
*/
|
|
41
|
+
setData(newData: any): any;
|
|
42
|
+
/**
|
|
43
|
+
* Converts Object matrix into a single array
|
|
44
|
+
* @returns Object[]
|
|
45
|
+
*/
|
|
46
|
+
getMatrixAsArray(): Object[];
|
|
47
|
+
/**
|
|
48
|
+
* Generate tabular data from display data
|
|
49
|
+
* @returns Array<Object>
|
|
50
|
+
*/
|
|
51
|
+
getTabularDataArray(): any[];
|
|
52
|
+
getColorClassName(configs: {
|
|
53
|
+
value?: number;
|
|
54
|
+
originalClassName?: string;
|
|
55
|
+
}): string;
|
|
56
|
+
protected setColorClassNames(): void;
|
|
57
|
+
}
|
package/model/heatmap.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
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 { AxisFlavor, ScaleTypes } from '../interfaces';
|
|
23
|
+
import { ChartModelCartesian } from './cartesian-charts';
|
|
24
|
+
import { Tools } from '../tools';
|
|
25
|
+
// d3 imports
|
|
26
|
+
import { extent } from 'd3-array';
|
|
27
|
+
import { scaleQuantize } from 'd3-scale';
|
|
28
|
+
/** The gauge chart model layer */
|
|
29
|
+
var HeatmapModel = /** @class */ (function (_super) {
|
|
30
|
+
__extends(HeatmapModel, _super);
|
|
31
|
+
function HeatmapModel(services) {
|
|
32
|
+
var _this = _super.call(this, services) || this;
|
|
33
|
+
_this.axisFlavor = AxisFlavor.HOVERABLE;
|
|
34
|
+
_this._colorScale = undefined;
|
|
35
|
+
// List of unique ranges and domains
|
|
36
|
+
_this._domains = [];
|
|
37
|
+
_this._ranges = [];
|
|
38
|
+
_this._matrix = {};
|
|
39
|
+
// Check which scale types are being used
|
|
40
|
+
var axis = Tools.getProperty(_this.getOptions(), 'axes');
|
|
41
|
+
// Need to check options since scale service hasn't been instantiated
|
|
42
|
+
if ((!!Tools.getProperty(axis, 'left', 'scaleType') &&
|
|
43
|
+
Tools.getProperty(axis, 'left', 'scaleType') !==
|
|
44
|
+
ScaleTypes.LABELS) ||
|
|
45
|
+
(!!Tools.getProperty(axis, 'right', 'scaleType') &&
|
|
46
|
+
Tools.getProperty(axis, 'right', 'scaleType') !==
|
|
47
|
+
ScaleTypes.LABELS) ||
|
|
48
|
+
(!!Tools.getProperty(axis, 'top', 'scaleType') &&
|
|
49
|
+
Tools.getProperty(axis, 'top', 'scaleType') !==
|
|
50
|
+
ScaleTypes.LABELS) ||
|
|
51
|
+
(!!Tools.getProperty(axis, 'bottom', 'scaleType') &&
|
|
52
|
+
Tools.getProperty(axis, 'bottom', 'scaleType') !==
|
|
53
|
+
ScaleTypes.LABELS)) {
|
|
54
|
+
throw Error('Heatmap only supports label scaletypes.');
|
|
55
|
+
}
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
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 data = this.getDisplayData().map(function (element) { return element.value; });
|
|
64
|
+
var limits = extent(data);
|
|
65
|
+
var domain = [];
|
|
66
|
+
// Round extent values to the nearest multiple of 10
|
|
67
|
+
// Axis rounds values to multiples of 2, 5, and 10s.
|
|
68
|
+
limits.forEach(function (number, index) {
|
|
69
|
+
var value = Number(number);
|
|
70
|
+
if (index === 0 && value >= 0) {
|
|
71
|
+
value = 0;
|
|
72
|
+
}
|
|
73
|
+
else if (value % 10 === 0 || value === 0) {
|
|
74
|
+
value;
|
|
75
|
+
}
|
|
76
|
+
else if (value < 0) {
|
|
77
|
+
value = Math.floor(value / 10) * 10;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
value = Math.ceil(value / 10) * 10;
|
|
81
|
+
}
|
|
82
|
+
domain.push(value);
|
|
83
|
+
});
|
|
84
|
+
// Ensure the median of the range is 0
|
|
85
|
+
if (domain[0] < 0 && domain[1] > 0) {
|
|
86
|
+
if (Math.abs(domain[0]) > domain[1]) {
|
|
87
|
+
domain[1] = Math.abs(domain[0]);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
domain[0] = -domain[1];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return domain;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @override
|
|
97
|
+
* @param value
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
HeatmapModel.prototype.getFillColor = function (value) {
|
|
101
|
+
return this._colorScale(value);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Generate a list of all unique domains
|
|
105
|
+
* @returns String[]
|
|
106
|
+
*/
|
|
107
|
+
HeatmapModel.prototype.getUniqueDomain = function () {
|
|
108
|
+
if (Tools.isEmpty(this._domains)) {
|
|
109
|
+
var displayData = this.getDisplayData();
|
|
110
|
+
var cartesianScales = this.services.cartesianScales;
|
|
111
|
+
var domainIdentifier_1 = cartesianScales.getDomainIdentifier();
|
|
112
|
+
var mainXAxisPosition = cartesianScales.getMainXAxisPosition();
|
|
113
|
+
var customDomain = cartesianScales.getCustomDomainValuesByposition(mainXAxisPosition);
|
|
114
|
+
// Use user defined domain if specified
|
|
115
|
+
if (!!customDomain) {
|
|
116
|
+
return customDomain;
|
|
117
|
+
}
|
|
118
|
+
// Get unique axis values & create a matrix
|
|
119
|
+
this._domains = Array.from(new Set(displayData.map(function (d) {
|
|
120
|
+
return d[domainIdentifier_1];
|
|
121
|
+
})));
|
|
122
|
+
}
|
|
123
|
+
return this._domains;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Generates a list of all unique ranges
|
|
127
|
+
* @returns String[]
|
|
128
|
+
*/
|
|
129
|
+
HeatmapModel.prototype.getUniqueRanges = function () {
|
|
130
|
+
if (Tools.isEmpty(this._ranges)) {
|
|
131
|
+
var displayData = this.getDisplayData();
|
|
132
|
+
var cartesianScales = this.services.cartesianScales;
|
|
133
|
+
var rangeIdentifier_1 = cartesianScales.getRangeIdentifier();
|
|
134
|
+
var mainYAxisPosition = cartesianScales.getMainYAxisPosition();
|
|
135
|
+
var customDomain = cartesianScales.getCustomDomainValuesByposition(mainYAxisPosition);
|
|
136
|
+
// Use user defined domain if specified
|
|
137
|
+
if (!!customDomain) {
|
|
138
|
+
return customDomain;
|
|
139
|
+
}
|
|
140
|
+
// Get unique axis values & create a matrix
|
|
141
|
+
this._ranges = Array.from(new Set(displayData.map(function (d) {
|
|
142
|
+
return d[rangeIdentifier_1];
|
|
143
|
+
})));
|
|
144
|
+
}
|
|
145
|
+
return this._ranges;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Generates a matrix (If doesn't exist) and returns it
|
|
149
|
+
* @returns Object
|
|
150
|
+
*/
|
|
151
|
+
HeatmapModel.prototype.getMatrix = function () {
|
|
152
|
+
var _this = this;
|
|
153
|
+
if (Tools.isEmpty(this._matrix)) {
|
|
154
|
+
var uniqueDomain = this.getUniqueDomain();
|
|
155
|
+
var uniqueRange = this.getUniqueRanges();
|
|
156
|
+
var domainIdentifier_2 = this.services.cartesianScales.getDomainIdentifier();
|
|
157
|
+
var rangeIdentifier_2 = this.services.cartesianScales.getRangeIdentifier();
|
|
158
|
+
// Create a column
|
|
159
|
+
var range_1 = {};
|
|
160
|
+
uniqueRange.forEach(function (ran) {
|
|
161
|
+
// Initialize matrix to empty state
|
|
162
|
+
range_1[ran] = {
|
|
163
|
+
value: null,
|
|
164
|
+
index: -1,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
// Complete the matrix by cloning the column to all domains
|
|
168
|
+
uniqueDomain.forEach(function (dom) {
|
|
169
|
+
_this._matrix[dom] = Tools.clone(range_1);
|
|
170
|
+
});
|
|
171
|
+
// Fill in user passed data
|
|
172
|
+
this.getDisplayData().forEach(function (d, i) {
|
|
173
|
+
_this._matrix[d[domainIdentifier_2]][d[rangeIdentifier_2]] = {
|
|
174
|
+
value: d['value'],
|
|
175
|
+
index: i,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return this._matrix;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param newData The new raw data to be set
|
|
184
|
+
*/
|
|
185
|
+
HeatmapModel.prototype.setData = function (newData) {
|
|
186
|
+
var sanitizedData = this.sanitize(Tools.clone(newData));
|
|
187
|
+
var dataGroups = this.generateDataGroups(sanitizedData);
|
|
188
|
+
this.set({
|
|
189
|
+
data: sanitizedData,
|
|
190
|
+
dataGroups: dataGroups,
|
|
191
|
+
});
|
|
192
|
+
// Set attributes to empty
|
|
193
|
+
this._domains = [];
|
|
194
|
+
this._ranges = [];
|
|
195
|
+
this._matrix = {};
|
|
196
|
+
return sanitizedData;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Converts Object matrix into a single array
|
|
200
|
+
* @returns Object[]
|
|
201
|
+
*/
|
|
202
|
+
HeatmapModel.prototype.getMatrixAsArray = function () {
|
|
203
|
+
var _this = this;
|
|
204
|
+
if (Tools.isEmpty(this._matrix)) {
|
|
205
|
+
this.getMatrix();
|
|
206
|
+
}
|
|
207
|
+
var uniqueDomain = this.getUniqueDomain();
|
|
208
|
+
var uniqueRange = this.getUniqueRanges();
|
|
209
|
+
var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
|
|
210
|
+
var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
|
|
211
|
+
var arr = [];
|
|
212
|
+
uniqueDomain.forEach(function (domain) {
|
|
213
|
+
uniqueRange.forEach(function (range) {
|
|
214
|
+
var element = {
|
|
215
|
+
value: _this._matrix[domain][range].value,
|
|
216
|
+
index: _this._matrix[domain][range].index,
|
|
217
|
+
};
|
|
218
|
+
element[domainIdentifier] = domain;
|
|
219
|
+
element[rangeIdentifier] = range;
|
|
220
|
+
arr.push(element);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
return arr;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Generate tabular data from display data
|
|
227
|
+
* @returns Array<Object>
|
|
228
|
+
*/
|
|
229
|
+
HeatmapModel.prototype.getTabularDataArray = function () {
|
|
230
|
+
var displayData = this.getDisplayData();
|
|
231
|
+
var _a = this.assignRangeAndDomains(), primaryDomain = _a.primaryDomain, primaryRange = _a.primaryRange, secondaryDomain = _a.secondaryDomain, secondaryRange = _a.secondaryRange;
|
|
232
|
+
var domainValueFormatter;
|
|
233
|
+
var result = __spreadArrays([
|
|
234
|
+
[primaryDomain.label, primaryRange.label, 'Value']
|
|
235
|
+
], displayData.map(function (datum) { return [
|
|
236
|
+
datum[primaryDomain.identifier] === null
|
|
237
|
+
? '–'
|
|
238
|
+
: domainValueFormatter
|
|
239
|
+
? domainValueFormatter(datum[primaryDomain.identifier])
|
|
240
|
+
: datum[primaryDomain.identifier],
|
|
241
|
+
datum[primaryRange.identifier] === null
|
|
242
|
+
? '–'
|
|
243
|
+
: datum[primaryRange.identifier].toLocaleString(),
|
|
244
|
+
datum['value'],
|
|
245
|
+
]; }));
|
|
246
|
+
return result;
|
|
247
|
+
};
|
|
248
|
+
// Uses quantize scale to return class names
|
|
249
|
+
HeatmapModel.prototype.getColorClassName = function (configs) {
|
|
250
|
+
return configs.originalClassName + " " + this._colorScale(configs.value);
|
|
251
|
+
};
|
|
252
|
+
HeatmapModel.prototype.setColorClassNames = function () {
|
|
253
|
+
var options = this.getOptions();
|
|
254
|
+
var customColors = Tools.getProperty(options, 'color', 'gradient', 'colors');
|
|
255
|
+
var customColorsEnabled = !Tools.isEmpty(customColors);
|
|
256
|
+
var colorPairingOption = Tools.getProperty(options, 'color', 'pairing', 'option');
|
|
257
|
+
// If domain consists of negative and positive values, use diverging palettes
|
|
258
|
+
var domain = this.getValueDomain();
|
|
259
|
+
var colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';
|
|
260
|
+
// Use default color pairing options if not in defined range
|
|
261
|
+
if (colorPairingOption < 1 &&
|
|
262
|
+
colorPairingOption > 4 &&
|
|
263
|
+
colorScheme === 'mono') {
|
|
264
|
+
colorPairingOption = 1;
|
|
265
|
+
}
|
|
266
|
+
else if (colorPairingOption < 1 &&
|
|
267
|
+
colorPairingOption > 2 &&
|
|
268
|
+
colorScheme === 'diverge') {
|
|
269
|
+
colorPairingOption = 1;
|
|
270
|
+
}
|
|
271
|
+
// Uses css classes for fill
|
|
272
|
+
var colorPairing = customColorsEnabled ? customColors : [];
|
|
273
|
+
if (!customColorsEnabled) {
|
|
274
|
+
// Add class names to list and the amount based on the color scheme
|
|
275
|
+
// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette
|
|
276
|
+
var colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;
|
|
277
|
+
for (var i = 1; i < colorGroupingLength + 1; i++) {
|
|
278
|
+
colorPairing.push("fill-" + colorScheme + "-" + colorPairingOption + "-" + i);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Save scale type
|
|
282
|
+
this._colorScale = scaleQuantize()
|
|
283
|
+
.domain(this.getValueDomain())
|
|
284
|
+
.range(colorPairing);
|
|
285
|
+
};
|
|
286
|
+
return HeatmapModel;
|
|
287
|
+
}(ChartModelCartesian));
|
|
288
|
+
export { HeatmapModel };
|
|
289
|
+
//# sourceMappingURL=../../src/model/heatmap.js.map
|
|
@@ -0,0 +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,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,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,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CAChD,CAAC;aACF;SACD;QAED,kBAAkB;QAClB,IAAI,CAAC,WAAW,GAAG,aAAa,EAAE;aAChC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAsB,CAAC;aACjD,KAAK,CAAC,YAAY,CAAC,CAAC;IACvB,CAAC;IACF,mBAAC;AAAD,CAAC,AAjVD,CAAkC,mBAAmB,GAiVpD","sourcesContent":["// Internal Imports\nimport { AxisFlavor, ScaleTypes } from '../interfaces';\nimport { ChartModelCartesian } from './cartesian-charts';\nimport { Tools } from '../tools';\n\n// d3 imports\nimport { extent } from 'd3-array';\nimport { scaleQuantize } 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 data = this.getDisplayData().map((element) => element.value);\n\t\tconst limits = extent(data);\n\t\tconst domain = [];\n\n\t\t// Round extent values to the nearest multiple of 10\n\t\t// Axis rounds values to multiples of 2, 5, and 10s.\n\t\tlimits.forEach((number, index) => {\n\t\t\tlet value = Number(number);\n\n\t\t\tif (index === 0 && value >= 0) {\n\t\t\t\tvalue = 0;\n\t\t\t} else if (value % 10 === 0 || value === 0) {\n\t\t\t\tvalue;\n\t\t\t} else if (value < 0) {\n\t\t\t\tvalue = Math.floor(value / 10) * 10;\n\t\t\t} else {\n\t\t\t\tvalue = Math.ceil(value / 10) * 10;\n\t\t\t}\n\n\t\t\tdomain.push(value);\n\t\t});\n\n\t\t// Ensure the median of the range is 0\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\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 {\n\t\t\tprimaryDomain,\n\t\t\tprimaryRange,\n\t\t\tsecondaryDomain,\n\t\t\tsecondaryRange,\n\t\t} = 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(this.getValueDomain() as [number, number])\n\t\t\t.range(colorPairing);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -37,6 +37,7 @@ export declare class CartesianScales extends Service {
|
|
|
37
37
|
determineOrientation(): void;
|
|
38
38
|
isDualAxes(): Boolean;
|
|
39
39
|
determineAxisDuality(): void;
|
|
40
|
+
getCustomDomainValuesByposition(axisPosition: AxisPositions): any;
|
|
40
41
|
getOrientation(): CartesianOrientations;
|
|
41
42
|
getScaleByPosition(axisPosition: AxisPositions): any;
|
|
42
43
|
getScaleTypeByPosition(axisPosition: AxisPositions): any;
|
|
@@ -181,6 +181,22 @@ var CartesianScales = /** @class */ (function (_super) {
|
|
|
181
181
|
this.dualAxes = true;
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
|
+
CartesianScales.prototype.getCustomDomainValuesByposition = function (axisPosition) {
|
|
185
|
+
var domain = Tools.getProperty(this.model.getOptions(), 'axes', axisPosition, 'domain');
|
|
186
|
+
// Check if domain is an array
|
|
187
|
+
if (domain && !Array.isArray(domain)) {
|
|
188
|
+
throw new Error("Domain in " + axisPosition + " axis is not a valid array");
|
|
189
|
+
}
|
|
190
|
+
// Determine number of elements passed in domain depending on scale types
|
|
191
|
+
if (Array.isArray(domain)) {
|
|
192
|
+
if ((this.scaleTypes[axisPosition] === ScaleTypes.LINEAR ||
|
|
193
|
+
this.scaleTypes[axisPosition] === ScaleTypes.TIME) &&
|
|
194
|
+
domain.length !== 2) {
|
|
195
|
+
throw new Error("There can only be 2 elements in domain for scale type: " + this.scaleTypes[axisPosition]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return domain;
|
|
199
|
+
};
|
|
184
200
|
CartesianScales.prototype.getOrientation = function () {
|
|
185
201
|
return this.orientation;
|
|
186
202
|
};
|