forked from fair-acc/chart-fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PolarPlotSample.java
80 lines (65 loc) · 2.71 KB
/
PolarPlotSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package de.gsi.chart.samples;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import de.gsi.chart.XYChart;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.plugins.EditAxis;
import de.gsi.chart.renderer.PolarTickStep;
import de.gsi.chart.renderer.datareduction.DefaultDataReducer;
import de.gsi.chart.renderer.spi.ErrorDataSetRenderer;
import de.gsi.dataset.spi.DefaultDataSet;
import de.gsi.dataset.spi.DefaultErrorDataSet;
/**
* small demo to experiment with polar plot geometries
*
* @author rstein
*/
public class PolarPlotSample extends Application {
private static final int N_SAMPLES = 10_000;
@Override
public void start(final Stage primaryStage) {
final StackPane root = new StackPane();
final DefaultNumericAxis xAxis = new DefaultNumericAxis("phi");
final DefaultNumericAxis yAxis = new DefaultNumericAxis("r");
yAxis.setMin(1e-3);
yAxis.setMax(1000);
yAxis.setForceZeroInRange(true);
yAxis.setLogAxis(true);
final XYChart chart = new XYChart(xAxis, yAxis);
// set them false to make the plot faster
chart.setAnimated(false);
chart.getPlugins().add(new EditAxis());
root.getChildren().add(chart);
chart.setPolarPlot(true);
chart.setPolarStepSize(PolarTickStep.THIRTY);
final ErrorDataSetRenderer renderer = (ErrorDataSetRenderer) chart.getRenderers().get(0);
// renderer.setDrawBars(true);
renderer.setDrawMarker(true);
final DefaultDataReducer reducer = (DefaultDataReducer) renderer.getRendererDataReducer();
reducer.setMinPointPixelDistance(3);
final DefaultErrorDataSet dataSet1 = new DefaultErrorDataSet("myData");
final DefaultDataSet dataSet2 = new DefaultDataSet("myData2");
renderer.getDatasets().addAll(dataSet1, dataSet2);
for (int n = 0; n < PolarPlotSample.N_SAMPLES; n++) {
final double x = n * 0.1;
final double y1 = 0.1 + Math.pow(20 * (double) n / PolarPlotSample.N_SAMPLES, 2);
final double y2 = 1e-3 + 1e-2 * Math.pow(200.0 * Math.cos(Math.toRadians(n * 0.1)), 4);
dataSet1.add(x, y1);
dataSet2.add(x, y2);
}
final Scene scene = new Scene(root, 800, 600);
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(evt -> Platform.exit());
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(final String[] args) {
Application.launch(args);
}
}