-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlotStyle.java
More file actions
184 lines (169 loc) · 5.24 KB
/
PlotStyle.java
File metadata and controls
184 lines (169 loc) · 5.24 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
/* Copyright (c) 2007-2014 by panayotis.com
*
* JavaPlot is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 2.
*
* JavaPlot is free in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CrossMobile; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Created on 26 Οκτώβριος 2007, 2:58 μμ
*/
package com.panayotis.gnuplot.style;
import com.panayotis.gnuplot.PropertiesHolder;
/**
* This object represents the styles which can be used in gnuplot to personalize
* each prot
*
* @author teras
*/
public class PlotStyle extends PropertiesHolder {
private Style type;
private FillStyle fill;
private int labelOffsetX;
private int labelOffsetY;
private int labelPointType = -1;
/**
* Creates a new instance of PlotStyle with default parameters
*/
public PlotStyle() {
this(null);
}
/**
* Creates a new instance of PlotStyle with a specified style
*
* @param style The style to use
*/
@SuppressWarnings("OverridableMethodCallInConstructor")
public PlotStyle(Style style) {
super(" ", "");
fill = null;
setStyle(style);
}
/**
* Set the current style to the given one
*
* @param style the style to use
*/
public void setStyle(Style style) {
this.type = style;
}
/**
* Gather the properties of this style. This method is used internally by
* GNUPlot
*
* @param buf The Srting buffer to store this object's properties.
*/
@Override
public void appendProperties(StringBuilder buf) {
if (type != null) {
buf.append(" with ").append(type.name().toLowerCase());
if (type.equals(Style.LABELS)){
if (!(labelOffsetX == 0 && labelOffsetY == 0)) {
buf.append(" offset ").append(labelOffsetX).append(',').append(labelOffsetY);
}
if (labelPointType != -1) {
buf.append(" point pt ").append(labelPointType);
}
}
super.appendProperties(buf);
if (fill != null && type.filled)
fill.appendProperties(buf);
}
}
/**
* Set the line width of this graph
*
* @param width The line width. If this number is less than zero, then the
* default parameter will be used
*/
public void setLineWidth(int width) {
if (width < 0)
unset("linewidth");
else
set("linewidth", String.valueOf(width));
}
/**
* Set the point size of this graph
*
* @param width The point size. If this number is less than zero, then the
* default parameter will be used
*/
public void setPointSize(int width) {
if (width < 0)
unset("pointsize");
else
set("pointsize", String.valueOf(width));
}
/**
* Set the line type of this graph. This option is terminal dependent.
*
* @param type The line type. If this number is less than zero, then the
* default parameter will be used
*/
public void setLineType(int type) {
if (type < -1)
unset("linetype");
else
set("linetype", String.valueOf(type));
}
/**
* Set the line type of this graph to be a specific color. This option is
* terminal dependent.
*
* @param col The color to use. If this parameter is null, then the default
* parameter will be used.
*/
public void setLineType(PlotColor col) {
if (col == null)
unset("linetype");
else
set("linetype", col.getColor());
}
/**
* Set the point type of this graph. This option is terminal dependent.
*
* @param type The point type. If this number is less than zero, then the
* default parameter will be used
*/
public void setPointType(int type) {
if (type < -1)
unset("pointtype");
else
set("pointtype", String.valueOf(type));
}
/**
* Set the fill style of this graph. If the desired style does not support
* fill then this parameter will be ignored.
*
* @param fillstyle The fill style to use. If this parameter is null, then
* the default parameter will be used.
*/
public void setFill(FillStyle fillstyle) {
this.fill = fillstyle;
}
/**
* Set the offset of label relative to the point. Used when style is LABELS.
*
* @param x
* @param y
*/
public void setLabelOffset(int x, int y){
this.labelOffsetX = x;
this.labelOffsetY = y;
}
/**
* Set the point type of label. Used instead of setPointType() when style is LABELS.
*
* @param pointType
*/
public void setLabelPointType(int pointType){
this.labelPointType = pointType;
}
}