forked from fair-acc/chart-fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeAxisSample.java
99 lines (82 loc) · 3.56 KB
/
TimeAxisSample.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package de.gsi.chart.samples;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import de.gsi.chart.XYChart;
import de.gsi.chart.axes.AxisLabelOverlapPolicy;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.plugins.DataPointTooltip;
import de.gsi.chart.plugins.EditAxis;
import de.gsi.chart.plugins.Zoomer;
import de.gsi.dataset.spi.DefaultErrorDataSet;
import de.gsi.dataset.utils.ProcessingProfiler;
/**
* @author rstein
*/
public class TimeAxisSample extends Application {
private static final int N_SAMPLES = 10_000; // default: 10000
private void generateData(final DefaultErrorDataSet dataSet) {
final long startTime = ProcessingProfiler.getTimeStamp();
dataSet.autoNotification().set(false);
dataSet.clearData();
final double now = System.currentTimeMillis() / 1000.0 + 1; // N.B. '+1'
// to check
// for
// resolution
for (int n = 0; n < TimeAxisSample.N_SAMPLES; n++) {
double t = now + n * 10;
t *= +1;
final double y = 100 * Math.cos(Math.PI * t * 0.0005) + 0 * 0.001 * (t - now) + 0 * 1e4;
final double ex = 0.1;
final double ey = 10;
dataSet.add(t, y, ex, ey);
}
dataSet.autoNotification().set(true);
Platform.runLater(() -> dataSet.fireInvalidated(null));
ProcessingProfiler.getTimeDiff(startTime, "adding data into DataSet");
}
@Override
public void start(final Stage primaryStage) {
ProcessingProfiler.setVerboseOutputState(true);
ProcessingProfiler.setLoggerOutputState(true);
ProcessingProfiler.setDebugState(false);
final BorderPane root = new BorderPane();
final Scene scene = new Scene(root, 800, 600);
final DefaultNumericAxis xAxis1 = new DefaultNumericAxis("time", "iso");
xAxis1.setOverlapPolicy(AxisLabelOverlapPolicy.SKIP_ALT);
final DefaultNumericAxis yAxis1 = new DefaultNumericAxis("y-axis", "a.u.");
final XYChart chart = new XYChart(xAxis1, yAxis1);
chart.legendVisibleProperty().set(true);
chart.getPlugins().add(new Zoomer());
chart.getPlugins().add(new EditAxis());
chart.getPlugins().add(new DataPointTooltip());
// set them false to make the plot faster
chart.setAnimated(false);
xAxis1.setAutoRangeRounding(false);
// xAxis1.invertAxis(true); TODO: bug inverted time axis crashes when zooming
xAxis1.setTimeAxis(true);
yAxis1.setAutoRangeRounding(true);
final DefaultErrorDataSet dataSet = new DefaultErrorDataSet("TestData");
generateData(dataSet);
long startTime = ProcessingProfiler.getTimeStamp();
chart.getDatasets().add(dataSet);
ProcessingProfiler.getTimeDiff(startTime, "adding data to chart");
startTime = ProcessingProfiler.getTimeStamp();
root.setCenter(chart);
ProcessingProfiler.getTimeDiff(startTime, "adding chart into StackPane");
startTime = ProcessingProfiler.getTimeStamp();
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(evt -> Platform.exit());
primaryStage.show();
ProcessingProfiler.getTimeDiff(startTime, "for showing");
}
/**
* @param args the command line arguments
*/
public static void main(final String[] args) {
Application.launch(args);
}
}