Skip to content

Commit

Permalink
labelXOffset = 10 is default for radar chart only
Browse files Browse the repository at this point in the history
+ also consider other renderers

Fixes #3406
  • Loading branch information
danielgindi committed Jan 23, 2020
1 parent 69eb361 commit 53f1763
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions Source/Charts/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ open class RadarChartView: PieRadarChartViewBase
super.initialize()

_yAxis = YAxis(position: .left)
_yAxis.labelXOffset = 10.0

renderer = RadarChartRenderer(chart: self, animator: _animator, viewPortHandler: _viewPortHandler)

Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Components/YAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ open class YAxis: AxisBase
@objc open var labelAlignment: NSTextAlignment = .left

/// the horizontal offset of the y-label
@objc open var labelXOffset: CGFloat = 10.0
@objc open var labelXOffset: CGFloat = 0.0

/// the side this axis object represents
private var _axisDependency = AxisDependency.left
Expand Down
4 changes: 3 additions & 1 deletion Source/Charts/Renderers/YAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ open class YAxisRenderer: AxisRendererBase
let from = yAxis.isDrawBottomYLabelEntryEnabled ? 0 : 1
let to = yAxis.isDrawTopYLabelEntryEnabled ? yAxis.entryCount : (yAxis.entryCount - 1)

let xOffset = yAxis.labelXOffset

for i in stride(from: from, to: to, by: 1)
{
let text = yAxis.getFormattedLabel(i)

ChartUtils.drawText(
context: context,
text: text,
point: CGPoint(x: fixedPosition, y: positions[i].y + offset),
point: CGPoint(x: fixedPosition + xOffset, y: positions[i].y + offset),
align: textAlign,
attributes: [.font: labelFont, .foregroundColor: labelTextColor]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer
let from = yAxis.isDrawBottomYLabelEntryEnabled ? 0 : 1
let to = yAxis.isDrawTopYLabelEntryEnabled ? yAxis.entryCount : (yAxis.entryCount - 1)

let xOffset = yAxis.labelXOffset

for i in stride(from: from, to: to, by: 1)
{
let text = yAxis.getFormattedLabel(i)

ChartUtils.drawText(
context: context,
text: text,
point: CGPoint(x: positions[i].x, y: fixedPosition - offset),
point: CGPoint(
x: positions[i].x, y:
fixedPosition - offset + xOffset
),
align: .center,
attributes: [NSAttributedString.Key.font: labelFont, NSAttributedString.Key.foregroundColor: labelTextColor])
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/YAxisRendererRadarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ open class YAxisRendererRadarChart: YAxisRenderer
let to = yAxis.isDrawTopYLabelEntryEnabled ? yAxis.entryCount : (yAxis.entryCount - 1)

let alignment: NSTextAlignment = yAxis.labelAlignment
let xOffset: CGFloat = yAxis.labelXOffset
let xOffset = yAxis.labelXOffset

for j in stride(from: from, to: to, by: 1)
{
Expand Down

0 comments on commit 53f1763

Please sign in to comment.