Repository: danielgindi/Charts
File: Source/Charts/Charts/ChartViewBase.swift (Swift)

Code before:
            return
        }
        
        if !_offsetsCalculated
        {
            calculateOffsets()
            _offsetsCalculated = true
        }
    }
    
    /// Draws the description text in the bottom right corner of the chart (per default)
    @objc internal func drawDescription(context: CGContext)
    {
        // check if description should be drawn
        guard
            let description = chartDescription,
            description.isEnabled,
            let descriptionText = description.text,
            descriptionText.characters.count > 0
            else { return }
        
        let position: CGPoint
        if let descriptionPosition = description.position {
            position = descriptionPosition
        } else {
            let frame = self.bounds
            position = CGPoint(
                x: frame.width - _viewPortHandler.offsetRight - description.xOffset,
                y: frame.height - _viewPortHandler.offsetBottom - description.yOffset - description.font.lineHeight)
        }
        
        var attrs = [NSAttributedStringKey : Any]()
        
        attrs[NSAttributedStringKey.font] = description.font
        attrs[NSAttributedStringKey.foregroundColor] = description.textColor

        ChartUtils.drawText(
            context: context,
            text: descriptionText,
            point: position,
            align: description.textAlign,
            attributes: attrs)
    }
    
    // MARK: - Highlighting
    
    /// - returns: The array of currently highlighted values. This might an empty if nothing is highlighted.
    @objc open var highlighted: [Highlight]
    {
        return _indicesToHighlight
    }

Review comment (bug):
It's generally good practice to short a variable call  (i.e. `let width = self.frame.size.width`), but in this case it is unnecessary and wrong. Unnecessary because you don't need to explicitly state `self`, and wrong because in Cocoa `frame` and `bounds` mean two different things. `frame` should have never been here in the first place.

So we can just write
```
CGPoint(x: bounds.width - _viewPortHandler.offsetRight - description.xOffset,
        y: bounds.height - _viewPortHandler.offsetBottom - description.yOffset - description.font.lineHeight)
```

Code after:
            return
        }
        
        if !_offsetsCalculated
        {
            calculateOffsets()
            _offsetsCalculated = true
        }
    }
    
    /// Draws the description text in the bottom right corner of the chart (per default)
    @objc internal func drawDescription(context: CGContext)
    {
        // check if description should be drawn
        guard
            let description = chartDescription,
            description.isEnabled,
            let descriptionText = description.text,
            descriptionText.count > 0
            else { return }
        
        let position = description.position ?? CGPoint(x: bounds.width - _viewPortHandler.offsetRight - description.xOffset,
                                                       y: bounds.height - _viewPortHandler.offsetBottom - description.yOffset - description.font.lineHeight)
        
        var attrs = [NSAttributedStringKey : Any]()
        
        attrs[NSAttributedStringKey.font] = description.font
        attrs[NSAttributedStringKey.foregroundColor] = description.textColor

        ChartUtils.drawText(
            context: context,
            text: descriptionText,
            point: position,
            align: description.textAlign,
            attributes: attrs)
    }
    
    // MARK: - Highlighting
    
    /// - returns: The array of currently highlighted values. This might an empty if nothing is highlighted.
    @objc open var highlighted: [Highlight]
    {
        return _indicesToHighlight
    }
    
    /// Set this to false to prevent values from being highlighted by tap gesture.
    /// Values can still be highlighted via drag or programmatically.
    /// **default**: true
    @objc open var highlightPerTapEnabled: Bool
    {
        get { return _highlightPerTapEnabled }