Esempio n. 1
0
        public static Dictionary<WaypointAttribute, RouteLineSettings> CreateDefaultRouteLineSettingsCollection()
        {
            var coll = new Dictionary<WaypointAttribute, RouteLineSettings>();
              RouteLineSettings rls;

              // default pace line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                       Color.FromArgb(128, Color.Yellow), 0.5,
                       Color.FromArgb(128, Color.Red), 1.0),
              3.5 * 60, 10 * 60),
            3,
            Color.FromArgb(160, Color.Black),
            1.5,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.Pace.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.Pace, rls);

              // default speed line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(128, Color.Red), 0.0,
                       Color.FromArgb(128, Color.Yellow), 0.5,
                       Color.FromArgb(128, Color.Green), 1.0),
              5, 20),
            3,
            Color.FromArgb(160, Color.Blue),
            1.5,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.Speed.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.Speed, rls);

              // default heart rate line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                       Color.FromArgb(128, Color.Yellow), 0.5,
                       Color.FromArgb(128, Color.Red), 1.0),
              120, 190),
            3,
            Color.FromArgb(160, Color.DarkRed),
            1.5,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.HeartRate.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.HeartRate, rls);

              // default altitude line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                       Color.FromArgb(128, Color.Yellow), 1.0 / 3,
                       Color.FromArgb(128, Color.Red), 2.0 / 3,
                       Color.FromArgb(128, Color.Blue), 1.0),
              0, 500),
            3,
            Color.FromArgb(160, Color.Brown),
            1.5,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.Altitude.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.Altitude, rls);

              // default direction line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(0, Color.White), 0.0,
                       Color.FromArgb(128, Color.Yellow), 0.5,
                       Color.FromArgb(128, Color.Red), 1.0),
              0, 45),
            3,
            Color.FromArgb(160, Color.Black),
            2,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.DirectionDeviationToNextLap.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.DirectionDeviationToNextLap, rls);

              // default map reading duration line settings
              rls = new RouteLineSettings(
            new ColorRange(
              new Gradient(Color.FromArgb(0, Color.White), 0.0,
                       Color.FromArgb(128, 255, 128, 128), 0.0001,
                       Color.FromArgb(128, 255, 0, 0), 0.5,
                       Color.FromArgb(128, 128, 0, 0), 1.0),
              0, 10),
            3,
            Color.FromArgb(160, Color.Black),
            2,
            true,
            0);
              // TODO: localize
              rls.ColorRange.Gradient.Name = WaypointAttribute.MapReadingDuration.ToString();
              rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
              rls.MonochromeWidth = rls.Width;
              coll.Add(WaypointAttribute.MapReadingDuration, rls);

              return coll;
        }
Esempio n. 2
0
 public KmlProperties(RouteLineSettings rls)
     : this()
 {
     RouteLineStyle.Color = rls.MonochromeColor;
       RouteLineStyle.Width = rls.MonochromeWidth;
       ReplayMarkerStyle.Color = rls.MonochromeColor;
       ReplayMarkerStyle.Size = replayMarkerSizeFactor * rls.MonochromeWidth;
 }
Esempio n. 3
0
        public static Dictionary <WaypointAttribute, RouteLineSettings> CreateDefaultRouteLineSettingsCollection()
        {
            var coll = new Dictionary <WaypointAttribute, RouteLineSettings>();
            RouteLineSettings rls;

            // default pace line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Red), 1.0),
                    3.5 * 60, 10 * 60),
                3,
                Color.FromArgb(160, Color.Black),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.Pace.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.Pace, rls);

            // default speed line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Red), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Green), 1.0),
                    5, 20),
                3,
                Color.FromArgb(160, Color.Blue),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.Speed.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.Speed, rls);

            // default heart rate line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Red), 1.0),
                    120, 190),
                3,
                Color.FromArgb(160, Color.DarkRed),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.HeartRate.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.HeartRate, rls);

            // default altitude line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 1.0 / 3,
                                 Color.FromArgb(128, Color.Red), 2.0 / 3,
                                 Color.FromArgb(128, Color.Blue), 1.0),
                    0, 500),
                3,
                Color.FromArgb(160, Color.Brown),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.Altitude.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.Altitude, rls);

            // default direction line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(0, Color.White), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Red), 1.0),
                    0, 45),
                3,
                Color.FromArgb(160, Color.Black),
                2,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.DirectionDeviationToNextLap.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.DirectionDeviationToNextLap, rls);

            // default map reading duration line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(0, Color.White), 0.0,
                                 Color.FromArgb(128, 255, 128, 128), 0.0001,
                                 Color.FromArgb(128, 255, 0, 0), 0.5,
                                 Color.FromArgb(128, 128, 0, 0), 1.0),
                    0, 10),
                3,
                Color.FromArgb(160, Color.Black),
                2,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.MapReadingDuration.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.MapReadingDuration, rls);

            // default cadence line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Red), 1.0),
                    30, 150),
                3,
                Color.FromArgb(160, Color.DarkCyan),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.Cadence.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.Cadence, rls);

            // default power line settings
            rls = new RouteLineSettings(
                new ColorRange(
                    new Gradient(Color.FromArgb(128, Color.Green), 0.0,
                                 Color.FromArgb(128, Color.Yellow), 0.5,
                                 Color.FromArgb(128, Color.Red), 1.0),
                    0, 600),
                3,
                Color.FromArgb(160, Color.DarkMagenta),
                1.5,
                true,
                0);
            // TODO: localize
            rls.ColorRange.Gradient.Name = WaypointAttribute.Power.ToString();
            rls.MonochromeColor          = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth          = rls.Width + 2 * rls.MaskWidth;
            coll.Add(WaypointAttribute.Power, rls);

            return(coll);
        }
