From c42ffe34cf764e9cf69c309464bd9fb8edaac586 Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Sun, 21 Jan 2018 14:27:45 -0400 Subject: [PATCH] Added custom text alignment for noData --- Source/Charts/Charts/ChartViewBase.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index a45eaa2493..346fdd81d7 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -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 @@ -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)