Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align ChartLimit.LabelPosition naming with UIRectCorner #3846

Merged
merged 5 commits into from
Mar 9, 2019
Merged
Changes from 1 commit
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
Next Next commit
Align ChartLimit.LabelPosition naming with UIRectCorner
jjatie committed Mar 7, 2019
commit 024c7da2b58754e1ea25fbb9577da42296b1aa70
6 changes: 3 additions & 3 deletions ChartsDemo-iOS/Swift/Demos/LineChart1ViewController.swift
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ class LineChart1ViewController: DemoBaseViewController {
let llXAxis = ChartLimitLine(limit: 10, label: "Index 10")
llXAxis.lineWidth = 4
llXAxis.lineDashLengths = [10, 10, 0]
llXAxis.labelPosition = .rightBottom
llXAxis.labelPosition = .bottomRight
llXAxis.valueFont = .systemFont(ofSize: 10)

chartView.xAxis.gridLineDashLengths = [10, 10]
@@ -58,13 +58,13 @@ class LineChart1ViewController: DemoBaseViewController {
let ll1 = ChartLimitLine(limit: 150, label: "Upper Limit")
ll1.lineWidth = 4
ll1.lineDashLengths = [5, 5]
ll1.labelPosition = .rightTop
ll1.labelPosition = .topRight
ll1.valueFont = .systemFont(ofSize: 10)

let ll2 = ChartLimitLine(limit: -30, label: "Lower Limit")
ll2.lineWidth = 4
ll2.lineDashLengths = [5,5]
ll2.labelPosition = .rightBottom
ll2.labelPosition = .bottomRight
ll2.valueFont = .systemFont(ofSize: 10)

let leftAxis = chartView.leftAxis
2 changes: 1 addition & 1 deletion Source/Charts/Charts/PieRadarChartViewBase.swift
100755 → 100644
Original file line number Diff line number Diff line change
@@ -680,7 +680,7 @@ open class PieRadarChartViewBase: ChartViewBase
}
velocitySamples.append(currentSample)
}

