forked from 617406160/JavaPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot.java
More file actions
164 lines (139 loc) · 3.28 KB
/
Copy pathPlot.java
File metadata and controls
164 lines (139 loc) · 3.28 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.sin.java.plot;
import java.util.ArrayList;
import java.util.List;
import com.sin.java.plot.model.DrawableObject;
import com.sin.java.plot.util.XLog;
/***
* UI方法,提供图形绘制接口
*
* @author RobinTang
*
*/
final public class Plot {
private static List<PlotFrame> plotFrameStack = null;
private static PlotFrame currenPlotFrame = null;
private static int plotFrameConter = 1;
private static boolean autoFigure = false; // 自动创建图形窗口
/**
* 初始化图形窗口栈
*/
private static void initPlotFrameStack() {
if (plotFrameStack == null) {
plotFrameStack = new ArrayList<PlotFrame>();
}
}
/**
* 初始化当前图形窗口
*/
private static void initCurrentPlotFrame() {
if (currenPlotFrame == null) {
figrue();
}
}
// like matlab
/**
* 开图形保存
*/
public static void hold_on() {
initCurrentPlotFrame();
currenPlotFrame.setHoldOn(true);
}
/**
* 关图形保持
*/
public static void hold_off() {
initCurrentPlotFrame();
currenPlotFrame.setHoldOn(false);
}
/**
* 开自动创建图形窗口
*/
public static void autofigure_on() {
autoFigure = true;
}
/**
* 关自动创建图形窗口
*/
public static void autofigure_off() {
autoFigure = false;
}
/**
* 打开图形窗口
*/
public static PlotFrame figrue() {
return figrue(plotFrameConter);
}
public static PlotFrame figrue(String title) {
initPlotFrameStack();
currenPlotFrame = null;
for (PlotFrame fm : plotFrameStack) {
if (title.equals(fm.getTitle())) {
currenPlotFrame = fm;
break;
}
}
if (currenPlotFrame == null)
addPlotFrame(new PlotFrame(title));
return currenPlotFrame;
}
public static PlotFrame figrue(int index) {
return figrue("Figure " + index);
}
/**
* 绘图
*/
public static PlotFrame plot(DrawableObject drawableObject) {
if (autoFigure)
figrue();
else
initCurrentPlotFrame();
currenPlotFrame.plot(drawableObject);
Plot.suit();
return currenPlotFrame;
}
public static PlotFrame plot(double[] y) {
return plot(new DrawableObject(y));
}
public static PlotFrame plot(double[] x, double[] y) {
return plot(new DrawableObject(x, y));
}
public static PlotFrame plot(double[][] pts) {
return plot(new DrawableObject(pts[0], pts[1]));
}
public static PlotFrame plot(double[] x, String pams) {
return plot(new DrawableObject(x, pams));
}
public static PlotFrame plot(double[] x, double[] y, String pams) {
return plot(new DrawableObject(x, y, pams));
}
public static PlotFrame plot(double[][] pts, String pams) {
return plot(new DrawableObject(pts[0], pts[1], pams));
}
/**
* 设置显示范围
*/
public static void axis(double sx, double ex, double sy, double ey) {
initCurrentPlotFrame();
currenPlotFrame.axis(sx, ex, sy, ey);
}
/**
* 最佳视野
*/
public static void suit() {
initCurrentPlotFrame();
currenPlotFrame.suit();
}
// internal
public static void addPlotFrame(PlotFrame frame) {
XLog.log("add plotframe %s", frame.getTitle());
initPlotFrameStack();
++plotFrameConter;
plotFrameStack.add(frame);
currenPlotFrame = frame;
}
public static boolean removePlotFrame(PlotFrame frame) {
XLog.log("remove plotframe %s", frame.getTitle());
plotFrameStack.remove(frame);
return plotFrameStack.size() != 0;
}
}