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

📄 axis.class

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 CLASS
📖 第 1 页 / 共 2 页
字号:
		if "`pos'" == "below" {
			local op -
		}
		else	local op +
		local y = `y0' `op' `.style.tickstyle.textgap.gmval'
		if `.style.alternate.istrue' {
			local yalt = `y' `op' 			   /*
			    */ `.style.alternate_gap.gmval' `op'   /*
			    */ `.style.tickstyle.textstyle.size.gmval'
		}

		local x = `.min'			/* standard */
		forvalues i = 1/`.numticks' {
			local yc `y'
			if `.style.alternate.istrue' {
				if mod((`i'-1), 2) {
					local yc `yalt'
				}
			} 
			gdi text `x' `yc' `=string(`x',"`fmt'")'
			local x = `x' + `delta'
		}
		if "`crt'" == "" {			/* create */
		    ._declare_array custom_labels
		    local x `.min'
		    forvalues i = 1/0`.numticks' {
			tempname tic
			.`tic' = .tick_g.new `x'		///
				 `"`=string(`x',"`fmt'")'"' , 	///
				 style(`.style.tickstyle.snm')	///
				 angle(`.style.tickangle.snm')
			.custom_labels[`.custom_labels.arrnels'+1] = ///
				.`tic'.ref
			local x = `x' + `delta'
		    }
		}

		forvalues i = 1/0`.majorlabels.arrnels' {  /* custom */
			local yc `y'
			if `.style.alternate.istrue' {
				if mod((`i'-1), 2) {
					local yc `yalt'
				}
			} 
			local x `.majorlabels[`i'][1]'
			gdi line `x' `y0' `x' `y1'
			gdi text `x' `yc' `.majorlabels[`i'][2]'
		}
	}
}
else {
	.`plotregion'.style.margin.setgdi, view(`.objkey') yonly

	if "`pos'" == "left" {
		local x0 = `x0' - `.style.tickstyle.tick0'
		local x1 = `x0' + `.style.tickstyle.length.gmval'
	}
	else {
		local x0 = `x0' + `.style.tickstyle.tick0'
		local x1 = `x0' - `.style.tickstyle.length.gmval'
	}

	.`plotregion'.yscale.setgdi `.ysize_ren'

	if ! `.style.extend' {			/* draw main line */
		gdi line `x0_0' `.min' `x0_0' `.max'   
		`crt' ._declare_array axis_line
		`crt' .Declare axis_line = .line_g.new `x1' `.min'  /*
		      */ `x1' `.max',				    /*
		      */ styleref(`.style.linestyle.objkey')
	}

	.style.tickstyle.setgdifull , 				/*
		*/ angle(`.style.tickangle.val') posdefault(`pos')

	`crt' ._declare_array major_ticks
	local y `.min'
	forvalues i = 1/`.numticks' {
		gdi line `x0' `y' `x1' `y'
		`crt' .Declare major_ticks = .line_g.new `x0' `y' `x1' /*
		    */ `y' ,					       /*
		    */ styleref(`.style.tickstyle.linestyle.objkey')
		local y = `y' + `delta'
	}

	if `.style.tickstyle.show_labels.istrue' {
		if "`pos'" == "left" {
			local op -
		}
		else {
			local op +
		}
		local x = `x0' `op' `.style.tickstyle.textgap.gmval'
		if `.style.alternate.istrue' {
			local xalt = `x' `op' 			   /*
			    */ `.style.alternate_gap.gmval' `op'   /*
			    */ `.style.tickstyle.textstyle.size.gmval'
		}

							/* standard */
		local y `.min'
		forvalues i = 1/`.numticks' {
		    local xc `x'
		    if `.style.alternate.istrue' {
			if mod((`i'-1), 2) {
				local xc `xalt'
			}
		    } 
		    gdi text `xc' `y' `=string(`y',"`fmt'")'
		    local y = `y' + `delta'
		}
		if "`crt'" == "" {			/* create */
		    ._declare_array major_labels
		    local y `.min'
		    forvalues i = 1/`.numticks' {
			local xc `x'
			if `.style.alternate.istrue' {
			    if mod((`i'-1), 2) {
				local xc `xalt'
			    }
			} 
			.Declare major_labels = .text.new, x(`xc')  /*
			   */ y(`y') text(`=string(`y',"`fmt'")')   /*
			   */ style(`.style.tickstyle.textstyle.snm')
			local y = `y' + `delta'
		    }
		}

		forvalues i = 1/0`.majorlabels.arrnels' {/* custom */
			local xc `x'
			if `.style.alternate.istrue' {
				if mod((`i'-1), 2) {
					local xc `xalt'
				}
			} 
			local y `.majorlabels[`i'][1]'
			gdi line `x0' `y' `x1' `y'
			gdi text `xc' `y' `.majorlabels[`i'][2]'
		}
	}
}