private func calculateVelocity() -> CGFloat
{
guard var firstSample = velocitySamples.first,
10 changes: 5 additions & 5 deletions Source/Charts/Components/ChartLimitLine.swift
Original file line number Diff line number Diff line change
@@ -20,10 +20,10 @@ open class ChartLimitLine: ComponentBase
@objc(ChartLimitLabelPosition)
public enum LabelPosition: Int
{
case leftTop
case leftBottom
case rightTop
case rightBottom
case topLeft
case topRight
case bottomLeft
case bottomRight
}

/// limit / maximum (the y-value or xIndex)
@@ -39,7 +39,7 @@ open class ChartLimitLine: ComponentBase

@objc open var drawLabelEnabled = true
@objc open var label = ""
@objc open var labelPosition = LabelPosition.rightTop
@objc open var labelPosition = LabelPosition.topRight

public override init()
{
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
@@ -478,7 +478,7 @@ open class LineChartRenderer: LineRadarRenderer
}

_xBounds.set(chart: dataProvider, dataSet: dataSet, animator: animator)

for j in _xBounds
{
guard let e = dataSet.entryForIndex(j) else { break }
115 changes: 53 additions & 62 deletions Source/Charts/Renderers/XAxisRenderer.swift
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@
import Foundation
import CoreGraphics

#if !os(OSX)
import UIKit
#endif

@objc(ChartXAxisRenderer)
open class XAxisRenderer: AxisRendererBase
{
@@ -334,29 +338,16 @@ open class XAxisRenderer: AxisRendererBase
{
guard
let xAxis = self.axis as? XAxis,
let transformer = self.transformer
let transformer = self.transformer,
!xAxis.limitLines.isEmpty
else { return }

var limitLines = xAxis.limitLines

if limitLines.count == 0
{
return
}

let trans = transformer.valueToPixelMatrix

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

for i in 0 ..< limitLines.count
for l in xAxis.limitLines where l.isEnabled
{
let l = limitLines[i]

if !l.isEnabled
{
continue
}

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

@@ -399,55 +390,55 @@ open class XAxisRenderer: AxisRendererBase
{

let label = limitLine.label

// if drawing the limit-value label is enabled
if limitLine.drawLabelEnabled && label.count > 0
{
guard limitLine.drawLabelEnabled, !label.isEmpty else {
return
}

let labelLineHeight = limitLine.valueFont.lineHeight

let xOffset: CGFloat = limitLine.lineWidth + limitLine.xOffset

if limitLine.labelPosition == .rightTop
{
ChartUtils.drawText(context: context,
text: label,
point: CGPoint(
x: position.x + xOffset,
y: viewPortHandler.contentTop + yOffset),
align: .left,
attributes: [NSAttributedString.Key.font: limitLine.valueFont, NSAttributedString.Key.foregroundColor: limitLine.valueTextColor])
}
else if limitLine.labelPosition == .rightBottom
{
ChartUtils.drawText(context: context,
text: label,
point: CGPoint(
x: position.x + xOffset,
y: viewPortHandler.contentBottom - labelLineHeight - yOffset),
align: .left,
attributes: [NSAttributedString.Key.font: limitLine.valueFont, NSAttributedString.Key.foregroundColor: limitLine.valueTextColor])
}
else if limitLine.labelPosition == .leftTop
{
ChartUtils.drawText(context: context,
text: label,
point: CGPoint(
x: position.x - xOffset,
y: viewPortHandler.contentTop + yOffset),
align: .right,
attributes: [NSAttributedString.Key.font: limitLine.valueFont, NSAttributedString.Key.foregroundColor: limitLine.valueTextColor])
}
else
{
ChartUtils.drawText(context: context,
text: label,
point: CGPoint(
x: position.x - xOffset,
y: viewPortHandler.contentBottom - labelLineHeight - yOffset),
align: .right,
attributes: [NSAttributedString.Key.font: limitLine.valueFont, NSAttributedString.Key.foregroundColor: limitLine.valueTextColor])
let attributes: [NSAttributedString.Key : Any] = [
.font : limitLine.valueFont,
.foregroundColor : limitLine.valueTextColor
]

let (point, align): (CGPoint, NSTextAlignment)
switch limitLine.labelPosition {
case .topRight:
point = CGPoint(
x: position.x + xOffset,
y: viewPortHandler.contentTop + yOffset
)
align = .left

case .bottomRight:
point = CGPoint(
x: position.x + xOffset,
y: viewPortHandler.contentBottom - labelLineHeight - yOffset
)
align = .left

case .topLeft:
point = CGPoint(
x: position.x - xOffset,
y: viewPortHandler.contentTop + yOffset
)
align = .right

case .bottomLeft:
point = CGPoint(
x: position.x - xOffset,
y: viewPortHandler.contentBottom - labelLineHeight - yOffset
)
align = .right
}
}
}

ChartUtils.drawText(
context: context,
text: label,
point: point,
align: align,
attributes: attributes
)
}
}
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer
let xOffset: CGFloat = 4.0 + l.xOffset
let yOffset: CGFloat = l.lineWidth + labelLineHeight + l.yOffset

if l.labelPosition == .rightTop
if l.labelPosition == .topRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -320,7 +320,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer
align: .right,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .rightBottom
else if l.labelPosition == .bottomRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -330,7 +330,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer
align: .right,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .leftTop
else if l.labelPosition == .topLeft
{
ChartUtils.drawText(context: context,
text: label,
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/YAxisRenderer.swift
Original file line number Diff line number Diff line change
@@ -340,7 +340,7 @@ open class YAxisRenderer: AxisRendererBase
let xOffset: CGFloat = 4.0 + l.xOffset
let yOffset: CGFloat = l.lineWidth + labelLineHeight + l.yOffset

if l.labelPosition == .rightTop
if l.labelPosition == .topRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -350,7 +350,7 @@ open class YAxisRenderer: AxisRendererBase
align: .right,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .rightBottom
else if l.labelPosition == .bottomRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -360,7 +360,7 @@ open class YAxisRenderer: AxisRendererBase
align: .right,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .leftTop
else if l.labelPosition == .topLeft
{
ChartUtils.drawText(context: context,
text: label,
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift
Original file line number Diff line number Diff line change
@@ -315,7 +315,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer
let xOffset: CGFloat = l.lineWidth + l.xOffset
let yOffset: CGFloat = 2.0 + l.yOffset

if l.labelPosition == .rightTop
if l.labelPosition == .topRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -325,7 +325,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer
align: .left,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .rightBottom
else if l.labelPosition == .bottomRight
{
ChartUtils.drawText(context: context,
text: label,
@@ -335,7 +335,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer
align: .left,
attributes: [NSAttributedString.Key.font: l.valueFont, NSAttributedString.Key.foregroundColor: l.valueTextColor])
}
else if l.labelPosition == .leftTop
else if l.labelPosition == .topLeft
{
ChartUtils.drawText(context: context,
text: label,