@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
97 lines • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2007-2019 GoodData Corporation
var cloneDeep = require("lodash/cloneDeep");
var last = require("lodash/last");
function between(x, lowerLimit, higherLimit) {
return Math.min(Math.max(lowerLimit, x), higherLimit);
}
// Fix Highchart issue https://github.com/highcharts/highcharts/issues/11229
function resetPointPaddingForTooSmallHeatmapCells(series) {
var xAxis = series.xAxis;
var yAxis = series.yAxis;
var options = series.options;
var seriesPointPadding = options.pointPadding || 0;
var pointPlacement = series.pointPlacementToXValue();
series.points.forEach(function (point) {
// Recalculate (x1, x2, y1, y2) <=> (left, right, top, bottom) of heatmap cells in pixels
// Transform the calculation of x1, x2, y1, y2 from javascripts to typescripts
// From source: https://github.com/highcharts/highcharts/blob/v7.1.1/js/parts-map/HeatmapSeries.js#L222
var xPad = (options.colsize || 1) / 2;
var yPad = (options.rowsize || 1) / 2;
var x1 = between(Math.round(xAxis.len - xAxis.translate(point.x - xPad, 0, 1, 0, 1, -pointPlacement)), -xAxis.len, 2 * xAxis.len);
var x2 = between(Math.round(xAxis.len - xAxis.translate(point.x + xPad, 0, 1, 0, 1, -pointPlacement)), -xAxis.len, 2 * xAxis.len);
var y1 = between(Math.round(yAxis.translate(point.y - yPad, 0, 1, 0, 1)), -yAxis.len, 2 * yAxis.len);
var y2 = between(Math.round(yAxis.translate(point.y + yPad, 0, 1, 0, 1)), -yAxis.len, 2 * yAxis.len);
var pointPadding = point.pointPadding || seriesPointPadding;
// width: Math.abs(x2 - x1) - pointPadding * 2
// height: Math.abs(y2 - y1) - pointPadding * 2
// Note for highchart upgrading later:
// 1. The modification reset only pointPadding property by below `if`.
// 2. Another parts just transform javascript to typescripts.
if (Math.abs(x2 - x1) < pointPadding * 2 || Math.abs(y2 - y1) < pointPadding * 2) {
// reset pointPadding if new width/Height is negative number
point.pointPadding = 0;
}
});
}
exports.resetPointPaddingForTooSmallHeatmapCells = resetPointPaddingForTooSmallHeatmapCells;
var HEATMAP_TEMPLATE = {
chart: {
type: "heatmap",
marginTop: 8,
marginRight: 0,
spacingRight: 0,
},
plotOptions: {
heatmap: {
dataLabels: {
enabled: true,
allowOverlap: false,
crop: true,
overflow: "justify",
},
point: {
events: {
// from Highcharts 5.0.0 cursor can be set by using 'className' for individual data items
mouseOver: function () {
if (this.drilldown) {
this.graphic.element.style.cursor = "pointer";
}
},
},
},
events: {
afterGeneratePoints: function () {
resetPointPaddingForTooSmallHeatmapCells(this);
},
},
},
},
yAxis: [
{
labels: {
formatter: function () {
var _a = this, axis = _a.axis, isLast = _a.isLast;
var tickPositions = axis.tickPositions, categories = axis.categories;
// tickPositions is array of index of categories
var lastIndex = parseInt(last(tickPositions).toString(), 10);
var lastCategory = categories ? categories[lastIndex] : null;
var labelValue = axis.defaultLabelFormatter.call(this);
// When generate linear tick positions base on categories length.
// Last tick position can be out of index of categories.
// In this case, set label value to null to ignore last label.
if (isLast && categories && !lastCategory) {
labelValue = null;
}
return labelValue;
},
},
},
],
};
function getHeatmapConfiguration() {
return cloneDeep(HEATMAP_TEMPLATE);
}
exports.getHeatmapConfiguration = getHeatmapConfiguration;
//# sourceMappingURL=heatmapConfiguration.js.map