<commit_before>//
//  BufferSlider.swift
//  Pods
//
//  Created by brianliu on 2016/2/22.
//
//

import UIKit

let padding:CGFloat = 2;

@IBDesignable
public class BufferSlider: UISlider {
    ///0.0 ~ 1.0
    @IBInspectable
    var bufferStartValue:Double = 0{
        didSet{
            if bufferStartValue < 0.0 {
                bufferStartValue = 0
            }
            if bufferStartValue > bufferEndValue {
                bufferStartValue = bufferEndValue
            }
            self.setNeedsDisplay()
        }
    }
    ///0.0 ~ 1.0
    @IBInspectable
    var bufferEndValue:Double = 0{
        didSet{
            if bufferEndValue > 1.0 {
                bufferEndValue = 1
            }
            if bufferEndValue < bufferStartValue{
                bufferEndValue = bufferStartValue
            }
            self.setNeedsDisplay()
        }
    }
    @IBInspectable
    var borderColor:UIColor = UIColor.blackColor()
    @IBInspectable
    var fillColor:UIColor? = nil

    @IBInspectable
    var borderWidth: Double = 0.5 {
        didSet{
            if borderWidth < 0.5 {
                borderWidth = 0.5
            }
            self.setNeedsDisplay()
        }
    }
    
    @IBInspectable
    var sliderHeight: Double = 6 {
        didSet{
            if sliderHeight < 6 {
                sliderHeight = 6
            }
        }
    }
    
    public override func trackRectForBounds(bounds: CGRect) -> CGRect {
        var result = super.trackRectForBounds(bounds)
        result.size.height = 0.01
        return result
    }
    
