From ef21083a27255366c669760473760f9520c83c02 Mon Sep 17 00:00:00 2001 From: ctran Date: Tue, 14 Feb 2017 12:20:01 +0100 Subject: [PATCH 1/5] Add option to rotate value text for line charts --- Source/Charts/Data/Implementations/ChartBaseDataSet.swift | 3 +++ Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift | 3 +++ Source/Charts/Renderers/LineChartRenderer.swift | 4 +++- Source/Charts/Utils/ChartUtils.swift | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index 190241efa3..f4c394c862 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -302,6 +302,9 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol /// the font for the value-text labels open var valueFont: NSUIFont = NSUIFont.systemFont(ofSize: 7.0) + /// the rotation angle for value-text labels + open var valueRotationAngle: CGFloat = CGFloat(0.0) + /// The form to draw for this dataset in the legend. open var form = Legend.Form.default diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index 8c6945f9ff..fab28d45f5 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -200,6 +200,9 @@ public protocol ChartDataSetProtocol /// the font for the value-text labels var valueFont: NSUIFont { get set } + /// the rotation angle for value-text labels + var valueRotationAngle: CGFloat { get set } + /// The form to draw for this dataset in the legend. /// /// Return `.Default` to use the default legend form. diff --git a/Source/Charts/Renderers/LineChartRenderer.swift b/Source/Charts/Renderers/LineChartRenderer.swift index 3c4f5040f3..fae5559422 100644 --- a/Source/Charts/Renderers/LineChartRenderer.swift +++ b/Source/Charts/Renderers/LineChartRenderer.swift @@ -523,6 +523,8 @@ open class LineChartRenderer: LineRadarRenderer let formatter = dataSet.valueFormatter + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) let valueToPixelMatrix = trans.valueToPixelMatrix @@ -564,7 +566,7 @@ open class LineChartRenderer: LineRadarRenderer viewPortHandler: viewPortHandler), at: CGPoint(x: pt.x, y: pt.y - CGFloat(valOffset) - valueFont.lineHeight), - align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: dataSet.valueTextColorAt(j)]) } diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift index df819c3619..3ac00d648c 100644 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -157,7 +157,7 @@ extension CGContext { NSUIGraphicsPopContext() } - open func drawText(_ text: String, at point: CGPoint, anchor: CGPoint, angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) + open func drawText(_ text: String, at point: CGPoint, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) { var drawOffset = CGPoint() From 5a1a46e3ebf080b4798b519febcbbc09cf493d97 Mon Sep 17 00:00:00 2001 From: Chinh Tran Date: Wed, 21 Feb 2018 20:38:59 +0100 Subject: [PATCH 2/5] Add value text rotation for bar charts --- .../Charts/Renderers/BarChartRenderer.swift | 29 ++++++++++--- .../HorizontalBarChartRenderer.swift | 14 +++++-- Source/Charts/Utils/ChartUtils.swift | 41 ++++++++++++------- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 6603d8a4fd..2b48276ee0 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -317,6 +317,8 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer shouldDrawValues(forDataSet: dataSet) else { continue } + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let isInverted = dataProvider.isInverted(axis: dataSet.axisDependency) // calculate the correct offset depending on the draw position of the value @@ -376,7 +378,9 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer : (rect.origin.y + rect.size.height + negOffset), font: valueFont, align: .center, - color: dataSet.valueTextColorAt(j)) + color: dataSet.valueTextColorAt(j), + anchor: CGPoint(x: 0.5, y: 0.5), + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled @@ -393,6 +397,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer atCenter: CGPoint(x: px, y: py), size: icon.size) } + } } else @@ -469,7 +474,9 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer yPos: y, font: valueFont, align: .center, - color: dataSet.valueTextColorAt(index)) + color: dataSet.valueTextColorAt(index), + anchor: CGPoint(x: 0.5, y: 0.5), + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled @@ -501,7 +508,9 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer (e.y >= 0 ? posOffset : negOffset), font: valueFont, align: .center, - color: dataSet.valueTextColorAt(index)) + color: dataSet.valueTextColorAt(index), + anchor: CGPoint(x: 0.5, y: 0.5), + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled @@ -527,10 +536,20 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } /// Draws a value at the specified x and y position. - @objc open func drawValue(context: CGContext, value: String, xPos: CGFloat, yPos: CGFloat, font: NSUIFont, align: NSTextAlignment, color: NSUIColor) + @objc open func drawValue(context: CGContext, value: String, xPos: CGFloat, yPos: CGFloat, font: NSUIFont, align: NSTextAlignment, color: NSUIColor, anchor: CGPoint, angleRadians: CGFloat) { - context.drawText(value, at: CGPoint(x: xPos, y: yPos), align: align, attributes: [.font: font, .foregroundColor: color]) + if (angleRadians == 0.0) + { + context.drawText(value, at: CGPoint(x: xPos, y: yPos), align: align, attributes: [.font: font, .foregroundColor: color]) + } + else + { + // align left to center text with rotation + context.drawText(value, at: CGPoint(x: xPos, y: yPos), align: align, anchor: anchor, + angleRadians: angleRadians, attributes: [.font: font, .foregroundColor: color]) + } } + open override func drawExtras(context: CGContext) { diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index f95648206a..11bbd6e28a 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -318,6 +318,8 @@ open class HorizontalBarChartRenderer: BarChartRenderer { guard let dataSet = dataSets[dataSetIndex] as? BarChartDataSetProtocol else { continue } + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + if !shouldDrawValues(forDataSet: dataSet) || !(dataSet.isDrawIconsEnabled && dataSet.isVisible) { continue @@ -392,7 +394,9 @@ open class HorizontalBarChartRenderer: BarChartRenderer yPos: y + yOffset, font: valueFont, align: textAlign, - color: dataSet.valueTextColorAt(j)) + color: dataSet.valueTextColorAt(j), + anchor: CGPoint.zero, + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled @@ -470,7 +474,9 @@ open class HorizontalBarChartRenderer: BarChartRenderer yPos: rect.origin.y + yOffset, font: valueFont, align: textAlign, - color: dataSet.valueTextColorAt(index)) + color: dataSet.valueTextColorAt(index), + anchor: CGPoint.zero, + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled @@ -569,7 +575,9 @@ open class HorizontalBarChartRenderer: BarChartRenderer yPos: y + yOffset, font: valueFont, align: textAlign, - color: dataSet.valueTextColorAt(index)) + color: dataSet.valueTextColorAt(index), + anchor: CGPoint.zero, + angleRadians: angleRadians) } if let icon = e.icon, dataSet.isDrawIconsEnabled diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift index 3ac00d648c..afd7b08642 100644 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -139,24 +139,22 @@ extension CGContext { open func drawText(_ text: String, at point: CGPoint, align: NSTextAlignment, attributes: [NSAttributedStringKey : Any]?) { - var point = point - - if align == .center - { - point.x -= text.size(withAttributes: attributes).width / 2.0 - } - else if align == .right - { - point.x -= text.size(withAttributes: attributes).width - } + let drawPoint = getDrawPoint(text: text, point: point, align: align, attributes: attributes) + NSUIGraphicsPushContext(self) - - (text as NSString).draw(at: point, withAttributes: attributes) - + + (text as NSString).draw(at: drawPoint, withAttributes: attributes) + NSUIGraphicsPopContext() } - + + open func drawText(_ text: String, at point: CGPoint, align: NSTextAlignment, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) + { + let drawPoint = getDrawPoint(text: text, point: point, align: align, attributes: attributes) + drawText(text, at: drawPoint, anchor: anchor, angleRadians: angleRadians, attributes: attributes) + } + open func drawText(_ text: String, at point: CGPoint, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) { var drawOffset = CGPoint() @@ -209,6 +207,21 @@ extension CGContext { NSUIGraphicsPopContext() } + func getDrawPoint(text: String, point: CGPoint, align: NSTextAlignment, attributes: [NSAttributedStringKey : Any]?) -> CGPoint + { + var point = point + + if align == .center + { + point.x -= text.size(withAttributes: attributes).width / 2.0 + } + else if align == .right + { + point.x -= text.size(withAttributes: attributes).width + } + return point + } + func drawMultilineText(_ text: String, at point: CGPoint, constrainedTo size: CGSize, anchor: CGPoint, knownTextSize: CGSize, angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) { var rect = CGRect(origin: .zero, size: knownTextSize) From 31f7ad5ec53e67ac592755b3f74f9616a2e271bb Mon Sep 17 00:00:00 2001 From: Chinh Tran Date: Wed, 21 Feb 2018 23:55:30 +0100 Subject: [PATCH 3/5] Add value text rotation for other charts --- .../Renderers/BubbleChartRenderer.swift | 3 +++ .../Renderers/CandleStickChartRenderer.swift | 3 +++ .../Charts/Renderers/PieChartRenderer.swift | 10 +++++++ .../Charts/Renderers/RadarChartRenderer.swift | 3 +++ .../Renderers/ScatterChartRenderer.swift | 3 +++ Source/Charts/Utils/ChartUtils.swift | 26 +++++++++---------- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index cda98e4a1c..4abd8e39d4 100644 --- a/Source/Charts/Renderers/BubbleChartRenderer.swift +++ b/Source/Charts/Renderers/BubbleChartRenderer.swift @@ -148,6 +148,8 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let valueToPixelMatrix = trans.valueToPixelMatrix let iconsOffset = dataSet.iconsOffset + + let angleRadians = dataSet.valueRotationAngle.DEG2RAD for j in _xBounds.min..._xBounds.range + _xBounds.min { @@ -182,6 +184,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer at: CGPoint(x: pt.x, y: pt.y - (0.5 * lineHeight)), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: valueTextColor]) } diff --git a/Source/Charts/Renderers/CandleStickChartRenderer.swift b/Source/Charts/Renderers/CandleStickChartRenderer.swift index 53bd613708..4b7338efac 100644 --- a/Source/Charts/Renderers/CandleStickChartRenderer.swift +++ b/Source/Charts/Renderers/CandleStickChartRenderer.swift @@ -267,6 +267,8 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer let iconsOffset = dataSet.iconsOffset + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + _xBounds.set(chart: dataProvider, dataSet: dataSet, animator: animator) let lineHeight = valueFont.lineHeight @@ -299,6 +301,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer at: CGPoint(x: pt.x, y: pt.y - yOffset), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: dataSet.valueTextColorAt(j)]) } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 4d8ec043cc..88642b2fe6 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -314,6 +314,8 @@ open class PieChartRenderer: NSObject, DataRenderer let iconsOffset = dataSet.iconsOffset + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let xValuePosition = dataSet.xValuePosition let yValuePosition = dataSet.yValuePosition @@ -429,6 +431,7 @@ open class PieChartRenderer: NSObject, DataRenderer context.drawText(valueText, at: labelPoint, align: align, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: valueTextColor]) @@ -438,6 +441,7 @@ open class PieChartRenderer: NSObject, DataRenderer at: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight), align: align, + angleRadians: angleRadians, attributes: [.font: entryLabelFont ?? valueFont, .foregroundColor: entryLabelColor ?? valueTextColor]) } @@ -450,6 +454,7 @@ open class PieChartRenderer: NSObject, DataRenderer at: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight / 2.0), align: align, + angleRadians: angleRadians, attributes: [.font: entryLabelFont ?? valueFont, .foregroundColor: entryLabelColor ?? valueTextColor]) } @@ -460,6 +465,7 @@ open class PieChartRenderer: NSObject, DataRenderer at: CGPoint(x: labelPoint.x, y: labelPoint.y + lineHeight / 2.0), align: align, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: valueTextColor]) } @@ -476,6 +482,7 @@ open class PieChartRenderer: NSObject, DataRenderer context.drawText(valueText, at: CGPoint(x: x, y: y), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: valueTextColor]) if j < data.entryCount && pe?.label != nil @@ -483,6 +490,7 @@ open class PieChartRenderer: NSObject, DataRenderer context.drawText(pe!.label!, at: CGPoint(x: x, y: y + lineHeight), align: .center, + angleRadians: angleRadians, attributes: [.font: entryLabelFont ?? valueFont, .foregroundColor: entryLabelColor ?? valueTextColor]) } @@ -494,6 +502,7 @@ open class PieChartRenderer: NSObject, DataRenderer context.drawText(pe!.label!, at: CGPoint(x: x, y: y + lineHeight / 2.0), align: .center, + angleRadians: angleRadians, attributes: [.font: entryLabelFont ?? valueFont, .foregroundColor: entryLabelColor ?? valueTextColor]) } @@ -503,6 +512,7 @@ open class PieChartRenderer: NSObject, DataRenderer context.drawText(valueText, at: CGPoint(x: x, y: y + lineHeight / 2.0), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: valueTextColor]) } } diff --git a/Source/Charts/Renderers/RadarChartRenderer.swift b/Source/Charts/Renderers/RadarChartRenderer.swift index ea4cbf1b21..57518cbb2b 100644 --- a/Source/Charts/Renderers/RadarChartRenderer.swift +++ b/Source/Charts/Renderers/RadarChartRenderer.swift @@ -160,6 +160,8 @@ open class RadarChartRenderer: LineRadarRenderer continue } + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let entryCount = dataSet.entryCount let iconsOffset = dataSet.iconsOffset @@ -183,6 +185,7 @@ open class RadarChartRenderer: LineRadarRenderer viewPortHandler: viewPortHandler), at: CGPoint(x: p.x, y: p.y - yoffset - valueFont.lineHeight), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: dataSet.valueTextColorAt(j)]) } diff --git a/Source/Charts/Renderers/ScatterChartRenderer.swift b/Source/Charts/Renderers/ScatterChartRenderer.swift index ce887005ad..d5fce840c1 100644 --- a/Source/Charts/Renderers/ScatterChartRenderer.swift +++ b/Source/Charts/Renderers/ScatterChartRenderer.swift @@ -132,6 +132,8 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer let iconsOffset = dataSet.iconsOffset + let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let shapeSize = dataSet.scatterShapeSize let lineHeight = valueFont.lineHeight @@ -169,6 +171,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer at: CGPoint(x: pt.x, y: pt.y - shapeSize - lineHeight), align: .center, + angleRadians: angleRadians, attributes: [.font: valueFont, .foregroundColor: dataSet.valueTextColorAt(j)] ) diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift index afd7b08642..c8e8a7d87d 100644 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -137,22 +137,22 @@ extension CGContext { NSUIGraphicsPopContext() } - open func drawText(_ text: String, at point: CGPoint, align: NSTextAlignment, attributes: [NSAttributedStringKey : Any]?) + open func drawText(_ text: String, at point: CGPoint, align: NSTextAlignment, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat = 0.0, attributes: [NSAttributedStringKey : Any]?) { - let drawPoint = getDrawPoint(text: text, point: point, align: align, attributes: attributes) - NSUIGraphicsPushContext(self) - - (text as NSString).draw(at: drawPoint, withAttributes: attributes) - - NSUIGraphicsPopContext() - } - - open func drawText(_ text: String, at point: CGPoint, align: NSTextAlignment, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) - { - let drawPoint = getDrawPoint(text: text, point: point, align: align, attributes: attributes) - drawText(text, at: drawPoint, anchor: anchor, angleRadians: angleRadians, attributes: attributes) + if (angleRadians == 0.0) + { + NSUIGraphicsPushContext(self) + + (text as NSString).draw(at: drawPoint, withAttributes: attributes) + + NSUIGraphicsPopContext() + } + else + { + drawText(text, at: drawPoint, anchor: anchor, angleRadians: angleRadians, attributes: attributes) + } } open func drawText(_ text: String, at point: CGPoint, anchor: CGPoint = CGPoint(x: 0.5, y: 0.5), angleRadians: CGFloat, attributes: [NSAttributedStringKey : Any]?) From ea87d1f0e17077badbeab28ed631e73b69984e31 Mon Sep 17 00:00:00 2001 From: Chinh Tran Date: Thu, 15 Mar 2018 15:54:12 +0100 Subject: [PATCH 4/5] Rename valueRotationAngle -> valueLabelAngle --- Source/Charts/Data/Implementations/ChartBaseDataSet.swift | 4 ++-- Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift | 4 ++-- Source/Charts/Renderers/BarChartRenderer.swift | 2 +- Source/Charts/Renderers/BubbleChartRenderer.swift | 2 +- Source/Charts/Renderers/CandleStickChartRenderer.swift | 2 +- Source/Charts/Renderers/HorizontalBarChartRenderer.swift | 2 +- Source/Charts/Renderers/LineChartRenderer.swift | 2 +- Source/Charts/Renderers/PieChartRenderer.swift | 2 +- Source/Charts/Renderers/RadarChartRenderer.swift | 2 +- Source/Charts/Renderers/ScatterChartRenderer.swift | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index f4c394c862..2f10622c92 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -302,8 +302,8 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol /// the font for the value-text labels open var valueFont: NSUIFont = NSUIFont.systemFont(ofSize: 7.0) - /// the rotation angle for value-text labels - open var valueRotationAngle: CGFloat = CGFloat(0.0) + /// The rotation angle (in degrees) for value-text labels + open var valueLabelAngle: CGFloat = CGFloat(0.0) /// The form to draw for this dataset in the legend. open var form = Legend.Form.default diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index fab28d45f5..6e4e775836 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -200,8 +200,8 @@ public protocol ChartDataSetProtocol /// the font for the value-text labels var valueFont: NSUIFont { get set } - /// the rotation angle for value-text labels - var valueRotationAngle: CGFloat { get set } + /// The rotation angle (in degrees) for value-text labels + var valueLabelAngle: CGFloat { get set } /// The form to draw for this dataset in the legend. /// diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 2b48276ee0..610f8ebb65 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -317,7 +317,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer shouldDrawValues(forDataSet: dataSet) else { continue } - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD let isInverted = dataProvider.isInverted(axis: dataSet.axisDependency) diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index 4abd8e39d4..6ee21bdefa 100644 --- a/Source/Charts/Renderers/BubbleChartRenderer.swift +++ b/Source/Charts/Renderers/BubbleChartRenderer.swift @@ -149,7 +149,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let iconsOffset = dataSet.iconsOffset - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD for j in _xBounds.min..._xBounds.range + _xBounds.min { diff --git a/Source/Charts/Renderers/CandleStickChartRenderer.swift b/Source/Charts/Renderers/CandleStickChartRenderer.swift index 4b7338efac..0d5c700f37 100644 --- a/Source/Charts/Renderers/CandleStickChartRenderer.swift +++ b/Source/Charts/Renderers/CandleStickChartRenderer.swift @@ -267,7 +267,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer let iconsOffset = dataSet.iconsOffset - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD _xBounds.set(chart: dataProvider, dataSet: dataSet, animator: animator) diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index 11bbd6e28a..fdca0687e5 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -318,7 +318,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer { guard let dataSet = dataSets[dataSetIndex] as? BarChartDataSetProtocol else { continue } - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD if !shouldDrawValues(forDataSet: dataSet) || !(dataSet.isDrawIconsEnabled && dataSet.isVisible) { diff --git a/Source/Charts/Renderers/LineChartRenderer.swift b/Source/Charts/Renderers/LineChartRenderer.swift index fae5559422..2e3accd60d 100644 --- a/Source/Charts/Renderers/LineChartRenderer.swift +++ b/Source/Charts/Renderers/LineChartRenderer.swift @@ -523,7 +523,7 @@ open class LineChartRenderer: LineRadarRenderer let formatter = dataSet.valueFormatter - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) let valueToPixelMatrix = trans.valueToPixelMatrix diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 88642b2fe6..8f70f5fd37 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -314,7 +314,7 @@ open class PieChartRenderer: NSObject, DataRenderer let iconsOffset = dataSet.iconsOffset - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD let xValuePosition = dataSet.xValuePosition let yValuePosition = dataSet.yValuePosition diff --git a/Source/Charts/Renderers/RadarChartRenderer.swift b/Source/Charts/Renderers/RadarChartRenderer.swift index 57518cbb2b..f5ee307c52 100644 --- a/Source/Charts/Renderers/RadarChartRenderer.swift +++ b/Source/Charts/Renderers/RadarChartRenderer.swift @@ -160,7 +160,7 @@ open class RadarChartRenderer: LineRadarRenderer continue } - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD let entryCount = dataSet.entryCount diff --git a/Source/Charts/Renderers/ScatterChartRenderer.swift b/Source/Charts/Renderers/ScatterChartRenderer.swift index d5fce840c1..630c851a7b 100644 --- a/Source/Charts/Renderers/ScatterChartRenderer.swift +++ b/Source/Charts/Renderers/ScatterChartRenderer.swift @@ -132,7 +132,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer let iconsOffset = dataSet.iconsOffset - let angleRadians = dataSet.valueRotationAngle.DEG2RAD + let angleRadians = dataSet.valueLabelAngle.DEG2RAD let shapeSize = dataSet.scatterShapeSize let lineHeight = valueFont.lineHeight From 66cd4359f4b3ef1317f6f947ac538bb41222d07c Mon Sep 17 00:00:00 2001 From: Chinh Tran Date: Thu, 15 Mar 2018 15:59:21 +0100 Subject: [PATCH 5/5] Make function private & remove line break --- Source/Charts/Renderers/BarChartRenderer.swift | 3 +-- Source/Charts/Utils/ChartUtils.swift | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 610f8ebb65..5a43d363fb 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -545,8 +545,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer else { // align left to center text with rotation - context.drawText(value, at: CGPoint(x: xPos, y: yPos), align: align, anchor: anchor, - angleRadians: angleRadians, attributes: [.font: font, .foregroundColor: color]) + context.drawText(value, at: CGPoint(x: xPos, y: yPos), align: align, anchor: anchor, angleRadians: angleRadians, attributes: [.font: font, .foregroundColor: color]) } } diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift index c8e8a7d87d..7d94841a44 100644 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -207,7 +207,7 @@ extension CGContext { NSUIGraphicsPopContext() } - func getDrawPoint(text: String, point: CGPoint, align: NSTextAlignment, attributes: [NSAttributedStringKey : Any]?) -> CGPoint + private func getDrawPoint(text: String, point: CGPoint, align: NSTextAlignment, attributes: [NSAttributedStringKey : Any]?) -> CGPoint { var point = point