<commit_before>//
//  ZGTooltipView.swift
//  ZGTooltipView
//
//  Created by <NAME> on 22/05/2016.
//  Copyright © 2016 Zigzag. All rights reserved.
//

import UIKit

private var tooltipTapGestureKey: UInt8 = 0
private var tooltipViewKey: UInt8 = 0
private var tooltipDisplayViewKey: UInt8 = 1

public extension UIView {
    
    public var tooltipTapGesture: UITapGestureRecognizer? {
        get {
            return objc_getAssociatedObject(self, &tooltipTapGestureKey) as? UITapGestureRecognizer
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipTapGestureKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }
    
    public var tooltipView: ZGTooltipView? {
        get {
            return objc_getAssociatedObject(self, &tooltipViewKey) as? ZGTooltipView
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipViewKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }

    public var tooltipDisplayView: UIView? {
        get {
            return objc_getAssociatedObject(self, &tooltipDisplayViewKey) as? UIView
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipDisplayViewKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }
    
    public func setTooltip(_ tooltipView:ZGTooltipView, displayInView displayView: UIView? = nil) {
        self.tooltipView = tooltipView
        self.tooltipDisplayView = displayView
        
        tooltipTapGesture = UITapGestureRecognizer(target: self, action: #selector(UIView.tooltipGestureHandler(_:)))
        self.addGestureRecognizer(tooltipTapGesture!)
    }
    
    public func removeTooltip() {
        if let gesture = tooltipTapGesture {
            self.removeGestureRecognizer(gesture)
        }
        
        tooltipView?.dismiss(remove:true)
    }
    
    public func showTooltip() {
        if tooltipView?.isVisible == false {
            tooltipView?.displayInView(tooltipDisplayView ?? self, origin: self)
        }
    }
    
    public func dismissTooltip(remove:Bool = false) {
        tooltipView?.dismiss(remove:remove)
    }
    
    @objc fileprivate func tooltipGestureHandler(_ gesture:UIGestureRecognizer) {
        
        if let tooltipView = tooltipView {
            tooltipView.isVisible ? dismissTooltip(remove:false) : showTooltip()
        }
    }
    
}

open class ZGTooltipView: UIView {
    
    static let triangleMargin : CGFloat = 10
    
    open var animationEnable = true
    open override var backgroundColor: UIColor? {
        didSet {
            triangleShapeLayer?.fillColor = backgroundColor?.cgColor
        }
    }
    
    fileprivate var isVisible = false
    fileprivate var contentView : UIView!
    fileprivate var direction : Direction = .left
    fileprivate var triangleShapeLayer : CAShapeLayer!
    
    @objc public enum Direction : Int {
        case left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight<commit_msg>Clarify dismiss vs remove methods<commit_after>//
//  ZGTooltipView.swift
//  ZGTooltipView
//
//  Created by <NAME> on 22/05/2016.
//  Copyright © 2016 Zigzag. All rights reserved.
//

import UIKit

private var tooltipTapGestureKey: UInt8 = 0
private var tooltipViewKey: UInt8 = 0
private var tooltipDisplayViewKey: UInt8 = 1

public extension UIView {
    
    public var tooltipTapGesture: UITapGestureRecognizer? {
        get {
            return objc_getAssociatedObject(self, &tooltipTapGestureKey) as? UITapGestureRecognizer
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipTapGestureKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }
    
    public var tooltipView: ZGTooltipView? {
        get {
            return objc_getAssociatedObject(self, &tooltipViewKey) as? ZGTooltipView
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipViewKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }

    public var tooltipDisplayView: UIView? {
        get {
            return objc_getAssociatedObject(self, &tooltipDisplayViewKey) as? UIView
        }
        set(newValue) {
            objc_setAssociatedObject(self, &tooltipDisplayViewKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }
    
    public func setTooltip(_ tooltipView:ZGTooltipView, displayInView displayView: UIView? = nil) {
        self.tooltipView = tooltipView
        self.tooltipDisplayView = displayView
        
        tooltipTapGesture = UITapGestureRecognizer(target: self, action: #selector(UIView.tooltipGestureHandler(_:)))
        self.addGestureRecognizer(tooltipTapGesture!)
    }
    
    public func removeTooltip() {
        if let gesture = tooltipTapGesture {
            self.removeGestureRecognizer(gesture)
        }
        
        tooltipView?.dismiss(remove: true)
        
        // Reset all variables
        tooltipView = nil
        tooltipDisplayView = nil
        tooltipTapGesture = nil
    }
    
    public func showTooltip() {
        if tooltipView?.isVisible == false {
            tooltipView?.displayInView(tooltipDisplayView ?? self, origin: self)
        }
    }
    
    public func dismissTooltip() {
        tooltipView?.dismiss(remove: false)
    }
    
    @objc fileprivate func tooltipGestureHandler(_ gesture:UIGestureRecognizer) {
        
        if let tooltipView = tooltipView {
            tooltipView.isVisible ? dismissTooltip() : showTooltip()
        }
    }
    
}

open class ZGTooltipView: UIView {
    
    static let triangleMargin : CGFloat = 10
    
    open var animationEnable = true
    open override var backgroundColor: UIColor? {
        didSet {
            triangleShapeLayer?.fillColor = backgroundColor?.cgColor
        }
    }
    
    fileprivate var isVisible = false
    fileprivate var contentView : UIView!
    fileprivate var direction : Direction = .left
    fileprivate var triangleShapeLayer : CAShapeLayer!
    
    @objc public enum Direction : Int {
        case left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight
{'fraction_non_alphanumeric': 0.07317468026550106, 'fraction_numerical': 0.006475635421725757, 'mean_word_length': 2.6107539450613677, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7046418', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1818, 'n_words': 385}