Skip to content

Commit

Permalink
Person Deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
smarthome committed Aug 6, 2023
1 parent 5ef5900 commit 87f5959
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion FamilyTree/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public static IEnumerable<float> GetCreateRadii(int numberOfGenerations)
{
if(i < 3)
radius = radius + 1.0f * Constants.ScalingFactor;
else if (i < 9)
else if (i < 7)
radius = radius + 2.0f * Constants.ScalingFactor;
else if (i < 9)
radius = radius + 3.0f * Constants.ScalingFactor;
else if (i == 9)
radius = radius + 1.5f * Constants.ScalingFactor;
else
Expand Down
22 changes: 22 additions & 0 deletions FamilyTree/PersonDeserializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Xml.Linq;

namespace FamilyTree
{
public static class PersonDeserializer
{
public static Person Deserialize(XElement root)
{
if (root == null)
return null;

var name = root.Attribute("Name").Value;
var familiyName = root.Attribute("FamilyName").Value;
int.TryParse(root.Attribute("Birth")?.Value, out var birthYear);
int.TryParse(root.Attribute("Death")?.Value, out var deathYear);
bool.TryParse(root.Attribute("IsAlive")?.Value, out var isAlive);
var father = Deserialize(root.Element("Father"));
var mother = Deserialize(root.Element("Mother"));
return new Person(name, familiyName, birthYear, deathYear, isAlive, father, mother);
}
}
}
9 changes: 8 additions & 1 deletion FamilyTree/TextPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private static void plotOuterPersons(SvgDocument document, PointF centre, float

private static void plotOuterPerson(SvgDocument document, PointF centre, float radius, float angle, Person person, int currentGeneration, float fontSize)
{
if (person == Person.NoPerson)
return;
// x / ( 2 * pi * r) = deltaAngle / 360
var deltaAngle = fontSize / (2.0f * MathF.PI * radius) * 360.0f;
if (angle < 0)
Expand Down Expand Up @@ -101,7 +103,8 @@ private static void plotOuterPerson(SvgDocument document, PointF centre, float r
}
else
{
var name = $"{person.Name.Remove(1,person.Name.Length - 1)}.{person.FamilyName}";
//var name = $"{person.Name.Remove(1,person.Name.Length - 1)}.{person.FamilyName}";
var name = $"{person.Name} {person.FamilyName}";
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
Expand All @@ -121,6 +124,8 @@ private static void plotInnerPersons(SvgDocument document, PointF centre, float

private static void plotInnerPerson(SvgDocument document, PointF centre, float radius, (float innerAngle, float outerAngle) angle, Person person, float fontSize)
{
if (person == Person.NoPerson)
return;
document.Children.Add(ArcCreator.CreateArcText( centre,
radius + fontSize,
angle.innerAngle,
Expand All @@ -146,6 +151,8 @@ private static void plotInnerPerson(SvgDocument document, PointF centre, float r

private static void plotMainPerson(SvgDocument document, PointF centre, Person person, float fontSize)
{
if (person == Person.NoPerson)
return;
document.Children.Add(TextCreator.CreateHorizontalText(new PointF(centre.X, centre.Y - fontSize),
person.Name,
Color.Black,
Expand Down

0 comments on commit 87f5959

Please sign in to comment.