📄 legend_g.class
字号:
local s .`.objkey'
._try_align east right middle center
local r = 2 * `rows' - 1
local c 0
local cc 0
local i 0
forvalues j = 1/0`n' {
if 0`:list j in holes' {
local c = `c' + 3
}
else {
`p'.insert (label = .sized_textbox.new , ///
mtext(`.labels[`++i']') ///
styleref(`.style.labelstyle.objkey')) at `r' `++c'
`p'.insert (keygap = `s'.keygap.ref) at `r' `++c'
local ++c
local k 0`.map[`i']'
if "`.keys[`k'].isa'" != "" {
.keys[`k'].set , xsize(`.style.key_xsize.gmval') ///
ysize(`.style.key_ysize.gmval') `force'
`p'.insert (key = `s'.keys[`k'].ref) at `r' `++c'
}
}
if `c' < 4 * `cols' - 1 {
`p'.insert (colsp = `s'.colsp.ref) at `r' `++c'
}
if `--r' < 2 {
local c = `c' + 1
local cc = `c'
local r = 2 * `rows' - 1
}
else {
`p'.insert (rowsp = `s'.rowsp.ref) at `r--' `c'
local c = `cc'
}
}
end
// Place legend components in Key-Text order, Text stacked below keys and Row
// first.
program PlaceKeyTextStackedRow
args n rows cols force
.keygap.set , ysize(`.style.key_gap.gmval')
local holes `.holes'
local p .plotregion1
local s .`.objkey'
._try_align west left middle west
local r = 4 * `rows'
local rr `r'
local c 0
local i 0
forvalues j = 1/0`n' {
if 0`:list j in holes' {
local ++c
local r = `r' - 3
}
else {
local ++c
local --r
local k 0`.map[`++i']'
if "`.keys[`k'].isa'" != "" {
.keys[`k'].set , xsize(`.style.key_xsize.gmval') ///
ysize(`.style.key_ysize.gmval') ///
pos(`.style.key_position.snm') `force'
`p'.insert (key = `s'.keys[`k'].ref) at `r' `c'
}
`p'.insert (keygap = `s'.keygap.ref) at `--r' `c'
`p'.insert (label = .sized_textbox.new , ///
mtext(`.labels[`i']') ///
styleref(`.style.labelstyle.objkey')) at `--r' `c'
}
if `c' >= 2*`cols'-1 {
if `j' < `n' {
`p'.insert (rowsp = `s'.rowsp.ref) at `--r' `c'
}
local c 0
local rr `r'
}
else {
`p'.insert (colsp = `s'.colsp.ref) at `r' `++c'
local r `rr'
}
}
end
// Place legend components in Text-Key order, Text stacked below keys and Row
// first.
program PlaceTextKeyStackedRow
args n rows cols force
.keygap.set , ysize(`.style.key_gap.gmval')
local holes `.holes'
local p .plotregion1
local s .`.objkey'
._try_align west left middle west
local r = 4 * `rows'
local rr `r'
local c 0
local i 0
forvalues j = 1/0`n' {
if 0`:list j in holes' {
local ++c
local r = `r' - 3
}
else {
`p'.insert (label = .sized_textbox.new , ///
mtext(`.labels[`++i']') ///
styleref(`.style.labelstyle.objkey')) at `--r' `++c'
`p'.insert (keygap = `s'.keygap.ref) at `--r' `c'
local --r
local k 0`.map[`i']'
if "`.keys[`k'].isa'" != "" {
.keys[`k'].set , xsize(`.style.key_xsize.gmval') ///
ysize(`.style.key_ysize.gmval') `force'
`p'.insert (key = `s'.keys[`k'].ref) at `r' `c'
}
}
if `c' >= 2*`cols'-1 {
if `j' < `n' {
`p'.insert (rowsp = `s'.rowsp.ref) at `--r' `c'
}
local c 0
local rr `r'
}
else {
`p'.insert (colsp = `s'.colsp.ref) at `r' `++c'
local r `rr'
}
}
end
// Place legend components in Key-Text order, Text stacked below keys and
// Column first.
program PlaceKeyTextStackedCol
args n rows cols force
.keygap.set , ysize(`.style.key_gap.gmval')
local holes `.holes'
local p .plotregion1
local s .`.objkey'
._try_align west left middle west
local r = 4 * `rows'
local rr `r'
local c 1
local cc 1
local i 0
forvalues j = 1/0`n' {
if 0`:list j in holes' {
local ++c
local r = `r' - 3
}
else {
local --r
local k 0`.map[`++i']'
if "`.keys[`k'].isa'" != "" {
.keys[`k'].set , xsize(`.style.key_xsize.gmval') ///
ysize(`.style.key_ysize.gmval') `force'
`p'.insert (key = `s'.keys[`k'].ref) at `r' `c'
}
`p'.insert (keygap = `s'.keygap.ref) at `--r' `c'
`p'.insert (label = .sized_textbox.new , ///
mtext(`.labels[`i']') ///
styleref(`.style.labelstyle.objkey')) at `--r' `c'
}
if `r' > 4 {
if `j' < `n' {
`p'.insert (rowsp = `s'.rowsp.ref) at `--r' `c'
}
local c `cc'
}
else {
`p'.insert (colsp = `s'.colsp.ref) at `r' `++c'
local ++c
local cc `c'
local r = 4 * `rows'
}
}
end
// Place legend components in Text-Key order, Text stacked below keys and
// Column first.
program PlaceTextKeyStackedCol
args n rows cols force
.keygap.set , ysize(`.style.key_gap.gmval')
local holes `.holes'
local p .plotregion1
local s .`.objkey'
._try_align west left middle west
local r = 4 * `rows'
local rr `r'
local c 1
local cc 1
local i 0
forvalues j = 1/0`n' {
if 0`:list j in holes' {
local ++c
local r = `r' - 3
}
else {
`p'.insert (label = .sized_textbox.new , ///
mtext(`.labels[`++i']') ///
styleref(`.style.labelstyle.objkey')) at `--r' `c'
`p'.insert (keygap = `s'.keygap.ref) at `--r' `c'
local --r
local k 0`.map[`i']'
if "`.keys[`k'].isa'" != "" {
.keys[`k'].set , xsize(`.style.key_xsize.gmval') ///
ysize(`.style.key_ysize.gmval') `force'
`p'.insert (key = `s'.keys[`k'].ref) at `r' `c'
}
}
if `r' > 4 {
if `j' < `n' {
`p'.insert (rowsp = `s'.rowsp.ref) at `--r' `c'
}
local c `cc'
}
else {
`p'.insert (colsp = `s'.colsp.ref) at `r' `++c'
local ++c
local cc `c'
local r = 4 * `rows'
}
}
end
// ---------------------------------------------------------------------------
// Parse and specify edits to the existing key labels and optional
// additional unkeyed labels to appear.
program parse_order
if `"`0'"' == `""' {
exit
}
tempname nmap nlabs // in case we fail.
.`nmap' = {}
.`nlabs' = {}
gettoken dex 0 : 0 , quotes
local i 0
while `"`dex'"' != `""' {
if `"`dex'"' == `"-"' {
.`nmap'[`++i'] = 0
}
else {
capture confirm integer number `dex'
if _rc {
di as error "`dex' not an integer, order()" ///
option ignored"
exit
}
.`nmap'[`++i'] = `dex'
capture .`nlabs'[`i'] = .labels[`dex']
}
local pass1 1
while 1 {
gettoken text 0 : 0 , quotes // quoted
gettoken tuq : text // unquoted
if `"`text'"' == `"`tuq'"' {
local dex `tuq' // assume next dex
continue , break
}
if `pass1' {
.`nlabs'[`i'] = `"`text'"'
local pass1 0
}
else {
.`nlabs'[`i'] = `"`.`nlabs'[`i']' `text'"'
}
}
}
.map.ref = .`nmap'.ref
.labels.ref = .`nlabs'.ref
.repositionkeys
end
program _try_align
args box just align key
if "`.style.labelstyle.box_alignment.stylename'" == "default" {
local edit `"labelstyle(box_alignment(`box'))"'
}
if "`.style.labelstyle.horizontal.stylename'" == "default" {
local edit `"`edit' labelstyle(horizontal(`just'))"'
}
if "`.style.labelstyle.vertical.stylename'" == "default" {
local edit `"`edit' labelstyle(vertical(`align'))"'
}
if "`.style.key_position.stylename'" == "default" {
local edit `"`edit' key_position(`key')"'
}
if `"`edit'"' != `""' {
.style.editstyle `edit' editcopy
}
end
// ---------------------------------------------------------------------------
// Clear the current keys and labels and their positioning in the
// "plotregion" grid. Does NOT clear the graphs.
program clear
foreach view in key label rowsp colsp keygap { // clear
if "`.plotregion1.`view'.isa'" != "" {
.plotregion1.delete `view'
}
}
.keys.ref = {}
.labels.ref = {}
.map.ref = {}
end
// ---------------------------------------------------------------------------
// Parse title options and push its declaration and any style edits onto the
// specified log.
//
// This call MUST occur after the declaration of plotregion1 has been pushed.
// Returns the unparsed options.
//
// Usage: local options = `".parse_and_log_title <logname> `options'"'
program parse_and_log_titles , rclass
if "`.title.isa'" != "" {
.parse_and_log_titles_edits `0'
exit
}
gettoken log 0 : 0
gettoken obj 0 : 0
// preferred span order
_fr_title_parse_and_log `log' "`obj'" note NOTE leg_note `0'
_fr_title_parse_and_log `log' "`obj'" caption CAPtion leg_caption `r(rest)'
_fr_title_parse_and_log `log' "`obj'" subtitle SUBtitle leg_subtitle `r(rest)'
_fr_title_parse_and_log `log' "`obj'" title Title leg_title `r(rest)'
return local rest `r(rest)'
end
program parse_and_log_titles_edits , rclass
gettoken log 0 : 0
gettoken obj 0 : 0
// preferred span order
_fr_tedits_parse_and_log `log' "`obj'" note NOTE `0'
_fr_tedits_parse_and_log `log' "`obj'" caption CAPtion `r(rest)'
_fr_tedits_parse_and_log `log' "`obj'" subtitle SUBtitle `r(rest)'
_fr_tedits_parse_and_log `log' "`obj'" title Title `r(rest)'
return local rest `r(rest)'
end
// ---------------------------------------------------------------------------
// Returns our size
program xsize
class exit = 0`.Super.xsize' + ///
0`.style.boxmargin.gmleft' + 0`.style.boxmargin.gmright'
end
program ysize
class exit = 0`.Super.ysize' + ///
0`.style.boxmargin.gmbottom' + 0`.style.boxmargin.gmtop'
end
// ---------------------------------------------------------------------------
// Use compass_draw to allow alignment of the sized legend in an area that
// is possibly larger than the size of the legend.
program draw
syntax [, * ]
.compass_draw , align(style.box_alignment) drawpgm(_super_draw) ///
margins(style.margin) `options'
end
program _super_draw
syntax [, XSize(real 0) YSize(real 0) * ]
.xsize_ren = `xsize'
.ysize_ren = `ysize'
.style.boxmargin.setgdi, view(`.objkey') // boxmargin
.Super.draw , xsize(`.xsize_ren') ysize(`.ysize_ren') `options'
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -