/// <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> /// draws the y-axis labels to the screen /// </summary> public virtual void RenderAxisLabels(SKCanvas c) { if (!YAxis.IsEnabled || !YAxis.IsDrawLabelsEnabled) { return; } SKPoint[] positions = GetTransformedPositions(); AxisLabelPaint.Typeface = YAxis.Typeface; AxisLabelPaint.TextSize = YAxis.TextSize; AxisLabelPaint.Color = YAxis.TextColor; float xoffset = YAxis.XOffset; float yoffset = AxisLabelPaint.MeasureHeight("A") / 2.5f + YAxis.YOffset; YAxisDependency dependency = YAxis.AxisDependency; YAxis.YAxisLabelPosition labelPosition = YAxis.Position; float xPos; if (dependency == YAxisDependency.Left) { if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart) { AxisLabelPaint.TextAlign = SKTextAlign.Right; xPos = ViewPortHandler.OffsetLeft - xoffset; } else { AxisLabelPaint.TextAlign = SKTextAlign.Left; xPos = ViewPortHandler.OffsetLeft + xoffset; } } else { if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart) { AxisLabelPaint.TextAlign = SKTextAlign.Left; xPos = ViewPortHandler.ContentRight + xoffset; } else { AxisLabelPaint.TextAlign = SKTextAlign.Right; xPos = ViewPortHandler.ContentRight - xoffset; } } DrawYLabels(c, xPos, positions, yoffset); }
public override void RenderAxisLabels(SKCanvas c) { if (!YAxis.IsEnabled || !YAxis.IsDrawLabelsEnabled) { return; } SKPoint[] positions = GetTransformedPositions(); AxisLabelPaint.Typeface = YAxis.Typeface; AxisLabelPaint.TextSize = YAxis.TextSize; AxisLabelPaint.Color = YAxis.TextColor; AxisLabelPaint.TextAlign = SKTextAlign.Center; float baseYOffset = 2.5f.DpToPixel(); float textHeight = AxisLabelPaint.MeasureHeight("Q"); YAxisDependency dependency = YAxis.AxisDependency; YAxis.YAxisLabelPosition labelPosition = YAxis.Position; float yPos; if (dependency == YAxisDependency.Left) { if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart) { yPos = ViewPortHandler.ContentTop - baseYOffset; } else { yPos = ViewPortHandler.ContentTop - baseYOffset; } } else { if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart) { yPos = ViewPortHandler.ContentBottom + textHeight + baseYOffset; } else { yPos = ViewPortHandler.ContentBottom + textHeight + baseYOffset; } } DrawYLabels(c, yPos, positions, YAxis.YOffset); }
protected virtual void ComputeSize() { var longest = XAxis.GetLongestLabel(); AxisLabelPaint.Typeface = XAxis.Typeface; AxisLabelPaint.TextSize = XAxis.TextSize; var labelSize = AxisLabelPaint.Measure(longest); float labelWidth = labelSize.Width; float labelHeight = AxisLabelPaint.MeasureHeight("Q"); var labelRotatedSize = ChartUtil.GetSizeOfRotatedRectangleByDegrees( labelWidth, labelHeight, XAxis.LabelRotationAngle); XAxis.LabelWidth = (int)Math.Round(labelWidth); XAxis.LabelHeight = (int)Math.Round(labelHeight); XAxis.LabelRotatedWidth = (int)MathF.Round(labelRotatedSize.Width); XAxis.LabelRotatedHeight = (int)MathF.Round(labelRotatedSize.Height); }