diff --git a/FamilyTree/ArcCreator.cs b/FamilyTree/ArcCreator.cs index 98b2cbb..1f34c71 100644 --- a/FamilyTree/ArcCreator.cs +++ b/FamilyTree/ArcCreator.cs @@ -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; @@ -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; diff --git a/FamilyTree/CirclePlotter.cs b/FamilyTree/CirclePlotter.cs index f2f8e74..c3c95c8 100644 --- a/FamilyTree/CirclePlotter.cs +++ b/FamilyTree/CirclePlotter.cs @@ -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)); } } } diff --git a/FamilyTree/Constants.cs b/FamilyTree/Constants.cs index 040e03d..fcaf22e 100644 --- a/FamilyTree/Constants.cs +++ b/FamilyTree/Constants.cs @@ -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"; diff --git a/FamilyTree/MathHelper.cs b/FamilyTree/MathHelper.cs index c41691b..79c2c90 100644 --- a/FamilyTree/MathHelper.cs +++ b/FamilyTree/MathHelper.cs @@ -23,7 +23,14 @@ public static IEnumerable 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; } } diff --git a/FamilyTree/Plotter.cs b/FamilyTree/Plotter.cs index 6ca11af..d55dcf7 100644 --- a/FamilyTree/Plotter.cs +++ b/FamilyTree/Plotter.cs @@ -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; diff --git a/FamilyTree/RayPlotter.cs b/FamilyTree/RayPlotter.cs index ccfa711..5ed906e 100644 --- a/FamilyTree/RayPlotter.cs +++ b/FamilyTree/RayPlotter.cs @@ -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; + } } } diff --git a/FamilyTree/RotatedLineCreator.cs b/FamilyTree/RotatedLineCreator.cs index f3ec7c9..b96735e 100644 --- a/FamilyTree/RotatedLineCreator.cs +++ b/FamilyTree/RotatedLineCreator.cs @@ -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); @@ -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; } diff --git a/FamilyTree/TextPlotter.cs b/FamilyTree/TextPlotter.cs index 8d5fbe3..a448433 100644 --- a/FamilyTree/TextPlotter.cs +++ b/FamilyTree/TextPlotter.cs @@ -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; @@ -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) { @@ -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 { @@ -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