public ConsoleApplication(ITextParcer textParser, ICloudLayouter cloud, Visualizer visualizer) { this.visualizer = visualizer; this.cloud = cloud; this.parser = textParser; }
protected void DrawCircle(Graphics canvas, ICloudLayouter layouter) { var centerPoint = layouter.GetCloudCenter(); var radius = (int)Math.Ceiling(CalculateСircumcircleRadius(layouter.GetCurrentLayout(), centerPoint)); canvas.DrawEllipse(new Pen(Color.ForestGreen, 2), centerPoint.X - radius, centerPoint.Y - radius, 2 * radius, 2 * radius); }
public void SetUp() { var textColorGenerator = Substitute.For <ITextColorGenerator>(); textColorGenerator.GetTextColor(Arg.Any <int>()).Returns(textColor); fontSizeCalculator = Substitute.For <IFontSizeCalculator>(); fontSizeCalculator.CalculateFontSize(Arg.Any <int>()).Returns(fontSize); fontSizeCalculatorFactory = Substitute.For <IFontSizeCalculatorFactory>(); fontSizeCalculatorFactory.Create(Arg.Any <int>(), Arg.Any <int>()).Returns(fontSizeCalculator); imageSettings = new CloudImageSettings( new Size(500, 500), Color.Black, new FontFamily("Arial"), textColorGenerator, fontSizeCalculatorFactory); cloudLayouter = Substitute.For <ICloudLayouter>(); cloudLayouter.PutNextRectangle(Arg.Any <Size>()) .Returns(c => new Rectangle(Point.Empty, c.Arg <Size>())); cloudLayouterFactory = Substitute.For <ICloudLayouterFactory>(); cloudLayouterFactory.Create(Arg.Any <Point>()).Returns(cloudLayouter); bitmapDrawer = new BitmapDrawer(imageSettings, cloudLayouterFactory); }
public CloudVisualizer(IDrawSettings settings, ICloudLayouter layouter, ICloudDrawer cloudDrawer, Size pictureSize) { Settings = settings; this.layouter = layouter; this.cloudDrawer = cloudDrawer; this.pictureSize = pictureSize; }
public Result <Bitmap> CreateBitmap(string[] cloudStrings, ICloudLayouter cloudLayouter, Size bitmapSize) { var bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height); using var graphics = GetGraphics(bitmap); using var backgroundBrush = new SolidBrush(backgroundColor); graphics.FillRectangle(backgroundBrush, new Rectangle(Point.Empty, bitmap.Size)); var tagDrawer = GetTagDrawer(graphics); var canvas = new Rectangle(Point.Empty, bitmapSize); foreach (var tag in GetTags(cloudStrings, graphics, cloudLayouter)) { if (tag.IsSuccess) { if (!canvas.Contains(tag.Value.TagBox)) { return(Result.Fail <Bitmap>($"Tag {tag.Value.TagBox} is out of canvas.")); } tagDrawer(tag.Value); } else { return(Result.Fail <Bitmap>($"Tag error was handled:{Environment.NewLine}{tag.Error}")); } } return(bitmap.AsResult()); }
public RectangleVisualizer(IEnumerable <Size> rectangles, ICloudLayouter layouter, ICloudVisualizer visualizer) { Rectangles = rectangles; Layouter = layouter; Visualizer = visualizer; }
public void SetUp() { defaultWords = new List <string> { "di", "solid", "mocking", "unit", "to" }; defaultHeights = Enumerable.Repeat(30, defaultWords.Count).ToList(); wordsPreprocessor1 = A.Fake <IWordsPreprocessor>(); wordsPreprocessor2 = A.Fake <IWordsPreprocessor>(); wordsFilter1 = A.Fake <IWordsFilter>(); wordsFilter2 = A.Fake <IWordsFilter>(); wordsFramer = A.Fake <IWordsHeighter>(); layouter = A.Fake <ICloudLayouter>(); writer = A.Fake <IWordsBitmapWriter>(); A.CallTo(() => wordsPreprocessor1.Process(null)).WithAnyArguments().Returns(defaultWords); A.CallTo(() => wordsPreprocessor2.Process(null)).WithAnyArguments().Returns(defaultWords); A.CallTo(() => wordsFilter1.GetFiltered(null)).WithAnyArguments().Returns(defaultWords); A.CallTo(() => wordsFilter2.GetFiltered(null)).WithAnyArguments().Returns(defaultWords); A.CallTo(() => wordsFramer.GetWithHeights(null)).WithAnyArguments().Returns(defaultWords.Zip(defaultHeights, Tuple.Create)); A.CallTo(() => layouter.PutNextRectangle(Size.Empty)).WithAnyArguments().Returns(Rectangle.Empty); A.CallTo(() => writer.Write(null)).WithAnyArguments().Returns(bitmapResult); container = new CloudContainer( new [] { wordsPreprocessor1, wordsPreprocessor2 }, new [] { wordsFilter1, wordsFilter2 }, wordsFramer, layouter, writer, ImageFormat.Bmp); }
public TagCloud CreateCloud(IEnumerable <string> words, ICloudLayouter layouter) { var tags = new List <Tag>(); var frequencyDictionary = new Dictionary <string, int>(); foreach (var word in words) { if (!frequencyDictionary.ContainsKey(word)) { frequencyDictionary[word] = 0; } frequencyDictionary[word]++; } var minFrequency = frequencyDictionary.Values.Min(); var maxFrequency = frequencyDictionary.Values.Max(); var sizesDifferent = maxFontSize != minFontSize ? (maxFontSize - minFontSize) : 1; var fontSizePerOneFrequency = sizesDifferent / (maxFrequency - minFrequency); foreach (var pair in frequencyDictionary) { var font = new Font("fantasy", (float)(minFontSize + fontSizePerOneFrequency * pair.Value)); var size = TextRenderer.MeasureText(pair.Key, font); tags.Add(new Tag(pair.Key, font, size, new Point(0, 0), Color.Red)); } var result = new TagCloud(); result.AddTags(tags); LocateTags(result, layouter); return(result); }
public TagsCloud(Preprocessor preprocessor, TagsCloudSettings settings, IDeterminatorOfWordSize determinatorOfWordSize, ICloudLayouter cloudLayouter) { Preprocessor = preprocessor; Settings = settings; CloudLayouter = cloudLayouter; DeterminatorOfWordSize = determinatorOfWordSize; }
public CloudDrawer(ICloudLayouter cloudLayouter, IColorProvider colorProvider, IImageSaver imageSaver) { this.cloudLayouter = cloudLayouter; ChangeImageSize(300); cloudLayouter.ChangeCenter(new Point(ImageSize / 2, ImageSize / 2)); ImageSaver = imageSaver; ColorProvider = colorProvider; }
public TagCreator(FontSettings fontSettings, ICloudLayouter cloudLayouter, TextAnalyzer textAnalyzer, IImageHolder imageHolder) { this.fontSettings = fontSettings; this.cloudLayouter = cloudLayouter; this.textAnalyzer = textAnalyzer; this.imageHolder = imageHolder; }
private void LocateTags(TagCloud cloud, ICloudLayouter layouter) { for (int i = 0; i < cloud.Tags.Count; i++) { var location = layouter.PushNextRectangle(cloud.Tags[i].Form).Location; cloud.Tags[i].Location = location; } }
public TagCloudVisualizator( VisualizatorProperties properties, ITextColorProvider colorGenerator, ICloudLayouter layouter) { this.properties = properties; this.colorGenerator = colorGenerator; this.layouter = layouter; }
public CloudBuilder(IDictionaryNormalizer dictionaryNormalizer, IWordsFilter filter, IFrequencyAnalyzer frequencyAnalyzer, ICloudDrawer cloudDrawer, ICloudLayouter cloudLayouter) { this.dictionaryNormalizer = dictionaryNormalizer; this.filter = filter; this.frequencyAnalyzer = frequencyAnalyzer; this.cloudDrawer = cloudDrawer; this.cloudLayouter = cloudLayouter; }
public TagCloudMaker(IWordProcessor wordProcessor, ICloudLayouter cloudLayouter, ITagCloudDrawer tagCloudDrawer, IImageSaver imageSaver, DrawingSettings settings) { this.wordProcessor = wordProcessor; this.cloudLayouter = cloudLayouter; this.tagCloudDrawer = tagCloudDrawer; this.imageSaver = imageSaver; this.settings = settings; }
public TagCloudContext(string imageName, Size imageSize, string[] tagCloudContent, TagCloud cloud, ICloudLayouter cloudLayouter) { ImageName = imageName; ImageSize = imageSize; TagCloudContent = tagCloudContent; Cloud = cloud; CloudLayouter = cloudLayouter; }
public Result <None> Run(string input, string output, ITextParcer textParser, ICloudLayouter cloud, Visualizer visualizer) { return(textParser.TryGetWordsFromText(input) .Then(textParser.ParseWords) .Then(cloud.AddWordsFromDictionary) .Then((parsedCloud) => visualizer.RenderCurrentConfig(parsedCloud, output))); }
public static Size CalculateSize(this ICloudLayouter layouter) { var minX = layouter.PlacedRectangles.Min(r => r.Left); var maxX = layouter.PlacedRectangles.Max(r => r.Right); var minY = layouter.PlacedRectangles.Min(r => r.Top); var maxY = layouter.PlacedRectangles.Max(r => r.Bottom); return(new Size(maxX - minX, maxY - minY)); }
private static CloudBuilder PrepareCloudBuilder( IWordsProvider wordsProvider, IStyleProvider styleProvider, ICloudLayouter layouter, ICloudSettingsProvider settingsProvider) { return(CloudBuilder.StartNew(layouter, settingsProvider) .WithWordsSize(word => TextRenderer.MeasureText(word, styleProvider.GetStyle(word).Font)) .WithWords(wordsProvider.GetWords())); }
public CloudRenderer( IWordsProvider wordsProvider, IStyleProvider styleProvider, ICloudLayouter cloudLayouter, ICloudSettingsProvider settingsProvider) { this.styleProvider = styleProvider; this.settingsProvider = settingsProvider; cloudBuilder = PrepareCloudBuilder(wordsProvider, styleProvider, cloudLayouter, settingsProvider); }
public void SetUp() { textReader = A.Fake <ITextReader>(); wordsFilter = A.Fake <IWordsFilter>(); wordsCounter = A.Fake <IWordsCounter>(); wordsToSizesConverter = A.Fake <IWordsToSizesConverter>(); ccl = A.Fake <ICloudLayouter>(); visualiser = A.Fake <IVisualiser>(); imageSaver = A.Fake <IFileSaver>(); }
public void SetUp() { fakeLayouter = A.Fake <ICloudLayouter>(); A.CallTo(() => fakeLayouter.PutNextRectangle(A <Size> .Ignored)) .ReturnsLazily((Size size) => new Rectangle(Point.Empty, size)); A.CallTo(() => fakeLayouter.NormalizedRectangles) .Returns(Enumerable.Repeat(Rectangle.Empty, sampleWordsSizes.Count).ToList()); wordsLayouter = new WordsLayouter(fakeLayouter); }
public TagsCloudCreator( ICloudLayouter layouter, IFrequencyWordsAnalyzer wordsAnalyzer, IProvider <IEnumerable <string> > sourceWordsProvider ) { this.layouter = layouter; this.wordsAnalyzer = wordsAnalyzer; this.sourceWordsProvider = sourceWordsProvider; }
public TagCloudCreator(ICloudLayouter layouter, IWordKeeper wordKeeper, Size imageSize) { this.layouter = layouter; this.wordKeeper = wordKeeper; this.imageSize = imageSize; var mainSide = imageSize.Height < imageSize.Width ? imageSize.Height : imageSize.Width; scale = mainSide / 100; }
private static void PopulateWithRandomRectangles(ICloudLayouter layouter) { var random = new Random(); for (var i = 0; i < 100; i++) { layouter.PutNextRectangle(new Size( random.Next(50, 201), random.Next(20, 61))); } }
public TagCloudVisualization( ICloudLayouter cloudLayouter) { font = defaultFont; color = defaultColor; backgroundColor = defaultBackColor; this.cloudLayouter = cloudLayouter; bitmapHeight = 1000; bitmapWidth = 1000; }
public void SetSettings(IFileReader reader, ICloudLayouter layouter, IPreprocessor preprocessor, IImageSaver saver, ICloudBuilder builder) { this.reader = reader; this.layouter = layouter; this.preprocessor = preprocessor; this.saver = saver; this.cloudBuilder = builder; }
public Application(IFileReader reader, IToSizeConverter wordConverter, IWordFilter filter, ICloudLayouter layouter, IVisualisator visualisator, IImageSaver saver) { this.reader = reader; this.wordConverter = wordConverter; this.filter = filter; this.layouter = layouter; this.saver = saver; this.visualisator = visualisator; this.saver = saver; }
public virtual void PresentCloudToFile(ICloudLayouter layouter, string fileName) { fileName = GetRealFileName(fileName); using (var presentation = new Bitmap(canvasWidth, canvasHeight)) { using (var canvas = Graphics.FromImage(presentation)) { DrawRectangles(canvas, layouter.GetCurrentLayout()); } presentation?.Save(fileName); } }
static void DrawLayoutResult(ICloudLayouter layouter, Size[] rects, string layoutName) { foreach (var el in rects) { layouter.PutNextRectangle(el); } var resultImagePath = Path.Combine(Directory.GetCurrentDirectory(), $"{layoutName}.png"); CloudLayoutVisualizer.SaveAsPngImage(layouter.GetLayout(), resultImagePath); System.Console.WriteLine($"Layout {layoutName} saved to {resultImagePath}"); }