-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContourLabel.java
More file actions
161 lines (136 loc) · 3.27 KB
/
ContourLabel.java
File metadata and controls
161 lines (136 loc) · 3.27 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
package pyplot4j.contour;
import static java.lang.String.format ;
import java.util.List;
import pyplot4j.style.Color;
public class ContourLabel {
// variable name
String name ;
// parameters
double[] levels ;
double fontsize = 10.0 ;
String color ;
boolean inline = true ;
double inlineSpacing = 5.0 ;
String fmt ; // label formatter
boolean manual = false ;
boolean rightsideUp = true ;
boolean useClabelText = false ;
public ContourLabel(String name) {
this.name = name ;
}
public ContourLabel name(String name) {
this.name = name ;
return this ;
}
// vararg
public ContourLabel levels(double... levels) {
this.levels = levels ;
return this ;
}
public ContourLabel levels(List<Double> levels) {
this.levels = new double[levels.size()] ;
for(int i=0; i<this.levels.length; i++)
this.levels[i] = levels.get(i) ;
return this ;
}
public ContourLabel fontsize(double fontsize) {
this.fontsize = fontsize ;
return this ;
}
public ContourLabel color(String color) {
this.color = (color!=null) ? color.trim() : null ;
return this ;
}
public ContourLabel color(Color color) {
this.color = (color!=null) ? color.toString().trim() : null ;
return this ;
}
public ContourLabel inline(boolean inline) {
this.inline = inline ;
return this ;
}
public ContourLabel inlineSpacing(double inlineSpacing) {
this.inlineSpacing = inlineSpacing ;
return this ;
}
public ContourLabel fmt(String fmt) {
this.fmt = (fmt!=null) ? fmt.trim() : null ;
return this ;
}
public ContourLabel manual(boolean manual) {
this.manual = manual ;
return this ;
}
public ContourLabel rightsideUp(boolean rightsideUp) {
this.rightsideUp = rightsideUp ;
return this ;
}
public ContourLabel useClabelText(boolean useClabelText) {
this.useClabelText = useClabelText ;
return this ;
}
String getPythonCode() {
StringBuilder sb = new StringBuilder() ;
sb.append(format("plt.clabel(%s ", name)) ;
if(color != null) {
sb.append(", ") ;
sb.append(format("colors='%s'", color)) ;
}
if(!inline) {
sb.append(", ") ;
sb.append(format("inline=%s", "False")) ;
}
else {
sb.append(", ") ;
sb.append(format("inline=%s", "True")) ;
}
if(inlineSpacing >= 0.0 ) {
sb.append(", ") ;
sb.append(format("inline_spacing=%f", inlineSpacing)) ;
}
if(fontsize >= 0.0 ) {
sb.append(", ") ;
sb.append(format("fontsize=%f", fontsize)) ;
}
if(fmt != null) {
sb.append(", ") ;
sb.append(format("fmt='%s'", fmt)) ;
}
if(manual) {
sb.append(", ") ;
sb.append(format("manual=%s", "True")) ;
}
else {
sb.append(", ") ;
sb.append(format("manual=%s", "False")) ;
}
if(rightsideUp) {
sb.append(", ") ;
sb.append(format("rightside_up=%s", "True")) ;
}
else {
sb.append(", ") ;
sb.append(format("rightside_up=%s", "False")) ;
}
if(useClabelText) {
sb.append(", ") ;
sb.append(format("use_clabeltext=%s", "True")) ;
}
else {
sb.append(", ") ;
sb.append(format("use_clabeltext=%s", "False")) ;
}
sb.append(")") ;
return sb.toString() ;
}
@Override
public String toString() {
return getPythonCode() ;
}
// test
public static void main(String[] args) {
ContourLabel clabel = new ContourLabel("cs1") ;
clabel.color("b").inline(false) ;
System.out.println(clabel);
}
}