Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for labels in pie and doughnut charts #311

Closed
wants to merge 1 commit into from

Conversation

buchen
Copy link
Contributor

@buchen buchen commented Dec 4, 2022

Issue: #286

This is draft to enables labels on pie and doughnut charts.

I propose to extend the ISeriesLabel to add options for positioning and a label provider. I happy to discuss alternatives how to integrate it into the existing API.

There are three things that I would love to hear your thoughts:

First, I would love to enable multiple label placements (say the percentage inside the pie slice, the label placed outside). But that does not really fit to the existing ISeriesLabel interface with the get/setter for the ISeriesLabel. One could add a createAdditionalLabel method.

Second, in PP I am rendering the label color - if placed inside the pie slice - based on the color of the slice (dark slice = white; bright slice = black). Again, I could ignore the Foreground method in the interface, but it is not intuitive as the interface has the method

Third, I am using Function<Node, String> labelProvider to not introduce a dependency to JFace. Any better idea?

Examples for the use of the new API:

circularSeries.getLabel().setVisible(true);
circularSeries.getLabel().setPosition(ICircularSeriesLabel.Position.Inside);
circularSeries.getLabel().setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_RED));
circularSeries.getLabel().setLabelProvider(node -> String.format("%s (%.1f%%)", node.getId(), node.getValue() / node.getParent().getValue() * 100));

Example charts:
Bildschirm­foto 2022-12-04 um 19 39 40

Bildschirm­foto 2022-12-04 um 19 40 00

Bildschirm­foto 2022-12-04 um 19 50 44

Bildschirm­foto 2022-12-04 um 19 52 09

@buchen
Copy link
Contributor Author

buchen commented Dec 4, 2022

(I will fix the copyright headers once we agreed on the API and I polished the pull request up)

@eselmeister
Copy link
Contributor

That looks really promising. Let me inspect it in detail and give you a feedback soon.

@eselmeister
Copy link
Contributor

@buchen I have refactored the Pie charts handling, see #319.

I will start a release of SWTChart by Monday, 16th of January. If you'd like to merge your improvements for the next release, please let me know.

@buchen buchen closed this Oct 25, 2024
@buchen
Copy link
Contributor Author

buchen commented Oct 25, 2024

Closing the stale pull request.

I can be done with custom code and we never never finished the discussion how to evolve the API.

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.

2 participants