Beispiel #1
0
        private void DrawValues(SKRect rect, SKCanvas canvas)
        {
            if (BarValues != null && BarValues.Count <= 0)
            {
                return;
            }

            var delta = rect.Width / (BarValues.Count);

            _foregroundPaint.StrokeWidth = delta / 1.5f;
            var xStart = delta / 2f;

            // draw start and end line
            if (ShowFirstAndLastLines)
            {
                var yTop    = rect.Height + 1;
                var yBottom = rect.Height + _yMargin;

                var LeftTop    = new SKPoint(xStart, yTop);
                var LeftBottom = new SKPoint(xStart, yBottom);

                var RightTop    = new SKPoint(rect.Right - xStart, yTop);
                var RightBottom = new SKPoint(rect.Right - xStart, yBottom);

                canvas.DrawLine(LeftTop, LeftBottom, _backgroundPaint);
                canvas.DrawLine(RightTop, RightBottom, _backgroundPaint);
            }

            canvas.ClipRect(rect);

            // draw bars
            for (var i = 0; i < BarValues.Count; i++)
            {
                if (BarValues.GetItem(i) is WalkingDayModel data)
                {
                    var xPos = xStart + i * delta;

                    var normalizedValue = data.MinutesBriskWalking / TotalY;

                    var yTop    = rect.Height - (rect.Height * normalizedValue) + (_foregroundPaint.StrokeWidth / 2f);
                    var yBottom = rect.Height + _foregroundPaint.StrokeWidth / 2f;

                    var bottom = new SKPoint(xPos, yBottom);
                    var top    = new SKPoint(xPos, yTop);

                    canvas.DrawLine(bottom, top, _foregroundPaint);
                }
            }
        }
Beispiel #2
0
        private void drawBars(DrawingContext drawingContext)
        {
            if (BarValues == null)
            {
                return;
            }

            var barWidth     = BarSize.TotalMilliseconds * xValuePrMs / 2;
            var barWidthHalf = barWidth / 2;
            var barLeft      = leftTime - (BarSize);

            foreach (var barValue in BarValues.Where(x => x.Item1 >= barLeft && x.Item1 <= rightTime + BarSize))
            {
                var x = getX(barValue.Item1);
                var y = getY(barValue.Item2);

                var leftEdge  = x - barWidthHalf;
                var rightEdge = x + barWidthHalf;
                if (rightEdge <= LeftMargin)
                {
                    // Out of bound, skip
                    continue;
                }

                if (leftEdge <= LeftMargin)
                {
                    var tempBarWidth = Math.Max(1, barWidth - (LeftMargin - leftEdge));
                    drawBar(drawingContext,
                            barValue.Item1.ToString(timeTextFormat),
                            new Point(x, y),
                            tempBarWidth,
                            new Point(LeftMargin, y),
                            barValue.Item2);
                }
                else
                {
                    drawBar(drawingContext,
                            barValue.Item1.ToString(timeTextFormat),
                            new Point(x, y),
                            Math.Max(0, barWidth),
                            new Point(x - barWidth / 2, y),
                            barValue.Item2);
                }
            }
        }
Beispiel #3
0
        private Tuple <double, double> getGraphBound()
        {
            double min = int.MaxValue;
            double max = int.MinValue;

            if (ReadingBoundMin != null)
            {
                min = (double)ReadingBoundMin;
            }
            if (ReadingBoundMax != null)
            {
                max = (double)ReadingBoundMax;
            }

            if (ReadingBoundMin == null || ReadingBoundMax == null)
            {
                if ((BarValues == null || BarValues.Count == 0) &&
                    (LineValues == null || LineValues.Count == 0))
                {
                    return(new Tuple <double, double>(0, 150));
                }

                List <Tuple <DateTime, double> > values = new List <Tuple <DateTime, double> >();
                if (BarValues == null)
                {
                    values.AddRange(LineValues);
                }
                else if (LineValues == null)
                {
                    values.AddRange(BarValues);
                }
                else
                {
                    values.AddRange(BarValues.Union(LineValues));
                }

                foreach (var source in values)
                {
                    if (ReadingBoundMin == null && source.Item2 < min)
                    {
                        min = source.Item2;
                    }
                    if (ReadingBoundMax == null && source.Item2 > max)
                    {
                        max = source.Item2;
                    }
                }
            }
            if (Math.Abs(max - min) < 10)
            {
                return(new Tuple <double, double>(Math.Max(60, min - 10), Math.Min(150, max + 10)));
            }
            if (min > ReadingLimit)
            {
                min = ReadingLimit - 10;
            }
            if (max < ReadingLimit)
            {
                max = ReadingLimit;
            }
            return(new Tuple <double, double>(min, max));
        }