Skip to content

Commit

Permalink
Merge pull request #2628 from jjatie/demos
Browse files Browse the repository at this point in the history
Swift iOS Demos
  • Loading branch information
pmairoldi authored Nov 15, 2017
2 parents fc22a27 + b4f84b6 commit 3672219
Show file tree
Hide file tree
Showing 125 changed files with 4,736 additions and 200 deletions.
451 changes: 413 additions & 38 deletions ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions ChartsDemo/Classes/RealmDemosViewController.h

This file was deleted.

35 changes: 0 additions & 35 deletions ChartsDemo/Classes/RealmDemosViewController.m

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"version" : 1,
"author" : "xcode"
}
}
}
54 changes: 54 additions & 0 deletions ChartsDemo/Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// AppDelegate.swift
// ChartsDemo-iOS
//
// Created by Jacob Christie on 2017-07-03.
// Copyright © 2017 jc. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)


let vc = DemoListViewController()
let nav = UINavigationController(rootViewController: vc)

window?.rootViewController = nav
window?.makeKeyAndVisible()

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

122 changes: 122 additions & 0 deletions ChartsDemo/Swift/Components/BalloonMarker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// BalloonMarker.swift
// ChartsDemo-iOS
//
// Created by Jacob Christie on 2017-07-09.
// Copyright © 2017 jc. All rights reserved.
//

import Foundation
import Charts

public class BalloonMarker: MarkerImage {
public var color: UIColor
public var arrowSize = CGSize(width: 15, height: 11)
public var font: UIFont
public var textColor: UIColor
public var insets: UIEdgeInsets
public var minimumSize = CGSize()

fileprivate var label: String?
fileprivate var _labelSize: CGSize = CGSize()
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
fileprivate var _drawAttributes = [NSAttributedStringKey : AnyObject]()

public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets) {
self.color = color
self.font = font
self.textColor = textColor
self.insets = insets

_paragraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle
_paragraphStyle?.alignment = .center
super.init()
}

public override func offsetForDrawing(atPoint point: CGPoint) -> CGPoint {
let size = self.size
var point = point
point.x -= size.width / 2.0
point.y -= size.height
return super.offsetForDrawing(atPoint: point)
}

public override func draw(context: CGContext, point: CGPoint) {
guard let label = label else { return }

let offset = self.offsetForDrawing(atPoint: point)
let size = self.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()

context.setFillColor(color.cgColor)
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))
context.addLine(to: CGPoint(
x: rect.origin.x + rect.size.width / 2.0,
y: rect.origin.y + rect.size.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))
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()

rect.origin.y += self.insets.top
rect.size.height -= self.insets.top + self.insets.bottom

UIGraphicsPushContext(context)

label.draw(in: rect, withAttributes: _drawAttributes)

UIGraphicsPopContext()

context.restoreGState()
}

public override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
setLabel(String(entry.y))
}

public func setLabel(_ newLabel: String) {
label = newLabel

_drawAttributes.removeAll()
_drawAttributes[.font] = self.font
_drawAttributes[.paragraphStyle] = _paragraphStyle
_drawAttributes[.foregroundColor] = self.textColor

_labelSize = label?.size(withAttributes: _drawAttributes) ?? CGSize.zero

var size = CGSize()
size.width = _labelSize.width + self.insets.left + self.insets.right
size.height = _labelSize.height + self.insets.top + self.insets.bottom
size.width = max(minimumSize.width, size.width)
size.height = max(minimumSize.height, size.height)
self.size = size
}

}
27 changes: 27 additions & 0 deletions ChartsDemo/Swift/Components/RadarMarkerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// RadarMarkerView.swift
// ChartsDemo
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/Charts
//

import Foundation
import Charts

public class RadarMarkerView: MarkerView {
@IBOutlet var label: UILabel!

public override func awakeFromNib() {
self.offset.x = -self.frame.size.width / 2.0
self.offset.y = -self.frame.size.height - 7.0
}

public override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
label.text = String.init(format: "%d %%", Int(round(entry.y)))
layoutIfNeeded()
}
}
32 changes: 32 additions & 0 deletions ChartsDemo/Swift/Components/XYMarkerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// XYMarkerView.swift
// ChartsDemo-iOS
//
// Created by Jacob Christie on 2017-07-09.
// Copyright © 2017 jc. All rights reserved.
//

import Foundation
import Charts

public class XYMarkerView: BalloonMarker {
public var xAxisValueFormatter: IAxisValueFormatter
fileprivate var yFormatter = NumberFormatter()

public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets,
xAxisValueFormatter: IAxisValueFormatter) {
self.xAxisValueFormatter = xAxisValueFormatter
yFormatter.minimumFractionDigits = 1
yFormatter.maximumFractionDigits = 1
super.init(color: color, font: font, textColor: textColor, insets: insets)
}

public override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
let string = "x: "
+ xAxisValueFormatter.stringForValue(entry.x, axis: XAxis())
+ ", y: "
+ yFormatter.string(from: NSNumber(floatLiteral: entry.y))!
setLabel(string)
}

}
Loading

0 comments on commit 3672219

Please sign in to comment.