예제 #1
0
파일: Program.cs 프로젝트: anaym/tddp
        private static void Main(string[] args)
        {
            var commandLineParser = PrepareCommandLineParser();

            if (commandLineParser.Parse(args).HelpCalled)
            {
                return;
            }

            var task = commandLineParser.Object;
            var data = Statistic.FromTask(task);

            if (task.XmlSource == null)
            {
                data.ToXml(new StreamWriter(File.OpenWrite("stat.xml")));
            }

            var layoter = new CircularCloudLayouter(Vector.Zero, new Vector((int)(task.Ratio * 10), (int)(10 / task.Ratio)));
            var max     = data.Count != 0 ? data.Max(p => p.Value) : 1;
            var min     = data.Count != 0 ? data.Min(p => p.Value) : 0;

            if (data.Count == 0)
            {
                Console.WriteLine("Data is not founded");
            }
            var tags     = TagCloud.FromLimits(layoter, task.MinWordHeight, task.MaxWordWidth, max, min);
            var renderer = new TagCloudRenderer(task.RenderBackgroundRectangles);

            renderer.AddManyColors(Color.DarkBlue, Color.OrangeRed, Color.DarkGreen);
            tags.PutManyTags(data);
            renderer.RenderToBitmap(tags).Save(task.OutFileName, ImageFormat.Png);
            Process.Start(task.OutFileName);
        }
예제 #2
0
 public TagCloudContext(string imageName, Size imageSize, string[] tagCloudContent, TagCloud cloud,
                        ICloudLayouter cloudLayouter)
 {
     ImageName       = imageName;
     ImageSize       = imageSize;
     TagCloudContent = tagCloudContent;
     Cloud           = cloud;
     CloudLayouter   = cloudLayouter;
 }
예제 #3
0
        public void BuildCloud()
        {
            var words = reader.GetWords(FileInputField.Text);

            words = preprocessor.GetProcessedWords(words);

            Cloud = cloudBuilder.CreateCloud(words, layouter);
            var imageSize = new Size(layouter.CloudWidth + layouter.Center.X, layouter.CloudHeight + layouter.Center.Y);

            Size = new Size(Cloud.Width + layouter.Center.X, Cloud.Height + layouter.Center.Y);

            Invalidate();
        }
예제 #4
0
        public Bitmap RenderToBitmap(TagCloud tags)
        {
            var    size   = (showRectangles ? tags.LayoutCoveringRectangle : tags.TagsCoveringRectangle).Size;
            Bitmap bitmap = null;

            try
            {
                bitmap = new Bitmap(size.Width, size.Height);
                Render(Graphics.FromImage(bitmap), tags);
                return(bitmap);
            }
            catch
            {
                bitmap?.Dispose();
                Console.WriteLine("Can not create bitmap. Too large :(");
                Environment.Exit(1);
            }
            return(null);
        }
예제 #5
0
        public void Render(Graphics graphics, TagCloud tagCloud)
        {
            var transform = new VectorCoordinateSystemConverter(showRectangles ? tagCloud.LayoutCoveringRectangle : tagCloud.TagsCoveringRectangle);

            if (showRectangles)
            {
                foreach (var rectangle in tagCloud.Rectangles)
                {
                    var rectF = transform.Transform(rectangle);
                    graphics.FillRectangle(new SolidBrush(rectangle.Size.ToColor()), rectF);
                    graphics.DrawRectangle(new Pen(Color.GreenYellow), rectF.X, rectF.Y, rectF.Width, rectF.Height);
                }
            }
            var rnd = new Random();

            foreach (var tag in tagCloud.Tags)
            {
                var rectF = transform.Transform(tag.Key);
                graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                var goodFont  = FindFont(graphics, tag.Value, rectF.Size, new Font(FontFamily.GenericMonospace, 128));
                var textBrush = textBrushes[rnd.Next(textBrushes.Count)];
                graphics.DrawString(tag.Value, goodFont, textBrush, rectF, stringFormat);
            }
        }