<commit_before>//
//  DialControl.swift
//  HOWL
//
//  Created by <NAME> on 5/12/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import Bezzy
import Degrad
import Lerp

@IBDesignable class DialControl: RoundedControl {
    
    // MARK: - Constants
    
    private let dialRadius: Float = 0.375
    
    private let minimumAngle: Float = 45°
    private let maximumAngle: Float = 315°
    
    private let minimumDeadZone: Float = 2°
    private let maximumDeadZone: Float = 358°
    
    // MARK: - Properties
    
    @IBInspectable var title: String? { didSet { titleLabel.text = titleText } }
    @IBInspectable var suffix: String? { didSet { valueLabel.text = valueText } }
    
    @IBInspectable var value: Float = 0.0 {
        didSet {
            valueLabel.text = valueText
            setNeedsDisplay()
            sendActionsForControlEvents([.ValueChanged])
        }
    }
    
    @IBInspectable var valueMinimum: Float = 0.0 { didSet { setNeedsDisplay() } }
    @IBInspectable var valueMaximum: Float = 1.0 { didSet { setNeedsDisplay() } }
    
    @IBInspectable var decimalPoints: Int = 1 { didSet { valueLabel.text = valueText } }
    
    @IBInspectable var scaleLogarithmic: Bool = false { didSet { setNeedsDisplay() } }
    @IBInspectable var scaleStep: Bool = false { didSet { setNeedsDisplay() } }
    
    @IBInspectable var textColor: UIColor = UIColor.blackColor() { didSet { configureLabels() } }
    @IBInspectable var fontName: String? { didSet { configureLabels() } }
    @IBInspectable var fontSize: CGFloat = 12.0 { didSet { configureLabels() } }
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .Center
        return label
    }()
    
    lazy var valueLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .Center
        return label
    }()
    
    // MARK: - Overrides
    
    override func awakeFromNib() {
        super.awakeFromNib()
        configure()
    }
    
    override func prepareForInterfaceBuilder() {
        super.prepareForInterfaceBuilder()
        configure()
    }
    
    override var selected: Bool {
        didSet {
            setNeedsDisplay()
        }
    }
    
    override var highlighted: Bool {
        didSet {
            setNeedsDisplay()
        }
    }

    override func drawRect(rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        
        CGContextClearRect(context, rect)
        
        CGContextSetFillColorWithColor(context, backgroundPathColor.CGColor)
        CGContextAddPath(context, backgroundPath.CGPath)
        CGContextFillPath(context)
        
        CGContextSetFillColorWithColor(context, foregroundPathColor.CGColor)
        CGContextAddPath(context, foregroundPath.CGPath)
        CGContextFillPath(context)
    }
    
    override func updateConstraints() {
        super.updateConstraints()
    }
    
    // MARK: - Configuration
    
    private func configure() {
        addSubview(titleLabel)
        addSubview(valueLabel)
        
        titleLabel.snp_updateConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.25)
        }
        
        valueLabel.snp_updateConstraints { make in<commit_msg>What was that doing there?<commit_after>//
//  DialControl.swift
//  HOWL
//
//  Created by <NAME> on 5/12/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import Bezzy
import Degrad
import Lerp

@IBDesignable class DialControl: RoundedControl {
    
    // MARK: - Constants
    
    private let dialRadius: Float = 0.375
    
    private let minimumAngle: Float = 45°
    private let maximumAngle: Float = 315°
    
    private let minimumDeadZone: Float = 2°
    private let maximumDeadZone: Float = 358°
    
    // MARK: - Properties
    
    @IBInspectable var title: String? { didSet { titleLabel.text = titleText } }
    @IBInspectable var suffix: String? { didSet { valueLabel.text = valueText } }
    
    @IBInspectable var value: Float = 0.0 {
        didSet {
            valueLabel.text = valueText
            setNeedsDisplay()
            sendActionsForControlEvents([.ValueChanged])
        }
    }
    
    @IBInspectable var valueMinimum: Float = 0.0 { didSet { setNeedsDisplay() } }
    @IBInspectable var valueMaximum: Float = 1.0 { didSet { setNeedsDisplay() } }
    
    @IBInspectable var decimalPoints: Int = 1 { didSet { valueLabel.text = valueText } }
    
    @IBInspectable var scaleLogarithmic: Bool = false { didSet { setNeedsDisplay() } }
    @IBInspectable var scaleStep: Bool = false { didSet { setNeedsDisplay() } }
    
    @IBInspectable var textColor: UIColor = UIColor.blackColor() { didSet { configureLabels() } }
    @IBInspectable var fontName: String? { didSet { configureLabels() } }
    @IBInspectable var fontSize: CGFloat = 12.0 { didSet { configureLabels() } }
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .Center
        return label
    }()
    
    lazy var valueLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .Center
        return label
    }()
    
    // MARK: - Overrides
    
    override func awakeFromNib() {
        super.awakeFromNib()
        configure()
    }
    
    override func prepareForInterfaceBuilder() {
        super.prepareForInterfaceBuilder()
        configure()
    }
    
    override var selected: Bool {
        didSet {
            setNeedsDisplay()
        }
    }
    
    override var highlighted: Bool {
        didSet {
            setNeedsDisplay()
        }
    }

    override func drawRect(rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        
        CGContextClearRect(context, rect)
        
        CGContextSetFillColorWithColor(context, backgroundPathColor.CGColor)
        CGContextAddPath(context, backgroundPath.CGPath)
        CGContextFillPath(context)
        
        CGContextSetFillColorWithColor(context, foregroundPathColor.CGColor)
        CGContextAddPath(context, foregroundPath.CGPath)
        CGContextFillPath(context)
    }
    
    // MARK: - Configuration
    
    private func configure() {
        addSubview(titleLabel)
        addSubview(valueLabel)
        
        titleLabel.snp_updateConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.25)
        }
        
        valueLabel.snp_updateConstraints { make in
{'fraction_non_alphanumeric': 0.08913308913308914, 'fraction_numerical': 0.010683760683760684, 'mean_word_length': 2.2392486406327237, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '896949', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1909, 'n_words': 439}