diff --git a/ChartsDemo/Swift/Demos/LineChart1ViewController.swift b/ChartsDemo/Swift/Demos/LineChart1ViewController.swift index bf5eb7f67d..6f34b8b763 100755 --- a/ChartsDemo/Swift/Demos/LineChart1ViewController.swift +++ b/ChartsDemo/Swift/Demos/LineChart1ViewController.swift @@ -126,7 +126,7 @@ class LineChart1ViewController: DemoBaseViewController { set1.valueFont = .systemFont(ofSize: 9) set1.formLineDashLengths = [5, 2.5] set1.formLineWidth = 1 - set1.formLineWidth = 15 + set1.formSize = 15 let gradientColors = [ChartColorTemplates.colorFromString("#00ff0000").cgColor, ChartColorTemplates.colorFromString("#ffff0000").cgColor] diff --git a/README.md b/README.md index e8025db751..5be133ac9c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**Version 3.0.4**, synced to [MPAndroidChart #f6a398b](https://github.com/PhilJay/MPAndroidChart/commit/f6a398b) +**Version 3.0.5**, synced to [MPAndroidChart #f6a398b](https://github.com/PhilJay/MPAndroidChart/commit/f6a398b) ![alt tag](https://raw.github.com/danielgindi/Charts/master/Assets/feature_graphic.png) ![Supported Platforms](https://img.shields.io/cocoapods/p/Charts.svg) [![Releases](https://img.shields.io/github/release/danielgindi/Charts.svg)](https://github.com/danielgindi/Charts/releases) [![Latest pod release](https://img.shields.io/cocoapods/v/Charts.svg)](http://cocoapods.org/pods/charts) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Build Status](https://travis-ci.org/danielgindi/Charts.svg?branch=master)](https://travis-ci.org/danielgindi/Charts) [![codecov](https://codecov.io/gh/danielgindi/Charts/branch/master/graph/badge.svg)](https://codecov.io/gh/danielgindi/Charts) @@ -7,7 +7,7 @@ ### Just a heads up: Charts 3.0 has some breaking changes. Please read [the release/migration notes](https://github.com/danielgindi/Charts/releases/tag/v3.0.0). ### Another heads up: ChartsRealm is now in a [separate repo](https://github.com/danielgindi/ChartsRealm). Pods is also now `Charts` and `ChartsRealm`, instead of ~`Charts/Core`~ and ~`Charts/Realm`~ -* Xcode 9.0 / Swift 4.0 +* Xcode 9.2 / Swift 4.0.2 * iOS >= 8.0 (Use as an **Embedded** Framework) * tvOS >= 9.0 * macOS >= 10.11 @@ -78,8 +78,8 @@ For [Realm](https://realm.io/) support, please add `pod 'ChartsRealm'` too. Charts now include Carthage prebuilt binaries. ```carthage -github "danielgindi/Charts" == 3.0.4 -github "danielgindi/Charts" ~> 3.0.4 +github "danielgindi/Charts" == 3.0.5 +github "danielgindi/Charts" ~> 3.0.5 ``` In order to build the binaries for a new release, use `carthage build --no-skip-current && carthage archive Charts`. diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index a45eaa2493..712e3e6910 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 @@ -198,6 +201,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate guard let _data = _data else { + setNeedsDisplay() return } @@ -308,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) diff --git a/Source/Charts/Charts/HorizontalBarChartView.swift b/Source/Charts/Charts/HorizontalBarChartView.swift index 13131942b7..380680d0d3 100644 --- a/Source/Charts/Charts/HorizontalBarChartView.swift +++ b/Source/Charts/Charts/HorizontalBarChartView.swift @@ -34,6 +34,67 @@ open class HorizontalBarChartView: BarChartView self.highlighter = HorizontalBarHighlighter(chart: self) } + internal override func calculateLegendOffsets(offsetLeft: inout CGFloat, offsetTop: inout CGFloat, offsetRight: inout CGFloat, offsetBottom: inout CGFloat) + { + guard + let legend = _legend, + legend.isEnabled, + legend.drawInside + else { return } + + // setup offsets for legend + switch legend.orientation + { + case .vertical: + switch legend.horizontalAlignment + { + case .left: + offsetLeft += min(legend.neededWidth, _viewPortHandler.chartWidth * legend.maxSizePercent) + legend.xOffset + + case .right: + offsetRight += min(legend.neededWidth, _viewPortHandler.chartWidth * legend.maxSizePercent) + legend.xOffset + + case .center: + + switch legend.verticalAlignment + { + case .top: + offsetTop += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset + + case .bottom: + offsetBottom += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset + + default: + break + } + } + + case .horizontal: + switch legend.verticalAlignment + { + case .top: + offsetTop += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset + + // left axis equals the top x-axis in a horizontal chart + if leftAxis.isEnabled && leftAxis.isDrawLabelsEnabled + { + offsetTop += leftAxis.getRequiredHeightSpace() + } + + case .bottom: + offsetBottom += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset + + // right axis equals the bottom x-axis in a horizontal chart + if rightAxis.isEnabled && rightAxis.isDrawLabelsEnabled + { + offsetBottom += rightAxis.getRequiredHeightSpace() + } + default: + break + } + } + } + internal override func calculateOffsets() { var offsetLeft: CGFloat = 0.0, @@ -81,7 +142,7 @@ open class HorizontalBarChartView: BarChartView offsetRight += self.extraRightOffset offsetBottom += self.extraBottomOffset offsetLeft += self.extraLeftOffset - + _viewPortHandler.restrainViewPort( offsetLeft: max(self.minOffset, offsetLeft), offsetTop: max(self.minOffset, offsetTop),