⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bygraph_g.class

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 CLASS
📖 第 1 页 / 共 3 页
字号:
	local glob_op `"subtitle(`"`title'"') `glob_op'"'  
	if ! `.style.indiv_legends.istrue' {
		local glob_op `"legend(nodraw) `glob_op'"'  
	}
	local glob_op `"`.style.special_options' `glob_op'"'  
	if "`do'" == "twoway" {
		local glob_op `"`.style.twoway_options' `glob_op'"'
	}


						// Prepare subgraph syntax

	if ("`missvar'" != "")  local missif "& `missvar'"

	if "`do'" == "twoway" {
							// add to global if
		if `"`glob_if'"' == `""' {		// the by restriction
			local glob_if if `_byindex' == `=_byindex()' `missif'
		}
		else {
			local 0 `"`glob_if'"'
			syntax [if/]
			local glob_if					///
			`"if (`if') & (`_byindex' == `=_byindex()' `missif')"'
		}

		qui count `glob_in' `glob_if'
		if (r(N) == 0)  exit			// if excludes group

							// fully cannonicalize
		local full `cmd_1' || `glob_if' `glob_in' , `glob_op'
	}
	else {						// all but twoway
		local 0 `"`cmd_1'"'
		syntax [anything(equalok)] [aw pw fw] [if/] [in] [ , * ]

		local byqual `_byindex' == `=_byindex()'

		if `"`if'"' != `""' {
			local ifqual `"if (`if') `missif'"'
			local ifand  `"& (`if')"'
		}
		else if `"`missvar'"' != `""' {
			local ifqual if `missvar'
		}

		qui count `in' if (`byqual') `ifand' `missif'
		if (r(N) == 0)  exit			// if excludes group

		if (`"`exp'"' != `""')  local wtopt `"[`weight'`exp']"'
		local full `"`anything' `wtopt' `ifqual' `in' , byif(`byqual') `glob_op' `options'"'

	}

	if ("`uniq_schm'" != "")  gr_setscheme		// graph has own scheme

	.graphs[`.graphs.arrnels'+1] = .`do'graph_g.new `full'

	if (`.graphs.arrnels' == 1)  ._check_aspect_shrink
end


program _check_aspect_shrink
	if 0`.style.shrink_plotregion.istrue' {
	    if 0`.graphs[1].style.aspect_ratio.val' != 0 {
		di as error "options aspect() and shrink may not be combined"
		exit 198
	    }
	}
end


program SetLegend

	if (`.style.indiv_legends.istrue')  exit

	if ! 0`.graphs[1].legend.isofclass legend_g' {
		exit
	}
							// parse postion

	syntax [ , POSition(string) RING(string) SPAN AT(integer 0)	///
		   NODRAW DRAW OFF ON * ]

	if (0`.graphs[1].legend.keys.arrnels' > 1)  local drawn yes
	else					    local drawn no
	if ("`nodraw'`off'" != "")  local drawn no
	if ("`draw'`on'"    != "")  local drawn yes

	tempname leg					// legend from graph[1]
	.`leg' = .bylegend_g.new `.graphs[1].legend.objkey'  `drawn'


							// position and ring
	if `"`position'"' != "" {
		.style.editstyle legend_position(`position') editcopy
	}
	if `"`ring'"' != "" {
		.style.editstyle legend_ring(`ring') editcopy
	}

	local pos `.style.legend_position.relative_position'

	local ring `.style.legend_ring.setting'


	if "`span'" != "" {				// handle spanning
		if "`pos'" != "on" {
			if "`pos'" == "above" | "`pos'" == "below" {
				local span spancols(all)
			}
			else {
				local span spanrows(all)
			}
		}
	}

							// insert
	if `at' {
		.at_legend.ref = .`leg'.ref
		.legend_hole = `at'
		local holes `.holes'
		local holes : list holes - at
		.holes = "`holes'"
	}
	else {
	   .insert (legend = .`leg'.ref) `pos' plotregion1 , ring(`ring') `span'
	}
						// over-ride box alignment
	.`leg'.style.editstyle editcopy					///
		     box_alignment(`.style.legend_position.compass2style')
	
end


// ---------------------------------------------------------------------------
//  Returns list of x/yaxes names.  If they are empty, repopulates the list.
//  Use these, rather that xlst and ylst.

program xaxes_list
	if "`.xlst'" == "" {
		.xlst = .graphs[1].list_axes x
	}
	class exit "`.xlst'"
end

program yaxes_list
	if "`.ylst'" == "" {
		.ylst = .graphs[1].list_axes y
	}
	class exit "`.ylst'"
end


// Same for plotregions

program plotregion_list
	if "`.prlst'" == "" {
		.prlst = .graphs[1].list_ofclass plotregion
	}
	class exit "`.prlst'"
end


// ---------------------------------------------------------------------------
program SetListStyle
	gettoken prefix  list : 0		// prefix of object name
	gettoken suffix  list : list		// prefix of object & setting


	forvalues i = 1/`.n' {
		foreach obj of local list {
			if ! 0`.graphs[`i'].isofclass bargraph_g' |	///
			     "`obj'" == "scaleaxis" {
				capture .graphs[`i']`prefix'.`obj'`suffix'
			}
		}
	}
end


//----------------------------------------------------------------------------
//  Number of graphs and "holes" (including legends and other views).

program define full_n
	class exit = `.n' + `:word count `.holes'' + (`.legend_hole' > 0)
end


// ---------------------------------------------------------------------------
//  Set the rows and cols based on .holes and number of graphs and
//  the optional positional arguments.

program set_rows_cols

	local n = 0`.full_n'
	if 0`.set_cols' {				// # of rows and cols
		.cols = `.set_cols'
		.rows    = 1 + int((`n' - 1) / `.cols')
	} 
	else if 0`.set_rows' {
		.rows    = `.set_rows'
		.cols = 1 + int((`n' - 1) / `.rows')
	}
	else {
		local r  = sqrt(`n')
		.cols = int(`r') + ((`r' - int(`r')) > .01)
		.rows    = 1 + int((`n' - 1) / `.cols')
	}
end

// ---------------------------------------------------------------------------
//  Place the by/subgraphs into the plotregion based on the current
//  style and bygraph settings.

program set_placement

	.plotregion1.clear_all_views

	.set_rows_cols 

	if 0`.style.indiv_margin.left' > 0 {
		local left
	}

	local holes `.holes'
	local subr = `.graphs[1].maxrow' +				///
		     (`.style.indiv_margin.left'  > 0) +		///
		     (`.style.indiv_margin.right' > 0)
	local subc = `.graphs[1].maxcol' +				///
		     (`.style.indiv_margin.top'    > 0) +		///
		     (`.style.indiv_margin.bottom' > 0)
	local r = `.rows'
	local c = 1
	local j = 0
	forvalues i=1/0`.full_n' {
		local r0 `r'
		local c0 `c'

		if ! 0`:list i in holes' {
		    if `i' == 0`.legend_hole' {
			if 0`.style.indiv_as_whole.istrue' {
			    local at at `r' `c'
			}
			else {
			    local at at `=(`r'-1)*`subr'+1'		///
			    	     `=(`c'-1)*`subc'+1' ,		///
				     spanrows(`=`subr'-1') spancols(`=`subc'-1')
			}
		    	local leg `.at_legend.objkey'
			.plotregion1.insert (atlegend = .`leg'.ref) `at'
		    }
		    else {
		    	if `++j' <= 0`.graphs.arrnels' {
			    if 0`.style.indiv_as_whole.istrue' {
				.plotregion1.insert			    ///
				    (graph`j' = .`.graphs[`j'].objkey'.ref) ///
				    at `r' `c'
			    }
			    else {
				.plotregion1.place_views		///
				    `.graphs[`j'].objkey'		///
				    `=(`r'-1)*`subr'' `=(`c'-1)*`subc''	///
				    .ref `.style.indiv_margin.objkey'
			    }
			}
		    }
		}

		if ! 0`.set_colfirst' {
		    local ++c
		    if `c' > `.cols' {
			local c 1
			local `r--'
		    }
		}
		else {
		    local --r
		    if `r' == 0 {
			local r `.rows'
			local `c++'
		    }
		}

	}
