fair-acc / chart-fx

A scientific charting library focused on performance optimised real-time data visualisation at 25 Hz update rates for data sets with a few 10 thousand up to 5 million data points.
GNU Lesser General Public License v3.0
488 stars 90 forks source link

ErrorDataSetRenderer with LineStyle.HISTOGRAM draws extra lines #649

Closed asmirn1 closed 5 months ago

asmirn1 commented 5 months ago

Describe the bug I'm creating a PCA plot with histograms displaying the distributions of the principal components. I followed Histogram2DimSample.java as an example: https://github.com/fair-acc/chart-fx/blob/main/docs/pics/Histogram2DimSample.png

I noticed some extra lines drawn that shouldn't be there. I highlighted those lines in this screenshot
Screenshot 2024-01-19 104530

This happens only for vertical histogram and when the number of datapoints (bins) is small.

To Reproduce this is part of my code that sets up renderers

projectionRendererX = new ErrorDataSetRenderer();
        projectionRendererX.getAxes().setAll(xAxis, projectionYAxis);
        projectionRendererX.setPolyLineStyle(LineStyle.HISTOGRAM);
        projectionRendererX.setDrawMarker(false);
        projectionRendererX.setPointReduction(false);
        projectionRendererX.setAssumeSortedData(false);
        projectionRendererX.setShowInLegend(false);

        projectionRendererY = new ErrorDataSetRenderer();
        projectionRendererY.getAxes().setAll(projectionXAxis, yAxis);
        projectionRendererY.setPolyLineStyle(LineStyle.HISTOGRAM);
        projectionRendererY.setDrawMarker(false);
        projectionRendererY.setPointReduction(false);
        projectionRendererY.setAssumeSortedData(false);
        projectionRendererY.setShowInLegend(false);

Environment:

wirew0rm commented 5 months ago

Hey, thanks for the detailed report, this looks like a bug in chart-fx. I don't see anything problematic in the renderer setup, and you already excluded some of the usual suspects :+1:

I see however that you are not using the latest chartfx version, did you check that this is not fixed in 11.3.0 ?

We cannot follow up bugs in older releases with limited resources unfortunately, I hope you understand.

I'll close this one, feel free to reopen if the bug persists in the latest release or to comment if you for some reason cannot switch and worked around it yourself and want to document it for others.

asmirn1 commented 5 months ago

Hi @wirew0rm Thank you for your reply. I thought that 11.2.7 was the latest version, and just realized that there is version 11.3.0 now. Thank you for still working on it.

I'm having some problems switching to version 11.3.0 though. For example, I couldn'd find de.gsi.chart.renderer.spi.utils.DefaultRenderColorScheme in the new version. I was using it as follows:

DefaultRenderColorScheme.getFillColor(colorIndex)

Are there better methods to get the default colors in chartfx?

wirew0rm commented 5 months ago

Hey asmirn1, 11.3.0 was a rather big release, with some breaking changes, it's probably a good Idea to go though the Release notes. While we tried to write everything down to make the transition as easy as possible there were some things we missed that were followed up by other users in the release discussion: https://github.com/fair-acc/chart-fx/discussions/629.

On your specific issue: we removed all custom Style related classes in favor of using the standard javafx way of setting colors and styles, which is CSS. This allows to define different styles on a chart by chart basis without having to define a lot of custom code. See the corresponding PR https://github.com/fair-acc/chart-fx/pull/598. If you want to get the color used for a specific data set, there is now a java-fx node for each dataset that you can get from the chart (var styleNode = renderer.getStyleNode(dataSet);) and which will update its color according to css + colors set by the code. If you just want to enumerate the color scheme colors, you can get them from the css file: https://github.com/fair-acc/chart-fx/blob/ed86318c5a1bde23d285633a94860648aee5fb32/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css#L118-L129

I hope that helps!