<commit_before>//
//  NapySlider.swift
//  NapySlider
//
//  Created by <NAME> on 12.12.15.
//  Copyright © 2015 naptics. All rights reserved.
//

import UIKit

@IBDesignable
class NapySlider: UIControl {
    
    // internal variables, our views
    internal var backgroundView: UIView!
    internal var titleBackgroundView: UIView!
    internal var sliderView: UIView!
    internal var sliderBackgroundView: UIView!
    internal var sliderFillView: UIView!
    internal var handleView: UIView!
    
    internal var titleLabel: UILabel!
    internal var handleLabel: UILabel!
    internal var currentPosLabel: UILabel!
    internal var maxLabel: UILabel!
    internal var minLabel: UILabel!
    
    // public variables
    var titleHeight: CGFloat = 30
    var sliderWidth: CGFloat = 20
    var handleHeight: CGFloat = 20
    var handleWidth: CGFloat = 50
    
    // public inspectable variables
    @IBInspectable var title: String = "Hello" {
        didSet {
            titleLabel.text = title
        }
    }
    
    @IBInspectable var min: Double = 0 {
        didSet {
            minLabel.text = textForPosition(min)
        }
    }
    
    @IBInspectable var max: Double = 10 {
        didSet {
            maxLabel.text = textForPosition(max)
        }
    }
    
    @IBInspectable var step: Double = 1
    
    // colors
    @IBInspectable var handleColor: UIColor = UIColor.grayColor()
    @IBInspectable var mainBackgroundColor: UIColor = UIColor.groupTableViewBackgroundColor()
    @IBInspectable var titleBackgroundColor: UIColor = UIColor.lightGrayColor()
    @IBInspectable var sliderUnselectedColor: UIColor = UIColor.lightGrayColor()
    
    /**
     the position of the handle. The handle moves animated when setting the variable
    */
    var handlePosition:Double {
        set (newHandlePosition) {
            moveHandleToPosition(newHandlePosition, animated: true)
        }
        get {
            let currentY = handleView.frame.origin.y + handleHeight/2
            let positionFromMin = -(Double(currentY) - minPosition - stepheight/2) / stepheight
            let position = Int((positionFromMin * step + min) / step) * Int(step)
            return Double(position)
        }
    }
    
    var disabled:Bool = false {
        didSet {
            sliderBackgroundView.alpha = disabled ? 0.4 : 1.0
        }
    }
    <commit_msg>fix position approximation when min value is negative<commit_after>//
//  NapySlider.swift
//  NapySlider
//
//  Created by <NAME> on 12.12.15.
//  Copyright © 2015 naptics. All rights reserved.
//

import UIKit

@IBDesignable
class NapySlider: UIControl {
    
    // internal variables, our views
    internal var backgroundView: UIView!
    internal var titleBackgroundView: UIView!
    internal var sliderView: UIView!
    internal var sliderBackgroundView: UIView!
    internal var sliderFillView: UIView!
    internal var handleView: UIView!
    
    internal var titleLabel: UILabel!
    internal var handleLabel: UILabel!
    internal var currentPosLabel: UILabel!
    internal var maxLabel: UILabel!
    internal var minLabel: UILabel!
    
    // public variables
    var titleHeight: CGFloat = 30
    var sliderWidth: CGFloat = 20
    var handleHeight: CGFloat = 20
    var handleWidth: CGFloat = 50
    
    // public inspectable variables
    @IBInspectable var title: String = "Hello" {
        didSet {
            titleLabel.text = title
        }
    }
    
    @IBInspectable var min: Double = 0 {
        didSet {
            minLabel.text = textForPosition(min)
        }
    }
    
    @IBInspectable var max: Double = 10 {
        didSet {
            maxLabel.text = textForPosition(max)
        }
    }
    
    @IBInspectable var step: Double = 1
    
    // colors
    @IBInspectable var handleColor: UIColor = UIColor.grayColor()
    @IBInspectable var mainBackgroundColor: UIColor = UIColor.groupTableViewBackgroundColor()
    @IBInspectable var titleBackgroundColor: UIColor = UIColor.lightGrayColor()
    @IBInspectable var sliderUnselectedColor: UIColor = UIColor.lightGrayColor()
    
    /**
     the position of the handle. The handle moves animated when setting the variable
    */
    var handlePosition:Double {
        set (newHandlePosition) {
            moveHandleToPosition(newHandlePosition, animated: true)
        }
        get {
            let currentY = handleView.frame.origin.y + handleHeight/2
            let positionFromMin = -(Double(currentY) - minPosition - stepheight/2) / stepheight
            
            // add an offset if slider should go to a negative value
            var stepOffset:Double = 0
            if min < 0 {
            let zeroPosition = (0 - min)/Double(step) + 0.5
                if positionFromMin < zeroPosition {
                    stepOffset = 0 - step
                }
            }
            
            let position = Int((positionFromMin * step + min + stepOffset) / step) * Int(step)
            return Double(position)
        }
    }
    
    var disabled:Bool = false {
        didSet {
            sliderBackgroundView.alpha = disabled ? 0.4 : 1.0
        }
    }
    
{'fraction_non_alphanumeric': 0.0774469741194785, 'fraction_numerical': 0.012064604008561977, 'mean_word_length': 2.1553100061387354, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3279012', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1467, 'n_words': 412}