Skip to content

Commit

Permalink
Merge pull request #3199 from jjatie/no-data-text-alignment
Browse files Browse the repository at this point in the history
Added custom text alignment for noData
  • Loading branch information
liuxuan30 authored Jan 25, 2018
2 parents 9a1838a + c42ffe3 commit 056e0e5
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 @@ -309,14 +312,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 056e0e5

Please sign in to comment.