Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
_xAxisRenderer.renderAxisLabels(context: context)
_leftYAxisRenderer.renderAxisLabels(context: context)
_rightYAxisRenderer.renderAxisLabels(context: context)
_xAxisRenderer.renderTickLines(context: context)
_rightYAxisRenderer.renderTickLines(context: context)

if clipValuesToContentEnabled
{
Expand Down
7 changes: 7 additions & 0 deletions Source/Charts/Components/AxisBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ open class AxisBase: ComponentBase
open var axisLineWidth = CGFloat(0.5)
open var axisLineDashPhase = CGFloat(0.0)
open var axisLineDashLengths: [CGFloat]!
open var tickLineColor = NSUIColor.white

open var gridColor = NSUIColor.gray.withAlphaComponent(0.9)
open var gridLineWidth = CGFloat(0.5)
open var gridLineDashPhase = CGFloat(0.0)
open var gridLineDashLengths: [CGFloat]!
open var gridLineCap = CGLineCap.butt
open var tickLineLength = CGFloat(10)
open var tickLineWidth = CGFloat(1)
open var tickLineOffset = CGFloat(-5)

open var drawGridLinesEnabled = true
open var drawAxisLineEnabled = true
open var drawTickLinesEnabled = true

/// flag that indicates of the labels of this axis should be drawn or not
open var drawLabelsEnabled = true
Expand Down Expand Up @@ -183,6 +188,8 @@ open class AxisBase: ComponentBase

open var isDrawLabelsEnabled: Bool { return drawLabelsEnabled }

open var isDrawTickLinesEnabled: Bool { return drawTickLinesEnabled }

/// Are the LimitLines drawn behind the data or in front of the data?
///
/// **default**: false
Expand Down
6 changes: 6 additions & 0 deletions Source/Charts/Renderers/AxisRendererBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ open class AxisRendererBase: Renderer
fatalError("renderLimitLines() cannot be called on AxisRendererBase")
}

/// Draws the TickLines associated with this axis to the screen.
open func renderTickLines(context: CGContext)
{
fatalError("renderTickLines() cannot be called on AxisRendererBase")
}

/// Computes the axis values.
/// - parameter min: the minimum value in the data object for this axis
/// - parameter max: the maximum value in the data object for this axis
Expand Down
54 changes: 54 additions & 0 deletions Source/Charts/Renderers/XAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,60 @@ open class XAxisRenderer: AxisRendererBase
}
}

// MARK: - Ticks
open override func renderTickLines(context: CGContext)
{
guard
let xAxis = self.axis as? XAxis,
let transformer = self.transformer
else { return }

if !xAxis.isDrawTickLinesEnabled
{
return
}

context.saveGState()
defer { context.restoreGState() }

context.setShouldAntialias(xAxis.gridAntialiasEnabled)
context.setStrokeColor(xAxis.tickLineColor.cgColor)
context.setLineWidth(xAxis.tickLineWidth)
context.setLineCap(xAxis.gridLineCap)
context.setLineDash(phase: 0.0, lengths: [])

let valueToPixelMatrix = transformer.valueToPixelMatrix

var position = CGPoint(x: 0.0, y: 0.0)

let entries = xAxis.entries

for i in stride(from: 0, to: entries.count, by: 1)
{
position.x = CGFloat(entries[i])
position.y = position.x
position = position.applying(valueToPixelMatrix)

drawTickLine(context: context, x: position.x, y: position.y, height: xAxis.tickLineLength)
}
}

open func drawTickLine(context: CGContext, x: CGFloat, y: CGFloat, height: CGFloat)
{
guard
let viewPortHandler = self.viewPortHandler
else { return }

if x >= viewPortHandler.offsetLeft
&& x <= viewPortHandler.chartWidth
{
context.beginPath()
context.move(to: CGPoint(x: x, y: viewPortHandler.contentBottom-height/2))
context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom+height/2))
context.strokePath()
}
}

open override func renderLimitLines(context: CGContext)
{
guard
Expand Down
41 changes: 41 additions & 0 deletions Source/Charts/Renderers/YAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,47 @@ open class YAxisRenderer: AxisRendererBase
context.drawPath(using: CGPathDrawingMode.stroke)
}

// MARK: - Ticks
open override func renderTickLines(context: CGContext)
{
guard let
yAxis = self.axis as? YAxis
else { return }

if !yAxis.isDrawTickLinesEnabled
{
return
}

let positions = transformedPositions()

context.saveGState()
defer { context.restoreGState() }

context.setShouldAntialias(yAxis.gridAntialiasEnabled)
context.setStrokeColor(yAxis.tickLineColor.cgColor)
context.setLineWidth(yAxis.tickLineWidth)
context.setLineCap(yAxis.gridLineCap)

// draw the grid
for i in 0 ..< positions.count
{
drawTickLine(context: context, position: positions[i], length: yAxis.tickLineLength, offset: yAxis.tickLineOffset)
}
}

open func drawTickLine(context: CGContext, position: CGPoint, length: CGFloat, offset: CGFloat)
{
guard
let viewPortHandler = self.viewPortHandler
else { return }

context.beginPath()
context.move(to: CGPoint(x: viewPortHandler.contentRight + offset , y: position.y))
context.addLine(to: CGPoint(x: viewPortHandler.contentRight + length + offset, y: position.y))
context.strokePath()
}

open override func renderLimitLines(context: CGContext)
{
guard
Expand Down