Esempio n. 4
0
        public void Draw(Graphics g, RectangleF drawingRectangle)
        {
            if (yAxisNumericConverter == null)
            {
                return;
            }
            if (yAxisScaleCreator == null)
            {
                return;
            }

            Brush fontBrush = new SolidBrush(fontColor);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            // calculate caption sizes
            SizeF xAxisCaptionSize = g.MeasureString(xAxisCaption, font);
            SizeF yAxisCaptionSize = g.MeasureString(yAxisCaption, font);

            // calculate max x axis label size
            switch (xAxisAttribute)
            {
            case DomainAttribute.TimeOfDay:
                xAxisNumericConverter = new TimeConverter(TimeConverter.TimeConverterType.TimeOfDay);
                XAxisScaleCreator     = new TimeScaleCreator(xAxisMinValue, xAxisMaxValue, 15, false);
                break;

            case DomainAttribute.ElapsedTime:
                xAxisNumericConverter = new TimeConverter(TimeConverter.TimeConverterType.ElapsedTime);
                XAxisScaleCreator     = new TimeScaleCreator(xAxisMinValue, xAxisMaxValue, 15, false);
                break;

            case DomainAttribute.Distance:
                xAxisNumericConverter = new NumericConverter();
                XAxisScaleCreator     = new DoubleScaleCreator(xAxisMinValue, xAxisMaxValue, 15, false);
                break;
            }

            SizeF maxXAxisLabelSize = SizeF.Empty;

            for (int i = 0; i < xAxisScaleCreator.NoOfMarkers; i++)
            {
                double value     = xAxisScaleCreator.MarkerValue(i);
                string label     = xAxisNumericConverter.ToString(value);
                SizeF  labelSize = g.MeasureString(label, font);
                maxXAxisLabelSize.Width  = Math.Max(maxXAxisLabelSize.Width, labelSize.Width);
                maxXAxisLabelSize.Height = Math.Max(maxXAxisLabelSize.Height, labelSize.Height);
            }

            // calculate max y axis label size
            SizeF maxYAxisLabelSize = SizeF.Empty;

            for (int i = 0; i < yAxisScaleCreator.NoOfMarkers; i++)
            {
                double value     = yAxisScaleCreator.MarkerValue(i);
                string label     = yAxisNumericConverter.ToString(value);
                SizeF  labelSize = g.MeasureString(label, font);
                maxYAxisLabelSize.Width  = Math.Max(maxYAxisLabelSize.Width, labelSize.Width);
                maxYAxisLabelSize.Height = Math.Max(maxYAxisLabelSize.Height, labelSize.Height);
            }

            // calculate graph drawing rectangle
            float leftMargin = Math.Max(1.5F * yAxisCaptionSize.Height + maxYAxisLabelSize.Width, maxXAxisLabelSize.Width / 2);
            int   width      = (int)(drawingRectangle.Width - leftMargin - maxXAxisLabelSize.Width / 2 - 1);
            int   height     = (int)(drawingRectangle.Height - maxYAxisLabelSize.Height / 2 - maxXAxisLabelSize.Height - xAxisCaptionSize.Height - 1);

            graphDrawingRectangle = new Rectangle(
                (int)(drawingRectangle.Left + leftMargin),
                (int)(drawingRectangle.Top + maxYAxisLabelSize.Height / 2),
                Math.Max(width, 1),
                Math.Max(height, 1));

            // draw graph background
            g.FillRectangle(lineGraphBackgroundBrush, GraphDrawingRectangle);

            // draw the axis labels
            // x axis
            for (int i = 0; i < xAxisScaleCreator.NoOfMarkers; i++)
            {
                double value     = xAxisScaleCreator.MarkerValue(i);
                int    x         = (int)Math.Round(ValueToX(value));
                string label     = xAxisNumericConverter.ToString(value);
                SizeF  labelSize = g.MeasureString(label, font);
                g.DrawString(label, font, fontBrush, new PointF(x - labelSize.Width / 2, GraphDrawingRectangle.Bottom));
                g.DrawLine(gridPen, new Point(x, GraphDrawingRectangle.Top), new Point(x, GraphDrawingRectangle.Bottom));
            }
            // y axis
            for (int i = 0; i < yAxisScaleCreator.NoOfMarkers; i++)
            {
                double value     = yAxisScaleCreator.MarkerValue(i);
                int    y         = (int)Math.Round(ValueToY(value));
                string label     = yAxisNumericConverter.ToString(value);
                SizeF  labelSize = g.MeasureString(label, font);
                g.DrawString(label, font, fontBrush, new PointF(GraphDrawingRectangle.Left - labelSize.Width, y - maxYAxisLabelSize.Height / 2));
                g.DrawLine(gridPen, new Point(GraphDrawingRectangle.Left, y), new Point(GraphDrawingRectangle.Right, y));
            }

            // draw the axis captions
            // x axis
            PointF xAxisCaptionLocation = new PointF(
                GraphDrawingRectangle.Left + (GraphDrawingRectangle.Width - xAxisCaptionSize.Width) / 2,
                GraphDrawingRectangle.Bottom + xAxisCaptionSize.Height);

            g.DrawString(xAxisCaption, font, fontBrush, xAxisCaptionLocation);
            // y axis, rotated 90 degrees
            PointF yAxisCaptionLocation = new PointF(
                GraphDrawingRectangle.Left - 3 * yAxisCaptionSize.Height,
                GraphDrawingRectangle.Bottom - (GraphDrawingRectangle.Height - yAxisCaptionSize.Width) / 2);

            g.ResetTransform();
            g.TranslateTransform(-yAxisCaptionLocation.X, -yAxisCaptionLocation.Y, MatrixOrder.Append);
            g.RotateTransform(-90F, MatrixOrder.Append);
            g.TranslateTransform(yAxisCaptionLocation.X, yAxisCaptionLocation.Y, MatrixOrder.Append);
            g.DrawString(yAxisCaption, font, fontBrush, yAxisCaptionLocation);
            g.ResetTransform();

            // create the line points
            var polygonList = new List <List <PointF> >();

            if (pointsList != null)
            {
                foreach (var points in pointsList)
                {
                    GraphicsPath path    = new GraphicsPath();
                    var          polygon = new List <PointF> {
                        new PointF(ValueToX(points[0].X), GraphDrawingRectangle.Bottom)
                    };
                    foreach (LineGraphPoint p in points)
                    {
                        polygon.Add(new PointF(ValueToX(p.X), ValueToY(p.Y)));
                    }
                    polygon.Add(new PointF(ValueToX(points[points.Count - 1].X), GraphDrawingRectangle.Bottom));
                    path.AddPolygon(polygon.ToArray());
                    polygonList.Add(polygon);
                    g.SetClip(path);

                    RouteLineSettings rls = session.Settings.RouteLineSettingsCollection[yAxisAttribute];

                    // draw the gradient filling
                    Bitmap   templateBitmap     = new Bitmap(32, GraphDrawingRectangle.Height);
                    Graphics templateGraphics   = Graphics.FromImage(templateBitmap);
                    double   colorRangeInterval = rls.ColorRange.EndValue - rls.ColorRange.StartValue;
                    if (colorRangeInterval == 0)
                    {
                        colorRangeInterval = 0.00001;
                    }
                    rls.ColorRange.Gradient.Draw(
                        templateGraphics,
                        new Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height),
                        (yAxisMinValue - rls.ColorRange.StartValue) / colorRangeInterval,
                        1 + (yAxisMaxValue - rls.ColorRange.EndValue) / colorRangeInterval,
                        Gradient.Direction.ReverseVertical);
                    templateGraphics.Dispose();
                    for (int i = 0; i < GraphDrawingRectangle.Width; i += templateBitmap.Width)
                    {
                        g.DrawImage(templateBitmap, GraphDrawingRectangle.Left + i, GraphDrawingRectangle.Top);
                    }
                }
            }

            g.SetClip(GraphDrawingRectangle);

            // draw lap lines
            foreach (Lap lap in session.Laps)
            {
                double xValue = 0;
                switch (xAxisAttribute)
                {
                case DomainAttribute.TimeOfDay:
                    xValue = (double)lap.Time.ToLocalTime().Ticks / TimeSpan.TicksPerSecond;
                    break;

                case DomainAttribute.ElapsedTime:
                    xValue =
                        session.Route.GetAttributeFromParameterizedLocation(
                            WaypointAttribute.ElapsedTime,
                            session.Route.GetParameterizedLocationFromTime(lap.Time)).Value;
                    break;

                case DomainAttribute.Distance:
                    xValue =
                        session.Route.GetAttributeFromParameterizedLocation(
                            WaypointAttribute.Distance,
                            session.Route.GetParameterizedLocationFromTime(lap.Time)).Value;
                    break;
                }

                int x = (int)Math.Round(ValueToX(xValue));
                g.DrawLine(lapPen, x, graphDrawingRectangle.Top, x, graphDrawingRectangle.Bottom);
            }

            // draw the line above the gradient area
            foreach (var polygon in polygonList)
            {
                g.DrawLines(linePen, polygon.ToArray());
            }
            g.ResetClip();
            g.DrawRectangle(borderPen, GraphDrawingRectangle);

            // dispose drawing objects
            fontBrush.Dispose();
        }