Ejemplo n.º 1
0
        public double GetYValueFromXValue(double xValue)
        {
            if (pointsList == null)
            {
                return(0);
            }
            LineGraphPoint p0 = null;
            LineGraphPoint p1 = null;

            foreach (var points in pointsList)
            {
                foreach (var p in points)
                {
                    if (p.X <= xValue && (p0 == null || p.X >= p0.X))
                    {
                        p0 = p;
                    }
                    if (p.X >= xValue && (p1 == null || p.X < p1.X))
                    {
                        p1 = p;
                    }
                }
            }
            if (p0 == null || p1 == null)
            {
                return(0);
            }
            if (p0.X == p1.X)
            {
                return(p0.Y);
            }
            return(p0.Y + (xValue - p0.X) / (p1.X - p0.X) * (p1.Y - p0.Y));
        }
Ejemplo n.º 2
0
        public void Calculate()
        {
            pointsList = new List<List<LineGraphPoint>>();
              DateTime startTime = session.Route.GetTimeFromParameterizedLocation(StartPL);
              DateTime endTime = session.Route.GetTimeFromParameterizedLocation(EndPL);

              foreach (RouteSegment rs in session.Route.Segments)
              {
            var points = new List<LineGraphPoint>();
            for (var i = 0; i < rs.Waypoints.Count; i++)
            {
              var previousWaypoint = i > 0 ? rs.Waypoints[i - 1] : null;
              var thisWaypoint = rs.Waypoints[i];
              var nextWaypoint = i < rs.Waypoints.Count - 1 ? rs.Waypoints[i + 1] : null;

              if (thisWaypoint.Time >= startTime && thisWaypoint.Time <= endTime)
              {
            var p = new LineGraphPoint
                      {
                        X = GetXValue(thisWaypoint),
                        Y = GetYValue(thisWaypoint),
                        Type = (i == 0 ? LineGraphPointType.Start
                                       : (i == rs.Waypoints.Count - 1 ? LineGraphPointType.End : LineGraphPointType.Intermediate))
                      };

            // handle null values
            List<LineGraphPoint> beforePoints = null;
            List<LineGraphPoint> afterPoints = null;
            if (previousWaypoint != null)
            {
              if (YAxisAttributeIsMapReadingAttribute && thisWaypoint.MapReadingState == MapReadingState.StartReading)
              {
                beforePoints = new List<LineGraphPoint>()
                                 {
                                   new LineGraphPoint() {X = p.X, Y = 0, Type = LineGraphPointType.Intermediate},
                                 };
              }
              else if (!previousWaypoint.Attributes[yAxisAttribute].HasValue && thisWaypoint.Attributes[yAxisAttribute].HasValue)
              {
                beforePoints = new List<LineGraphPoint>()
                {
                  new LineGraphPoint() {X = (GetXValue(previousWaypoint) + p.X)/2, Y = 0, Type = LineGraphPointType.Intermediate},
                  new LineGraphPoint() {X = (GetXValue(previousWaypoint) + p.X)/2, Y = p.Y, Type = LineGraphPointType.Intermediate}
                };
              }
            }
            if (nextWaypoint != null)
            {
              if (YAxisAttributeIsMapReadingAttribute && thisWaypoint.MapReadingState == MapReadingState.EndReading)
              {
                afterPoints = new List<LineGraphPoint>()
                                 {
                                   new LineGraphPoint() {X = p.X, Y = 0, Type = LineGraphPointType.Intermediate},
                                 };
              }
              else if (!nextWaypoint.Attributes[yAxisAttribute].HasValue && thisWaypoint.Attributes[yAxisAttribute].HasValue)
              {
                afterPoints = new List<LineGraphPoint>()
                {
                  new LineGraphPoint() {X = (GetXValue(nextWaypoint) + p.X)/2, Y = p.Y, Type = LineGraphPointType.Intermediate},
                  new LineGraphPoint() {X = (GetXValue(nextWaypoint) + p.X)/2, Y = 0, Type = LineGraphPointType.Intermediate}
                };
              }
            }
            if (beforePoints != null) points.AddRange(beforePoints);
            points.Add(p);
            if (afterPoints != null) points.AddRange(afterPoints);
              }
            }
            if (points.Count > 0)
            {
              points[0].Type = LineGraphPointType.Start;
              points[points.Count - 1].Type = LineGraphPointType.End;
              pointsList.Add(points);
            }
              }

              bool first = true;
              foreach (var points in pointsList)
              {
            foreach (var p in points)
            {
              if (first || p.X < xAxisMinValue) xAxisMinValue = p.X;
              if (first || p.X > xAxisMaxValue) xAxisMaxValue = p.X;
              //if (first || p.Y < yAxisMinValue) yAxisMinValue = p.Y;
              //if (first || p.Y > yAxisMaxValue) yAxisMaxValue = p.Y;
              first = false;
            }
              }
        }
