Skip to content

Commit

Permalink
Plotter for Generations < 7
Browse files Browse the repository at this point in the history
  • Loading branch information
smarthome committed Aug 3, 2023
1 parent f0e1686 commit 666811a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
22 changes: 22 additions & 0 deletions FamilyTree/ModelMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace FamilyTree
{
public static class ModelMock
{
public static Person Create(int numberOfGenerations)
{
return create(numberOfGenerations, 1);
}

private static Person create(int currentGeneration, int extend)
{
if(currentGeneration == 0)
return new Person($"Name{extend}", $"FamilyName{extend}", 1900 + extend, 2100 - extend, false, null, null);
else
{
var person1 = create(currentGeneration - 1, extend * 2);
var person2 = create(currentGeneration - 1, extend * 2 + 1);
return new Person($"Name{extend}", $"FamilyName{extend}", 1900 + extend, 2100 - extend, false, person1, person2);
}
}
}
}
27 changes: 27 additions & 0 deletions FamilyTree/Plotter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Svg;
using System.Drawing;
using System.Linq;

namespace FamilyTree
{
public static class Plotter
{
public static SvgDocument Plot(Person model, int numberOfGenerations)
{
var outerRadius = MathHelper.GetCreateRadii(numberOfGenerations).Last() + 20;
var size = new SizeF(2 * outerRadius, 2 * outerRadius);
var document = new SvgDocument();
document.Width = size.Width;
document.Height = size.Height;
document.Ppi = 96;

var centre = new PointF(outerRadius, outerRadius);

RayPlotter.PlotRays(document, centre, numberOfGenerations);
CirclePlotter.PlotCircles(document, centre, numberOfGenerations);
TextPlotter.PlotText(document, centre, model, numberOfGenerations);

return document;
}
}
}
21 changes: 13 additions & 8 deletions FamilyTree/TextPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ public static void PlotText(SvgDocument document, PointF centre, Person model, i
var personSet_2 = MathHelper.GetPersonsOfLevel(model, 3).ToArray();
plotInnerPersons(document, centre, radii[1], angleSets_2, personSet_2);

// Generation 3
var angleSet_3 = MathHelper.GetCreateAngles(4).Intersect().Compute(i => (i.start + i.end) / 2.0f).ToArray();
var personSet_3 = MathHelper.GetPersonsOfLevel(model, 4).ToArray();
plotOuterPersons(document, centre, radii[2], angleSet_3, personSet_3);
// Generation 3 .. n
for (int i = 3; i < numberOfGenerations; ++i)
{
var angleSet_N = MathHelper.GetCreateAngles(i+1).Intersect().Compute(i => (i.start + i.end) / 2.0f).ToArray();
var personSet_N = MathHelper.GetPersonsOfLevel(model, i+1).ToArray();
plotOuterPersons(document, centre, radii[i-1], angleSet_N, personSet_N);
}
}

private static void plotOuterPersons(SvgDocument document, PointF centre, float radius, float[] angleSets, Person[] personSet)
Expand All @@ -41,26 +44,28 @@ private static void plotOuterPerson(SvgDocument document, PointF centre, float r
{
// x / ( 2 * pi * r) = deltaAngle / 360
var deltaAngle = Constants.MainFontSize / (2.0f * MathF.PI * radius) * 360.0f;
if (angle < 0)
deltaAngle = -deltaAngle;
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle - deltaAngle,
person.Name,
Color.Red,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle,
person.FamilyName,
Color.Red,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle,
createYearText(person),
Color.Red,
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));
}

Expand Down

0 comments on commit 666811a

Please sign in to comment.