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
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
6 changes: 3 additions & 3 deletions ChartsDemo-iOS/Objective-C/Demos/LineChart1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (void)viewDidLoad
ChartLimitLine *llXAxis = [[ChartLimitLine alloc] initWithLimit:10.0 label:@"Index 10"];
llXAxis.lineWidth = 4.0;
llXAxis.lineDashLengths = @[@(10.f), @(10.f), @(0.f)];
llXAxis.labelPosition = ChartLimitLabelPositionRightBottom;
llXAxis.labelPosition = ChartLimitLabelPositionBottomRight;
llXAxis.valueFont = [UIFont systemFontOfSize:10.f];

//[_chartView.xAxis addLimitLine:llXAxis];
Expand All @@ -72,13 +72,13 @@ - (void)viewDidLoad
ChartLimitLine *ll1 = [[ChartLimitLine alloc] initWithLimit:150.0 label:@"Upper Limit"];
ll1.lineWidth = 4.0;
ll1.lineDashLengths = @[@5.f, @5.f];
ll1.labelPosition = ChartLimitLabelPositionRightTop;
ll1.labelPosition = ChartLimitLabelPositionTopRight;
ll1.valueFont = [UIFont systemFontOfSize:10.0];

ChartLimitLine *ll2 = [[ChartLimitLine alloc] initWithLimit:-30.0 label:@"Lower Limit"];
ll2.lineWidth = 4.0;
ll2.lineDashLengths = @[@5.f, @5.f];
ll2.labelPosition = ChartLimitLabelPositionRightBottom;
ll2.labelPosition = ChartLimitLabelPositionBottomRight;
ll2.valueFont = [UIFont systemFontOfSize:10.0];

ChartYAxis *leftAxis = _chartView.leftAxis;
Expand Down
6 changes: 3 additions & 3 deletions ChartsDemo-iOS/Swift/Demos/LineChart1ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Charts/PieRadarChartViewBase.swift
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ open class PieRadarChartViewBase: ChartViewBase
}
velocitySamples.append(currentSample)
}

private func calculateVelocity() -> CGFloat
{
guard var firstSample = velocitySamples.first,
Expand Down Expand Up @@ -714,12 +714,12 @@ open class PieRadarChartViewBase: ChartViewBase
{
lastSample.angle += 360.0
}

// The velocity
let velocity = abs((lastSample.angle - firstSample.angle) / timeDelta)
return isClockwise ? velocity : -velocity
}

/// sets the starting angle of the rotation, this is only used by the touch listener, x and y is the touch position
private func setGestureStartAngle(x: CGFloat, y: CGFloat)
{
Expand Down
10 changes: 5 additions & 5 deletions Source/Charts/Components/ChartLimitLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
123 changes: 55 additions & 68 deletions Source/Charts/Renderers/XAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ open class XAxisRenderer: AxisRendererBase
let paraStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paraStyle.alignment = .center

let labelAttrs: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: xAxis.labelFont,
NSAttributedString.Key.foregroundColor: xAxis.labelTextColor,
NSAttributedString.Key.paragraphStyle: paraStyle]
let labelAttrs: [NSAttributedString.Key : Any] = [
.font: xAxis.labelFont,
.foregroundColor: xAxis.labelTextColor,
.paragraphStyle: paraStyle
]
let labelRotationAngleRadians = xAxis.labelRotationAngle.DEG2RAD

let centeringEnabled = xAxis.isCenterAxisLabelsEnabled
Expand Down Expand Up @@ -334,29 +336,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() }

Expand Down Expand Up @@ -399,55 +388,53 @@ open class XAxisRenderer: AxisRendererBase
{

let label = limitLine.label

// if drawing the limit-value label is enabled
if limitLine.drawLabelEnabled && label.count > 0
{
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])
}
guard limitLine.drawLabelEnabled, !label.isEmpty else { return }

let labelLineHeight = limitLine.valueFont.lineHeight

let xOffset: CGFloat = limitLine.lineWidth + limitLine.xOffset
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
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/YAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down