Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. use axis.centerAxisLabelsEnabled instead of local variable to avoid dirty read
2. fix xAxis label missing issue
  • Loading branch information
liuxuan30 committed Sep 27, 2016
1 parent 3a2da1b commit 67ad1ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Source/Charts/Components/AxisBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ open class AxisBase: ComponentBase
/// This is useful especially for grouped BarChart.
open var centerAxisLabelsEnabled: Bool
{
get { return _centerAxisLabelsEnabled && entryCount > 1 }
get { return _centerAxisLabelsEnabled && entryCount > 0 }
set { _centerAxisLabelsEnabled = newValue }
}

Expand Down
15 changes: 5 additions & 10 deletions Source/Charts/Renderers/AxisRendererBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ open class AxisRendererBase: Renderer
// Use one order of magnitude higher, to avoid intervals like 0.9 or 90
interval = floor(10.0 * Double(intervalMagnitude))
}

let centeringEnabled = axis.centerAxisLabelsEnabled
var n = centeringEnabled ? 1 : 0

var n = axis.centerAxisLabelsEnabled ? 1 : 0

// force label count
if axis.isForceLabelsEnabled
Expand All @@ -158,7 +157,7 @@ open class AxisRendererBase: Renderer

var first = interval == 0.0 ? 0.0 : ceil(yMin / interval) * interval

if centeringEnabled
if axis.centerAxisLabelsEnabled
{
first -= interval
}
Expand Down Expand Up @@ -204,16 +203,12 @@ open class AxisRendererBase: Renderer
axis.decimals = 0
}

if centeringEnabled
if axis.centerAxisLabelsEnabled
{
axis.centeredEntries.reserveCapacity(n)
axis.centeredEntries.removeAll()

var offset: Double = 0.0
if axis.entries.count > 1
{
offset = (axis.entries[1] - axis.entries[0]) / 2.0
}
let offset: Double = interval / 2.0

for i in 0 ..< n
{
Expand Down

0 comments on commit 67ad1ba

Please sign in to comment.