Charts icon indicating copy to clipboard operation
Charts copied to clipboard

MarkerView add tap event

Open Eonlychen opened this issue 4 years ago • 2 comments

i want add a tap action for markerView, how should i do for this

Eonlychen avatar Sep 25 '20 02:09 Eonlychen

open class CHLineChartView: BarLineChartViewBase, LineChartDataProvider {

private var markViewShow: Bool = false

open var lineData: LineChartData? { return _data as? LineChartData }

internal override func initialize()
{
    super.initialize()
    
    renderer = LineChartRenderer(dataProvider: self, animator: _animator, viewPortHandler: _viewPortHandler)
    
    _tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(tap(_:)))
    addGestureRecognizer(_tapGestureRecognizer)
}

@objc func tap(_ recognizer: UITapGestureRecognizer) {
    if _data === nil
    {
        return
    }
    
    if recognizer.state == NSUIGestureRecognizerState.ended
    {
        
        if !isHighLightPerTapEnabled { return }
        let h = getHighlightByTouchPoint(recognizer.location(in: self))
        if self.markViewShow {
            if let markerView = self.marker as? CHMarkerView {
                let location = recognizer.location(in: self)
                if !highlighted.isEmpty && markerView.rect.contains(location) {
                    
                    return
                }
            }
        }
        if h === nil || h == self.lastHighlighted
        {
            
            lastHighlighted = nil
            highlightValue(nil, callDelegate: true)
            
            self.markViewShow = false
        }
        else
        {

            lastHighlighted = h
            highlightValue(h, callDelegate: true)
            
            self.markViewShow = true
        }
    }
}

}

Eonlychen avatar Sep 25 '20 08:09 Eonlychen

have you figured out?

i tried your code, but seems not working

CavalcanteLeo avatar Aug 07 '22 18:08 CavalcanteLeo