-
Notifications
You must be signed in to change notification settings - Fork 9
/
brewmorepalettes.ado
145 lines (103 loc) · 5.01 KB
/
brewmorepalettes.ado
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
// Drops the program if already defined
cap prog drop brewmorepalettes
// Defines the program
prog def brewmorepalettes
// Version to use for Stata's internal version control
version 14.1
// Defines calling syntax
syntax [ anything(name = pals id = "Must specify the palettes to add") ]
// Palette names for the color palettes below
loc nms grmg budrd12 budrd18 budor12 budor18 bugr14 brbu10 brbu12 bugy8 ///
buor8 buor10 buor12 buorr14 rdylbu11 bu10 bu7 cat12 stepseq25 kelly22 kelly7
// If no palettes are specified assume the user wants all the palettes
if `"`pals'"' == "" loc pals `"`nms'"'
// Test whether or not palette names exist in the names of valid additional
// palettes
if `: list pals in nms' == 0 {
// Print error message to screen
di as err `"The palette(s) `pals' contains invalid arguments."' _n ///
`"The names of the available palettes are:"' as res `"`nms'"'
// Return error code
err 198
} // End IF Block to test for valid palettes
// Defines location where brewscheme user files are stored
loc brewuser `c(sysdir_personal)'brewuser
// Maximum colors for color palettes below
loc maxc 16 18 18 18 18 14 12 12 8 12 12 12 14 11 10 10 12 25 20 7
// pcolor values for the color palettes below
loc pcolor 16 12 18 12 18 14 10 12 8 8 10 12 14 11 10 7 12 25 20 7
// Meta data properties for the color palettes below
loc meta "Diverging" "Diverging" "Diverging" "Diverging" "Diverging" ///
"Diverging" "Diverging" "Diverging" "Diverging" "Diverging" "Diverging" ///
"Diverging" "Diverging" "Diverging" "Sequential" "Sequential" ///
"Qualitative" "Sequential" "Qualitative" "Qualitative"
// Links to the file definitions for the color palettes to be added
loc files "http://geog.uoregon.edu/datagraphics/color/GrMg_16tn.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuDRd_12.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuDRd_18.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuDOr_12.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuDOr_18.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuGr_14.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BrBu_10.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BrBu_12.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuGy_8.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuOr_8.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuOr_10.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuOr_12.txt" ///
"http://geog.uoregon.edu/datagraphics/color/BuOrR_14.txt" ///
"http://geog.uoregon.edu/datagraphics/color/RdYlBu_11b.txt" ///
"http://geog.uoregon.edu/datagraphics/color/Bu_10.txt" ///
"http://geog.uoregon.edu/datagraphics/color/Bu_7.txt" ///
"http://geog.uoregon.edu/datagraphics/color/Cat_12.txt" ///
"http://geog.uoregon.edu/datagraphics/color/StepSeq_25.txt" ///
"kelly22.txt" ///
"kelly7.txt"
// Define colorblind friendly palettes
loc cbfriendly kelly22 kelly7
// Loop over files containing color palettes
forv i = 1/`: word count `pals'' {
// Store the current palette
loc thispalette "`: word `i' of `pals''"
// Store the macro position for the other look up macros
loc idx `: list posof "`thispalette'" in nms'
// Define colorblind friendly lookup value
if `"`thispalette'"' != "" loc cbfriend `: list thispalette in cbfriendly'
// Makes the value 0 if the thispalette macro is empty
else loc cbfriend 0
di as res `"`: word `idx' of `files''"'
// Load data from remote site
qui: import delimited using `: word `idx' of `files'', clear varn(2) ///
delim(" ", collapse)
// Create RGB string
qui: g rgb = strofreal(v12) + " " + strofreal(v13) + " " + strofreal(v14)
// Keep the RGB string
qui: keep rgb
// Create palette name
qui: g palette = "`: word `idx' of `nms''"
// Create meta data properties
qui: g meta = "`: word `idx' of `meta''"
// Maximum number of colors for the palette
qui: g byte maxcolors = `: word `idx' of `maxc''
// Pcolor value for the palette
qui: g byte pcolor = `: word `idx' of `pcolor''
// Color ID variable
qui: g byte colorid = _n
// Sequence ID variable
qui: g seqid = palette + strofreal(pcolor) + strofreal(colorid)
// Other metadata properties
foreach v in print photocopy lcd colorblind {
// Generate missing properties
if `"`v'"' != "colorblind" qui: g byte `v' = .n
// For the Kelly paper palettes set the colorblind friendly field
else if `cbfriend' == 1 & `"`v'"' == "colorblind" qui: g byte `v' = 1
} // End Loop over properties
// Set display order
qui: order palette colorblind print photocopy lcd colorid pcolor rgb ///
maxcolors meta
// Save to brewuser directory
qui: save `"`brewuser'/`: word `idx' of `nms''.dta"', replace
// Add to the extra's file
brewextra, files(`"`brewuser'/`: word `idx' of `nms''.dta"')
} // End Loop over files
// End of program
end