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

📄 graph_g.class

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 CLASS
📖 第 1 页 / 共 2 页
字号:

program _use_aspect_ratio
	class exit = 0`.style.aspect_ratio.val' != 0 &			///
		     "`.spacerl.isa'" != "" & "`.spacerr.isa'" != "" &	///
		     "`.spacert.isa'" != "" & "`.spacerb.isa'" != ""
end
	

// ---------------------------------------------------------------------------
// Redraw the graph without repositioning the objects in the grid.

program drawgraph_noposition
	._Gr_Cglobal.set noposition 1
	.drawgraph `0'
	._Gr_Cglobal.set noposition 0
end


/* -------------------------------------------------------------------------*/
/*  Sets the supplied variables to be the series set for the graph

	Usage:  .graphvars [index] <serset.new syntax>

    If you already have an instance of .serset, say myserset, then it may be
    directly assigned to the sersets for the graph, e.g.

        .graphname.sersets[1] = myserset
        .graphname.sersets[#] = myserset
*/

program define graphvars

	gettoken index : 0
	capture confirm integer number `index'
	if _rc == 0 { 
		gettoken index 0 : 0 
	}
	else	index 1

	.sersets[`index'] = `.serset.new `0'
end


/* -------------------------------------------------------------------------*/
/* Create "standard" titles						

   deprecated

   Assumes that .plotregion is already available so titles can be positioned
   relative to the .plotregion.

   Spanning of the right and left titles is currently set up assuming that 
   there are cells for top and bottom axes and their labels.

*/

program define maketitles, rclass

	syntax [ , B1title(string) B2title(string) BStyle(string) 	/*
	      */   L1title(string) L2title(string) LStyle(string) 	/*
	      */   R1title(string) R2title(string) RStyle(string) 	/*
	      */   T1title(string) T2title(string) TStyle(string) 	/*
	      */   TItle(string) noDEFAULT * ]

	return local options `options'

	if `"`title'"' != `""' & `"`t1title'"' == "" {
		local t1title `title'
	}

	if "`default'" == "" {				/* default title */
		if `"`t1title'"' == `""' {
			local t1title `.sersets[1].sers.[1].label'
			if `"`t1title'"' == `""' {
				local t1title `.sersets[1].sers.[1].name'
			}

			if 0`.sersets.arrnels' > 0 | 			///
			   0`.sersets[1].sers.arrnels > 2' {
				local t1title `t1title' ...
			}
		}
	}

	foreach t in t2title t1title b1title b2title l2title l1title 	/*
		*/ r1title r2title {
		local p = substr("`t'", 1, 1)
		
		local place = cond("`p'"=="b", "bottom",		/*
			*/    cond("`p'"=="t", "top",			/*
			*/    cond("`p'"=="l", "fullleft", "fullright")))

		if "`p'"=="l" | "`p'"=="r" {
			local orient orientation(vertical)
			local span spanrows(all) 	/*fitspan(above below)*/
		}
		else	local span spancols(all) /*fitspan(left right)*/

		local style ``=substr("`t'", 1, 1) + "style"''
		if "`style'" == "" {
			local style = cond("`place'"=="top", 		/*
				*/ "scheme heading", "scheme subheading") 
		}

		.insert (`t' = .textbox.new, text(`"``t''"')		/*
			*/ style(`style') `orient') `place', `span'

		if `"``t''"' == `""' {
			.`t'.draw_view.setstyle , style(no)
		}
	}

end


/* -------------------------------------------------------------------------*/
/*
	Parse and log x/yoptions , x/ytitles , x/y[m]label , x/y[m]ticks , 
	and x/yline options for axes.  When there are mulptiple axes the axis
	is determined by an axis(#) sub option.

	26aug2003 -- logic was added for time axis options, to be translated
	to x-axis options.
*/
program ParseAndLogAxes , rclass
	gettoken log 0 : 0			// log to push to
	gettoken ax  0 : 0			// axis # if !=0 ignore axis()
	gettoken nm  0 : 0			// name of view,  "" ok
	gettoken xs  0 : 0			// valid xaxis #s
	gettoken ys  0 : 0			// valid yaxis #s

					// labels, ticks, titles, axisstyle
	//		1	2	3	4	5	6	7
	local names     ignored	major	minor	majornl	minornl	title	ignored
	local optnames  SCale	Labels	MLabels	TICks	MTicks	Title	LInes

	local options `"`0'"'

	// NOTE: time axis options, override the -x- axis options
	foreach d in X T Y {
	    if "`d'" == "T" {
	    	    local datesok datesok
	    	    local dl = cond("`d'"=="T","x",lower("`d'"))
	    }
	    else {
	    	    local datesok
	    	    local dl = lower("`d'")
	    }

	    local optdex 0
	    foreach opt of local optnames {

		local optnm = lower("`d'`opt'")
		local ++optdex
		local viewname `:word `optdex' of `names''

		local comma = cond(`optdex'==1, ",", "")

		local 0 `", `options'"'
		syntax [ , `d'`opt'(string asis) * ]

		while `"``optnm''"' != `""' {

//		    local n `._axisnum `comma'``optnm'''	// buglet
		    if `optdex' == 6 {
			_parse comma unused opts : `optnm'
			._axisnum n : `opts'
		    }
		    else {
			._axisnum n : `comma'``optnm''
		    }
		    local n = cond(`ax' , `ax' , `n')
		    if ! `:list n in `dl's' {
			di as error "`optnm'(``optnm'') not allowed, "	///
				"`dl'axis`n' does not exist"
			exit 198
		    }

		    if `optdex' > 1 & `optdex' < 6 {
			_gs_parse_and_log_tickset `log'  `nm'`dl'axis`n' ///
			    "`viewname'" "`datesok'" ``optnm''
		    }
		    else {
		    	if `optdex' == 6 {
			    _gs_parse_and_log_axtitle `log'		///
				`nm'`dl'axis`n'.`viewname' ``optnm''
			}
			else {
			    if `optdex' == 1 {
				_gs_parse_and_log_axoptions `log'	///
				    `nm'`dl'axis`n' "`datesok'" ``optnm''
			    }
			    else {
				_gs_parse_and_log_lines `log' `dl'	///
				    `nm'`dl'axis`n' "`datesok'" ``optnm''
			    }
			}
		    }

		    local 0 , `options'
		    syntax [ , `d'`opt'(string asis) * ]
		}
	    }
	}

	return local rest `"`options'"'
