Skip to content

Commit

Permalink
Added custom text alignment for noData
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatie committed Jan 21, 2018
1 parent 43ccf8e commit c42ffe3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate

/// color of the no data text
@objc open var noDataTextColor: NSUIColor = NSUIColor.black


/// alignment of the no data text
open var noDataTextAlignment: NSTextAlignment = .left

internal var _legendRenderer: LegendRenderer!

/// object responsible for rendering the data
Expand Down Expand Up @@ -308,14 +311,20 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
{
context.saveGState()
defer { context.restoreGState() }


let paragraphStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.minimumLineHeight = noDataFont.lineHeight
paragraphStyle.lineBreakMode = .byWordWrapping
paragraphStyle.alignment = noDataTextAlignment

ChartUtils.drawMultilineText(
context: context,
text: noDataText,
point: CGPoint(x: frame.width / 2.0, y: frame.height / 2.0),
attributes:
[NSAttributedStringKey.font: noDataFont,
NSAttributedStringKey.foregroundColor: noDataTextColor],
[.font: noDataFont,
.foregroundColor: noDataTextColor,
.paragraphStyle: paragraphStyle],
constrainedToSize: self.bounds.size,
anchor: CGPoint(x: 0.5, y: 0.5),
angleRadians: 0.0)
Expand Down

0 comments on commit c42ffe3

Please sign in to comment.