Coder Social home page Coder Social logo

graphs's Introduction

#Graphs Badge w/ Version Carthage compatible MIT License

###Light weight charts view generater for iOS. Written in Swift.

Graphs mock

Requirements

  • iOS 8.0+
  • XCode 7.3+

Installation

$ pod init

specify it in your Podfile

platform :ios, '8.0'

target 'TargetName' do

  use_frameworks!
  pod 'Graphs', '~> 0.1.2'

end

And run CocoaPods

$ pod install

--

You can install Carthage with Homebrew.

$ brew update
$ brew install carthage

specify it in your Cartfile

github "recruit-mtl/Graphs"

And run carthage

$ carthage update --platform ios

Usage

#####import Graphs

import Graphs
Range -> GraphView (Bar)
let view = (1 ... 10).barGraph(GraphRange(min: 0, max: 11)).view(viewFrame)

Array -> GraphView (Line)
let view = [10, 20, 4, 8, 25, 18, 21, 24, 8, 15].lineGraph(GraphRange(min: 0, max: 30)).view(viewFrame)

Dictionary -> GraphView (Pie)
let view = ["a": 3, "b": 8, "c": 9, "d": 20].pieGraph().view(viewFrame)
GraphData protocol -> GraphView (Pie)
import Graphs

struct Data<T: Hashable, U: NumericType>: GraphData {
    typealias GraphDataKey = T
    typealias GraphDataValue = U
    
    private let _key: T
    private let _value: U
    
    init(key: T, value: U) {
        self._key = key
        self._value = value
    }
    
    var key: T { get{ return self._key } }
    var value: U { get{ return self._value } }
}

let data = [
    Data(key: "John", value: 18.9),
    Data(key: "Ken", value: 32.9),
    Data(key: "Taro", value: 15.3),
    Data(key: "Micheal", value: 22.9),
    Data(key: "Jun", value: 12.9),
    Data(key: "Hanako", value: 32.2),
    Data(key: "Kent", value: 3.8)
]

let view = data.pieGraph() { (unit, totalValue) -> String? in
    return unit.key! + "\n" + String(format: "%.0f%%", unit.value / totalValue * 100.0)
}.view(viewFrame)

More detail

-> Read Playgrounds

Demo

$ git clone https://github.com/recruit-mtl/Graphs.git
$ cd /path/to/Graphs/GraphsExample
$ pod install

And Open GraphsExample.xcworkspace

Issues

GraphView doesn't work on Interface builder.

Interface Builder talks to code through the ObjC runtime. And ObjC doesn't do generics.

Licence

MIT

Author

graphs's People

Contributors

kokoron avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.