end

program _axisnum
	gettoken macnm 0 : 0
	gettoken colon 0 : 0

	syntax [anything] [, AXis(integer 1) * ]

	c_local `macnm' `axis'
//	class exit `axis'
end


// ---------------------------------------------------------------------------
//  Parses and logs additional text options -- text() -- where the target
//  plotregion is specified.

program ParseAndLogText , rclass
	gettoken log   0 : 0
	gettoken plreg 0 : 0

	syntax [ , TEXT(string asis) TTEXT(string asis) * ]
	while `"`text'`ttext'"' != `""' {
		if `"`text'"' != "" {
			._parse_log_1textbox `log' "`plreg'" "" `text'
		}
		if `"`ttext'"' != "" {
			._parse_log_1textbox `log' "`plreg'" "datesok" `ttext'
		}
		local 0 `", `options'"'
		syntax [ , TEXT(string asis) TTEXT(string asis) * ]
	}

	return local rest `"`options'"'
end

program _parse_log_1textbox
	gettoken log		0 : 0
	gettoken plreg		0 : 0
	gettoken datesok	0 : 0

	syntax [ anything(name=triplets) ] [ , TSTYle(string) * ]

	local fullopts `"`options'"'

	if `"`tstyle'"' == `""' {
		local tstyle "scheme text_option"
	}
							// Insert the textboxes
	gettoken y triplets : triplets
	gettoken x triplets : triplets

	while `"`y'"' != `""' {
		capture numlist "`x' `y'" , max(2) min(2)	// x-y point
		local rc = _rc
		if `rc' & "`datesok'" != "" {
			capture	{
				numlist "`y'" , max(1) min(1)
				_confirm_number_or_date `x'
			}
			local rc = _rc
		}
		if `rc' {
			di as error `"invalid point, `x' `y'"'
			exit 198
		}

		gettoken txtq triplets : triplets , quotes	// text
		gettoken txt           : txtq
		while `"`txtq'"' != `""' & `"`txtq'"' != `"`txt'"' {
			local mtext `"`mtext' `txtq'"'
			gettoken txtq triplets : triplets , quotes
			gettoken txt           : txtq
		}

		.n_text = `.n_text' + 1
		// pass the format indirectly to the textbox
		if "`datesok'" != "" {
			local dopt datesok(\`r(fmt)')
		}
		.`log'.Arrpush .`plreg'.get_time_format
		.`log'.Arrpush .`plreg'.Declare textbox`.n_text' =	///
			.pos_textbox.new , ypos(`y') xpos(`x')		///
			forcesized mtext(`mtext') style(`tstyle')	///
			`macval(dopt)'
		local mtext

		_fr_sztextbox_parse_and_log `log' `plreg'.textbox`.n_text' ///
			, `fullopts'

		local 0 `", `r(rest)'"'
		syntax [, FAKE_OPT_FOR_BETTER_MSG ]

		local    y `txt'
		gettoken x triplets : triplets
	}

end


/* -------------------------------------------------------------------------*/
/* A graph dialog box that waits until all items have been changed to redraw

   Note, currently redraws even on final cancel.
*/

program define graphdb
	.db
	.drawgraph
end

// ---------------------------------------------------------------------------
program runlog
	_fr_runlog `0'
end


// ---------------------------------------------------------------------------
// Set the header information

program record_header

	tempname log
	.`log' = {}

	.`log'.Arrpush .command  = `"`0'"'
	.`log'.Arrpush .date     = "`c(current_date)'"
	.`log'.Arrpush .time     = "`c(current_time)'"
	.`log'.Arrpush .dta_file = "`c(filename)'"
	.`log'.Arrpush .dta_date = "`c(filedate)'"

	_fr_runlog `log'
end

// ---------------------------------------------------------------------------
//  _setsyle_  member programs to set styles in .style that have side effects


program _setstyle_title_position
	_setstyle_xyz_position title `0'
end

program _setstyle_subtitle_position
	_setstyle_xyz_position subtitle `0'
end

program _setstyle_caption_position
	_setstyle_xyz_position caption `0'
end

program _setstyle_note_position
	_setstyle_xyz_position note `0'
end


program _setstyle_title_ring
	_setstyle_xyz_ring title `0'
end

program _setstyle_subtitle_ring
	_setstyle_xyz_ring subtitle `0'
end

program _setstyle_caption_ring
	_setstyle_xyz_ring caption `0'
end

program _setstyle_note_ring
	_setstyle_xyz_ring note `0'
end


program _setstyle_xyz_position

	gettoken xyz 0 : 0
	tokenize `0'

	if "`1'" == "`.style.`xyz'_position.setting'" {
		exit
	}

	.style.`xyz'_position.setstyle, style(`1')

	if 0`.style.`xyz'_ring.setting' == 0 {	// new position in grid
		local pos unmoved
	}
	else {
		local pos `.style.`xyz'_position.relative_position'
	}

						// over-ride box alignment
	.`xyz'.style.box_alignment.setstyle, 				///
			style(`.style.`xyz'_position.compass2style')

/*
						// over-ride text halign
	if "`pos'" != "leftof" & "`pos'" != "rightof"  {
		.`xyz'.style.horizontal.setstyle, 			///
			style(`.style.`xyz'_position.horizontal_style')
	}
*/

	if "`pos'" != "unmoved" {
	      .move `xyz' `pos' plotregion1 , ring(`.style.`xyz'_ring.setting')
	}
end

program _setstyle_xyz_ring

	gettoken xyz 0 : 0
	tokenize `0'

	if "`1'" == "`.style.`xyz'_ring.setting'" {
		exit
	}

	.style.`xyz'_ring.setstyle, style(`1')

	if 0`.style.`xyz'_ring.setting' == 0 {	// new position in grid
		local pos on
	}
	else {
		local pos `.style.`xyz'_position.relative_position'
	}

						// over-ride box alignment
	.`xyz'.style.box_alignment.setstyle, 				///
			style(`.style.`xyz'_position.compass2style')

      .move `xyz' `pos' plotregion1 , ring(`.style.`xyz'_ring.setting')
end



// -------------------------------------------------------------------------*/
//  Return a list of all the axes at the specified locations
//
//	Usage:  .list_axes {x|y|left|right|above|below}
// 
//  Note that y is just left and right and x is just top and bottom.

program list_axes
	args pos

	local axlist `.list_ofclass axis'

	if "`pos'" == "x" {
		foreach axis of local axlist {
			if "`.`axis'.position.stylename'" == "above" |	///
			   "`.`axis'.position.stylename'" == "below" {
				local list `list' `axis'
			}
		}
		class exit "`list'"				// Exit
	}

	if "`pos'" == "y" {
		foreach axis of local axlist {
			if "`.`axis'.position.stylename'" == "left" |	///
			   "`.`axis'.position.stylename'" == "right" {
				local list `list' `axis'
			}
		}
		class exit "`list'"				// Exit
	}

	foreach axis of local axlist {
		if "`.`axis'.position.stylename'" == "`pos'" {
			local list `list' `axis'
		}
	}
	class exit "`list'"					// Exit
