protected override void DrawLabels(SKCanvas c, float pos, SKPoint anchor) { float labelRotationAngleDegrees = XAxis.LabelRotationAngle; var centeringEnabled = XAxis.IsCenterAxisLabelsEnabled; SKPoint[] positions = new SKPoint[XAxis.entryCount]; for (int i = 0; i < positions.Length; i++) { // only fill x values if (centeringEnabled) { positions[i].Y = XAxis.centeredEntries[i]; } else { positions[i].Y = XAxis.entries[i]; } } positions = Trasformer.PointValuesToPixel(positions); for (int i = 0; i < positions.Length; i++) { float y = positions[i].Y; if (ViewPortHandler.IsInBoundsY(y)) { DrawLabel(c, XAxis.ValueFormatter.GetFormattedValue(XAxis.entries[i], XAxis), pos, y, anchor, labelRotationAngleDegrees); } } }
/// <summary> /// draws the x-labels on the specified y-position /// </summary> protected virtual void DrawLabels(SKCanvas c, float pos, SKPoint anchor) { float labelRotationAngleDegrees = XAxis.LabelRotationAngle; var centeringEnabled = XAxis.IsCenterAxisLabelsEnabled; SKPoint[] positions = new SKPoint[XAxis.entryCount]; for (int i = 0; i < positions.Length; i++) { // only fill x values if (centeringEnabled) { positions[i].X = XAxis.centeredEntries[i]; } else { positions[i].X = XAxis.entries[i]; } } positions = Trasformer.PointValuesToPixel(positions); for (int i = 0; i < positions.Length; i++) { float x = positions[i].X; if (ViewPortHandler.IsInBoundsX(x)) { var label = XAxis.ValueFormatter.GetFormattedValue(XAxis.entries[i], XAxis); if (XAxis.AvoidFirstLastClipping) { // avoid clipping of the last if (i == XAxis.entryCount - 1 && XAxis.entryCount > 1) { float width = AxisLabelPaint.MeasureWidth(label); if (width > ViewPortHandler.OffsetRight * 2 && x + width > ViewPortHandler.ChartWidth) { x -= width / 2; } // avoid clipping of the first } else if (i == 0) { float width = AxisLabelPaint.MeasureWidth(label); x += width / 2; } } DrawLabel(c, label, x, pos, anchor, labelRotationAngleDegrees); } } }
/// <summary> /// Transforms the values contained in the axis entries to screen pixels and returns them in form of a float array /// of x- and y-coordinates. /// </summary> /// <returns></returns> protected virtual SKPoint[] GetTransformedPositions() { if (TransformedPositionsBuffer.Length != YAxis.entryCount) { TransformedPositionsBuffer = new SKPoint[YAxis.entryCount]; } SKPoint[] positions = TransformedPositionsBuffer; for (int i = 0; i < positions.Length; i++) { // only fill y values, x values are not needed for y-labels positions[i].Y = YAxis.entries[i]; } return(Trasformer.PointValuesToPixel(positions)); }
public void RenderGridLines(SKCanvas c) { if (!this.XAxis.IsDrawGridLinesEnabled || !this.XAxis.IsEnabled) { return; } int clipRestoreCount = c.Save(); c.ClipRect(GetGridClippingRect()); if (RenderGridLinesBuffer.Length != Axis.entryCount) { RenderGridLinesBuffer = new SKPoint[XAxis.entryCount]; } var positions = RenderGridLinesBuffer; for (int i = 0; i < positions.Length; i++) { float entry = (float)Axis.entries[i]; positions[i] = new SKPoint(entry, entry); } positions = Trasformer.PointValuesToPixel(positions); SetupGridPaint(); var gridLinePath = RenderGridLinesPath; gridLinePath.Reset(); foreach (SKPoint pos in positions) { DrawGridLine(c, pos, gridLinePath); } c.RestoreToCount(clipRestoreCount); }