Beispiel #1
0
        internal string ChartDataFor(
            MeasurementComparisonDictionary sourceData,
            AxisLimits limits,
            Size size)
        {
            InitChart(size);
            var timeUnit = limits.TimeUnit;

            limits.EnsureNonZeroRanges();
            InitSeries(sourceData, limits.StartTimestamp, timeUnit);
            InitChartArea();
            SetAxisDimensions(_area.AxisX, XAxisTitleTemplate.FillIn(timeUnit.Caption), limits.X);
            SetAxisDimensions(_area.AxisY, YAxisTitle, limits.Y);
            _area.AxisY.Crossing = 0.0;
            _chart.ChartAreas.Add(_area);
            _chart.Legends.Add(new Legend(ChartLegend));
            _chart.Legends[ChartLegend].DockedToChartArea = ChartAreaName;
            return(AsBase64String(ChartImageFormat.Png));
        }
Beispiel #2
0
        private void InitSeries(
            MeasurementComparisonDictionary sourceData,
            DateTime baseTimestamp,
            TimeUnitForDisplay timeUnit)
        {
            _actualSeries   = new Series(ActualCaption);
            _expectedSeries = new Series(ExpectedCaption);
            _failSeries     = new Series(FailCaption);

            var hasFailure = false;

            foreach (var key in sourceData.Keys)
            {
                var xValue    = timeUnit.ConvertFromSeconds((key - baseTimestamp).TotalSeconds);
                var value     = sourceData[key].Value;
                var expectedY = value.ExpectedValueOut?.To <double>();
                // if we have a non-convertible value, return null, so it is skipped
                var actualY = value.ActualValueOut?.ToWithDefault <double?>(null);
                // ensure that IsGood issues are also marked as failures.
                var pass = sourceData[key].IsOk();

                var failValue = actualY ?? expectedY;
                AddPoint(_expectedSeries, xValue, expectedY);
                AddPoint(_actualSeries, xValue, actualY);
                if (pass)
                {
                    continue;
                }
                AddPoint(_failSeries, xValue, failValue);
                hasFailure = true;
            }

            SetSeriesStyle(_actualSeries, SeriesType.Actual, hasFailure);
            SetSeriesStyle(_expectedSeries, SeriesType.Expected, hasFailure);
            SetSeriesStyle(_failSeries, SeriesType.Fail, hasFailure);

            _chart.Series.Add(_actualSeries);
            _chart.Series.Add(_expectedSeries);
            _chart.Series.Add(_failSeries);
        }
        internal string ChartDataFor(MeasurementComparisonDictionary sourceData, AxisLimits limits, Size size)
        {
            InitChart(size);
            var axisPaint = new SolidColorPaint(AxisColor)
            {
                StrokeThickness = LineThickness
            };
            var timeUnit = limits.TimeUnit;

            limits.EnsureNonZeroRanges();
            InitSeries(sourceData, limits.StartTimestamp, timeUnit);
            _chart.Sections = new List <RectangularSection>()
                              .Append(new RectangularSection {
                Xi = 0, Xj = 0, Stroke = axisPaint
            })
                              .Append(new RectangularSection {
                Yi = 0, Yj = 0, Stroke = axisPaint
            });
            _chart.XAxes = CreateAxes(limits.X, XAxisTitleTemplate.FillIn(timeUnit.Caption));

            _chart.YAxes = CreateAxes(limits.Y, YAxisTitle);
            return(AsBase64PngString());
        }
Beispiel #4
0
        internal string ChartInHtmlFor(MeasurementComparisonDictionary sourceData, AxisLimits limits, Size size)
        {
            var chartInBase64 = ChartDataFor(sourceData, limits, size);

            return(WebFunctions.AsImg(chartInBase64));
        }
        private void InitSeries(
            MeasurementComparisonDictionary sourceData,
            DateTime baseTimestamp,
            TimeUnitForDisplay timeUnit)
        {
            _expectedSeries = new LineSeries <ObservablePoint>
            {
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                LineSmoothness = 0,
                GeometrySize   = 0,
                Stroke         = new SolidColorPaint(ExpectedColor)
                {
                    StrokeThickness = LineThickness, PathEffect = new DashEffect(new[] { 5f, 5f })
                },
                Name = ExpectedCaption
            };
            _actualSeries = new LineSeries <ObservablePoint>
            {
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                LineSmoothness = 0,
                GeometrySize   = 0,
                Stroke         = new SolidColorPaint(ActualColor)
                {
                    StrokeThickness = LineThickness + 1
                },
                Name = ActualCaption
            };
            var errorPaint = new SolidColorPaint(FailColor);

            _failSeries = new LineSeries <ObservablePoint, CircleGeometry>
            {
                GeometrySize   = 9,
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                Stroke         = null,
                GeometryStroke = errorPaint,
                GeometryFill   = errorPaint,
                LineSmoothness = 0,
                Name           = FailCaption
            };

            foreach (var key in sourceData.Keys)
            {
                var xValue    = timeUnit.ConvertFromSeconds((key - baseTimestamp).TotalSeconds);
                var value     = sourceData[key].Value;
                var expectedY = value.ExpectedValueOut?.To <double>();
                // if we have a non-convertible value, return null, so it is skipped
                var actualY = value.ActualValueOut?.ToWithDefault <double?>(null);
                // ensure that IsGood issues are also marked as failures.
                var pass = sourceData[key].IsOk();

                var failValue = actualY ?? expectedY;
                AddPoint(_expectedSeries, xValue, expectedY);
                AddPoint(_actualSeries, xValue, actualY);
                if (pass)
                {
                    continue;
                }
                AddPoint(_failSeries, xValue, failValue);
            }

            var chartSeries = new List <ISeries> {
                _actualSeries, _expectedSeries
            };
            var errors = _failSeries.Values as List <ObservablePoint>;

            Debug.Assert(errors != null, nameof(errors) + " != null");
            if (errors.Any())
            {
                chartSeries.Add(_failSeries);
            }
            _chart.Series          = chartSeries;
            _chart.DrawMarginFrame = new DrawMarginFrame
            {
                Fill   = new SolidColorPaint(ChartColor),
                Stroke = new SolidColorPaint(MajorGridColor)
            };
        }