Ejemplo n.º 1
0
        public void RenderLimitLineLabel(SKCanvas c, LimitLine limitLine, SKPoint position, float yOffset)
        {
            string label = limitLine.Label;

            // if drawing the limit-value label is enabled
            if (string.IsNullOrEmpty(label) == false)
            {
                LimitLinePaint.Style       = limitLine.TextStyle;
                LimitLinePaint.PathEffect  = null;
                LimitLinePaint.Color       = limitLine.TextColor;
                LimitLinePaint.StrokeWidth = 0.5f;
                LimitLinePaint.TextSize    = limitLine.TextSize;

                float xOffset = limitLine.LineWidth + limitLine.XOffset;

                LimitLine.LimitLabelPosition labelPosition = limitLine.LabelPosition;

                if (labelPosition == LimitLine.LimitLabelPosition.RightTop)
                {
                    float labelLineHeight = LimitLinePaint.MeasureHeight(label);
                    LimitLinePaint.TextAlign = SKTextAlign.Left;
                    c.DrawText(label, position.X + xOffset, ViewPortHandler.ContentTop + yOffset + labelLineHeight,
                               LimitLinePaint);
                }
                else if (labelPosition == LimitLine.LimitLabelPosition.RightBottom)
                {
                    LimitLinePaint.TextAlign = SKTextAlign.Left;
                    c.DrawText(label, position.X + xOffset, ViewPortHandler.ContentBottom - yOffset, LimitLinePaint);
                }
                else if (labelPosition == LimitLine.LimitLabelPosition.LeftTop)
                {
                    LimitLinePaint.TextAlign = SKTextAlign.Right;
                    float labelLineHeight = LimitLinePaint.MeasureHeight(label);
                    c.DrawText(label, position.X - xOffset, ViewPortHandler.ContentTop + yOffset + labelLineHeight,
                               LimitLinePaint);
                }
                else
                {
                    LimitLinePaint.TextAlign = SKTextAlign.Right;
                    c.DrawText(label, position.X - xOffset, ViewPortHandler.ContentBottom - yOffset, LimitLinePaint);
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void RenderLimitLines(SKCanvas c)
        {
            IList <LimitLine> limitLines = YAxis.LimitLines;

            if (limitLines == null || limitLines.Count <= 0)
            {
                return;
            }

            SKPath limitLinePath = RenderLimitLinesPath;

            limitLinePath.Reset();

            foreach (LimitLine l in limitLines)
            {
                if (!l.IsEnabled)
                {
                    continue;
                }

                int    clipRestoreCount      = c.Save();
                SKRect limitLineClippingRect = ViewPortHandler.ContentRect.InsetVertically(l.LineWidth);
                c.ClipRect(limitLineClippingRect);

                LimitLinePaint.Style       = SKPaintStyle.Stroke;
                LimitLinePaint.Color       = l.LineColor;
                LimitLinePaint.StrokeWidth = l.LineWidth;
                LimitLinePaint.PathEffect  = l.DashPathEffect;

                SKPoint pt = Trasformer.PointValueToPixel(0f, l.Limit);

                limitLinePath.MoveTo(ViewPortHandler.ContentLeft, pt.Y);
                limitLinePath.LineTo(ViewPortHandler.ContentRight, pt.Y);

                c.DrawPath(limitLinePath, LimitLinePaint);
                limitLinePath.Reset();
                // c.drawLines(pts, mLimitLinePaint);

                string label = l.Label;

                // if drawing the limit-value label is enabled
                if (string.IsNullOrEmpty(label) == false)
                {
                    LimitLinePaint.Style       = l.TextStyle;
                    LimitLinePaint.PathEffect  = null;
                    LimitLinePaint.Typeface    = l.Typeface;
                    LimitLinePaint.Color       = l.TextColor;
                    LimitLinePaint.StrokeWidth = 0.5f;
                    LimitLinePaint.TextSize    = l.TextSize;

                    float labelLineHeight = LimitLinePaint.MeasureHeight(label);
                    float xOffset         = 4f.DpToPixel() + l.XOffset;
                    float yOffset         = l.LineWidth + labelLineHeight + l.YOffset;

                    LimitLine.LimitLabelPosition position = l.LabelPosition;

                    if (position == LimitLine.LimitLabelPosition.RightTop)
                    {
                        LimitLinePaint.TextAlign = SKTextAlign.Right;
                        c.DrawText(label,
                                   ViewPortHandler.ContentRight - xOffset,
                                   pt.Y - yOffset + labelLineHeight, LimitLinePaint);
                    }
                    else if (position == LimitLine.LimitLabelPosition.RightBottom)
                    {
                        LimitLinePaint.TextAlign = SKTextAlign.Right;
                        c.DrawText(label,
                                   ViewPortHandler.ContentRight - xOffset,
                                   pt.Y + yOffset, LimitLinePaint);
                    }
                    else if (position == LimitLine.LimitLabelPosition.LeftTop)
                    {
                        LimitLinePaint.TextAlign = SKTextAlign.Left;
                        c.DrawText(label,
                                   ViewPortHandler.ContentLeft + xOffset,
                                   pt.Y - yOffset + labelLineHeight, LimitLinePaint);
                    }
                    else
                    {
                        LimitLinePaint.TextAlign = SKTextAlign.Left;
                        c.DrawText(label,
                                   ViewPortHandler.OffsetLeft + xOffset,
                                   pt.Y + yOffset, LimitLinePaint);
                    }
                }

                c.RestoreToCount(clipRestoreCount);
            }
        }