Skip to content

Commit

Permalink
Fix function_body_length warning
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Dec 31, 2023
1 parent e775dfe commit c8bd81f
Showing 1 changed file with 115 additions and 91 deletions.
206 changes: 115 additions & 91 deletions SWDestinyTrades/Classes/DeckGraph/View/GraphMarker/BalloonMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,113 +71,137 @@ open class BalloonMarker: MarkerImage {
}

override open func draw(context: CGContext, point: CGPoint) {
if labelns == nil {
guard let labelns = labelns else {
return
}

let offset = offsetForDrawing(atPoint: point)
let size = self.size
var rect = calculateRect(atPoint: point, withOffset: offset, andSize: size)

var rect = CGRect(
origin: CGPoint(
x: point.x + offset.x,
y: point.y + offset.y
),
size: size
)
rect.origin.x -= size.width / 2.0
rect.origin.y -= size.height
context.saveGState()

if let color = color {
context.setFillColor(color.cgColor)
if offset.y > 0 {
context.beginPath()
context.move(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
y: rect.origin.y + arrowSize.height
))
// arrow vertex
context.addLine(to: CGPoint(
x: point.x,
y: point.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + rect.size.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + rect.size.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + arrowSize.height
))
context.fillPath()
} else {
context.beginPath()
context.move(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
y: rect.origin.y + rect.size.height - arrowSize.height
))
// arrow vertex
context.addLine(to: CGPoint(
x: point.x,
y: point.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y
))
context.fillPath()
}
drawBackground(context: context, point: point, rect: rect, offset: offset, color: color)
}

rect = adjustRectForInsets(rect, offset: offset)

drawLabel(in: rect, withAttributes: _drawAttributes, context: context)

context.restoreGState()
}

private func calculateRect(atPoint point: CGPoint, withOffset offset: CGPoint, andSize size: CGSize) -> CGRect {
var rect = CGRect(origin: CGPoint(x: point.x + offset.x, y: point.y + offset.y), size: size)
rect.origin.x -= size.width / 2.0
rect.origin.y -= size.height
return rect
}

private func drawBackground(context: CGContext, point: CGPoint, rect: CGRect, offset: CGPoint, color: UIColor) {
context.setFillColor(color.cgColor)

context.beginPath()
if offset.y > 0 {
rect.origin.y += insets.top + arrowSize.height
drawUpwardArrow(context: context, point: point, rect: rect)
} else {
rect.origin.y += insets.top
drawDownwardArrow(context: context, point: point, rect: rect)
}
rect.size.height -= insets.top + insets.bottom
context.fillPath()
}

UIGraphicsPushContext(context)
private func drawUpwardArrow(context: CGContext, point: CGPoint, rect: CGRect) {
context.beginPath()
context.move(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
y: rect.origin.y + arrowSize.height
))
// arrow vertex
context.addLine(to: CGPoint(
x: point.x,
y: point.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + rect.size.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + rect.size.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + arrowSize.height
))
context.fillPath()
}

labelns?.draw(in: rect, withAttributes: _drawAttributes)
private func drawDownwardArrow(context: CGContext, point: CGPoint, rect: CGRect) {
context.beginPath()
context.move(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
y: rect.origin.y + rect.size.height - arrowSize.height
))
// arrow vertex
context.addLine(to: CGPoint(
x: point.x,
y: point.y
))
context.addLine(to: CGPoint(
x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y + rect.size.height - arrowSize.height
))
context.addLine(to: CGPoint(
x: rect.origin.x,
y: rect.origin.y
))
context.fillPath()
}

UIGraphicsPopContext()
private func adjustRectForInsets(_ rect: CGRect, offset: CGPoint) -> CGRect {
var adjustedRect = rect
if offset.y > 0 {
adjustedRect.origin.y += insets.top + arrowSize.height
} else {
adjustedRect.origin.y += insets.top
}
adjustedRect.size.height -= insets.top + insets.bottom
return adjustedRect
}

context.restoreGState()
private func drawLabel(in rect: CGRect, withAttributes attributes: [NSAttributedString.Key: Any], context: CGContext) {
UIGraphicsPushContext(context)
labelns?.draw(in: rect, withAttributes: attributes)
UIGraphicsPopContext()
}

override open func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
Expand Down

0 comments on commit c8bd81f

Please sign in to comment.