if ! `.style.minor_ticks' { 
	._draw_title `xtitle' `ytitle' `xtitlesz' `ytitlesz'
	exit						/* EXIT */
}			

						/* minor ticks */
.style.minortickstyle.setgdifull , 				/*
	*/ angle(`.style.minor_tickangle.val') posdefault(`pos')

local fmt `.label_format'

local mticks = 1 + `.style.minor_ticks'
local gaps = `mticks' * (`.numticks' - 1)
local minordelta = (`.max'-`.min') / `gaps'
local gaps1 = `gaps' - 1

if "`pos'" == "below" | "`pos'" == "above" { 
	if "`pos'" == "below" {
		local y0 = `y0_0' - `.style.minortickstyle.tick0'
		local y1 = `y0' + `.style.minortickstyle.length.gmval'
	}
	else {
		local y0 = `y0_0' + `.style.minortickstyle.tick0'
		local y1 = `y0' - `.style.minortickstyle.length.gmval'
	}

	if `gaps1' >= 0 & "`crt'" != "*" { 
		._declare_array minor_ticks 
	}
	local x `.min'
	forvalues i = 0/`gaps1' {			/* ticks */
		if mod(`i', `mticks') != 0 {
		    gdi line `x' `y0' `x' `y1'
		    `crt' .Declare minor_ticks = .line_g.new `x' /*
		    */ `y0' `x' `y0' , 			         /*
		    */ styleref(`.style.minortickstyle.linestyle.objkey')
		}
		local x = `x' + `minordelta'
	}

							/* labels */
	local style .style.minortickstyle
	if ``style'.show_labels.istrue' {
		if "`pos'" == "below" {
			local y = `y0' - ``style'.textgap.gmval'
		}
		else	local y = `y0' + ``style'.textgap.gmval'

		local x `.min'
		forvalues i = 0/`gaps1' {
			if mod(`i', `mticks') != 0 {
				gdi text `x' `y' `=string(`x',"`fmt'")'
			}
			local x = `x' + `minordelta'
		}
	}
}
else {
	if "`pos'" == "left" {
		local x0 = `x0_0' - `.style.minortickstyle.tick0'
		local x1 = `x0' + `.style.minortickstyle.length.gmval'
	}
	else {
		local x0 = `x0_0' + `.style.minortickstyle.tick0'
		local x1 = `x0' - `.style.minortickstyle.length.gmval'
	}

	if `gaps1' >= 0 & "`crt'" != "*" { 
		._declare_array minor_ticks 
	}
	local y = `.min'
	forvalues i = 0/`gaps1' {			/* ticks */
		if mod(`i', `mticks') != 0 {
		    gdi line `x0' `y' `x1' `y'
		    `crt' .Declare minor_ticks = .line_g.new `x0' /*
		    */ `y' `x1' `y' , 			    	  /*
		    */ styleref(`.style.minortickstyle.linestyle.objkey')
		}
		local y = `y' + `minordelta'
	}

							/* labels */
	local style .style.minortickstyle
	if ``style'.show_labels.istrue' {
		if "`pos'" == "left" {
			local x = `x0' - ``style'.textgap.gmval'
		}
		else	local x = `x0' + ``style'.textgap.gmval'

		local y `.min'
		forvalues i = 0/`gaps1' {
			if mod(`i', `mticks') != 0 {
				gdi text `x' `y' `=string(`y',"`fmt'")'
			}
			local y = `y' + `minordelta'
		}
	}
}

