diff --git a/js/ternary-plot.js b/js/ternary-plot.js index 36a7813..04bfb20 100644 --- a/js/ternary-plot.js +++ b/js/ternary-plot.js @@ -590,7 +590,13 @@ function TernaryPlotPlugin(H) { e.isInsidePlot = pointInTriangle(px, py, Ax, Ay, Bx, By, Cx, Cy); }); addEvent(Series, 'afterDrawDataLabels', function () { - if (!(this.options.minSize && this.options.maxSize)) { + // Data labels can be enabled either as a single object or as an array + // of objects (#5) + const dataLabelsOption = this.options.dataLabels; + const dataLabelsEnabled = dataLabelsOption === undefined + ? true + : H.splat(dataLabelsOption).some(d => (d === null || d === void 0 ? void 0 : d.enabled) !== false); + if (!(this.options.minSize && this.options.maxSize) || !dataLabelsEnabled) { return; } this.points.forEach(point => { diff --git a/ts/ternary-plot.ts b/ts/ternary-plot.ts index 272d7fb..4b29fc5 100644 --- a/ts/ternary-plot.ts +++ b/ts/ternary-plot.ts @@ -115,6 +115,7 @@ type TernarySeriesOptions = Highcharts.SeriesOptions & { minSize?: number; maxSize?: number; componentColors?: ComponentColors; + dataLabels?: Highcharts.DataLabelsOptions | Highcharts.DataLabelsOptions[]; }; type TernarySeries = Highcharts.Series & { @@ -1071,7 +1072,14 @@ export default function TernaryPlotPlugin(H: HighchartsPlugin): void { }); addEvent(Series, 'afterDrawDataLabels', function (this: TernarySeries) { - if (!(this.options.minSize && this.options.maxSize)) { + // Data labels can be enabled either as a single object or as an array + // of objects (#5) + const dataLabelsOption = this.options.dataLabels; + const dataLabelsEnabled = dataLabelsOption === undefined + ? true + : H.splat(dataLabelsOption).some(d => d?.enabled !== false); + + if (!(this.options.minSize && this.options.maxSize) || !dataLabelsEnabled) { return; }