UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

40 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2007-2018 GoodData Corporation var get = require("lodash/get"); var fill = require("lodash/fill"); var helpers_1 = require("../../helpers"); // delete this plugin once we upgrade to newer highcharts, // set allowOverlap: false to get this behaviour var autohidePieLabels = function (chart) { var visibleSeries = helpers_1.getVisibleSeries(chart); var visiblePoints = helpers_1.getDataPoints(visibleSeries); if (!visiblePoints || visiblePoints.length === 0) { return; } var visibilityMap = fill(Array(visiblePoints.length), true); for (var i = 0; i < visiblePoints.length; i++) { var actualLabel = get(visiblePoints, i + ".dataLabel"); // do nothing if label not found or already hidden if (!actualLabel || !visibilityMap[i]) { continue; } for (var neighborIdx = i + 1; neighborIdx < visiblePoints.length; neighborIdx++) { var neighborLabel = get(visiblePoints, neighborIdx + ".dataLabel"); // do nothing if label not found or already hidden if (!neighborLabel || !visibilityMap[neighborIdx]) { continue; } var intersects = helpers_1.isIntersecting(actualLabel, neighborLabel); if (!intersects) { neighborLabel.show(); } else { visibilityMap[neighborIdx] = false; neighborLabel.hide(); } } } }; exports.default = autohidePieLabels; //# sourceMappingURL=autohidePieLabels.js.map