Skip to content

Commit

Permalink
Final adjustments for lvl 10
Browse files Browse the repository at this point in the history
  • Loading branch information
smarthome committed Aug 3, 2023
1 parent e293a15 commit fd4a206
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 51 deletions.
8 changes: 4 additions & 4 deletions FamilyTree/ArcCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace FamilyTree
{
public static class ArcCreator
{
public static SvgElement CreateCircle(PointF centre, float radius, Color color)
public static SvgElement CreateCircle(PointF centre, float radius, Color color, float lineWidth)
{
var circle = new SvgCircle();
circle.CenterX = centre.X;
circle.CenterY = centre.Y;
circle.Radius = radius;
circle.Stroke = new SvgColourServer(color);
circle.StrokeWidth = Constants.StrokeWidth;
circle.StrokeWidth = lineWidth;
circle.Fill = new SvgColourServer(Color.Empty);

return circle;
Expand Down Expand Up @@ -48,11 +48,11 @@ public static SvgElement CreateArcText(PointF centre, float radius, float startA
return svgText;
}

public static SvgElement CreateArcBorder(PointF centre, float radius, float startAngle, float endAngle, Color color)
public static SvgElement CreateArcBorder(PointF centre, float radius, float startAngle, float endAngle, Color color, float lineWidth)
{
var path = createArcPath(centre, radius, startAngle, endAngle);
path.Stroke = new SvgColourServer(color);
path.StrokeWidth = Constants.StrokeWidth;
path.StrokeWidth = lineWidth;
path.Fill = new SvgColourServer(Color.Empty);

return path;
Expand Down
12 changes: 6 additions & 6 deletions FamilyTree/CirclePlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ namespace FamilyTree
{
public static class CirclePlotter
{
public static void PlotCircles(SvgDocument document, PointF centre, int numberOfGenerations)
public static void PlotCircles(SvgDocument document, PointF centre, int numberOfGenerations, float lineWidth)
{
var radii = MathHelper.GetCreateRadii(numberOfGenerations).ToArray();
document.Children.Add(ArcCreator.CreateCircle(centre, radii[0], Color.FromArgb(255, 219, 219, 217)));
document.Children.Add(ArcCreator.CreateCircle(centre, radii[0], Color.FromArgb(255, 219, 219, 217), lineWidth));
foreach (var radius in radii.Skip(1))
{
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, -Constants.OuterAngle, -Constants.OuterAngle/2.0f, Color.FromArgb(255, 44, 195, 242)));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, -Constants.OuterAngle / 2.0f, 0, Color.FromArgb(255, 116, 158, 56)));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, 0, Constants.OuterAngle / 2.0f, Color.FromArgb(255, 217, 84, 67)));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, Constants.OuterAngle / 2.0f, Constants.OuterAngle, Color.FromArgb(255, 242, 201, 35)));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, -Constants.OuterAngle, -Constants.OuterAngle/2.0f, Color.FromArgb(255, 44, 195, 242), lineWidth));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, -Constants.OuterAngle / 2.0f, 0, Color.FromArgb(255, 116, 158, 56), lineWidth));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, 0, Constants.OuterAngle / 2.0f, Color.FromArgb(255, 217, 84, 67), lineWidth));
document.Children.Add(ArcCreator.CreateArcBorder(centre, radius, Constants.OuterAngle / 2.0f, Constants.OuterAngle, Color.FromArgb(255, 242, 201, 35), lineWidth));
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions FamilyTree/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
public static class Constants
{
public static int StrokeWidth = 3;
public static int MainFontSize = 9;
public static float ScalingFactor = 50.0f;
public static float OuterAngle = 105.0f;
public static string Font = "Calibri";
Expand Down
9 changes: 8 additions & 1 deletion FamilyTree/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public static IEnumerable<float> GetCreateRadii(int numberOfGenerations)

for (int i = 1; i < numberOfGenerations; ++i)
{
radius = radius + (i > 2 ? 2.0f : 1.0f) * Constants.ScalingFactor;
if(i < 3)
radius = radius + 1.0f * Constants.ScalingFactor;
else if (i < 9)
radius = radius + 2.0f * Constants.ScalingFactor;
else if (i == 9)
radius = radius + 1.5f * Constants.ScalingFactor;
else
radius = radius + 0.75f * Constants.ScalingFactor;
yield return radius;
}
}
Expand Down
2 changes: 1 addition & 1 deletion FamilyTree/Plotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static SvgDocument Plot(Person model, int numberOfGenerations)
var centre = new PointF(outerRadius, outerRadius);

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

return document;
Expand Down
13 changes: 12 additions & 1 deletion FamilyTree/RayPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ public static void PlotRays(SvgDocument document, PointF centre, int numberOfGen
var angles = MathHelper.GetCreateAngles(j+1).ToArray();
for (int i = 0; i < angles.Length; ++i)
{
document.Children.Add(RotatedLineCreator.CreateRotatedLine(centre, radii[j-1], radii[j], angles[i], Color.FromArgb(255, 219, 219, 217)));
document.Children.Add(RotatedLineCreator.CreateRotatedLine(centre, radii[j-1], radii[j], angles[i], Color.FromArgb(255, 219, 219, 217), getLineWidth(j)));
}
}
}

private static float getLineWidth(int currentGeneration)
{
if (currentGeneration < 8)
return 3.0f;
else if (currentGeneration == 8)
return 2.0f;
else if (currentGeneration == 9)
return 1.0f;
return 0.5f;
}
}
}
6 changes: 3 additions & 3 deletions FamilyTree/RotatedLineCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static SvgElement CreateRotatedText(PointF centre, float radius, float an
Fill = new SvgColourServer(color),
Text = text,
Font = Constants.Font,
Transforms = new SvgTransformCollection() {new SvgTranslate(textCentre.X, textCentre.Y), new SvgRotate(adjustAngle(angle)), new SvgTranslate(0 ,Constants.MainFontSize / 4.0f) }
Transforms = new SvgTransformCollection() {new SvgTranslate(textCentre.X, textCentre.Y), new SvgRotate(adjustAngle(angle)), new SvgTranslate(0 ,fontSize / 4.0f) }
};

return svgText;
}

public static SvgElement CreateRotatedLine(PointF centre, float startRadius, float endRadius, float angle, Color color)
public static SvgElement CreateRotatedLine(PointF centre, float startRadius, float endRadius, float angle, Color color, float lineWidth)
{
PointF p1 = MathHelper.CreatePoint(centre, startRadius, angle);
PointF p2 = MathHelper.CreatePoint(centre, endRadius, angle);
Expand All @@ -37,7 +37,7 @@ public static SvgElement CreateRotatedLine(PointF centre, float startRadius, flo
line.EndX = p2.X;
line.EndY = p2.Y;
line.Stroke = new SvgColourServer(color);
line.StrokeWidth = Constants.StrokeWidth;
line.StrokeWidth = lineWidth;

return line;
}
Expand Down
77 changes: 44 additions & 33 deletions FamilyTree/TextPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,49 @@ public static void PlotText(SvgDocument document, PointF centre, Person model, i
var radii = MathHelper.GetCreateRadii(numberOfGenerations).Intersect().Compute(i => (i.start + i.end) / 2.0f).ToArray();

// Main Person
plotMainPerson(document, centre, model);
plotMainPerson(document, centre, model, 12);

// Generation 1
var angleSets_1 = MathHelper.GetCreateAngles(2).Intersect().ToArray();
var personSet_1 = MathHelper.GetPersonsOfLevel(model, 2).ToArray();
plotInnerPersons(document, centre, radii[0], angleSets_1, personSet_1);
plotInnerPersons(document, centre, radii[0], angleSets_1, personSet_1, 12);

// Generation 2
var angleSets_2 = MathHelper.GetCreateAngles(3).Intersect().ToArray();
var personSet_2 = MathHelper.GetPersonsOfLevel(model, 3).ToArray();
plotInnerPersons(document, centre, radii[1], angleSets_2, personSet_2);
plotInnerPersons(document, centre, radii[1], angleSets_2, personSet_2, 12);

// 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, i);
plotOuterPersons(document, centre, radii[i-1], angleSet_N, personSet_N, i, getFontForLevel(i));
}
}

private static void plotOuterPersons(SvgDocument document, PointF centre, float radius, float[] angleSets, Person[] personSet, int currentGeneration)
private static float getFontForLevel(int currentGeneration)
{
if(currentGeneration < 8)
return 12.0f;
else if (currentGeneration == 8)
return 9.0f;
else if (currentGeneration == 9)
return 6.0f;
return 3.0f;
}

