[heatmap] numerous improvements (#3456)

* [heatmap] numerous improvements

* flexibility as to how to sort X and Y axis (alpha/value, desc/asc)
* option to show a legend
* fixed margins, maximize real estate
* allowed users to define bounds

* Tunning
This commit is contained in:
Maxime Beauchemin
2017-09-13 16:13:45 -07:00
committed by GitHub
parent 8223729e1e
commit 49f24d128b
7 changed files with 141 additions and 42 deletions

View File

@@ -116,17 +116,20 @@ export const getColorFromScheme = (function () {
};
}());
export const colorScalerFactory = function (colors, data, accessor) {
export const colorScalerFactory = function (colors, data, accessor, extents) {
// Returns a linear scaler our of an array of color
if (!Array.isArray(colors)) {
/* eslint no-param-reassign: 0 */
colors = spectrums[colors];
}
let ext = [0, 1];
if (data !== undefined) {
if (extents) {
ext = extents;
}
if (data) {
ext = d3.extent(data, accessor);
}
const chunkSize = (ext[1] - ext[0]) / (colors.length - 1);
const points = colors.map((col, i) => i * chunkSize);
return d3.scale.linear().domain(points).range(colors);
const points = colors.map((col, i) => ext[0] + (i * chunkSize));
return d3.scale.linear().domain(points).range(colors).clamp(true);
};