end


// ---------------------------------------------------------------------------
//  Place or replace the boundary axes if requested.
//  Assumes that any axes that are not supposed to be drawn have already been
//  set to not drawn.

program set_outer_axes
	args d

	if ! 0`.style.edgelabel.istrue' {
		.set_outer_axes_edges_only `d'
		exit						// Exit
	}

	if "`d'" == "" {
		.set_outer_axes x
		.set_outer_axes y
		exit
	}

	if 0`.graphs[1].isofclass bargraph_g' & ! 0`.graphs[1].is_scale `d'' {
		exit
	}

	if 0`.style.outer_`d'axes.isfalse' | 0`.style.indiv_as_whole.istrue' {
		exit						// Exit
	}

						// lists of plotregs and axes
	local plotregions `.plotregion1.list_ofclass plotregion'
	local axes        `.plotregion1.list_ofclass axis'

	if "`d'" == "x" & 0`.style.outer_xaxes.istrue' {
	    forvalues col = 1/0`.plotregion1.maxcol' {
		local minr = `.plotregion1.minrow_oflist_incol `col'	///
			     `plotregions''
		local maxr = `.plotregion1.maxrow_oflist_incol `col'	///
			     `plotregions''
		if 0`minr' + 0`maxr' == 0 {
			continue				// Continue
		}

		foreach ax of local axes {
		    if 0`.plotregion1.in_col `ax' `col'' {
			if 0`.plotregion1.minrowof `ax'' < `minr' |	///
			   0`.plotregion1.maxrowof `ax'' > `maxr' {
				.plotregion1.`ax'.draw_view.set_true
//				.plotregion1.`ax'.set_labels_onoff	///
//					`.style.outer_xlabels.stylename'
//				.plotregion1.`ax'.set_ticks_onoff	///
//					`.style.outer_xticks.stylename'
			}
		    }
		}
	    }
	}

	if "`d'" == "y" & 0`.style.outer_yaxes.istrue' {
	    forvalues row = 1/0`.plotregion1.maxrow' {
		local minc = `.plotregion1.mincol_oflist_inrow `row'	///
			     `plotregions''
		local maxc = `.plotregion1.maxcol_oflist_inrow `row'	///
			     `plotregions''
		if 0`minc' + 0`maxc' == 0 {
			continue				// Continue
		}

		foreach ax of local axes {
		    if 0`.plotregion1.in_row `ax' `row'' {
			if 0`.plotregion1.mincolof `ax'' < `minc' |	///
			   0`.plotregion1.maxcolof `ax'' > `maxc' {
				.plotregion1.`ax'.draw_view.set_true
//				.plotregion1.`ax'.set_labels_onoff	///
//					`.style.outer_ylabels.stylename'
//				.plotregion1.`ax'.set_ticks_onoff	///
//					`.style.outer_yticks.stylename'
			}
		    }
		}
	    }
	}

