From 4fbeb9de992b27d6c1d3359054ee8b45420dbc14 Mon Sep 17 00:00:00 2001 From: Xuan Date: Mon, 22 Jan 2018 02:07:43 +0800 Subject: [PATCH 1/5] call setNeedsDisplay() here to trigger render noDataText (#3198) when chart view already rendered, if updating the chartData with nil, it will not rerender, and display the old content --- Source/Charts/Charts/ChartViewBase.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index a45eaa2493..b1c6d503ca 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -198,6 +198,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate guard let _data = _data else { + setNeedsDisplay() return } From b0022f8fa7311cfcd63e4a3b3fa043ad605578b0 Mon Sep 17 00:00:00 2001 From: Sven Bone Date: Sun, 21 Jan 2018 19:18:30 +0100 Subject: [PATCH 2/5] Fixes the distance issue between the legend and the horizontal bar chart (Fixes #2138) (#2214) * Fixes the distance issue between the legend and the horizontal bar chart (Fixes #2138) Override the function calculateLegendOffsets in HorizontalBarChartView in order to select the correct axis for distance calculation. In case of horizontal chart the x-axis is described the the rightAxis (bottom) or the leftAxis(top). * Added guard for _legend status --- .../Charts/HorizontalBarChartView.swift | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) 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), From c42ffe34cf764e9cf69c309464bd9fb8edaac586 Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Sun, 21 Jan 2018 14:27:45 -0400 Subject: [PATCH 3/5] 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) From 859f24ee8c57a44df5d06bb33a79fa71549135fb Mon Sep 17 00:00:00 2001 From: jjatie Date: Sun, 21 Jan 2018 22:09:40 -0400 Subject: [PATCH 4/5] Updated README for 3.0.5 (#3183) * Updated README for 3.0.5 * Updated Xcode and Swift versions --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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`. From 9a1838ae66242a3af581d51034b9a217697ba869 Mon Sep 17 00:00:00 2001 From: canapio Date: Tue, 23 Jan 2018 12:00:57 +0900 Subject: [PATCH 5/5] Fixed a duplicated assignment compared with obj-c code. (#3179) * fixed duplicated assignment compared with obj-c code. --- ChartsDemo/Swift/Demos/LineChart1ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChartsDemo/Swift/Demos/LineChart1ViewController.swift b/ChartsDemo/Swift/Demos/LineChart1ViewController.swift index bf5eb7f67d..6f34b8b763 100644 --- 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]