    public override func drawRect(rect: CGRect) {
        borderColor.set()
        let rect = CGRectInset(self.bounds, CGFloat(borderWidth)+padding, CGFloat(borderWidth))
        let height = sliderHeight.CGFloatValue
        let radius = height/2
        let sliderRect = CGRectMake(rect.origin.x, rect.origin.y + (rect.height/2-radius), rect.width, height)

        let path = UIBezierPath()
        path.addArcWithCenter(CGPointMake(sliderRect.origin.x + radius, sliderRect.origin.y+radius), radius: radius, startAngle: CGFloat(M_PI)/2, endAngle: -CGFloat(M_PI)/2, clockwise: true)
        path.addLineToPoint(CGPointMake(sliderRect.width-radius, sliderRect.origin.y))
        path.addArcWithCenter(CGPointMake(sliderRect.width-radius, sliderRect.origin.y+radius), radius: radius, startAngle: -CGFloat(M_PI)/2, endAngle: CGFloat(M_PI)/2, clockwise: true)
        path.addLineToPoint(CGPointMake(sliderRect.origin.x + radius, sliderRect.origin.y+height))
        
        borderColor.setStroke()
        path.lineWidth = borderWidth.CGFloatValue
        path.stroke()
        path.addClip()
        
        var fillHeight = sliderRect.size.height-borderWidth.CGFloatValue
        if fillHeight < 0 {
            fillHeight = 0
        }
        
        let fillRect = CGRectMake(
            sliderRect.origin.x + sliderRect.size.width*CGFloat(bufferStartValue),
            sliderRect.origin.y + borderWidth.CGFloatValue/2,
            sliderRect.size.width*CGFloat(bufferEndValue-bufferStartValue),
            fillHeight)
        if let color = fillColor { color.setFill() }
        else if let color = self.superview?.tintColor{ color.setFill()}<commit_msg>Add header doc. Make properties public.<commit_after>//
//  BufferSlider.swift
//  Pods
//
//  Created by brianliu on 2016/2/22.
//
//

import UIKit

let padding:CGFloat = 2;

/// - Easily use
/// - Easily customize
/// - Drop-In replacement
/// - Supports **Objective-C** and **Swift**
/// - *@IBDesignable* class *BufferSlider*
/// - *@IBInspectable* property *bufferStartValue* (*Swift.Double*)
/// - 0.0 ~ 1.0
/// - *@IBInspectable* property *bufferEndValue* (*Swift.Double*)
/// - 0.1 ~ 1.0
/// - *@IBInspectable* property *borderColor* (*UIKit.UIColor*)
/// - *@IBInspectable* property *fillColor* (*UIKit.UIColor*)
/// - *@IBInspectable* property *borderWidth* (*Swift.Double*)
/// - *@IBInspectable* property *sliderHeight* (*Swift.Double*)
@IBDesignable public class BufferSlider: UISlider {
    ///0.0 ~ 1.0. @IBInspectable
    @IBInspectable public var bufferStartValue:Double = 0{
        didSet{
            if bufferStartValue < 0.0 {
                bufferStartValue = 0
            }
            if bufferStartValue > bufferEndValue {
                bufferStartValue = bufferEndValue
            }
            self.setNeedsDisplay()
        }
    }
    ///0.0 ~ 1.0. @IBInspectable
    @IBInspectable public var bufferEndValue:Double = 0{
        didSet{
            if bufferEndValue > 1.0 {
                bufferEndValue = 1
            }
            if bufferEndValue < bufferStartValue{
                bufferEndValue = bufferStartValue
            }
            self.setNeedsDisplay()
        }
    }
    
    ///fillColor property. @IBInspectable
    @IBInspectable public var borderColor:UIColor = UIColor.blackColor()
    
    ///fillColor property. @IBInspectable
    @IBInspectable public var fillColor:UIColor? = nil

    ///BorderWidth property. @IBInspectable
    @IBInspectable public var borderWidth: Double = 0.5 {
        didSet{
            if borderWidth < 0.5 {
                borderWidth = 0.5
            }
            self.setNeedsDisplay()
        }
    }
    
    ///Slider height property. @IBInspectable
    @IBInspectable public var sliderHeight: Double = 6 {
        didSet{
            if sliderHeight < 6 {
                sliderHeight = 6
            }
        }
    }
    ///Do not call this delegate mehtod directly. This is for hiding built-in slider drawing after iOS 7.0
    public override func trackRectForBounds(bounds: CGRect) -> CGRect {
        var result = super.trackRectForBounds(bounds)
        result.size.height = 0.01
        return result
    }
    
    ///Custom Drawing. Subclass and and override to suit you needs.
    public override func drawRect(rect: CGRect) {
        borderColor.set()
        let rect = CGRectInset(self.bounds, CGFloat(borderWidth)+padding, CGFloat(borderWidth))
        let height = sliderHeight.CGFloatValue
        let radius = height/2
        let sliderRect = CGRectMake(rect.origin.x, rect.origin.y + (rect.height/2-radius), rect.width, height)

        let path = UIBezierPath()
        path.addArcWithCenter(CGPointMake(sliderRect.origin.x + radius, sliderRect.origin.y+radius), radius: radius, startAngle: CGFloat(M_PI)/2, endAngle: -CGFloat(M_PI)/2, clockwise: true)
        path.addLineToPoint(CGPointMake(sliderRect.width-radius, sliderRect.origin.y))
        path.addArcWithCenter(CGPointMake(sliderRect.width-radius, sliderRect.origin.y+radius), radius: radius, startAngle: -CGFloat(M_PI)/2, endAngle: CGFloat(M_PI)/2, clockwise: true)
        path.addLineToPoint(CGPointMake(sliderRect.origin.x + radius, sliderRect.origin.y+height))
        
        borderColor.setStroke()
        path.lineWidth = borderWidth.CGFloatValue
        path.stroke()
        path.addClip()
        
        var fillHeight = sliderRect.size.height-borderWidth.CGFloatValue
        if fillHeight < 0 {
            fillHeight = 0
        }
        
        let fillRect = CGRectMake(
            sliderRect.origin.x + sliderRect.size.width*CGFloat(bufferStartValue),
            sliderRect.origin.y + borderWidth.CGFloatValue/2,
            sliderRect.size.width*CGFloat(bufferEndValue-bufferStartValue),
            fillHeight)
        if let color = fillColor { color.setFill() }
        else if let color = self.superview?.tintColor{ color.setFill()}
{'fraction_non_alphanumeric': 0.10506616762464911, 'fraction_numerical': 0.01336719689881032, 'mean_word_length': 2.137106918238994, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '3602536', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2238, 'n_words': 461}