public void CreateCloud(Dummy d) { //fontFamily = new FontFamily("Comic Sans"); Random rad = new Random(); int factor = rad.Next(5, 10); holder = new List<Element>(); for (int i = 0; i < d.dummy.Count; i++) { int x = rad.Next(50, 650); int y = rad.Next(50, 400); int fSize = d.dummy[i].Occurences * factor; Element el = new Element(d.dummy[i].Text, x, y, fSize); holder.Add(el); } }
public void CreateCloud(List<Word> d) { holder = new List<Element>(); Random rad = new Random(); bool grouped_by_font = true; double opacity = 1.0; int font_step = 1; int prev_occ = 0; int fontSize = maxFontSize; int font_groups = maxFontSize - minFontSize; int n_words_in_groups = d.Count / font_groups; int top_words = d.Count % font_groups; string color = setColor(rad); if (n_words_in_groups < 2) { top_words = 0; font_step = 5; grouped_by_font = false; } for (int i = 0; i < d.Count; i++) { if (grouped_by_font) { if (top_words > 0) { top_words--; if (top_words == 0) { opacity = 1.0; } } else if ((i % n_words_in_groups) == 0 && top_words <= 0) { color = setColor(rad); fontSize -= font_step; opacity = 1.0; } if (d[i].Count != prev_occ && opacity > 0.1) { opacity -= 0.1; if (opacity < 0.1) { opacity = 0.1; } } } else { if (d[i].Count != prev_occ && fontSize > minFontSize) { color = setColor(rad); fontSize -= font_step; } } double lineHeight = Math.Ceiling(fontSize * fontFamily.LineSpacing + fontFamily.LineSpacing); FormattedText dum = new FormattedText(d[i].Name, System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), fontSize, Brushes.Black); double wordWidth = dum.Width - 4; int x = CanvasWidth / 2; if (d.Count > 200) { x = rad.Next(CanvasWidth / 8, CanvasWidth - CanvasWidth / 8); } //else x = rad.Next(CanvasWidth/4, CanvasWidth - CanvasWidth/4); int y = Convert.ToInt32(CanvasHeight / 2 - lineHeight); ResolveCollisions(ref x, ref y, ref lineHeight, ref wordWidth); Element el = new Element(d[i].Name, x, y, fontSize, lineHeight, wordWidth, opacity); el.Color = color; holder.Add(el); prev_occ = d[i].Count; } }