@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
152 lines • 5.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2007-2020 GoodData Corporation
var cloneDeep = require("lodash/cloneDeep");
var invoke = require("lodash/invoke");
var get = require("lodash/get");
var set = require("lodash/set");
var isEmpty = require("lodash/isEmpty");
var highchartsEntryPoint_1 = require("./highchartsEntryPoint");
var drilldownEventing_1 = require("../../utils/drilldownEventing");
var variables_1 = require("../../styles/variables");
var common_1 = require("../../utils/common");
var chartOptionsBuilder_1 = require("../chartOptionsBuilder");
var setupDrilldownToParentAttribute_1 = require("../events/setupDrilldownToParentAttribute");
var isTouchDevice = "ontouchstart" in window || navigator.msMaxTouchPoints;
var HIGHCHART_PLOT_LIMITED_RANGE = 1e5;
exports.DEFAULT_SERIES_LIMIT = 1000;
exports.DEFAULT_CATEGORIES_LIMIT = 365;
exports.DEFAULT_DATA_POINTS_LIMIT = 2000;
exports.MAX_POINT_WIDTH = 100;
exports.HOVER_BRIGHTNESS = 0.1;
exports.MINIMUM_HC_SAFE_BRIGHTNESS = Number.MIN_VALUE;
function handleTooltipOffScreen(renderTo) {
// allow tooltip over the container wrapper
highchartsEntryPoint_1.default.css(renderTo, { overflow: "visible" });
}
function fixNumericalAxisOutOfMinMaxRange(axis) {
var range = axis.max - axis.min;
if (range < 0) {
// all data points is outside
axis.translationSlope = axis.transA = HIGHCHART_PLOT_LIMITED_RANGE;
}
}
var previousChart = null;
var BASE_TEMPLATE = {
credits: {
enabled: false,
},
title: {
// setting title to empty string prevents it from being shown
text: "",
},
series: [],
legend: {
enabled: false,
},
drilldown: {
activeDataLabelStyle: {
color: "#000",
textDecoration: "none",
},
activeAxisLabelStyle: {
color: variables_1.styleVariables.gdColorText,
textDecoration: "none",
},
drillUpButton: {
theme: {
style: {
// https://forum.highcharts.com/highcharts-usage/empty-checkbox-
// after-drilldown-with-x-axis-label-t33414/
display: "none",
},
},
},
},
plotOptions: {
series: {
animation: false,
enableMouseTracking: true,
turboThreshold: exports.DEFAULT_CATEGORIES_LIMIT,
dataLabels: {
style: {
textOutline: "none",
},
},
events: {
legendItemClick: function () {
if (this.visible) {
this.points.forEach(function (point) { return point.dataLabel && point.dataLabel.hide(); });
}
},
},
point: {
events: {
click: function () {
if (isTouchDevice) {
// Close opened tooltip on previous clicked chart
// (click between multiple charts on dashboards)
var currentChart = this.series.chart;
var currentId = get(currentChart, "container.id");
var prevId = get(previousChart, "container.id");
var previousChartDisconnected = isEmpty(previousChart);
if (previousChart && !previousChartDisconnected && prevId !== currentId) {
// Remove line chart point bubble
invoke(previousChart, "hoverSeries.onMouseOut");
previousChart.tooltip.hide();
}
if (!previousChart || prevId !== currentId) {
previousChart = currentChart;
}
}
},
},
},
},
},
chart: {
animation: false,
style: {
fontFamily: 'Avenir, "Helvetica Neue", Arial, sans-serif',
},
events: {
afterGetContainer: function () {
handleTooltipOffScreen(this.renderTo);
},
},
},
xAxis: [
{
events: {
afterSetAxisTranslation: function () {
fixNumericalAxisOutOfMinMaxRange(this);
},
},
},
],
};
function registerDrilldownHandler(configuration, chartOptions, drillConfig) {
set(configuration, "chart.events.drilldown", function chartDrilldownHandler(event) {
drilldownEventing_1.chartClick(drillConfig, event, this.container, chartOptions.type);
});
return configuration;
}
function handleChartLoad(chartType) {
return function () {
setupDrilldownToParentAttribute_1.setupDrilldown(this, chartType);
};
}
exports.handleChartLoad = handleChartLoad;
function registerRenderHandler(configuration, chartOptions) {
if (common_1.isOneOfTypes(chartOptions.type, chartOptionsBuilder_1.supportedDualAxesChartTypes)) {
set(configuration, "chart.events.render", handleChartLoad(chartOptions.type));
}
return configuration;
}
function getCommonConfiguration(chartOptions, drillConfig) {
var commonConfiguration = cloneDeep(BASE_TEMPLATE);
var handlers = [registerDrilldownHandler, registerRenderHandler];
return handlers.reduce(function (configuration, handler) { return handler(configuration, chartOptions, drillConfig); }, commonConfiguration);
}
exports.getCommonConfiguration = getCommonConfiguration;
//# sourceMappingURL=commonConfiguration.js.map