Skip to content
New issue

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

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

Already on GitHub? # to your account

Unusual behavior with FlowPlot and setNodeColorSwatch #21

Open
trashgod opened this issue Feb 5, 2023 · 0 comments
Open

Unusual behavior with FlowPlot and setNodeColorSwatch #21

trashgod opened this issue Feb 5, 2023 · 0 comments

Comments

@trashgod
Copy link

trashgod commented Feb 5, 2023

While pursuing this discussion, I encountered an unusual behavior with FlowPlot when invoking setNodeColorSwatch() with JavaFX. Using java 17.0.6, openjfx 17.0.2, jfreechart-1.5.4, org.jfree.chart.fx-2.0.1, org.jfree.fxgraphics2d-2.1.4 and the code below, I see the first result pictured. With setNodeColorSwatch(), the font is unexpectedly larger and the colors lack the intended gradient; a click anywhere on the chart results in the expected appearance.

As a workaround, evoking either of the chart changed events after show() produces the expected font size and gradients.As the color swatch is not a bound property, an explicit redraw is not unreasonable. This is a low priority issue, but I'd welcome any insight.

Without setNodeColorSwatch():
FlowPlotFXTest

With setNodeColorSwatch():
FlowPlotSwatch

With viewer.getCanvas().getChart().fireChartChanged():
FlowPlotChangeEvent

Code:

import java.awt.Color;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.plot.flow.FlowPlot;
import org.jfree.data.flow.DefaultFlowDataset;
import org.jfree.data.flow.FlowDataset;
import org.jfree.data.flow.NodeKey;

/**
 * FlowPlot example adapted from https://github.com/jfree/flowplot.git
 */
public class FlowPlotFXTest extends Application {

    // Adapted from FlowPlotDemo1.java
    private FlowDataset<String> createDataset() {
        var dataset = new DefaultFlowDataset<String>();
        dataset.setFlow(0, "A", "X", 4);
        dataset.setFlow(0, "A", "Y", 2);
        dataset.setFlow(0, "A", "Z", 1);
        dataset.setFlow(0, "B", "X", 2);
        dataset.setFlow(0, "B", "Y", 2);
        dataset.setFlow(0, "B", "Z", 2);

        dataset.setFlow(1, "X", "D", 3);
        dataset.setFlow(1, "X", "E", 4);
        dataset.setFlow(1, "Y", "D", 5);
        dataset.setFlow(1, "Y", "E", 3);
        dataset.setFlow(1, "Z", "D", 2);
        dataset.setFlow(1, "Z", "E", 1);

        dataset.setFlow(2, "D", "H", 2);
        dataset.setFlow(2, "D", "I", 3);
        dataset.setFlow(2, "D", "J", 0);
        dataset.setFlow(2, "E", "H", 3);
        dataset.setFlow(2, "E", "I", 2);
        dataset.setFlow(2, "E", "J", 3);
        return dataset;
    }

    private JFreeChart createChart(FlowDataset dataset) {
        var plot = new FlowPlot(dataset);
        plot.setBackgroundPaint(Color.BLACK);
        plot.setDefaultNodeLabelPaint(Color.WHITE);
        plot.setDefaultNodeColor(Color.CYAN.darker());
        plot.setNodeFillColor(new NodeKey(1, "Y"), Color.MAGENTA);
        //plot.setNodeColorSwatch(FlowColors.getDefaultColors());
        var chart = new JFreeChart("FlowPlot FX Test", plot);
        return chart;
    }

    public ChartViewer createViewer() {
        var dataset = createDataset();
        var chart = createChart(dataset);
        var viewer = new ChartViewer(chart);
        viewer.setPrefSize(768, 512);
        return viewer;
    }

    @Override
    public void start(Stage stage) throws Exception {
        ChartViewer viewer = createViewer();
        stage.setTitle(viewer.getChart().getTitle().getText());
        stage.setScene(new Scene(viewer));
        stage.show();
        //viewer.getCanvas().getChart().fireChartChanged();
        //viewer.getCanvas().chartChanged(null);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant