summaryrefslogtreecommitdiffstats
path: root/src/CS340.Plotter/TourPlot.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/CS340.Plotter/TourPlot.cs')
-rw-r--r--src/CS340.Plotter/TourPlot.cs26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/CS340.Plotter/TourPlot.cs b/src/CS340.Plotter/TourPlot.cs
index 11f23ba..7c03957 100644
--- a/src/CS340.Plotter/TourPlot.cs
+++ b/src/CS340.Plotter/TourPlot.cs
@@ -1,3 +1,4 @@
+using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
@@ -10,10 +11,15 @@ namespace Plotter
{
public Tour Tour { get; set; }
public PictureBox Canvas { get; set; }
+ public Label WeightLabel { get; set; }
+ public Label RuntimeLabel { get; set; }
+ public TimeSpan RunTime { get; set; }
- public TourPlot(PictureBox canvas)
+ public TourPlot(PictureBox canvas, Label weightLabel, Label runtimeLabel)
{
Canvas = canvas;
+ WeightLabel = weightLabel;
+ RuntimeLabel = runtimeLabel;
}
public void Render()
@@ -26,6 +32,7 @@ namespace Plotter
using Font font = new("Arial", 16);
using Font gridFont = new("Arial", 10);
using SolidBrush brush = new(Color.Black);
+ using StringFormat stringFormat = new StringFormat();
gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
gfx.Clear(Color.White);
@@ -35,12 +42,16 @@ namespace Plotter
Point left = ScaleLocation(new Coordinate(0, i));
Point right = ScaleLocation(new Coordinate(100, i));
gfx.DrawLine(gridPen, left, right);
- gfx.DrawString(i.ToString(), gridFont, brush, left);
+ stringFormat.Alignment = StringAlignment.Far;
+ stringFormat.LineAlignment = StringAlignment.Center;
+ gfx.DrawString(i.ToString(), gridFont, brush, left, stringFormat);
Point bottom = ScaleLocation(new Coordinate(i, 0));
Point top = ScaleLocation(new Coordinate(i, 100));
gfx.DrawLine(gridPen, bottom, top);
- gfx.DrawString(i.ToString(), gridFont, brush, bottom);
+ stringFormat.Alignment = StringAlignment.Center;
+ stringFormat.LineAlignment = StringAlignment.Near;
+ gfx.DrawString(i.ToString(), gridFont, brush, bottom, stringFormat);
}
foreach (City city in Tour.Cities.Where(city => city.Parent != -1))
@@ -58,10 +69,15 @@ namespace Plotter
Canvas.Image?.Dispose();
Canvas.Image = (Bitmap)bmp.Clone();
+ RuntimeLabel.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
+ RunTime.Hours, RunTime.Minutes, RunTime.Seconds, RunTime.Milliseconds / 10);
+
+ WeightLabel.Text = Tour.Weight.ToString("F3");
+
Point ScaleLocation(Coordinate coordinate)
{
- int x = Canvas.Width * (coordinate.X + 10) / Scaler;
- int y = Canvas.Height * ((coordinate.Y - 100) * -1 + 15) / Scaler;
+ int x = Canvas.Width * (coordinate.X + 12) / Scaler;
+ int y = Canvas.Height * ((coordinate.Y - 100) * -1 + 12) / Scaler;
return new Point(x, y);
}