Пример #1
0
        private FrameFieldValues GetFrameFieldValues(SummaryColumnFlags flags, int lapIdx, int frameIdx, int fieldIdx, float?minWarning, float?maxWarning)
        {
            IEnumerable <TelemetryValues> lapFieldValues = TelemetryData.GetLapFieldValues(lapIdx, fieldIdx).ToList();

            FrameFieldValues ffv;

            if (lapFieldValues.Count() == 0)
            {
                ffv = new FrameFieldValues(false);
            }
            else
            {
                ffv = new FrameFieldValues(true);

                ffv.Value = lapFieldValues.FirstOrDefault(v => v.FrameIdx == frameIdx).Value.GetValueOrDefault();

                IEnumerable <float> lapValues = lapFieldValues.Select(v => v.Value.GetValueOrDefault());

                var lapMin = lapValues.Min();
                var lapMax = lapValues.Max();

                if (flags.HasFlag(SummaryColumnFlags.LapMin))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapMin, lapMin);
                }

                if (flags.HasFlag(SummaryColumnFlags.LapMax))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapMax, lapMax);
                }

                if (flags.HasFlag(SummaryColumnFlags.LapDelta))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapDelta, lapMax - lapMin);
                }

                if (flags.HasFlag(SummaryColumnFlags.LapMode))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapMode, lapValues.Mode());
                }

                if (flags.HasFlag(SummaryColumnFlags.LapAvg))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapAvg, lapValues.Average());
                }

                if (flags.HasFlag(SummaryColumnFlags.LapStdDev))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.LapStdDev, lapValues.StandardDeviation());
                }

                IEnumerable <TelemetryValues> sessionFieldValues = TelemetryData.GetSessionFieldValues(fieldIdx);

                IEnumerable <float> sessionValues = sessionFieldValues.Select(v => v.Value.GetValueOrDefault());

                var sessionMin = sessionValues.Min();
                var sessionMax = sessionValues.Max();

                if (flags.HasFlag(SummaryColumnFlags.SessionMin))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionMin, sessionMin);
                }

                if (flags.HasFlag(SummaryColumnFlags.SessionMax))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionMax, sessionMax);
                }

                if (flags.HasFlag(SummaryColumnFlags.SessionDelta))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionDelta, sessionMax - sessionMin);
                }

                if (flags.HasFlag(SummaryColumnFlags.SessionMode))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionMode, sessionValues.Mode());
                }

                if (flags.HasFlag(SummaryColumnFlags.SessionAvg))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionAvg, sessionValues.Average());
                }

                if (flags.HasFlag(SummaryColumnFlags.SessionStdDev))
                {
                    ffv.SummaryValues.Add(SummaryColumnFlags.SessionStdDev, sessionValues.StandardDeviation());
                }

                if (maxWarning.HasValue)
                {
                    ffv.MaxWarning = ffv.Value >= maxWarning.Value;
                }

                if (minWarning.HasValue)
                {
                    ffv.MinWarning = ffv.Value <= minWarning.Value;
                }
            }

            return(ffv);
        }