Ejemplo n.º 3
0
        public void Calculate()
        {
            pointsList = new List <List <LineGraphPoint> >();
            DateTime startTime = session.Route.GetTimeFromParameterizedLocation(StartPL);
            DateTime endTime   = session.Route.GetTimeFromParameterizedLocation(EndPL);

            foreach (RouteSegment rs in session.Route.Segments)
            {
                var points = new List <LineGraphPoint>();
                for (var i = 0; i < rs.Waypoints.Count; i++)
                {
                    var previousWaypoint = i > 0 ? rs.Waypoints[i - 1] : null;
                    var thisWaypoint     = rs.Waypoints[i];
                    var nextWaypoint     = i < rs.Waypoints.Count - 1 ? rs.Waypoints[i + 1] : null;

                    if (thisWaypoint.Time >= startTime && thisWaypoint.Time <= endTime)
                    {
                        var p = new LineGraphPoint
                        {
                            X    = GetXValue(thisWaypoint),
                            Y    = GetYValue(thisWaypoint),
                            Type = (i == 0 ? LineGraphPointType.Start
                                       : (i == rs.Waypoints.Count - 1 ? LineGraphPointType.End : LineGraphPointType.Intermediate))
                        };

                        // handle null values
                        List <LineGraphPoint> beforePoints = null;
                        List <LineGraphPoint> afterPoints  = null;
                        if (previousWaypoint != null)
                        {
                            if (YAxisAttributeIsMapReadingAttribute && thisWaypoint.MapReadingState == MapReadingState.StartReading)
                            {
                                beforePoints = new List <LineGraphPoint>()
                                {
                                    new LineGraphPoint()
                                    {
                                        X = p.X, Y = 0, Type = LineGraphPointType.Intermediate
                                    },
                                };
                            }
                            else if (!previousWaypoint.Attributes[yAxisAttribute].HasValue && thisWaypoint.Attributes[yAxisAttribute].HasValue)
                            {
                                beforePoints = new List <LineGraphPoint>()
                                {
                                    new LineGraphPoint()
                                    {
                                        X = (GetXValue(previousWaypoint) + p.X) / 2, Y = 0, Type = LineGraphPointType.Intermediate
                                    },
                                    new LineGraphPoint()
                                    {
                                        X = (GetXValue(previousWaypoint) + p.X) / 2, Y = p.Y, Type = LineGraphPointType.Intermediate
                                    }
                                };
                            }
                        }
                        if (nextWaypoint != null)
                        {
                            if (YAxisAttributeIsMapReadingAttribute && thisWaypoint.MapReadingState == MapReadingState.EndReading)
                            {
                                afterPoints = new List <LineGraphPoint>()
                                {
                                    new LineGraphPoint()
                                    {
                                        X = p.X, Y = 0, Type = LineGraphPointType.Intermediate
                                    },
                                };
                            }
                            else if (!nextWaypoint.Attributes[yAxisAttribute].HasValue && thisWaypoint.Attributes[yAxisAttribute].HasValue)
                            {
                                afterPoints = new List <LineGraphPoint>()
                                {
                                    new LineGraphPoint()
                                    {
                                        X = (GetXValue(nextWaypoint) + p.X) / 2, Y = p.Y, Type = LineGraphPointType.Intermediate
                                    },
                                    new LineGraphPoint()
                                    {
                                        X = (GetXValue(nextWaypoint) + p.X) / 2, Y = 0, Type = LineGraphPointType.Intermediate
                                    }
                                };
                            }
                        }
                        if (beforePoints != null)
                        {
                            points.AddRange(beforePoints);
                        }
                        points.Add(p);
                        if (afterPoints != null)
                        {
                            points.AddRange(afterPoints);
                        }
                    }
                }
                if (points.Count > 0)
                {
                    points[0].Type = LineGraphPointType.Start;
                    points[points.Count - 1].Type = LineGraphPointType.End;
                    pointsList.Add(points);
                }
            }

            bool first = true;

            foreach (var points in pointsList)
            {
                foreach (var p in points)
                {
                    if (first || p.X < xAxisMinValue)
                    {
                        xAxisMinValue = p.X;
                    }
                    if (first || p.X > xAxisMaxValue)
                    {
                        xAxisMaxValue = p.X;
                    }
                    //if (first || p.Y < yAxisMinValue) yAxisMinValue = p.Y;
                    //if (first || p.Y > yAxisMaxValue) yAxisMaxValue = p.Y;
                    first = false;
                }
            }
        }