UNPKG

highcharts

Version:
74 lines (73 loc) 2.5 kB
/* * * * * */ 'use strict'; import U from '../Core/Utilities.js'; const { syncTimeout } = U; import A from '../Core/Animation/AnimationUtilities.js'; const { animObject } = A; /** * Create a setTimeout for the first drawDataLabels() * based on the dataLabels.animation.defer value * for series which have enabled simulation. * @private */ function initDataLabelsDefer() { const dlOptions = this.options.dataLabels; // Method drawDataLabels() fires for the first time after // dataLabels.animation.defer time unless // the dataLabels.animation = false or dataLabels.defer = false // or if the simulation is disabled if (!dlOptions?.defer || !this.options.layoutAlgorithm?.enableSimulation) { this.deferDataLabels = false; } else { syncTimeout(() => { this.deferDataLabels = false; }, dlOptions ? animObject(dlOptions.animation).defer : 0); } } /** * Initialize the SVG group for the DataLabels with correct opacities * and correct styles so that the animation for the series that have * simulation enabled works fine. * @private */ function initDataLabels() { const series = this, dlOptions = series.options.dataLabels; if (!series.dataLabelsGroup) { // Those series support only one group of data labels (index 0) const dataLabelsGroup = this.initDataLabelsGroup(0, dlOptions); // Apply the dataLabels.style not only to the // individual dataLabels but also to the entire group if (!series.chart.styledMode && dlOptions?.style) { dataLabelsGroup.css(dlOptions.style); } // Initialize the opacity of the group to 0 (start of animation) dataLabelsGroup.attr({ opacity: 0 }); if (series.visible) { // #2597, #3023, #3024 // #19663, initial data labels animation if (series.options.animation && dlOptions?.animation) { dataLabelsGroup.animate({ opacity: 1 }, dlOptions.animation); } else { dataLabelsGroup.attr({ opacity: 1 }); } dataLabelsGroup.show(); } return dataLabelsGroup; } // Place it on first and subsequent (redraw) calls series.dataLabelsGroup.attr({ opacity: 1, ...this.getPlotBox('data-labels') }); return series.dataLabelsGroup; } const DataLabelsDeferUtils = { initDataLabels, initDataLabelsDefer }; export default DataLabelsDeferUtils;