Repository navigation
Expand file tree
/
Copy pathDrawableObject.java
More file actions
204 lines (171 loc) · 4.54 KB
/
Copy pathDrawableObject.java
File metadata and controls
204 lines (171 loc) · 4.54 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package com.sin.java.plot.model;
import java.awt.Color;
/**
* 可绘制对象
*
* @author RobinTang
*
*/
public class DrawableObject {
public double[] x = null;
public double[] y = null;
public DrawableType type;
public DrawableAttribute attribute;
public boolean show = true;
// 内部标记
private boolean dataUpdated; // 数据是否被更新过
// 全局静态属性
private double suitableHorizon = 0.9; // 视野(最佳视野时用到)
public DrawableObject(double[] x, double[] y) {
this(x, y, DrawableType.Line, new DrawableAttribute());
}
public DrawableObject(double[] x, double[] y, DrawableType type, DrawableAttribute attribute) {
this.initDrawableObject(x, y, type, attribute);
}
public DrawableObject(double[] x, double[] y, String pams) {
this.initDrawableObject(x, y, pams);
}
public DrawableObject(int x, int y, String pams) {
this.initDrawableObject(new double[] { x }, new double[] { y }, pams);
}
public DrawableObject(double[] y) {
this(y, "");
}
public DrawableObject(double[] y, String pams) {
int len = y.length;
double[] x = new double[len];
for (int i = 0; i < len; ++i) {
x[i] = (double) i;
}
this.initDrawableObject(x, y, pams);
}
public void initDrawableObject(double[] x, double[] y, String pams) {
this.setData(x, y);
this.setAttribute(pams);
}
public void setAttribute(String pams){
DrawableType type = null;
DrawableAttribute attb = new DrawableAttribute();
pams = pams.toLowerCase();
if (pams.indexOf("-") >= 0) {
type = DrawableType.Line;
} else if (pams.indexOf("*") >= 0) {
type = DrawableType.Mark;
} else if (pams.indexOf("o") >= 0) {
type = DrawableType.Point;
} else if (pams.indexOf("n") >= 0) {
type = DrawableType.Columnar;
} else if (pams.indexOf("$") >= 0) {
type = DrawableType.MarkLine;
} else if (pams.indexOf("z") >= 0) {
type = DrawableType.Step;
} else {
type = DrawableType.Line;
}
if (pams.indexOf("r") >= 0) {
attb.lineColor = Color.red;
attb.fillColor = attb.lineColor;
} else if (pams.indexOf("g") >= 0) {
attb.lineColor = Color.green;
attb.fillColor = attb.lineColor;
} else if (pams.indexOf("b") >= 0) {
attb.lineColor = Color.blue;
attb.fillColor = attb.lineColor;
}
this.type = type;
this.attribute = attb;
}
private void initDrawableObject(double[] x, double[] y, DrawableType type, DrawableAttribute attribute) {
this.type = type;
this.attribute = attribute;
this.setData(x, y);
}
/*
* 设置数据
*/
private void setData(double[] x, double[] y) {
int len = x.length;
this.x = new double[len];
this.y = new double[len];
System.arraycopy(x, 0, this.x, 0, len);
System.arraycopy(y, 0, this.y, 0, len);
this.dataUpdated = true;
}
// 对外方法
/*
* 复制对象
*/
public DrawableObject copy(){
return new DrawableObject(x, y, type, attribute.copy());
}
/*
* 获取数据长度
*/
public int length() {
return this.x != null ? this.x.length : 0;
}
private double maxX;
private double maxY;
private double minX;
private double minY;
/*
* 计算极值
*/
private void reLimitValue() {
maxX = minX = this.x[0];
maxY = minY = this.y[0];
int len = this.length();
for (int i = 0; i < len; ++i) {
if (this.x[i] < minX)
minX = this.x[i];
if (this.x[i] > maxX)
maxX = this.x[i];
if (this.y[i] < minY)
minY = this.y[i];
if (this.y[i] > maxY)
maxY = this.y[i];
}
this.dataUpdated = false;
}
// 获取极值
public double getMaxX() {
if (this.dataUpdated)
this.reLimitValue();
return maxX;
}
public double getMaxY() {
if (this.dataUpdated)
this.reLimitValue();
return maxY;
}
public double getMinX() {
if (this.dataUpdated)
this.reLimitValue();
return minX;
}
public double getMinY() {
if (this.dataUpdated)
this.reLimitValue();
return minY;
}
// 获取最佳视野位置
public double suitableSX(){
return getMinX()-getWidth()*(1-suitableHorizon)/2;
}
public double suitableEX(){
return getMaxX()+getWidth()*(1-suitableHorizon)/2;
}
public double suitableSY(){
return getMinY()-getHeight()*(1-suitableHorizon)/2;
}
public double suitableEY(){
return getMaxY()+getHeight()*(1-suitableHorizon)/2;
}
// 范围
public double getWidth() {
return this.getMaxX() - this.getMinX();
}
public double getHeight() {
return this.getMaxY() - this.getMinY();
}
}