Latest 0.0.1
Homepage https://github.com/robhendriks/Staaf
License MIT
Platforms ios 9.0
Authors

Low-effort bar graph.

Demo

Features

  • [x] Grouped Bar Graph
  • [x] Customizable Graphics
  • [x] Flexible Formatting
  • [ ] Unit and Integration Testing
  • [ ] Documentation

Usage

Data Model

import Staaf

let staafData = StaafData([
    StaafDataGroup([1, 2, 3], label: "A"),
    StaafDataGroup([2, 4, 6], label: "B"),
    StaafDataGroup([3, 6, 9], label: "C")
])

Grouped Bar Graph

import Staaf

let staaf = Staaf(frame: CGRect(x: 0, y: 0, width: 320, height: 320))

staaf.setup {
    // Configure y-axis
    $0.minimumValue = 0
    $0.maximumValue = 100

    // Configure layout
    $0.barSpacing = 5 // horizontal space between each individual bar
    $0.barOffset = 5 // vertical space between bars and the border
    $0.groupDistribution = .proportionally // or .equally
    $0.groupSpacing = 15 // horizontal space between each group

    // Configure group labels
    $0.groupLabelFont = UIFont.systemFont(ofSize: 9)
    $0.groupLabelColor = UIColor.gray
    $0.groupLabelOffset = 5

    // Configure value labels
    $0.valueLabelFont = UIFont.systemFont(ofSize: 7)
    $0.valueLabelColor = UIColor.lightGray
    $0.valueLabelOffset = 3

    // Configure border
    $0.borderWidth = 0.5
    $0.borderColor = UIColor.lightGray

    // Configure formatting
    $0.valueFormatter = WholeNumberFormatter()

    // Configure color
    $0.colorStrategy = SingleColorStrategy()

    // Set data
    $0.data = staafData
}

Formatting

staaf.valueFormatter = WholeNumberFormatter() // Outputs: 0

// OR
staaf.valueFormatter = DecimalFormatter() // Outputs: 0.00

// OR
staaf.valueFormatter = DecimalFormatter(1) // Outputs: 0.0

Styling

staaf.colorStrategy = SingleColorStrategy(UIColor.red)

// OR
staaf.colorStrategy = OddEvenColorStrategy(UIColor.red, UIColor.green)

// OR
staaf.colorStrategy = RainbowColorStrategy([UIColor.red, UIColor.green, UIColor.blue])

Change the strategy’s behaviour.

staaf.colorStrategy.mode = .relative

.relative, .absolute or .group

Latest podspec

{
    "name": "Staaf",
    "version": "0.0.1",
    "summary": "Simple grouped bar graph",
    "homepage": "https://github.com/robhendriks/Staaf",
    "license": "MIT",
    "authors": {
        "Rob Hendriks": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/robhendriks/Staaf.git",
        "commit": "2bdcaf31672097f60dd7dac6f06e3742ff079ff3"
    },
    "source_files": "Sources/**/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This