._draw_title `xtitle' `ytitle' `xtitlesz' `ytitlesz'

end


/* -------------------------------------------------------------------------*/
/*  
	Draw axis title							

        Must reset transform because .axis is holding a view (.textbox) but
        is not itself a container

	This must be the last thing drawn because it does not hold and restore
	the current transform.
*/
program define _draw_title
	args x y xsz ysz


	.xtransform.reset			/* back to transform when */
	.ytransform.reset			/* .axis was called 	  */

	.xtransform.translate `x'		/* translate to position of */
	.ytransform.translate `y'		/* title 		    */

	.title.draw , xsize(`xsz') ysize(`ysz')		/* draw title */

end


/* -------------------------------------------------------------------------*/
program define draw2

	._drawem axis_line1

	local ord =							      /*
	 */ cond("`.position.snm'" == "left" | "`.position.snm'" == "right", /*
	 */ "y", "x")

	.plotregion.style.margin.setgdi, view(`.objkey') `ord'only

	._drawem axis_line

	.plotregion.`ord'scale.setgdi `.`ord'size_ren'

	._drawem major_ticks
	._drawem major_labels 						/*
	    */ "angle(`.style.tickangle.val') posdefault(`.position.snm')"

	._drawem minor_ticks

	local pos `.position.snm'
	if "`pos'" == "default" { 
		local pos below 
	}

	if "`pos'" == "below" | "`pos'" == "above" {
	    local xtitle 0
	    local xtitlesz `.xsize_ren'
	    local ytitlesz `.title.extent y'
	    if "`pos'" == "below" {
		local ytitle `.style.outer_space.gmval'
	    }
	    else {
		local ytitle = `.ysize_notitle' + `.style.title_gap.gmval'
	    }
	}
	else if "`pos'" == "left" | "`pos'" == "right" {
	    local ytitle = 0
	    local xtitlesz `.title.extent x'
	    local ytitlesz `.ysize_ren'
	    if "`pos'" == "left" {
		local xtitle = `.style.outer_space.gmval'
	    }
	    else {
		local xtitle = `.xsize_notitle' + `.style.title_gap.gmval'
	    }
	}


	._draw_title `xtitle' `ytitle' `xtitlesz' `ytitlesz'

end

/* -------------------------------------------------------------------------*/
/*
	Usage:  _drawem name "drawing_options"

	Draws either nothing, a single object called name, or the array of
	objects held in the array called name.
*/
program define _drawem

	args name options

	if "`.Local.`name'.isa'" == "" { 
		exit						/* Exit */
	}		

	if "`.Local.`name'.isa'" != "array" {
		capture .`name'.draw , `options'
		exit						/* Exit */
	}

	forvalues i = 1/0`.`name'.arrnels' {
		.`name'[`i'].draw , `options'
	}


end


program _drawem2
	gettoken name 0 : 0

	if "`.Local.`name'.isa'" != "array" {
		exit						// Exit
	}

	forvalues i = 1/0`.`name'.arrnels' {
		.`name'[`i'].draw `0'
	}
end


