📄 plotregion.class
字号:
/* plotregion
A view and region for holding data views. Controls the common scale
for a set of views
May contain a set of dynamically declared views that share the plot
region.
*/
*! version 1.1.4 19oct2004
version 8
class {
style = .plotregionstyle.new
xscale = .scale.new, size(6) dim(x)
yscale = .scale.new, size(6) dim(y)
xsize = 0
ysize = 0
array _xylines // x and y lines across the region
array graphs // string keys of graphs, may be empty
array axes // string array of associated axes,
// may be empty
draw_view = .yesno.new, style(yes)
fill_if_drawn = .yesno.new, style(no)
}, inherit(view)
/* -------------------------------------------------------------------------*/
program define new
.xstretch.set shared /* shared stretchability */
.ystretch.set shared /* shared stretchability */
.set `0'
end
/* -------------------------------------------------------------------------*/
program define set
syntax [ , GRAPH(string) * ]
if "`graph'" != "" {
.graphs.Arrpush `.`graph'.objkey'
}
.style.set , `options'
end
/* -------------------------------------------------------------------------*/
/* Insert a view into the plot region.
Usage:
insert <new_view>
<new_view> := name = rvalue (returning a view)
class viewclass [name]
Could also just use the internal class system's declare
.myregion.Declare <name = view_rvalue>
*/
program insert
.Declare `0'
end
/* -------------------------------------------------------------------------*/
/* Declare the specified xyline into the xyline array.
*/
program declare_xyline
._xylines[`=0`._xylines.arrnels'+1'] = `0'
end
// ---------------------------------------------------------------------------
// Look for a time format in the axes attached to this plotregion.
program get_time_format, rclass
.xscale.get_time_format
return add
class exit "`return(fmt)'"
end
/* -------------------------------------------------------------------------*/
/* Add an axis to the list of axes associated with the plotregion
*/
program addaxis
if 0`.axes.arrindexof "`.`0'.objkey'"' {
exit // already there
}
.axes.Arrpush `.`0'.objkey'
end
/* -------------------------------------------------------------------------*/
/*
Reset the plotregion's X and Y scaling using the plotregion's views
Usage: reset_scales [x|y] [, noclear]
*/
program reset_scales
syntax [name] [ , noCLear ]
if "`clear'" == "" {
if "`namelist'" == "x" | "`namelist'" == "" {
.xscale.reinit
}
if "`namelist'" == "y" | "`namelist'" == "" {
.yscale.reinit
}
}
forvalues i = 1/0`.dynamicmv.arrnels' {
if "`.dynamicmv[`i'].isa'" != "array" {
._set_scales dynamicmv[`i'] `namelist'
continue /* CONTINUE */
}
/* loop over any name that are arrays */
forvalues j = 1/0`.dynamicmv[`i'].arrnels' {
._set_scales dynamicmv[`i'][`j'] `namelist'
}
}
end
program _set_scales
args view xy
capture .`view'.ranges
if "`xy'" == "x" | "`xy'" == "" {
if r(xmin) < . {
.xscale.addmin `r(xmin)'
}
if r(xmax) < . {
.xscale.addmax `r(xmax)'
}
}
if "`xy'" == "y" | "`xy'" == "" {
if r(ymin) < . {
.yscale.addmin `r(ymin)'
}
if r(ymax) < . {
.yscale.addmax `r(ymax)'
}
}
end
program clear_scales
syntax [name]
if ("`namelist'" == "x" | "`namelist'" == "") .xscale.reinit
if ("`namelist'" == "y" | "`namelist'" == "") .yscale.reinit
end
// ---------------------------------------------------------------------------
// Use compass_draw to allow alignment of the sized plotregion in an area
// that is possibly larger than the size of the plotregion.
program draw
/*
.real_draw `0'
exit
*/
syntax [, * ]
.compass_draw , align(style.box_alignment) drawpgm(_sized_draw) ///
margins(style.margin) `options'
end
program _sized_draw
syntax [, XSize(real 0) YSize(real 0) * ]
.xsize_ren = `xsize'
.ysize_ren = `ysize'
.real_draw , xsize(`.xsize_ren') ysize(`.ysize_ren') `options'
end
// --------------------------------------------------------------------------
// gridonly implies that only the filled background, grid, and x/ylines are
// to be drawn, otherwise everything but these are drawn.
program define real_draw
syntax [, XSize(real -1) YSize(real -1) GRIDONLY ]
if `xsize' != -1 {
.xsize_ren = `xsize'
}
if `ysize' != -1 {
.ysize_ren = `ysize'
}
if "`gridonly'" != "" | 0`._Gr_Cglobal.gversion' < 2 {
if 0`.style.boxstyle.is_drawn' { /* outer box */
.style.boxstyle.draw 0 0 `.xsize_ren' `.ysize_ren'
}
.style.margin.setgdi, view(`.objkey') // allow margins
if 0`.style.inner_boxstyle.is_drawn' { /* inner box */
.style.inner_boxstyle.draw 0 0 `.xsize_ren' `.ysize_ren'
}
/* draw grids */
forvalues i = 1/0`.axes.arrnels' {
if 0`.`.axes[`i']'.isofclass axis' {
.`.axes[`i']'.draw , xsize(`.xsize_ren') ///
ysize(`.ysize_ren') gridonly ///
plotregion(`.objkey')
}
}
/* draw x and y lines */
forvalues i = 1/0`._xylines.arrnels' {
._xylines[`i'].draw
}
if (0`._Gr_Cglobal.gversion' > 1) exit // Exit
}
else .style.margin.setgdi, view(`.objkey') // allow margins
.xscale.setgdi `.xsize_ren' /* set the gdi transforms */
.yscale.setgdi `.ysize_ren'
/* loop over objects in the
* plotregion and draw */
forvalues i = 1/0`.dynamicmv.arrnels' {
if `.dynamicmv[`i'].isofclass view' | /*
*/ `.dynamicmv[`i'].isofclass subview' {
.dynamicmv[`i'].draw
continue
}
/* loop over any name that are arrays */
if "`.dynamicmv[`i'].isa'" == "array" {
forvalues j = 1/0`.dynamicmv[`i'].arrnels' {
if `.dynamicmv[`i'][`j'].isofclass view' | ///
`.dynamicmv[`i'][`j'].isofclass subview' {
.dynamicmv[`i'][`j'].draw
}
}
}
}
end
/* -------------------------------------------------------------------------*/
program define reset_gdi
.xscale.setgdi `.xsize_ren' /* set the gdi transforms */
.yscale.setgdi `.ysize_ren'
end
/* -------------------------------------------------------------------------*/
/*
Returns a composite label for the specified dimension.
If more than one view uses the dimension and the views have different
titles, the titles are separated by slashes -- /.
If option [, clean] is specified and if more than one view uses the
dimension and the views have different titles, then nothing is
returned.
*/
program dimtitle
gettoken dim 0 : 0
syntax [, ONE CLEAN ]
forvalues i = 1/0`.dynamicmv.arrnels' {
if "`.dynamicmv[`i'].isa'" != "array" {
capture local t0 `.dynamicmv[`i'].dimtitle `dim''
local pos :list posof `"`t0'"' in tlist
if `pos' == 0 {
local slash = cond(`"`title'"'=="", "", "/")
if "`one'" != "" & "`slash'" != "" {
local title
continue , break
}
if "`clean'" != "" {
if `"`title'"' != `""' & `"`slash'"' != `""' {
class exit ""
}
}
local title `title'`slash'`t0'
local tlist `"`tlist' `"`t0'"'"'
}
continue // Continue
}
/* loop over any name that are arrays */
forvalues j = 1/0`.dynamicmv[`i'].arrnels' {
capture local t0 `.dynamicmv[`i'][`j'].dimtitle `dim''
local pos :list posof `"`t0'"' in tlist
if `pos' == 0 {
local slash = cond(`"`title'"'=="", "", "/")
if "`one'" != "" & "`slash'" != "" {
local title
local quit 1
continue , break
}
if "`clean'" != "" {
if `"`title'"' != `""' & `"`slash'"' != `""' {
class exit ""
}
}
local title `title'`slash'`t0'
local tlist `"`tlist' `"`t0'"'"'
}
}
if 0`quit' {
continue , break
}
}
class exit `"`title'"'
end
program dimtitle_safe
local title `"`.dimtitle `0''"'
local title : subinstr local title `"""' `""' , count(local ct)
if ! `ct' & substr(`"`title'"',1,1) != `"""'{
local unused : subinstr local title "(" "(" , count(local ct)
if ! `ct' {
local unused : subinstr local title ")" ")" , count(local ct)
}
}
if `ct' {
class exit `"`"`title'"'"'
}
else {
class exit `"`title'"'
}
end
// -------------------------------------------------------------------------
//
// Returns a simple label for the specified dimension.
//
// If more than one view uses the dimension and the views have different
// titles, then nothing is returned.
program dimtitle_clean
local title `"`.dimtitle `0', clean'"'
local title : subinstr local title `"""' `""' , count(local ct)
if ! `ct' & substr(`"`title'"',1,1) != `"""'{
local unused : subinstr local title "(" "(" , count(local ct)
if ! `ct' {
local unused : subinstr local title ")" ")" , count(local ct)
}
}
if `ct' {
class exit `"`"`title'"'"'
}
else {
class exit `"`title'"'
}
end
/* -------------------------------------------------------------------------*/
/*
Returns the first encountered variable format in the specified
dimension/ordinate
*/
program dimformat
gettoken dim 0 : 0
syntax
local found 0
forvalues i = 1/0`.dynamicmv.arrnels' {
if `"`fmt'"' != `""' {
continue // Continue
}
if "`.dynamicmv[`i'].isa'" != "array" {
capture local fmt `.dynamicmv[`i'].dimformat `dim''
continue // Continue
}
/* loop over any name that are arrays */
forvalues j = 1/0`.dynamicmv[`i'].arrnels' {
capture local fmt `.dynamicmv[`i'][`j'].dimformat `dim''
if `"`fmt'"' != `""' {
continue // Continue
}
}
}
class exit `"`fmt'"'
end
/* -------------------------------------------------------------------------*/
/* Return a list of .Declared objects that are of the specified class type
or inherit from the specified classtype.
Usage: .list_ofclass
*/
program list_ofclass
args classnm
forvalues i = 1/0`.dynamicmv.arrnels' {
if "`.dynamicmv[`i'].isa'" == "array" {
forvalues j = 1/0`.dynamicmv[`i'].arrnels' {
if 0`.dynamicmv[`i'][`j'].isofclass `classnm'' {
class nameoflocal dynamicmv[`i']
local list `list' `r(name)'[`j']
}
}
}
else {
if 0`.dynamicmv[`i'].isofclass `classnm'' {
class nameoflocal dynamicmv[`i']
local list `list' `r(name)'
}
}
}
class exit "`list'"
end
exit
/*
tempname xtrans ytrans // must hold transforms
.`xtrans' = .transform.new , dimension(x)
.`ytrans' = .transform.new , dimension(y)
.`xtrans'.get_from_gdi
.`ytrans'.get_from_gdi
*/
/*
.`xtrans'.reset // reset the transform
.`ytrans'.reset // reset the transform
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -