Skip to content

Commit

Permalink
Small plot corrections. Drawing up to level 9
Browse files Browse the repository at this point in the history
  • Loading branch information
smarthome committed Aug 3, 2023
1 parent 666811a commit e293a15
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
2 changes: 1 addition & 1 deletion FamilyTree/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public static class Constants
{
public static int StrokeWidth = 3;
public static int MainFontSize = 10;
public static int MainFontSize = 9;
public static float ScalingFactor = 50.0f;
public static float OuterAngle = 105.0f;
public static string Font = "Calibri";
Expand Down
2 changes: 1 addition & 1 deletion FamilyTree/RotatedLineCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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)) }
Transforms = new SvgTransformCollection() {new SvgTranslate(textCentre.X, textCentre.Y), new SvgRotate(adjustAngle(angle)), new SvgTranslate(0 ,Constants.MainFontSize / 4.0f) }
};

return svgText;
Expand Down
82 changes: 57 additions & 25 deletions FamilyTree/TextPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,76 @@ public static void PlotText(SvgDocument document, PointF centre, Person model, 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);
plotOuterPersons(document, centre, radii[i-1], angleSet_N, personSet_N, i);
}
}

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

}

private static void plotOuterPerson(SvgDocument document, PointF centre, float radius, float angle, Person person)
private static void plotOuterPerson(SvgDocument document, PointF centre, float radius, float angle, Person person, int currentGeneration)
{
// 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.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle,
createYearText(person),
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));

if (currentGeneration < 6)
{
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle - deltaAngle,
person.Name,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle,
createYearText(person),
Color.FromArgb(255, 139, 139, 142),
Constants.MainFontSize));
}
else if (currentGeneration < 7)
{
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle - deltaAngle /2.0f,
person.Name,
Color.Black,
Constants.MainFontSize));
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle + deltaAngle / 2.0f,
person.FamilyName,
Color.Black,
Constants.MainFontSize));
}
else
{
var name = $"{person.Name.Remove(1,person.Name.Length - 1)}.{person.FamilyName}";
document.Children.Add(RotatedLineCreator.CreateRotatedText(
centre,
radius,
angle,
name,
Color.Black,
Constants.MainFontSize));
}
}

private static void plotInnerPersons(SvgDocument document, PointF centre, float radius, (float start, float end)[] angleSets, Person[] personSet)
Expand Down

0 comments on commit e293a15

Please sign in to comment.