/* -------------------------------------------------------------------------*/
program define _cleanup_created

	foreach array in axis_line axis_line1 major_ticks major_labels 	/*
	    */ minor_ticks {
		forvalues i = 1/0`.`array'.arrnels' {
			.`array'.Arrpop
		}
	}
end


/* -------------------------------------------------------------------------*/
program define _declare_array

	args name

	if "`.`name'.isa'" == "" {
		.Declare array `name'
	}
end


/* -------------------------------------------------------------------------*/
/*  Return a string containing the object key of the x/y series of the first
    plot in our plotregion.  Typically used to fetch value labels for ticks.
*/

program _value_label_series
	args ord

	class exit "`.plotregion.dynamicmv[1].dim_value_label_series `ord''"
		//		 ^^^^^^^^^^^^
		//	usually  plot1
end


// ---------------------------------------------------------------------------
//  Turn off labeling on all ticks/labels
program define set_labels_off
	.style.majorstyle.tickstyle.show_labels.set_false
	.style.minorstyle.tickstyle.show_labels.set_false
	.style.majornlstyle.tickstyle.show_labels.set_false
	.style.minornlstyle.tickstyle.show_labels.set_false
end


// ---------------------------------------------------------------------------
//  Turn off ticking on all ticks/labels
program define set_ticks_off
	.style.majorstyle.tickstyle.show_ticks.set_false
	.style.minorstyle.tickstyle.show_ticks.set_false
	.style.majornlstyle.tickstyle.show_ticks.set_false
	.style.minornlstyle.tickstyle.show_ticks.set_false
end


// ---------------------------------------------------------------------------
//  Turn on/off ticking/labeling on all ticks/labels
program define set_labels_onoff

	if "`1'" == "`.style.majorstyle.tickstyle.show_labels.stylename'" & ///
	   "`1'" == "`.style.minorstyle.tickstyle.show_labels.stylename'" {
		exit
	}

	.style.editstyle majorstyle(  tickstyle(show_labels(`1')))	///
			 minorstyle(  tickstyle(show_labels(`1')))	///
			 editcopy
end

program define set_ticks_onoff

	if "`1'" == "`.style.majorstyle.tickstyle.show_ticks.stylename'"   & ///
	   "`1'" == "`.style.minorstyle.tickstyle.show_ticks.stylename'"   & ///
	   "`1'" == "`.style.majornlstyle.tickstyle.show_ticks.stylename'" & ///
	   "`1'" == "`.style.minornlstyle.tickstyle.show_ticks.stylename'" {
		exit
	}

	.style.editstyle majorstyle(  tickstyle(show_ticks(`1')))	///
			 minorstyle(  tickstyle(show_ticks(`1')))	///
			 majornlstyle(tickstyle(show_ticks(`1')))	///
			 minornlstyle(tickstyle(show_ticks(`1'))) editcopy
end


// ---------------------------------------------------------------------------
//  Turn off drawing of the axis, but turn on filling
program define set_draw_off_fill
	if 0`.draw_view.istrue' {
		.draw_view.set_false
	}
	if ! 0`.fill_if_undrawn' {
		.fill_if_undrawn.set_true
	}
end

// ---------------------------------------------------------------------------
// Apply the supplied setting to all of the ticksets

program define set_allticksets
	
	foreach ticks in major majornl minor {
		.`ticks'`0'
	}
end

// ---------------------------------------------------------------------------
// Apply the supplied setting to all of tickset styles

program define set_alltickstyles
	
	foreach ticks in major majornl minor {
		.style.`ticks'style`0'
	}
end


// ---------------------------------------------------------------------------
// Used by .dialog_box to update a value -- substitute for a trigger


// must usually set maxs and mins at the axis level because only the axis has
// sufficient information to safely curset the scale.

program define _set_major_min
	.major.min = `1'
	.reset_scale
end
program define _set_minor_min
	.minor.min = `1'
	.reset_scale
end
program define _set_majornl_min
	.majornl.min = `1'
	.reset_scale
end
program define _set_minornl_min
	.minornl.min = `1'
	.reset_scale
end

program define _set_major_max
	.major.max = `1'
	.reset_scale
end
program define _set_major_max
	.major.max = `1'
	.reset_scale
end
program define _set_majornl_max
	.majornl.max = `1'
	.reset_scale
end
program define _set_minornl
	.minornl.max = `1'
	.reset_scale
end


// ---------------------------------------------------------------------------
// add a min/max value to the scale used by the axis.

program addmin
	local ord = cond("`.position.snm'"=="left" |			///
			 "`.position.snm'"=="right", "y", "x") 

	.plotregion.`ord'scale.addmin `0'
end

program addmax
	local ord = cond("`.position.snm'"=="left" |			///
			 "`.position.snm'"=="right", "y", "x") 

	.plotregion.`ord'scale.addmax `0'
end

program daterange
	.get_time_format
	local fmt `r(fmt)'
	_date2elapsed, format(`fmt') datelist(`0')
	local 0 `",  range(`s(args)')"'
	syntax [ , Range(numlist missingok max=100 sort) * ]

	local min =  .
	local max = -1e300
	foreach r of local range {
		if `r' >= . {
			continue, break
		}
		local min = min(`min', `r')
		local max = max(`max', `r')
	}
	if `min' < . {
		.addmin `min'
	}
	if `max' > -1e-300 {
		.addmax `max'
	}
end

program get_time_format, rclass
	local ticksets major minor majornl minornl
	if inlist("`.position.snm'", "below", "above") {
		foreach tickset of local ticksets{
			local fmt "`.`tickset'.label_format'"
			if inlist(substr("`fmt'",1,2),"%t","%d") {
				local tfmt `fmt'
				continue, break
			}
		}
	}
	return local fmt "`tfmt'"
end

⌨️ 快捷键说明

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