end

// ---------------------------------------------------------------------------
// Just like set_outer_axes, but defines edge as only the square outer edge of
// the views.  Does not turn on axes where there are gaps in the outer
// edge.

program set_outer_axes_edges_only
	args d

	if "`d'" == "" {
		.set_outer_axes x
		.set_outer_axes y
		exit
	}

	if 0`.style.outer_`d'axes.isfalse' | 0`.style.indiv_as_whole.istrue' {
		exit						// Exit
	}

						// lists of plotregs and axes
	local plotregions `.plotregion1.list_ofclass plotregion'
	local axes        `.plotregion1.list_ofclass axis'

	if "`d'" == "x" & 0`.style.outer_xaxes.istrue' &		///
	   (! 0`.graphs[1].isofclass bargraph_g' | 0`.graphs[1].is_scale `d'') {
		local minr = `.plotregion1.minrow_oflist `plotregions''
		local maxr = `.plotregion1.maxrow_oflist `plotregions''

		foreach ax of local axes {
			if 0`.plotregion1.minrowof `ax'' < `minr' |	///
			   0`.plotregion1.maxrowof `ax'' > `maxr' {
				.plotregion1.`ax'.draw_view.set_true
//				.plotregion1.`ax'.set_labels_onoff	///
//					`.style.outer_xlabels.stylename'
//				.plotregion1.`ax'.set_ticks_onoff	///
//					`.style.outer_xticks.stylename'
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -