<commit_before>//
//  GradientView.swift
//  Gradient View
//
//  Created by <NAME> on 10/27/09.
//  Copyright (c) 2009-2014 <NAME>. All rights reserved.
//

import UIKit

/// Simple view for drawing gradients and borders.
@IBDesignable
public class GradientView: UIView {

	// MARK: - Types

	/// The mode of the gradient.
  public enum Type {
		/// A linear gradient.
		case Linear

		/// A radial gradient.
		case Radial
	}


	/// The direction of the gradient.
	public enum Direction {
		/// The gradient is vertical.
		case Vertical

		/// The gradient is horizontal
		case Horizontal
	}


	// MARK: - Properties

	/// An optional array of `UIColor` objects used to draw the gradient. If the value is `nil`, the `backgroundColor`
	/// will be drawn instead of a gradient. The default is `nil`.
	public var colors: [UIColor]? {
		didSet {
			updateGradient()
		}
	}

	/// An array of `UIColor` objects used to draw the dimmed gradient. If the value is `nil`, `colors` will be
	/// converted to grayscale. This will use the same `locations` as `colors`. If length of arrays don't match, bad
	/// things will happen. You must make sure the number of dimmed colors equals the number of regular colors.
	///
	/// The default is `nil`.
	public var dimmedColors: [UIColor]? {
		didSet {
			updateGradient()
		}
	}

	/// Automatically dim gradient colors when prompted by the system (i.e. when an alert is shown).
	///
  /// The default is `true`.
	public var automaticallyDims: Bool = true

	/// An optional array of `CGFloat`s defining the location of each gradient stop.
	///
	/// The gradient stops are specified as values between `0` and `1`. The values must be monotonically increasing. If
	/// `nil`, the stops are spread uniformly across the range.
	///
	/// Defaults to `nil`.
	public var locations: [CGFloat]? {
		didSet {
			updateGradient()
		}
	}

  /// The mode of the gradient. The default is `.Linear`.
  @IBInspectable
	public var mode: Type = .Linear {
		didSet {
			setNeedsDisplay()
		}
	}

  /// The direction of the gradient. Only valid for the `Mode.Linear` mode. The default is `.Vertical`.
  @IBInspectable
	public var direction: Direction = .Vertical {
		didSet {
			setNeedsDisplay()
		}
	}

  /// 1px borders will be drawn instead of 1pt borders. The default is `true`.
  @IBInspectable
	public var drawsThinBorders: Bool = true {
		didSet {
			setNeedsDisplay()
		}
	}

  /// The top border color. The default is `nil`.
  @IBInspectable
	public var topBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

  /// The right border color. The default is `nil`.
  @IBInspectable
	public var rightBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

  ///  The bottom border color. The default is `nil`.
  @IBInspectable
	public var bottomBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

  /// The left border color. The default is `nil`.
  @IBInspectable
	public var leftBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}


	// MARK: - UIView

	override public func drawRect(rect: CGRect) {
		let context = UIGraphicsGetCurrentContext()
		let size = bounds.size

		// Gradient
		if let gradient = gradient {
            let options: CGGradientDrawingOptions = [.DrawsAfterEndLocation]

			if mode == .Linear {
				let startPoint = CGPointZero
				let endPoint = direction == .Vertical ? CGPoint(x: 0, y: size.height) : CGPoint(x: size.width, y: 0)
				CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, options)
			} else {
				let center = CGPoint(x: bounds.midX, y: bounds.midY)
				CGContextDrawRadialGradient(context, gradient, center, 0, center, min(size.width, size.height) / 2, options)
			}<commit_msg>Change to original whitespace<commit_after>//
//  GradientView.swift
//  Gradient View
//
//  Created by <NAME> on 10/27/09.
//  Copyright (c) 2009-2014 <NAME>. All rights reserved.
//

import UIKit

/// Simple view for drawing gradients and borders.
@IBDesignable
public class GradientView: UIView {

	// MARK: - Types

	/// The mode of the gradient.
	public enum Type {
		/// A linear gradient.
		case Linear

		/// A radial gradient.
		case Radial
	}


	/// The direction of the gradient.
	public enum Direction {
		/// The gradient is vertical.
		case Vertical

		/// The gradient is horizontal
		case Horizontal
	}


	// MARK: - Properties

	/// An optional array of `UIColor` objects used to draw the gradient. If the value is `nil`, the `backgroundColor`
	/// will be drawn instead of a gradient. The default is `nil`.
	public var colors: [UIColor]? {
		didSet {
			updateGradient()
		}
	}

	/// An array of `UIColor` objects used to draw the dimmed gradient. If the value is `nil`, `colors` will be
	/// converted to grayscale. This will use the same `locations` as `colors`. If length of arrays don't match, bad
	/// things will happen. You must make sure the number of dimmed colors equals the number of regular colors.
	///
	/// The default is `nil`.
	public var dimmedColors: [UIColor]? {
		didSet {
			updateGradient()
		}
	}

	/// Automatically dim gradient colors when prompted by the system (i.e. when an alert is shown).
	///
	/// The default is `true`.
	public var automaticallyDims: Bool = true

	/// An optional array of `CGFloat`s defining the location of each gradient stop.
	///
	/// The gradient stops are specified as values between `0` and `1`. The values must be monotonically increasing. If
	/// `nil`, the stops are spread uniformly across the range.
	///
	/// Defaults to `nil`.
	public var locations: [CGFloat]? {
		didSet {
			updateGradient()
		}
	}

	/// The mode of the gradient. The default is `.Linear`.
	@IBInspectable
	public var mode: Type = .Linear {
		didSet {
			setNeedsDisplay()
		}
	}

	/// The direction of the gradient. Only valid for the `Mode.Linear` mode. The default is `.Vertical`.
	@IBInspectable
	public var direction: Direction = .Vertical {
		didSet {
			setNeedsDisplay()
		}
	}

	/// 1px borders will be drawn instead of 1pt borders. The default is `true`.
	@IBInspectable
	public var drawsThinBorders: Bool = true {
		didSet {
			setNeedsDisplay()
		}
	}

	/// The top border color. The default is `nil`.
	@IBInspectable
	public var topBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

	/// The right border color. The default is `nil`.
	@IBInspectable
	public var rightBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

	///  The bottom border color. The default is `nil`.
	@IBInspectable
	public var bottomBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}

	/// The left border color. The default is `nil`.
	@IBInspectable
	public var leftBorderColor: UIColor? {
		didSet {
			setNeedsDisplay()
		}
	}


	// MARK: - UIView

	override public func drawRect(rect: CGRect) {
		let context = UIGraphicsGetCurrentContext()
		let size = bounds.size

		// Gradient
		if let gradient = gradient {
	          let options: CGGradientDrawingOptions = [.DrawsAfterEndLocation]

			if mode == .Linear {
				let startPoint = CGPointZero
				let endPoint = direction == .Vertical ? CGPoint(x: 0, y: size.height) : CGPoint(x: size.width, y: 0)
				CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, options)
			} else {
				let center = CGPoint(x: bounds.midX, y: bounds.midY)
				CGContextDrawRadialGradient(context, gradient, center, 0, center, min(size.width, size.height) / 2, options)
			}
{'fraction_non_alphanumeric': 0.10953346855983773, 'fraction_numerical': 0.005949966193373901, 'mean_word_length': 2.8987875593041643, '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': '4634981', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2283, 'n_words': 855}