Skip to content

Fixed rendering chart with dataLabels disabled#6

Open
annavvis wants to merge 4 commits intomainfrom
bugfix/5-minsize-maxsize-datalabels-disabled
Open

Fixed rendering chart with dataLabels disabled#6
annavvis wants to merge 4 commits intomainfrom
bugfix/5-minsize-maxsize-datalabels-disabled

Conversation

@annavvis
Copy link
Copy Markdown
Collaborator

Fixed #5, the chart didn't render without dataLabels enabled.

@annavvis annavvis requested a review from raf18seb April 23, 2026 11:51
Copy link
Copy Markdown
Contributor

@raf18seb raf18seb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The solution is good, but it's narrowing the dataLabels TS type and might not work in all cases, so we need to discuss before merging. Please see my comments below.

Also, adding a regression test might be a good idea (at least something to consider too).

Comment thread ts/ternary-plot.ts Outdated
minSize?: number;
maxSize?: number;
componentColors?: ComponentColors;
dataLabels?: Highcharts.DataLabelsOptions;
Copy link
Copy Markdown
Contributor

@raf18seb raf18seb Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to narrow down this type? What if the dataLabels are defined as an array?

If you're sure that we should resign from dataLabels array config, then at least please add an explanation comment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As SeriesOptions type doesn’t accept dataLablels, I added Highcharts.DataLabelsOptions[] to the type.

Comment thread ts/ternary-plot.ts Outdated
@annavvis annavvis requested a review from raf18seb April 23, 2026 15:36
Copy link
Copy Markdown
Contributor

@raf18seb raf18seb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @annavvis, please double-check your solution because it's not solving the issue (the error still occurs). If I had to guess, I'd say you didn't use the simplified demo.

Remember that dataLabels can be enabled for a single point, not just at the series level.

Also, please see the comments below 👇

Comment thread ts/ternary-plot.ts Outdated
// Data labels can be enabled either as a single object or as an array
// of objects (#5)
const dataLabels = this.options.dataLabels;
const dataLabelsEnabled = Array.isArray(dataLabels)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using H.splat() to be consistent with Highcharts patterns.

Comment thread tests/dataLabels.test.ts Outdated
Comment on lines +23 to +25
it('returns true when dataLabels is undefined', () => {
expect(labelsEnabled(undefined)).toBe(true);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does labelsEnabled return true when dataLabels are undefined? Shouldn't it be the opposite?

Comment thread tests/dataLabels.test.ts Outdated
Comment on lines +15 to +19
function labelsEnabled(dl: DL | DL[] | undefined): boolean {
return Array.isArray(dl)
? dl.some(d => d.enabled !== false)
: dl?.enabled !== false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing tests for functions that aren't imported from the source code is an antipattern. Imagine this: if your code in the .ts file changes and something breaks, your local labelsEnabled implementation in the tests won't change - so the tests will keep passing and won't catch the problem.

Comment thread tests/dataLabels.test.ts Outdated
Comment on lines +1 to +11
import { describe, it, expect } from 'vitest';

// Regression test for #5: the afterDrawDataLabels handler must skip
// repositioning when dataLabels is disabled, and must handle both the
// object form and the array form of the dataLabels option.
//
// The condition from the plugin, extracted for unit testing:
// const dl = this.options.dataLabels;
// const labelsEnabled = Array.isArray(dl)
// ? (dl as Highcharts.DataLabelsOptions[]).some(d => d.enabled !== false)
// : dl?.enabled !== false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what, you can skip the tests. We don't have integration tests with Highcharts yet, so we can't properly test it anyway.

@annavvis
Copy link
Copy Markdown
Collaborator Author

I’ve deleted the test and updated the fix to use H.splat and also added an explicit check for undefined to preserve the original behavior since in Highcharts data labels are enabled by default.

@annavvis annavvis requested a review from raf18seb April 29, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minSize & maxSize doesn't work with dataLabels disabled

2 participants