Skip to content

Commit

Permalink
Merge branch 'master' into algorithm-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatie committed Mar 9, 2019
2 parents 35a47a4 + 34dafbc commit b14b75d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 85 deletions.
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
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
118 changes: 56 additions & 62 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 @@ -330,22 +332,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 l in limitLines where l.isEnabled
{
for l in xAxis.limitLines where l.isEnabled
{
context.saveGState()
defer { context.restoreGState() }

Expand Down Expand Up @@ -388,55 +384,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 @@ -333,7 +333,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 @@ -343,7 +343,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 @@ -353,7 +353,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 @@ -310,7 +310,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 @@ -320,7 +320,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 @@ -330,7 +330,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

0 comments on commit b14b75d

Please sign in to comment.