Пример #2
0
        private Bitmap GetGraphBitmap()
        {
            Bitmap bitmap = _graphBitmap;

            try
            {
                Size size = GetGraphSize();

                if (bitmap != null && bitmap.Size == size)
                {
                    return(bitmap);
                }

                bitmap = new Bitmap(
                    size.Width,
                    size.Height,
                    pixelFormat);

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.SmoothingMode = smoothingMode;

                    g.Clear(Color.Black);

                    Bitmap backgroundBitmap = GetGraphBackgroundBitmap();

                    g.DrawImage(backgroundBitmap, 0, 0);

                    int frameCount = TelemetryData.GetLapFrameCount(_selectedLapIdx);

                    if (frameCount > 0)
                    {
                        float frameSpacing = (float)graphPanel.Width / (float)frameCount;

                        int seriesCount = Model.SeriesCollection.Count();

                        ILineGraphSeries[] seriesArray = new ILineGraphSeries[seriesCount];
                        IEnumerable <TelemetryValues>[] telemetryValuesArray = new IEnumerable <TelemetryValues> [seriesCount];
                        Pen[]          seriesPens      = new Pen[seriesCount];
                        PointF[]       seriesLastPoint = new PointF[seriesCount];
                        GraphicsPath[] graphicsPaths   = new GraphicsPath[seriesCount];
                        float[][]      fieldLapValues  = new float[seriesCount][];

                        for (int s = 0; s < seriesCount; s++)
                        {
                            var lapFieldValues = TelemetryData.GetLapFieldValues(_selectedLapIdx, s);
                            telemetryValuesArray[s] = lapFieldValues;

                            fieldLapValues[s] = lapFieldValues.Select(v => v.Value.Value).ToArray();

                            ILineGraphSeries series = Model.SeriesCollection.ToArray()[s];
                            series.SeriesMapper.GraphicsSize = size;
                            seriesArray[s] = series;

                            Pen seriesPen = new Pen(series.Color, series.AxisBaseLineThickness);
                            seriesPens[s] = seriesPen;

                            seriesLastPoint[s] = PointF.Empty;

                            graphicsPaths[s] = new GraphicsPath();
                        }

                        for (int x = 0; x < frameCount; x++)
                        {
                            float frameX = x * frameSpacing;

                            float frameY = 0;

                            for (int s = 0; s < seriesCount; s++)
                            {
                                float seriesFrameValue = fieldLapValues[s][x];

                                if (seriesArray[s].InvertRange)
                                {
                                    frameY = seriesArray[s].SeriesMapper.MapValueInverted(seriesFrameValue);
                                }
                                else
                                {
                                    frameY = seriesArray[s].SeriesMapper.MapValue(seriesFrameValue);
                                }

                                if (seriesLastPoint[s] == PointF.Empty)
                                {
                                    seriesLastPoint[s] = new PointF(frameX, frameY);
                                }

                                graphicsPaths[s].AddLine(seriesLastPoint[s], new PointF(frameX, frameY));

                                seriesLastPoint[s] = new PointF(frameX, frameY);
                            } // for (int s = 0; s < Model.SeriesCollection.Count(); s++)
                        }     // for (int x = 0; x < frameCount; x++)

                        for (int s = 0; s < seriesCount; s++)
                        {
                            g.DrawPath(seriesPens[s], graphicsPaths[s]);

                            if (seriesArray[s].ShowMinimumWarning)
                            {
                                float minWarningY = 0F;
                                if (seriesArray[s].InvertRange)
                                {
                                    minWarningY = seriesArray[s].SeriesMapper.MapValueInverted(seriesArray[s].MinWarning);
                                }
                                else
                                {
                                    minWarningY = seriesArray[s].SeriesMapper.MapValue(seriesArray[s].MinWarning);
                                }

                                seriesPens[s].DashStyle = DashStyle.DashDotDot;
                                g.DrawLine(seriesPens[s], new PointF(0, minWarningY), new PointF(graphPanel.Width, minWarningY));
                            }
                            if (seriesArray[s].ShowMaximumWarning)
                            {
                                float maxWarningY = 0F;
                                if (seriesArray[s].InvertRange)
                                {
                                    maxWarningY = seriesArray[s].SeriesMapper.MapValueInverted(seriesArray[s].MaxWarning);
                                }
                                else
                                {
                                    maxWarningY = seriesArray[s].SeriesMapper.MapValue(seriesArray[s].MaxWarning);
                                }

                                seriesPens[s].DashStyle = DashStyle.Dash;
                                g.DrawLine(seriesPens[s], new PointF(0, maxWarningY), new PointF(graphPanel.Width, maxWarningY));
                            }
                        }

                        for (int p = 0; p < seriesPens.Length; p++)
                        {
                            seriesPens[p].Dispose();
                        }
                    } // if (frameCount > 0)
                }     // using (Graphics g = Graphics.FromImage(bitmap))
            }         // try
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }

            _graphBitmap = bitmap;

            return(bitmap);
        }