Пример #1
0
        public override void Render(IRenderContext rc)
        {
            var numberOfSeries = PlotModel.Series.OfType <TotalSeries>().Count();
            var slotWidth      = PlotModel.Width / numberOfSeries;

            var slotNumber             = PlotModel.Series.IndexOf(this);
            var startOffset            = slotNumber * slotWidth;
            var endOffset              = (slotNumber + 1) * slotWidth;
            var middleHorizontalOffset = startOffset + (slotWidth / 2);
            var middleVerticalOffset   = PlotModel.Height / 2;
            var slotColor              = PlotModel.DefaultColors[slotNumber];

            var label = GetTotalText();

            var totalTextSize     = rc.MeasureText(label, PlotModel.DefaultFont, TotalFontSize);
            var totalTextPosition = new ScreenPoint(middleHorizontalOffset - (totalTextSize.Width / 2), middleVerticalOffset - (totalTextSize.Height / 2));

            var keyShapeSize    = new OxySize(PlotModel.DefaultFontSize, PlotModel.DefaultFontSize);
            var keyShapePadding = PlotModel.DefaultFontSize;
            var keyTextSize     = rc.MeasureText(metric.GetTitle(), PlotModel.DefaultFont, PlotModel.DefaultFontSize);

            var keyWidth            = keyShapeSize.Width + keyTextSize.Width;
            var keyHorizontalOffset = middleHorizontalOffset - (keyWidth + keyShapePadding) / 2;

            var keyShapePosition = new ScreenPoint(keyHorizontalOffset, middleVerticalOffset + totalTextSize.Height);
            var keyTextPosition  = new ScreenPoint(keyHorizontalOffset + keyShapeSize.Width + keyShapePadding, middleVerticalOffset + totalTextSize.Height);

            rc.DrawText(totalTextPosition, label, PlotModel.TextColor, PlotModel.DefaultFont, TotalFontSize);
            rc.DrawRectangle(new OxyRect(keyShapePosition, keyShapeSize), slotColor, new OxyColor());
            rc.DrawText(keyTextPosition, metric.GetTitle(), PlotModel.TextColor, PlotModel.DefaultFont, PlotModel.DefaultFontSize);
        }
Пример #2
0
        public XYAxisSeries BuildXYSeries(PlotMetric metric, IList <Datapoint> dataPoints, XYAxisSeries series)
        {
            series.Title = metric.GetTitle();

            DateTime startTime = dataPoints.Min(x => x.Timestamp).ToUniversalTime();
            DateTime endTime   = dataPoints.Max(x => x.Timestamp).ToUniversalTime();

            IDictionary <DateTime, double> points = metric.GetIncrements(startTime, endTime).ToDictionary(x => x, y => double.NaN);

            foreach (var dataPoint in dataPoints)
            {
                DateTime timestamp = dataPoint.Timestamp.ToUniversalTime();

                if (!points.ContainsKey(timestamp))
                {
                    throw new InvalidOperationException($"Generated time slice array doesn't contain {timestamp}");
                }

                points[timestamp] = dataPoint.StatisticTypeValue(metric.StatisticType);
            }

            series.ItemsSource = points.Select(x => DateTimeAxis.CreateDataPoint(x.Key, x.Value));
            return(series);
        }