关闭

一个显示图例的coldfusion程序

624人阅读 评论(0) 收藏 举报

这个程序只是让使用者更简单地显示图例。希望对大家有帮助。在IE,Firefox和Chrome测试过。当然,可能要大家自己测试一下才行。

调用如下:

<cf_这个程序 color1="red" text1="你好" color2=“blue” text2=“大家好”>

显示结果如下:

你好大家好

 

代码如下:

<cfsilent>
<cfparam name="attributes.height" default="10">
<cfparam name="attributes.width" default="10">
<cfparam name="attributes.topmargin" default="3">
<cfparam name="attributes.float" default=""> <!--- empty, left or right --->
<cfparam name="attributes.PaddingBetweenLegend" default="4">
<cfparam name="attributes.PaddingBetweenColorAndText" default="2">
<cfset legendSequence = "">
<cfloop collection="#attributes#" item="attribute">
	<cfset numberSequence = "">
	<cfif isvalid("regex", lcase(attribute), "color(\d+)$")>
		<cfset numberSequence = replacenocase(attribute,"color", "")>
	</cfif>
	<cfif isvalid("regex", lcase(attribute), "text(\d+)$")>
		<cfset numberSequence = replacenocase(attribute,"text", "")>
	</cfif>
	<cfif listfind(legendSequence, numberSequence) eq 0>
		<cfset legendSequence = listappend(legendSequence, numberSequence)>
	</cfif>
</cfloop>
<cfset legendSequence = listsort(legendSequence, "numeric")>
<cfif legendSequence eq ""><cfexit></cfif>
<cfset displayString = "">
<cfloop list="#legendSequence#" index="keyLegend">
	<cfif isdefined("attributes.color#keyLegend#")>
		<cfset colorName = attributes["color" & keyLegend]>
	<cfelse>
		<cfset colorName = "##ffffff">
	</cfif>
	<cfif isdefined("attributes.text#keyLegend#")>
		<cfset textName = attributes["text" & keyLegend]>
	<cfelse>
		<cfset textName = "N/A">
	</cfif>	
	<cfoutput><cfsavecontent variable="displaySubstring"><span style="width:#attributes.width#px; height:#attributes.height#px; font-size:5px; padding:0px;margin:0px; display:inline-block; background-color:#colorName#; border:1px solid black;"></span><span style="margin-left:#attributes.PaddingBetweenColorAndText#px;margin-right:#attributes.PaddingBetweenLegend#px;"> #textName#</span></cfsavecontent></cfoutput>
	<cfset displayString = displayString & displaySubstring>
</cfloop>
<cfset cssFloat = attributes.float>
<cfif cssFloat neq "">
	<cfset cssFloat = "float:" & cssFloat & ";">
</cfif>
<cfset cssMarginTop = attributes.topmargin>
<cfif cssMarginTop neq "">
	<cfset cssMarginTop = "margin-top:" & cssMarginTop & ";">
</cfif>
</cfsilent>
<cfoutput><div style="#cssMarginTop# #cssFloat#">#displayString#</div></cfoutput>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:482478次
    • 积分:7037
    • 等级:
    • 排名:第3333名
    • 原创:239篇
    • 转载:20篇
    • 译文:4篇
    • 评论:99条
    文章分类
    最新评论