-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththeme.go
100 lines (87 loc) · 1.88 KB
/
theme.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
package plot
import "image/color"
// Style represents a drawing style for an element.
type Style struct {
Stroke color.Color
Fill color.Color
Size Length
// line only
Dash []Length
DashOffset []Length
// text only
Font string
Rotation float64
Origin Point // {-1..1, -1..1}
// SVG
Class string
}
// mustExists checks whether style is valid and panics if it is not.
func (style *Style) mustExist() {
if style == nil {
panic("style missing")
}
}
// IsZero checks whether style has been assigned.
func (style *Style) IsZero() bool {
if style == nil {
return true
}
return style.Stroke == nil && style.Fill == nil && style.Size == 0 && style.Font == ""
}
// Theme is a collection of different default styles.
type Theme struct {
Line Style
Font Style
FontSmall Style
Fill Style
Bar Style
Grid GridTheme
}
// GridTheme is a default style for grid.
type GridTheme struct {
Fill color.Color
Major color.Color
Minor color.Color
}
// IsZero checks whether theme has been defined.
func (theme *GridTheme) IsZero() bool {
if theme == nil {
return true
}
return theme.Fill == nil && theme.Major == nil && theme.Minor == nil
}
// NewTheme creates a theme with default values.
func NewTheme() Theme {
return Theme{
Line: Style{
Stroke: color.NRGBA{0, 0, 0, 255},
Fill: nil,
Size: 1.0,
},
Font: Style{
Stroke: nil,
Fill: color.NRGBA{0, 0, 0, 255},
Size: 12,
},
FontSmall: Style{
Stroke: nil,
Fill: color.NRGBA{0, 0, 0, 255},
Size: 10,
},
Fill: Style{
Stroke: nil,
Fill: color.NRGBA{255, 255, 255, 255},
Size: 1.0,
},
Bar: Style{
Stroke: color.NRGBA{0, 0, 0, 255},
Fill: color.NRGBA{0, 0, 0, 100},
Size: 1.0,
},
Grid: GridTheme{
Fill: color.NRGBA{230, 230, 230, 255},
Major: color.NRGBA{255, 255, 255, 255},
Minor: color.NRGBA{255, 255, 255, 100},
},
}
}