public class UtilityController : Controller
{
//
// GET: /Utility/
public ContentResult SvgBuilder(string stops)
{
string[] values = stops.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var sb = new StringBuilder();
sb.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100%\" height=\"100%\">");
sb.AppendLine();
sb.Append("<defs>");
sb.AppendLine();
sb.Append("<linearGradient id=\"linear-gradient\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">");
sb.AppendLine();
foreach (var val in values)
{
string[] items = val.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
sb.Append("<stop offset=\"" + items[1] + "\" stop-color=\"" + items[0] + "\" stop-opacity=\"1\"/>");
sb.AppendLine();
}
sb.Append("</linearGradient>");
sb.AppendLine();
sb.Append("</defs>");
sb.AppendLine();
sb.Append("<rect width=\"100%\" height=\"100%\" fill=\"url(#linear-gradient)\"/>");
sb.AppendLine();
sb.Append("</svg>");
sb.AppendLine();
return Content(sb.ToString(), "image/svg+xml");
}
}