-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Заколюкин Степан #212
base: master
Are you sure you want to change the base?
Заколюкин Степан #212
Changes from 1 commit
48656d8
babec8f
68da871
4b94c15
2c31add
b3431aa
58c1e1f
597a500
4af1662
9a978c6
dcac338
8c52b56
7a360bc
6d8969e
1a486c3
2569e50
f6a5c10
41bafeb
e09aa6b
bb9ab34
920d2e7
c0d9643
8add5a0
95b3853
a16dd56
fb1f857
5ef9ffa
0f9a2fc
51a539f
8ba7752
abb4479
0795e0e
0e67a79
fea7fca
d1d619c
bc06977
469aca6
64aa067
1e3c569
b145408
60b65ca
f0b3625
5b8d9a5
ddbe887
fe860f5
9d3cbec
bc4377b
e4c76aa
3e50a41
bc7f922
9a681eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,14 @@ | |
using FluentAssertions; | ||
using NUnit.Framework.Interfaces; | ||
using TagCloud.CloudLayout; | ||
using TagCloud.Visualization; | ||
|
||
namespace TagCloud.Tests; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тестов явно мало.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UP Тестов маловато:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Исправил |
||
|
||
|
||
[TestFixture] | ||
public class CircularCloudTests | ||
{ | ||
private readonly List<Rectangle> listRectangles = []; | ||
private readonly List<RectangleF> listRectangles = []; | ||
|
||
[Test] | ||
public void CircularCloud_CorrectInitialization_NoExceptions() | ||
|
@@ -25,33 +24,31 @@ public void CircularCloud_CorrectInitialization_NoExceptions() | |
[Test] | ||
public void PutNextRectangle_RandomSizes_MustBeRightSize() | ||
{ | ||
var cloud = new CircularCloud(new Point(960, 540)); | ||
var random = new Random(); | ||
var cloud = new CircularCloud(new Point(960, 540)); | ||
|
||
for (var i = 0; i < 50; i++) | ||
{ | ||
var width = random.Next(30, 200); | ||
var actualSize = new Size(width, random.Next(width / 6, width / 3)); | ||
var actualSize = new SizeF(width, random.Next(width / 6, width / 3)); | ||
|
||
var rectangle = cloud.PutNextRectangle(actualSize); | ||
|
||
actualSize | ||
.Should() | ||
.Be(rectangle.Size); | ||
actualSize.Should().Be(rectangle.Size); | ||
} | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_RandomSizes_ShouldNotIntersect() | ||
{ | ||
var cloudLayouter = new CircularCloud(new Point(960, 540)); | ||
var random = new Random(); | ||
var cloudLayouter = new CircularCloud(new Point(960, 540)); | ||
|
||
for (int i = 0; i < 100; i++) | ||
for (var i = 0; i < 100; i++) | ||
{ | ||
var width = random.Next(30, 200); | ||
|
||
var rectangle = cloudLayouter.PutNextRectangle(new(width, random.Next(width / 6, width / 3))); | ||
var rectangle = cloudLayouter.PutNextRectangle(new SizeF(width, random.Next(width / 6, width / 3))); | ||
|
||
listRectangles.Any(rect => rect.IntersectsWith(rectangle)) | ||
.Should() | ||
|
@@ -67,12 +64,10 @@ public void CreateReportInCaseOfAnError() | |
if (TestContext.CurrentContext.Result.Outcome == ResultState.Failure) | ||
{ | ||
var colors = new[] { Color.Red, Color.Green, Color.Brown, Color.Yellow, Color.Blue }; | ||
var path = "../../../../TagsCloudVisualization/TestErrorReports/сloud.png"; | ||
var path = $"../../../TestErrorReports/{TestContext.CurrentContext.Test.FullName}.png"; | ||
var visual = new VisualizationCloudLayout(1920, 1080, Color.White, colors); | ||
|
||
visual.CreateImage(listRectangles) | ||
.Save(path); | ||
|
||
visual.CreateImage(listRectangles).Save(path); | ||
System.Console.WriteLine($"Tag cloud visualization saved to file {Path.GetFullPath(path)}"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Drawing; | ||
|
||
namespace TagCloud.Tests; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Странновато. По логике вещей эта штука должна относиться к основному проекту + её нужно спрятать за абстракцией |
||
|
||
public class VisualizationCloudLayout | ||
{ | ||
private readonly int width; | ||
private readonly int height; | ||
private readonly Color backgroundColor; | ||
private readonly Color[] rectanglePalette; | ||
|
||
public VisualizationCloudLayout(int width, int height, Color backgroundColor, IEnumerable<Color> rectanglePalette) | ||
{ | ||
this.width = width; | ||
this.height = height; | ||
this.backgroundColor = backgroundColor; | ||
this.rectanglePalette = rectanglePalette.ToArray(); | ||
} | ||
|
||
public Bitmap CreateImage(IEnumerable<RectangleF> rectangles) | ||
{ | ||
var image = new Bitmap(width, height); | ||
|
||
DrawCloudLayout(Graphics.FromImage(image), rectangles); | ||
|
||
return image; | ||
} | ||
|
||
private void DrawCloudLayout(Graphics graphics, IEnumerable<RectangleF> rectangles) | ||
{ | ||
var random = new Random(); | ||
var array = rectangles.ToArray(); | ||
var color = rectanglePalette[random.Next(rectanglePalette.Length)]; | ||
|
||
graphics.FillRectangle(new SolidBrush(backgroundColor), 0, 0, width, height); | ||
graphics.FillRectangles(new SolidBrush(color), array); | ||
graphics.DrawRectangles(new Pen(Color.Black, 1), array); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Drawing; | ||
|
||
namespace TagCloud.CloudLayout; | ||
|
||
public interface ILayoutProvider | ||
{ | ||
public RectangleF PutNextRectangle(SizeF rectangleSize); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Drawing; | ||
using TagCloud.TextProcessing; | ||
|
||
namespace TagCloud; | ||
|
||
public interface IColorPicker | ||
{ | ||
public Color GetColorForWord(WordInfo word); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,66 @@ | ||
using System.Drawing; | ||
using TagCloud.CloudLayout; | ||
using TagCloud.TextProcessing; | ||
|
||
namespace TagCloud.Visualization; | ||
namespace TagCloud.ImageGeneration; | ||
|
||
public class VisualizationCloudLayout | ||
{ | ||
private readonly int width; | ||
private readonly int height; | ||
private readonly Color backgroundColor; | ||
private readonly Color[] rectanglePalette; | ||
private readonly int numberOfWords; | ||
private float coefficient; | ||
private readonly IColorPicker colorPicker; | ||
private readonly ILayoutProvider layoutProvider; | ||
private readonly IEnumerable<WordInfo> wordsInfo; | ||
public Size ImageSize { get; set; } = new(1080, 1080); | ||
public FontFamily FontFamily { get; set; } = new("Arial"); | ||
public Color BackgroundColor { get; set; } = Color.Transparent; | ||
|
||
public VisualizationCloudLayout(int width, int height, Color backgroundColor, IEnumerable<Color> rectanglePalette) | ||
private float cloudCompressionRatio; | ||
public float CloudCompressionRatio | ||
{ | ||
this.width = width; | ||
this.height = height; | ||
this.backgroundColor = backgroundColor; | ||
this.rectanglePalette = rectanglePalette.ToArray(); | ||
get => cloudCompressionRatio; | ||
set | ||
{ | ||
if (1 - value < 0.01 || value < 0.01) | ||
throw new ArgumentException("Должно быть больше 0, номеньше или равно единице", nameof(value)); | ||
|
||
cloudCompressionRatio = value; | ||
coefficient = ImageSize.Width * cloudCompressionRatio / numberOfWords;; | ||
} | ||
} | ||
|
||
public Bitmap CreateImage(CircularCloud cloud, int amountRectangles, | ||
Size minSize, Size maxSize) | ||
public VisualizationCloudLayout(IColorPicker colorPicker, | ||
ILayoutProvider layoutProvider, IEnumerable<WordInfo> words) | ||
{ | ||
var image = new Bitmap(width, height); | ||
var rectangles = RectangleGenerator.GenerateCloudLayout( | ||
amountRectangles, | ||
minSize, | ||
maxSize, | ||
cloud); | ||
|
||
DrawCloudLayout(Graphics.FromImage(image), rectangles); | ||
|
||
return image; | ||
wordsInfo = words; | ||
numberOfWords = words.Count(); | ||
CloudCompressionRatio = 0.8f; | ||
this.colorPicker = colorPicker; | ||
this.layoutProvider = layoutProvider; | ||
} | ||
|
||
public Bitmap CreateImage(IEnumerable<Rectangle> rectangles) | ||
public Bitmap CreateImage(IEnumerable<WordInfo> rectangles) | ||
{ | ||
var image = new Bitmap(width, height); | ||
|
||
DrawCloudLayout(Graphics.FromImage(image), rectangles); | ||
var image = new Bitmap(ImageSize.Width, ImageSize.Height); | ||
DrawСloudOfWords(Graphics.FromImage(image)); | ||
|
||
return image; | ||
} | ||
|
||
private void DrawCloudLayout(Graphics graphics, IEnumerable<Rectangle> rectangles) | ||
private void DrawСloudOfWords(Graphics graphics) | ||
{ | ||
var random = new Random(); | ||
|
||
graphics.FillRectangle(new SolidBrush(backgroundColor), 0, 0, width, height); | ||
// рисуем фон | ||
graphics.FillRectangle(new SolidBrush(BackgroundColor), 0, 0, ImageSize.Width, ImageSize.Height); | ||
|
||
foreach (var rect in rectangles) | ||
//рисуем слова | ||
foreach (var word in wordsInfo) | ||
{ | ||
var color = rectanglePalette[random.Next(rectanglePalette.Length)]; | ||
var color = colorPicker.GetColorForWord(word); | ||
var height = word.NumberInText * coefficient; | ||
var font = new Font(FontFamily, height, GraphicsUnit.Pixel); | ||
var size = graphics.MeasureString(word.Word, font); | ||
var location = layoutProvider.PutNextRectangle(size); | ||
|
||
graphics.FillRectangle(new SolidBrush(color), rect); | ||
graphics.DrawRectangle(new Pen(Color.Black, 1), rect); | ||
graphics.DrawString(word.Word, font, new SolidBrush(color), location); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TagCloud.TextProcessing; | ||
|
||
namespace TagCloud; | ||
|
||
public interface IWordsProvider | ||
{ | ||
public IEnumerable<WordInfo> PerformPreprocessing(string pathToSourceTxtFile); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему тут постой файл. Ещё не доделал или забыл пушнуть?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Щас норм