/// <summary> /// You can supply any of the parameters you like. You must supply either 'percentage' (as a whole number out of 100) or 'amount' and 'outOfTotal' parameters. /// </summary> /// <example> /// <%=Beweb.Html.BarGraph(percentage:project.PercentOfBudget.ToInt(0), amount:actualHours, showAmount:true, decimalPlaces:1) %> /// <%=Beweb.Html.BarGraph(amount:totalHoursUsed, outOfTotal:totalHoursPurchased, showPercentage:true) %> /// </example> public static string BarGraph(decimal?amount = null, decimal?outOfTotal = null, bool showPercentage = false, bool showAmount = false, bool showOutOf = false, decimal?percentage = null, string label = null, int decimalPlaces = 0) { /* You need to add the following CSS to your stylesheet. * .svyBarGraph { width: 150px; } * .svyBarGraphLabel { position: absolute;color:white;margin-left: 5px; } * .svyBarGraphOuter { width:50px;background:#333;float:left;margin-right:10px;height:18px;border-radius: 5px; } * .svyBarGraphInner { background:green;height:14px;margin-top:2px;margin-left:2px;border-radius: 4px; } */ if (percentage == null && amount != null && outOfTotal != null) { percentage = Numbers.Floor(Numbers.SafeDivide(amount.Value, outOfTotal.Value) * 100); } else if (percentage == null) { percentage = 0; } if (showAmount && amount == null) { throw new BewebException("Html.BarGraph: You need to supply 'amount' parameter if you set 'showAmount' to true."); } if (showOutOf && outOfTotal == null) { throw new BewebException("Html.BarGraph: You need to supply 'outOfTotal' parameter if you set 'showOutOf' to true."); } if (label.IsBlank()) { if (showAmount) { label = Fmt.Number(amount, decimalPlaces); if (showOutOf) { label += " of " + Fmt.Number(outOfTotal, decimalPlaces); } if (showPercentage) { label += " (" + Fmt.Percent(percentage, decimalPlaces) + ")"; } } else if (showPercentage) { label = Fmt.Percent(percentage, decimalPlaces); } } var html = new HtmlTag("div").Add("class", "svyBarGraph"); var labelSpan = new HtmlTag("span").Add("class", "svyBarGraphLabel").SetInnerText(label); var barOuter = new HtmlTag("div").Add("class", "svyBarGraphOuter"); var barInner = new HtmlTag("div").Add("class", "svyBarGraphInner").Add("style", "width:" + Fmt.Number(percentage, 0, false) + "%"); barOuter.AddTag(barInner); html.AddTag(labelSpan); html.AddTag(barOuter); return(html.ToString()); }
public string ToHtml() { // return an html table var table = new HtmlTag("table style='xwidth: 1000px; background-color: white ; border: 1px solid #CCC;'"); //style='font-family: 'Open Sans', Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 13px;color: #000;' var thStyle = "background-color: #e0e7a2;font-family: Open Sans, Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 13px;color: #000;text-align:left;"; var tdStyle = "font-family: Open Sans, Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 12px;color: #000;border-bottom:1px solid #CCC;'"; var tr = new HtmlTag("tr"); HtmlTag th; //var th = new HtmlTag("th style='width:100px;" + thStyle + "'"); //th.SetInnerText("Status"); //tr.AddTag(th); th = new HtmlTag("th width=20% style='" + thStyle + "'"); th.SetInnerText("Title"); tr.AddTag(th); th = new HtmlTag("th width=20% style='" + thStyle + "'"); th.SetInnerText("Code"); tr.AddTag(th); th = new HtmlTag("th width=50% style='" + thStyle + "'"); th.SetInnerText("Description"); tr.AddTag(th); th = new HtmlTag("th width=10% style='" + thStyle + "'"); th.SetInnerText("Url"); tr.AddTag(th); table.AddTag(tr); foreach (var line in ImportReportLines) { // tr tr = new HtmlTag("tr"); HtmlTag td; var textColour = ""; if (line.Status == StatusFailed) { textColour = StatusFailed.DisplayName; } else if (line.Status == StatusWarning) { textColour = StatusWarning.DisplayName; } else if (line.Status == StatusInfo) { textColour = StatusInfo.DisplayName; } else if (line.Status == StatusSuccess) { textColour = StatusSuccess.DisplayName; } else { textColour = ""; } //td = new HtmlTag("td style='" + textColour + "" + tdStyle + "'"); //td.SetInnerText(line.Status); //tr.AddTag(td); if (line.LineType == LineTypeSubtitle) { td = new HtmlTag("td colspan='4' style ='" + LineTypeSubtitle.DisplayName + "" + tdStyle + "'"); td.SetInnerText(line.Title); tr.AddTag(td); } else if (line.LineType == LineTypeTitle) { td = new HtmlTag("td colspan=4 style ='" + LineTypeTitle.DisplayName + "" + tdStyle + "'"); var spanTag = new HtmlTag("span style = '" + textColour + "'"); spanTag.SetInnerHtml(line.Title); td.AddTag(spanTag); tr.AddTag(td); } else { td = new HtmlTag("td style ='" + textColour + "" + tdStyle + "'"); var spanTag = new HtmlTag("span style = '" + textColour + "'"); spanTag.SetInnerHtml(line.Title); td.AddTag(spanTag); tr.AddTag(td); } td = new HtmlTag("td style='" + tdStyle + "'"); td.SetInnerText(line.Identifier); tr.AddTag(td); td = new HtmlTag("td style='" + tdStyle + "'"); if (line.Description.IsBlank()) { td.SetInnerText(""); } else { td.SetInnerText(line.Description); } tr.AddTag(td); td = new HtmlTag("td style='" + tdStyle + "'"); if (line.LinkUrl.IsNotBlank()) { td.AddRawHtml("<a href='" + Web.ResolveUrlFull(line.LinkUrl) + "' target='_blank'>" + line.UrlCaption.DefaultValue("View/edit") + "</a>"); } tr.AddTag(td); table.AddTag(tr); } return(table.ToString()); }