end



// ---------------------------------------------------------------------------
//  Swap an axis from one side of the plotregion to the other.  Assumes the
//  target plotregion is the first one found in the graph unless a specific
//  plotregion is specified
//
//	Usage:  .alt_axis axis [plotregion]

program alt_axis
	args axis plotregion

	local pfrom  left  right  below  above
	local pto    right left   above  below

	if "`plotregion'" == "" {
		local plotregion `:word 1 of `.list_ofclass plotregion''
	}

	local pos	///
		`:word `:list posof "`.`axis'.position.snm'" in pfrom' of `pto''
	if "`pos'" == "" | "`plotregion'" == "" {
		di in green "cannot find location to alterate axis"
		exit
	}

	local of = cond("`pos'"=="left" | "`pos'"=="right", "of", "")

	.move `axis' `pos'`of' `plotregion' , ring(`.cells.`axis'.ring')

	.`axis'.position.setstyle, style(`pos')
end

// ---------------------------------------------------------------------------
//  Used to replay an axis into its current position to change its ring.
program reinsert_axis
	args axis plotregion

	if "`plotregion'" == "" {
		local plotregion `:word 1 of `.list_ofclass plotregion''
	}

	local pos `.`axis'.position.snm' 
	if "`pos'" == "" | "`plotregion'" == "" {
		di in green "cannot find location to alterate axis"
		exit
	}

	local of = cond("`pos'"=="left" | "`pos'"=="right", "of", "")

	.move `axis' `pos'`of' `plotregion' , ring(`.cells.`axis'.ring')

	.`axis'.position.setstyle, style(`pos')
end

// ---------------------------------------------------------------------------
// Returns the axis title for the specified dimension/ordinate.  Only the
// first axis in the dimension is checked for a title.

program get_axis_title
	args d

	if (0`.horizontal.istrue')  local d = cond("`d'" == "x" , "y" , "x")
					// only some families support horizontal

	class exit `"`.`d'axis1.title.get_text'"'
end


// ---------------------------------------------------------------------------
// Returns a reference to the style of the axis title for the specified 
// dimension/ordinate.  Only the first axis in the dimension is checked for 
// a title.

program get_axis_title_styleref
	args d

	if (0`.horizontal.istrue')  local d = cond("`d'" == "x" , "y" , "x")
					// only some families support horizontal

	class exit `"`.`d'axis1.title.style.objkey'"'
end

⌨️ 快捷键说明

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