public static void RenderTagCloud(string id, Dictionary <string, double> TagsAndFreqs, System.Web.UI.Page page, CloudContext context, PoliticalLeaningContext leaning, double MaxFontSize = 15.0) { // Define the name and type of the client scripts on the page. String csname1 = "tagcloud" + id; Type cstype = page.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname1)) { cs.RegisterStartupScript(cstype, csname1, utilities.WordCloud.GenerateWordCloud( id, TagsAndFreqs, MaxFontSize, context, leaning).ToString()); } }
public static StringBuilder GenerateWordCloud(string WordCloudId, Dictionary <string, double> TagsAndFreqs, double MaxFontSize, CloudContext context = CloudContext.HomePage, PoliticalLeaningContext leaning = PoliticalLeaningContext.Conservative) { StringBuilder sbCloud = new StringBuilder(); sbCloud.Append(StartJsScript()); sbCloud.Append(SetCloudControlEntitiesJsScript(TagsAndFreqs, context)); sbCloud.Append(CreateCloudSettingJsScript()); sbCloud.AppendLine(string.Format(" $('#{0}').svg3DTagCloud(settings);", WordCloudId)); Dictionary <string, S3KeyWordFreqFontMapping> freqMap = null; if (context == CloudContext.HomePage) { switch (leaning) { case PoliticalLeaningContext.Conservative: if (GetConservativeFrequencyMatrixMappingData == null) { freqMap = GenerateWordFrequencies(TagsAndFreqs, MaxFontSize); SetConservativeFrequencyMatrixMappingData = freqMap; } else { freqMap = GetConservativeFrequencyMatrixMappingData; } break; case PoliticalLeaningContext.Liberal: if (GetLiberalFrequencyMatrixMappingData == null) { freqMap = GenerateWordFrequencies(TagsAndFreqs, MaxFontSize); SetLiberalFrequencyMatrixMappingData = freqMap; } else { freqMap = GetLiberalFrequencyMatrixMappingData; } break; default: freqMap = new Dictionary <string, S3KeyWordFreqFontMapping>(); break; } } else { freqMap = GenerateWordFrequencies(TagsAndFreqs, MaxFontSize); } foreach (var item in freqMap) { //$("[*|href]:not([href])").find("text:contains('DEVIANTART')").attr("font-size","35") sbCloud.AppendLine( string.Format("$('[*|href]:not([href])').find(\"text:contains('{1}')\").attr('font-size','{0}');", item.Value.Font, item.Value.UppercaseKey)); } if (context == CloudContext.HomePage) { sbCloud.AppendLine("setFrequencies();"); } sbCloud.Append(EndJsScript()); return(sbCloud); }