-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.go
386 lines (330 loc) · 7.54 KB
/
config.go
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package gridder
import (
"image/color"
)
const (
defaultGridWidth = 500 * 2
defaultGridHeight = 500
defaultGridMarginWidth = 0
defaultGridLineStrokeWidth = 2.0
defaultGridBorderStrokeWidth = 4.0
defaultLineLength = 10.0
defaultLineStrokeWidth = 1.0
defaultCircleRadius = 10.0
defaultCircleStrokeWidth = 1.0
defaultRectangleWidth = 20.0
defaultRectangleHeight = 20.0
defaultRectangleStrokeWidth = 1.0
)
var (
defaultGridBackgroundColor = color.White
defaultGridBorderColor = color.Black
defaultGridLineColor = color.NRGBA{R: 0, G: 0, B: 0, A: 255 / 4}
defaultStringColor = color.Gray{}
defaultLineColor = color.Gray{}
defaultCircleColor = color.Gray{}
defaultRectangleColor = color.NRGBA{R: 0, G: 0, B: 0, A: 255 / 2}
)
// ImageConfig Grid Configuration
type ImageConfig struct {
Width int
Height int
Name string
}
// GetWidth gets image width
func (g *ImageConfig) GetWidth() int {
if g.Width <= 0 {
return defaultGridWidth
}
return g.Width
}
// GetHeight gets image height
func (g *ImageConfig) GetHeight() int {
if g.Height <= 0 {
return defaultGridHeight
}
return g.Height
}
// GetName gets image name
func (g *ImageConfig) GetName() string {
return g.Name
}
// GridConfig Grid Configuration
type GridConfig struct {
Rows int
Columns int
MarginWidth int
LineDashes float64
LineStrokeWidth float64
BorderDashes float64
BorderStrokeWidth float64
LineColor color.Color
BorderColor color.Color
BackgroundColor color.Color
}
// GetWidth gets grid width
func (g *GridConfig) GetWidth(imageWidth int) int {
return imageWidth - g.GetMarginWidth()*2
}
// GetHeight gets grid height
func (g *GridConfig) GetHeight(imageHeight int) int {
return imageHeight - g.GetMarginWidth()*2
}
// GetMarginWidth gets margin width
func (g *GridConfig) GetMarginWidth() int {
if g.MarginWidth < 0 {
return defaultGridMarginWidth
}
return g.MarginWidth
}
// GetLineDashes gets line dashes
func (g *GridConfig) GetLineDashes() float64 {
return g.LineDashes
}
// GetLineStrokeWidth gets line stroke width
func (g *GridConfig) GetLineStrokeWidth() float64 {
if g.LineStrokeWidth < 0 {
return defaultGridLineStrokeWidth
}
return g.LineStrokeWidth
}
// GetBorderDashes gets border dashes
func (g *GridConfig) GetBorderDashes() float64 {
return g.BorderDashes
}
// GetBorderStrokeWidth gets border stroke width
func (g *GridConfig) GetBorderStrokeWidth() float64 {
if g.BorderStrokeWidth < 0 {
return defaultGridBorderStrokeWidth
}
return g.BorderStrokeWidth
}
// GetLineColor gets line color
func (g *GridConfig) GetLineColor() color.Color {
if g.LineColor == nil {
return defaultGridLineColor
}
return g.LineColor
}
// GetBorderColor gets border color
func (g *GridConfig) GetBorderColor() color.Color {
if g.BorderColor == nil {
return defaultGridBorderColor
}
return g.BorderColor
}
// GetBackgroundColor gets background color
func (g *GridConfig) GetBackgroundColor() color.Color {
if g.BackgroundColor == nil {
return defaultGridBackgroundColor
}
return g.BackgroundColor
}
// GetRows gets rows
func (g *GridConfig) GetRows() int {
if g.Rows < 0 {
return 0
}
return g.Rows
}
// GetColumns gets columns
func (g *GridConfig) GetColumns() int {
if g.Columns < 0 {
return 0
}
return g.Columns
}
// PathConfig Path Configuration
type PathConfig struct {
StrokeWidth float64
Dashes float64
Color color.Color
}
// GetStrokeWidth gets stroke width
func (g *PathConfig) GetStrokeWidth() float64 {
if g.StrokeWidth <= 0 {
return defaultLineStrokeWidth
}
return g.StrokeWidth
}
// GetColor gets color
func (g *PathConfig) GetColor() color.Color {
if g.Color == nil {
return defaultLineColor
}
return g.Color
}
// GetDashes gets dashes
func (g *PathConfig) GetDashes() float64 {
return g.Dashes
}
// LineConfig Line Configuration
type LineConfig struct {
Length float64
Rotate float64
StrokeWidth float64
Dashes float64
Color color.Color
}
// GetLength gets length
func (g *LineConfig) GetLength() float64 {
if g.Length <= 0 {
return defaultLineLength
}
return g.Length
}
// GetRotate gets rotation
func (g *LineConfig) GetRotate() float64 {
return g.Rotate
}
// GetStrokeWidth gets stroke width
func (g *LineConfig) GetStrokeWidth() float64 {
if g.StrokeWidth <= 0 {
return defaultLineStrokeWidth
}
return g.StrokeWidth
}
// GetColor gets color
func (g *LineConfig) GetColor() color.Color {
if g.Color == nil {
return defaultLineColor
}
return g.Color
}
// GetDashes gets dashes
func (g *LineConfig) GetDashes() float64 {
return g.Dashes
}
// CircleConfig Grid Circle Configuration
type CircleConfig struct {
Radius float64
Color color.Color
Dashes float64
Stroke bool
StrokeWidth float64
}
// GetRadius gets radius
func (g *CircleConfig) GetRadius() float64 {
if g.Radius <= 0 {
return defaultCircleRadius
}
return g.Radius
}
// GetDashes gets dashes
func (g *CircleConfig) GetDashes() float64 {
return g.Dashes
}
// GetColor gets color
func (g *CircleConfig) GetColor() color.Color {
if g.Color == nil {
return defaultCircleColor
}
return g.Color
}
// IsStroke determines if Stroke or Fill
func (g *CircleConfig) IsStroke() bool {
return g.Stroke
}
// GetStrokeWidth gets stroke width
func (g *CircleConfig) GetStrokeWidth() float64 {
if g.StrokeWidth <= 0 {
return defaultCircleStrokeWidth
}
return g.StrokeWidth
}
// RectangleConfig Rectangle Configuration
type RectangleConfig struct {
Width float64
Height float64
Rotate float64
Dashes float64
Color color.Color
Stroke bool
StrokeWidth float64
}
// GetWidth gets width
func (g *RectangleConfig) GetWidth() float64 {
if g.Width <= 0 {
return defaultRectangleWidth
}
return g.Width
}
// GetHeight gets height
func (g *RectangleConfig) GetHeight() float64 {
if g.Height <= 0 {
return defaultRectangleHeight
}
return g.Height
}
// GetRotate gets rotation
func (g *RectangleConfig) GetRotate() float64 {
return g.Rotate
}
// GetDashes gets dashes
func (g *RectangleConfig) GetDashes() float64 {
return g.Dashes
}
// GetColor gets color
func (g *RectangleConfig) GetColor() color.Color {
if g.Color == nil {
return defaultRectangleColor
}
return g.Color
}
// IsStroke determines if Stroke or Fill
func (g *RectangleConfig) IsStroke() bool {
return g.Stroke
}
// GetStrokeWidth gets stroke width
func (g *RectangleConfig) GetStrokeWidth() float64 {
if g.StrokeWidth <= 0 {
return defaultRectangleStrokeWidth
}
return g.StrokeWidth
}
// StringConfig Grid String Configuration
type StringConfig struct {
Rotate float64
Color color.Color
}
// GetRotate gets rotatio
func (g *StringConfig) GetRotate() float64 {
return g.Rotate
}
// GetColor gets color
func (g *StringConfig) GetColor() color.Color {
if g.Color == nil {
return defaultStringColor
}
return g.Color
}
func getFirstRectangleConfig(configs ...RectangleConfig) RectangleConfig {
if len(configs) == 0 {
return RectangleConfig{}
}
return configs[0]
}
func getFirstCircleConfig(configs ...CircleConfig) CircleConfig {
if len(configs) == 0 {
return CircleConfig{}
}
return configs[0]
}
func getFirstPathConfig(configs ...PathConfig) PathConfig {
if len(configs) == 0 {
return PathConfig{}
}
return configs[0]
}
func getFirstLineConfig(configs ...LineConfig) LineConfig {
if len(configs) == 0 {
return LineConfig{}
}
return configs[0]
}
func getFirstStringConfig(configs ...StringConfig) StringConfig {
if len(configs) == 0 {
return StringConfig{}
}
return configs[0]
}