Giter Site home page Giter Site logo

tbxark / tkradarchart Goto Github PK

View Code? Open in Web Editor NEW
209.0 8.0 29.0 596 KB

A customizable radar chart in Swift

Home Page: https://tbxark.com

License: MIT License

Swift 94.61% Ruby 2.79% Objective-C 2.61%
swift cocoapods carthage radar-chart chart

tkradarchart's Introduction

TKRadarChart

A customizable radar chart in Swift

Xcode 9.0+ iOS 8.0+ Swift 4.0+ Build Status CocoaPods Carthage compatible License MIT

Requirements

  • iOS 8.0+
  • Xcode 9.0
  • Swift 4.0

Installation

CocoaPods

You can use CocoaPods to install TKRadarChart by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'TKRadarChart'

To get the full benefits import TKRadarChart wherever you import UIKit

import UIKit
import TKRadarChart

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/TKRadarChart.framework to an iOS project.

github "tbxark/TKRadarChart"

Manually

  1. Download and drop TKRadarChart.swift in your project.
  2. Congratulations!

Usage example

Base

Base Description Demo
Step Background polygon laps(min 1) image image
Row Number of edges of polygon (min 3) image image
Section At the same time show the number of data image image

TKRadarChartConfig

This structure is used for custom charts

    var radius: CGFloat    
    var minValue: CGFloat
    var maxValue: CGFloat

    var showPoint: Bool
    var showBorder: Bool
    var fillArea: Bool
    var clockwise: Bool
    var autoCenterPoint: Bool

TKRadarChartDataSource

This protocol represents the data model object. as such, it supplies no information about appearance

protocol TKRadarChartDataSource: class {
    func numberOfStepForRadarChart(_ radarChart: TKRadarChart) -> Int
    func numberOfRowForRadarChart(_ radarChart: TKRadarChart) -> Int
    func numberOfSectionForRadarChart(_ radarChart: TKRadarChart) -> Int

    func titleOfRowForRadarChart(_ radarChart: TKRadarChart, row: Int) -> String
    func valueOfSectionForRadarChart(withRow row: Int, section: Int) -> CGFloat
}

TKRadarChartDelegate

This represents the display and behaviour of the TKRadarChart.

protocol TKRadarChartDelegate: class {
    func colorOfTitleForRadarChart(_ radarChart: TKRadarChart) -> UIColor
    func colorOfLineForRadarChart(_ radarChart: TKRadarChart) -> UIColor
    func colorOfFillStepForRadarChart(_ radarChart: TKRadarChart, step: Int) -> UIColor

    func colorOfSectionFillForRadarChart(_ radarChart: TKRadarChart, section: Int) -> UIColor
    func colorOfSectionBorderForRadarChart(_ radarChart: TKRadarChart, section: Int) -> UIColor
}

Release History

  • 1.4.3 Upgrade to swift 4.2

  • 1.4.2 Fix bugs that can not change the title font

  • 1.4.1 Fix warnign

  • 1.4.0 Upgrade to swift 4.0

  • 1.3.1 Upgrade framework config

  • 1.3.0 Support swift 3.0

  • 1.0.1 Complete basic functions, add Cocoapod and Carthage support

Contribute

We would love for you to contribute to TKRadarChart, check the LICENSE file for more info.

Meta

TBXark โ€“ @tbxark โ€“ [email protected]

Distributed under the MIT license. See LICENSE for more information.

https://github.com/TBXark

tkradarchart's People

Contributors

pilgwon avatar tbxark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tkradarchart's Issues

Custom legend

Hello,

I use your spider chart, it works perfectly well, except I want to custom just a little more the legend of my chart. change the color, the number of line and the font.

If is it possible, How can I do you it ?

Chart is too small and not centered?

Screen Shot 2020-09-10 at 13 19 52

I expect the chart to fill the entire space within the white border, and that it's centered?

Code:

import Reusable
import TKRadarChart
import UIKit

final class ReportSpiderChart: UITableViewCell, Reusable, NibLoadable {
  let labels = ["ARTISTS", "TRACKS", "ALBUMS"]

  @IBOutlet private var chartView: TKRadarChart!
  private var data: ReportData?

  override func awakeFromNib() {
    super.awakeFromNib()
    chartView.configuration.borderWidth = 1
    chartView.dataSource = self
    chartView.delegate = self
    chartView.layer.borderWidth = 1
    chartView.layer.borderColor = UIColor.white.cgColor
  }

  func configure(data: ReportData) {
    self.data = data
    chartView.configuration.maxValue = CGFloat(max(data.artists, data.albums, data.tracks, data.previousArtists, data.previousAlbums, data.previousTracks))
    chartView.reloadData()
  }
}

extension ReportSpiderChart: TKRadarChartDataSource {
  func numberOfStepForRadarChart(_ radarChart: TKRadarChart) -> Int {
    return 3
  }

  func numberOfRowForRadarChart(_ radarChart: TKRadarChart) -> Int {
    return 3
  }

  func numberOfSectionForRadarChart(_ radarChart: TKRadarChart) -> Int {
    return 2
  }

  func titleOfRowForRadarChart(_ radarChart: TKRadarChart, row: Int) -> String {
    return labels[row]
  }

  func valueOfSectionForRadarChart(withRow row: Int, section: Int) -> CGFloat {
    guard let data = data else {
      return 0
    }

    if row == 0 {
      return CGFloat(section == 0 ? data.artists : data.previousArtists)
    }

    if row == 1 {
      return CGFloat(section == 0 ? data.albums : data.previousAlbums)
    }

    if row == 2 {
      return CGFloat(section == 0 ? data.tracks : data.previousTracks)
    }

    return 0
  }
}

extension ReportSpiderChart: TKRadarChartDelegate {
  func colorOfLineForRadarChart(_ radarChart: TKRadarChart) -> UIColor {
    return .reportDivider
  }

  func colorOfFillStepForRadarChart(_ radarChart: TKRadarChart, step: Int) -> UIColor {
    return .black
  }

  func colorOfSectionFillForRadarChart(_ radarChart: TKRadarChart, section: Int) -> UIColor {
    return section == 0 ? UIColor.reportRed.withAlphaComponent(0.75) : UIColor.reportChartInactive.withAlphaComponent(0.75)
  }

  func fontOfTitleForRadarChart(_ radarChart: TKRadarChart) -> UIFont {
    return .systemFont(ofSize: 11, weight: .semibold)
  }

  func colorOfTitleForRadarChart(_ radarChart: TKRadarChart) -> UIColor {
    return .reportGrayText
  }
}

Better Installation Section

Hey, your library is really interesting.

The only problem I found was the README.md, which needs a better Installation Section.
I created this iOS Open source Readme Template so you can take a look on how to easily make the Installation Section better.
If you want, I can help you to organize the lib.

What are your thoughts? ๐Ÿ˜„

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.