private static void plotOuterPersons(SvgDocument document, PointF centre, float radius, float[] angleSets, Person[] personSet, int currentGeneration, float fontSize)
{
for (int i = 0; i < angleSets.Length; ++i)
plotOuterPerson(document, centre, radius, angleSets[i], personSet[i], currentGeneration);
plotOuterPerson(document, centre, radius, angleSets[i], personSet[i], currentGeneration, fontSize);

}

private static void plotOuterPerson(SvgDocument document, PointF centre, float radius, float angle, Person person, int currentGeneration)
private static void plotOuterPerson(SvgDocument document, PointF centre, float radius, float angle, Person person, int currentGeneration, float fontSize)
{
// x / ( 2 * pi * r) = deltaAngle / 360
var deltaAngle = Constants.MainFontSize / (2.0f * MathF.PI * radius) * 360.0f;
var deltaAngle = fontSize / (2.0f * MathF.PI * radius) * 360.0f;
if (angle < 0)
deltaAngle = -deltaAngle;

Expand All @@ -55,21 +66,21 @@ private static void plotOuterPerson(SvgDocument document, PointF centre, float r
angle - deltaAngle,
person.Name,
Color.Black,
Constants.MainFontSize));
fontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
fontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle,
createYearText(person),
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));
fontSize));
}
else if (currentGeneration < 7)
{
Expand All @@ -79,14 +90,14 @@ private static void plotOuterPerson(SvgDocument document, PointF centre, float r
angle - deltaAngle /2.0f,
person.Name,
Color.Black,
Constants.MainFontSize));
fontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle / 2.0f,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
fontSize));
}
else
{
Expand All @@ -97,56 +108,56 @@ private static void plotOuterPerson(SvgDocument document, PointF centre, float r
angle,
name,
Color.Black,
Constants.MainFontSize));
fontSize));
}
}

private static void plotInnerPersons(SvgDocument document, PointF centre, float radius, (float start, float end)[] angleSets, Person[] personSet)
private static void plotInnerPersons(SvgDocument document, PointF centre, float radius, (float start, float end)[] angleSets, Person[] personSet, float fontSize)
{
for(int i = 0; i <angleSets.Length; ++i)
plotInnerPerson(document, centre, radius, angleSets[i], personSet[i]);
plotInnerPerson(document, centre, radius, angleSets[i], personSet[i], fontSize);

}

private static void plotInnerPerson(SvgDocument document, PointF centre, float radius, (float innerAngle, float outerAngle) angle, Person person)
private static void plotInnerPerson(SvgDocument document, PointF centre, float radius, (float innerAngle, float outerAngle) angle, Person person, float fontSize)
{
document.Children.Add(ArcCreator.CreateArcText( centre,
radius + Constants.MainFontSize,
radius + fontSize,
angle.innerAngle,
angle.outerAngle,
person.Name,
Color.Black,
Constants.MainFontSize));
fontSize));
document.Children.Add(ArcCreator.CreateArcText( centre,
radius,
angle.innerAngle,
angle.outerAngle,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
Color.Black,
fontSize));
document.Children.Add(ArcCreator.CreateArcText( centre,
radius - Constants.MainFontSize,
radius - fontSize,
angle.innerAngle,
angle.outerAngle,
createYearText(person),
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));
Color.FromArgb(255, 139, 139, 142),
fontSize));
}

private static void plotMainPerson(SvgDocument document, PointF centre, Person person)
private static void plotMainPerson(SvgDocument document, PointF centre, Person person, float fontSize)
{
document.Children.Add(TextCreator.CreateHorizontalText(new PointF(centre.X, centre.Y - Constants.MainFontSize),
document.Children.Add(TextCreator.CreateHorizontalText(new PointF(centre.X, centre.Y - fontSize),
person.Name,
Color.Black,
Constants.MainFontSize));
Color.Black,
fontSize));
document.Children.Add(TextCreator.CreateHorizontalText( centre,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
document.Children.Add(TextCreator.CreateHorizontalText( new PointF(centre.X, centre.Y + Constants.MainFontSize),
Color.Black,
fontSize));
document.Children.Add(TextCreator.CreateHorizontalText( new PointF(centre.X, centre.Y + fontSize),
createYearText(person),
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));
Color.FromArgb(255, 139, 139, 142),
fontSize));
}

private static string createYearText(Person person)
Expand Down

0 comments on commit fd4a206

Please sign in to comment.