diff --git a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj index 3877e224d3..1f7770bacd 100644 --- a/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj +++ b/ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj @@ -629,6 +629,7 @@ 5B57BBAE1A9B26AA0036A6CC = { CreatedOnToolsVersion = 6.1.1; LastSwiftMigration = 0800; + ProvisioningStyle = Manual; }; }; }; @@ -850,7 +851,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -869,7 +870,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -896,7 +897,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -908,7 +909,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -924,6 +925,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = "$(SOURCE_ROOT)/../Carthage/Build/iOS"; INFOPLIST_FILE = "Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -944,6 +946,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = "$(SOURCE_ROOT)/../Carthage/Build/iOS"; INFOPLIST_FILE = "Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/Source/Charts/Animation/ChartAnimationEasing.swift b/Source/Charts/Animation/ChartAnimationEasing.swift index 6afdd2a6e9..9085484f93 100644 --- a/Source/Charts/Animation/ChartAnimationEasing.swift +++ b/Source/Charts/Animation/ChartAnimationEasing.swift @@ -211,17 +211,17 @@ internal struct EasingFunctions internal static let EaseInSine = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in var position: TimeInterval = elapsed / duration - return Double( -cos(position * M_PI_2) + 1.0 ) + return Double( -cos(position * .pi/2) + 1.0 ) } internal static let EaseOutSine = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in var position: TimeInterval = elapsed / duration - return Double( sin(position * M_PI_2) ) + return Double( sin(position * .pi/2) ) } internal static let EaseInOutSine = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in var position: TimeInterval = elapsed / duration - return Double( -0.5 * (cos(M_PI * position) - 1.0) ) + return Double( -0.5 * (cos(.pi * position) - 1.0) ) } internal static let EaseInExpo = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in @@ -286,9 +286,9 @@ internal struct EasingFunctions } var p = duration * 0.3 - var s = p / (2.0 * M_PI) * asin(1.0) + var s = p / (2.0 * .pi) * asin(1.0) position -= 1.0 - return Double( -(pow(2.0, 10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p)) ) + return Double( -(pow(2.0, 10.0 * position) * sin((position * duration - s) * (2.0 * .pi) / p)) ) } internal static let EaseOutElastic = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in @@ -304,8 +304,8 @@ internal struct EasingFunctions } var p = duration * 0.3 - var s = p / (2.0 * M_PI) * asin(1.0) - return Double( pow(2.0, -10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p) + 1.0 ) + var s = p / (2.0 * .pi) * asin(1.0) + return Double( pow(2.0, -10.0 * position) * sin((position * duration - s) * (2.0 * .pi) / p) + 1.0 ) } internal static let EaseInOutElastic = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in @@ -321,14 +321,14 @@ internal struct EasingFunctions } var p = duration * (0.3 * 1.5) - var s = p / (2.0 * M_PI) * asin(1.0) + var s = p / (2.0 * .pi) * asin(1.0) if position < 1.0 { position -= 1.0 - return Double( -0.5 * (pow(2.0, 10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p)) ) + return Double( -0.5 * (pow(2.0, 10.0 * position) * sin((position * duration - s) * (2.0 * .pi) / p)) ) } position -= 1.0 - return Double( pow(2.0, -10.0 * position) * sin((position * duration - s) * (2.0 * M_PI) / p) * 0.5 + 1.0 ) + return Double( pow(2.0, -10.0 * position) * sin((position * duration - s) * (2.0 * .pi) / p) * 0.5 + 1.0 ) } internal static let EaseInBack = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index 160872e097..7b10fa3c53 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -39,34 +39,52 @@ open class AxisBase: ComponentBase open var gridLineCap = CGLineCap.butt open var drawGridLinesEnabled = true - open var drawAxisLineEnabled = true + open var drawAxisLineEnabled = true + + open var logarithmicEnabled = false + open var isLogarithmicEnabled: Bool { return logarithmicEnabled } + + open var maskAxis = [1.0, 2.0, 4.0, 6.0, 8.0] + open var maskLabels = [true, true, true, true, true] + + open var logAxis = [Double]() + open var logLabels = [Bool]() + + open var labelsAxisChanged = true + open var isLabelsAxisChanged: Bool { return labelsAxisChanged } + + open var stickEnabled = false + open var isStickEnabled: Bool { return stickEnabled } + + open var stickMajorEnabled = true + open var isStickMajorEnabled: Bool { return stickMajorEnabled } /// flag that indicates of the labels of this axis should be drawn or not open var drawLabelsEnabled = true fileprivate var _centerAxisLabelsEnabled = false - + /// Centers the axis labels instead of drawing them at their original position. /// This is useful especially for grouped BarChart. open var centerAxisLabelsEnabled: Bool - { + { get { return _centerAxisLabelsEnabled && entryCount > 0 } set { _centerAxisLabelsEnabled = newValue } } open var isCenterAxisLabelsEnabled: Bool - { + { get { return centerAxisLabelsEnabled } } - + /// array of limitlines that can be set for the axis fileprivate var _limitLines = [ChartLimitLine]() /// Are the LimitLines drawn behind the data or in front of the data? - /// + /// /// **default**: false open var drawLimitLinesBehindDataEnabled = false - + /// the flag can be used to turn off the antialias for grid lines open var gridAntialiasEnabled = true @@ -100,7 +118,7 @@ open class AxisBase: ComponentBase /// /// **default**: 1.0 open var granularity: Double - { + { get { return _granularity @@ -116,7 +134,7 @@ open class AxisBase: ComponentBase /// The minimum interval between axis values. open var isGranularityEnabled: Bool - { + { get { return granularityEnabled @@ -150,6 +168,10 @@ open class AxisBase: ComponentBase { return "" } + if isLogarithmicEnabled == true + { + return valueFormatter?.stringForValue(pow(10, entries[index]), axis: self) ?? "" + } return valueFormatter?.stringForValue(entries[index], axis: self) ?? "" } @@ -158,7 +180,7 @@ open class AxisBase: ComponentBase /// If no formatter is set, the chart will automatically determine a reasonable formatting (concerning decimals) for all the values that are drawn inside the chart. /// Use `nil` to use the formatter calculated by the chart. open var valueFormatter: IAxisValueFormatter? - { + { get { if _axisValueFormatter == nil || @@ -184,7 +206,7 @@ open class AxisBase: ComponentBase open var isDrawLabelsEnabled: Bool { return drawLabelsEnabled } /// Are the LimitLines drawn behind the data or in front of the data? - /// + /// /// **default**: false open var isDrawLimitLinesBehindDataEnabled: Bool { return drawLimitLinesBehindDataEnabled } @@ -219,7 +241,7 @@ open class AxisBase: ComponentBase /// default = 6, /// be aware that this number is not fixed and can only be approximated open var labelCount: Int - { + { get { return _labelCount @@ -230,7 +252,7 @@ open class AxisBase: ComponentBase if _labelCount > 25 { - _labelCount = 25 + _labelCount = 50 } if _labelCount < 2 { @@ -302,7 +324,7 @@ open class AxisBase: ComponentBase /// This property is deprecated - Use `axisMinimum` instead. @available(*, deprecated: 1.0, message: "Use axisMinimum instead.") open var axisMinValue: Double - { + { get { return axisMinimum } set { axisMinimum = newValue } } @@ -310,7 +332,7 @@ open class AxisBase: ComponentBase /// This property is deprecated - Use `axisMaximum` instead. @available(*, deprecated: 1.0, message: "Use axisMaximum instead.") open var axisMaxValue: Double - { + { get { return axisMaximum } set { axisMaximum = newValue } } @@ -319,7 +341,7 @@ open class AxisBase: ComponentBase /// If set, this value will not be calculated automatically depending on the provided data. /// Use `resetCustomAxisMin()` to undo this. open var axisMinimum: Double - { + { get { return _axisMinimum @@ -336,7 +358,7 @@ open class AxisBase: ComponentBase /// If set, this value will not be calculated automatically depending on the provided data. /// Use `resetCustomAxisMax()` to undo this. open var axisMaximum: Double - { + { get { return _axisMaximum diff --git a/Source/Charts/Data/Implementations/Standard/ChartData.swift b/Source/Charts/Data/Implementations/Standard/ChartData.swift index 046c209d52..16ce798c4d 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartData.swift @@ -13,14 +13,14 @@ import Foundation open class ChartData: NSObject { - internal var _yMax: Double = -DBL_MAX - internal var _yMin: Double = DBL_MAX - internal var _xMax: Double = -DBL_MAX - internal var _xMin: Double = DBL_MAX - internal var _leftAxisMax: Double = -DBL_MAX - internal var _leftAxisMin: Double = DBL_MAX - internal var _rightAxisMax: Double = -DBL_MAX - internal var _rightAxisMin: Double = DBL_MAX + internal var _yMax: Double = -.greatestFiniteMagnitude + internal var _yMin: Double = .greatestFiniteMagnitude + internal var _xMax: Double = -.greatestFiniteMagnitude + internal var _xMin: Double = .greatestFiniteMagnitude + internal var _leftAxisMax: Double = -.greatestFiniteMagnitude + internal var _leftAxisMin: Double = .greatestFiniteMagnitude + internal var _rightAxisMax: Double = -.greatestFiniteMagnitude + internal var _rightAxisMin: Double = .greatestFiniteMagnitude internal var _dataSets = [IChartDataSet]() @@ -71,20 +71,20 @@ open class ChartData: NSObject /// calc minimum and maximum y value over all datasets open func calcMinMax() { - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -.greatestFiniteMagnitude + _yMin = .greatestFiniteMagnitude + _xMax = -.greatestFiniteMagnitude + _xMin = .greatestFiniteMagnitude for set in _dataSets { calcMinMax(dataSet: set) } - _leftAxisMax = -DBL_MAX - _leftAxisMin = DBL_MAX - _rightAxisMax = -DBL_MAX - _rightAxisMin = DBL_MAX + _leftAxisMax = -.greatestFiniteMagnitude + _leftAxisMin = .greatestFiniteMagnitude + _rightAxisMax = -.greatestFiniteMagnitude + _rightAxisMin = .greatestFiniteMagnitude // left axis let firstLeft = getFirstLeft(dataSets: dataSets) @@ -257,7 +257,7 @@ open class ChartData: NSObject { if axis == .left { - if _leftAxisMin == DBL_MAX + if _leftAxisMin == .greatestFiniteMagnitude { return _rightAxisMin } @@ -268,7 +268,7 @@ open class ChartData: NSObject } else { - if _rightAxisMin == DBL_MAX + if _rightAxisMin == .greatestFiniteMagnitude { return _leftAxisMin } @@ -295,7 +295,7 @@ open class ChartData: NSObject { if axis == .left { - if _leftAxisMax == -DBL_MAX + if _leftAxisMax == -.greatestFiniteMagnitude { return _rightAxisMax } @@ -306,7 +306,7 @@ open class ChartData: NSObject } else { - if _rightAxisMax == -DBL_MAX + if _rightAxisMax == -.greatestFiniteMagnitude { return _leftAxisMax } diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift b/Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift index 84441bd202..fe3d0aeccb 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift @@ -79,7 +79,7 @@ open class ChartDataEntry: ChartDataEntryBase return false } - if fabs((object! as AnyObject).x - x) > DBL_EPSILON + if fabs((object! as AnyObject).x - x) > Double.ulpOfOne { return false } @@ -125,12 +125,12 @@ public func ==(lhs: ChartDataEntry, rhs: ChartDataEntry) -> Bool return false } - if fabs(lhs.x - rhs.x) > DBL_EPSILON + if fabs(lhs.x - rhs.x) > Double.ulpOfOne { return false } - if fabs(lhs.y - rhs.y) > DBL_EPSILON + if fabs(lhs.y - rhs.y) > Double.ulpOfOne { return false } diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataEntryBase.swift b/Source/Charts/Data/Implementations/Standard/ChartDataEntryBase.swift index 3e9f96b32a..36bb8e2725 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataEntryBase.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataEntryBase.swift @@ -90,7 +90,7 @@ open class ChartDataEntryBase: NSObject return false } - if fabs((object! as AnyObject).y - y) > DBL_EPSILON + if fabs((object! as AnyObject).y - y) > Double.ulpOfOne { return false } @@ -123,7 +123,7 @@ public func ==(lhs: ChartDataEntryBase, rhs: ChartDataEntryBase) -> Bool return false } - if fabs(lhs.y - rhs.y) > DBL_EPSILON + if fabs(lhs.y - rhs.y) > Double.ulpOfOne { return false } diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index da81c4766d..ed472dc21a 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -58,16 +58,16 @@ open class ChartDataSet: ChartBaseDataSet internal var _values: [ChartDataEntry]! /// maximum y-value in the value array - internal var _yMax: Double = -DBL_MAX + internal var _yMax: Double = -Double.greatestFiniteMagnitude /// minimum y-value in the value array - internal var _yMin: Double = DBL_MAX + internal var _yMin: Double = Double.greatestFiniteMagnitude /// maximum x-value in the value array - internal var _xMax: Double = -DBL_MAX + internal var _xMax: Double = -Double.greatestFiniteMagnitude /// minimum x-value in the value array - internal var _xMin: Double = DBL_MAX + internal var _xMin: Double = Double.greatestFiniteMagnitude /// * /// - note: Calls `notifyDataSetChanged()` after setting a new value. @@ -98,10 +98,10 @@ open class ChartDataSet: ChartBaseDataSet return } - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -Double.greatestFiniteMagnitude + _yMin = Double.greatestFiniteMagnitude + _xMax = -Double.greatestFiniteMagnitude + _xMin = Double.greatestFiniteMagnitude for e in _values { @@ -116,15 +116,15 @@ open class ChartDataSet: ChartBaseDataSet return } - _yMax = -DBL_MAX - _yMin = DBL_MAX + _yMax = -Double.greatestFiniteMagnitude + _yMin = Double.greatestFiniteMagnitude let indexFrom = entryIndex(x: fromX, closestToY: Double.nan, rounding: .down) let indexTo = entryIndex(x: toX, closestToY: Double.nan, rounding: .up) if indexTo <= indexFrom { return } - for i in indexFrom.. (Int) + { + guard input != 0 else { return 0} + var order = 0 + var temp = abs(input) + if temp < 10 { + while temp < 10 + { + temp = temp * 10 + order = order - 1 + } + } else if temp > 1 { + while temp > 1 { + temp = temp / 10 + order = order + 1 + } + } + return order + } + + open func logAxisRange(min: Double, max : Double) + { + guard let axis = self.axis else { return } + + // create arrays to hold the positive of the input data + var logScaleAxis: [Double] = [] + var logScaleLabels: [Bool] = [] + + let min = min + let max = max + + // multiplying the step array with a multiple of 10 to get the drawn steps (gridlines and values) from the minimum to the maximum + let mini = order(input: min) - 1 + let maxi = order(input: max + 1) + for i in mini ... maxi + { + logScaleAxis = logScaleAxis + axis.maskAxis.map{$0 * pow(10 ,Double(i))} + logScaleLabels = logScaleLabels + axis.maskLabels + } + axis.logAxis = logScaleAxis + axis.logLabels = logScaleLabels + } } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 18c01ff706..fb424806d1 100755 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -130,7 +130,7 @@ open class PieChartRenderer: DataRenderer for j in 0 ..< entryCount { guard let e = dataSet.entryForIndex(j) else { continue } - if ((abs(e.y) > DBL_EPSILON)) + if ((abs(e.y) > .ulpOfOne)) { visibleAngleCount += 1 } @@ -147,8 +147,10 @@ open class PieChartRenderer: DataRenderer guard let e = dataSet.entryForIndex(j) else { continue } + // 'ulpOfOne' is deprecated: Please use 'ulpOfOne' or '.ulpOfOne'. + // draw only if the value is greater than zero - if (abs(e.y) > DBL_EPSILON) + if (abs(e.y) > .ulpOfOne) { if !chart.needsHighlight(index: j) { @@ -708,7 +710,7 @@ open class PieChartRenderer: DataRenderer for j in 0 ..< entryCount { guard let e = set.entryForIndex(j) else { continue } - if ((abs(e.y) > DBL_EPSILON)) + if ((abs(e.y) > Double.ulpOfOne)) { visibleAngleCount += 1 } diff --git a/Source/Charts/Renderers/XAxisRenderer.swift b/Source/Charts/Renderers/XAxisRenderer.swift index 7bec034e63..1092547716 100644 --- a/Source/Charts/Renderers/XAxisRenderer.swift +++ b/Source/Charts/Renderers/XAxisRenderer.swift @@ -19,6 +19,7 @@ import CoreGraphics @objc(ChartXAxisRenderer) open class XAxisRenderer: AxisRendererBase { + public init(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, transformer: Transformer?) { super.init(viewPortHandler: viewPortHandler, transformer: transformer, axis: xAxis) @@ -32,6 +33,7 @@ open class XAxisRenderer: AxisRendererBase var min = min, max = max + if let transformer = self.transformer { // calculate the starting and entry point of the y-labels (depending on @@ -53,7 +55,6 @@ open class XAxisRenderer: AxisRendererBase } } } - computeAxisValues(min: min, max: max) } @@ -191,12 +192,12 @@ open class XAxisRenderer: AxisRendererBase paraStyle.alignment = .center let labelAttrs = [NSFontAttributeName: xAxis.labelFont, - NSForegroundColorAttributeName: xAxis.labelTextColor, - NSParagraphStyleAttributeName: paraStyle] as [String : NSObject] + NSForegroundColorAttributeName: xAxis.labelTextColor, + NSParagraphStyleAttributeName: paraStyle] as [String : NSObject] let labelRotationAngleRadians = xAxis.labelRotationAngle * ChartUtils.Math.FDEG2RAD let centeringEnabled = xAxis.isCenterAxisLabelsEnabled - + let valueToPixelMatrix = transformer.valueToPixelMatrix var position = CGPoint(x: 0.0, y: 0.0) @@ -208,10 +209,21 @@ open class XAxisRenderer: AxisRendererBase labelMaxSize.width = xAxis.wordWrapWidthPercent * valueToPixelMatrix.a } - let entries = xAxis.entries + let entries: [Double] + if xAxis.isLogarithmicEnabled == true + { + xAxis.entries = xAxis.logAxis + entries = xAxis.logAxis.map{log10($0)} + } else { + entries = xAxis.entries + } for i in stride(from: 0, to: entries.count, by: 1) { + if xAxis.isLogarithmicEnabled == true && xAxis.logLabels[i] == false + { + continue + } if centeringEnabled { position.x = CGFloat(xAxis.centeredEntries[i]) @@ -227,7 +239,7 @@ open class XAxisRenderer: AxisRendererBase if viewPortHandler.isInBoundsX(position.x) { let label = xAxis.valueFormatter?.stringForValue(xAxis.entries[i], axis: xAxis) ?? "" - + let labelns = label as NSString if xAxis.isAvoidFirstLastClippingEnabled @@ -300,7 +312,6 @@ open class XAxisRenderer: AxisRendererBase context.setShouldAntialias(xAxis.gridAntialiasEnabled) context.setStrokeColor(xAxis.gridColor.cgColor) - context.setLineWidth(xAxis.gridLineWidth) context.setLineCap(xAxis.gridLineCap) if xAxis.gridLineDashLengths != nil @@ -316,7 +327,12 @@ open class XAxisRenderer: AxisRendererBase var position = CGPoint(x: 0.0, y: 0.0) - let entries = xAxis.entries + let entries: [Double] + if xAxis.isLogarithmicEnabled == true { + entries = xAxis.logAxis.map{log10($0)} + } else { + entries = xAxis.entries + } for i in stride(from: 0, to: entries.count, by: 1) { @@ -324,7 +340,17 @@ open class XAxisRenderer: AxisRendererBase position.y = position.x position = position.applying(valueToPixelMatrix) - drawGridLine(context: context, x: position.x, y: position.y) + context.setLineWidth(xAxis.gridLineWidth ) + var major = false + if xAxis.logAxis.count > 0 && xAxis.isLogarithmicEnabled == true + { + if (log10 (abs(xAxis.logAxis[i])) - floor (log10(abs(xAxis.logAxis[i])))) == 0 + { + context.setLineWidth(xAxis.gridLineWidth * 3) + major = true + } + } + drawGridLine(context: context, x: position.x, y: position.y, major: major) } } @@ -337,19 +363,43 @@ open class XAxisRenderer: AxisRendererBase return contentRect } - open func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat) + open func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat, major : Bool) { guard + let xAxis = self.axis as? XAxis, let viewPortHandler = self.viewPortHandler else { return } - if x >= viewPortHandler.offsetLeft - && x <= viewPortHandler.chartWidth + if x >= viewPortHandler.offsetLeft && x <= viewPortHandler.chartWidth { - context.beginPath() - context.move(to: CGPoint(x: x, y: viewPortHandler.contentTop)) - context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom)) - context.strokePath() + if xAxis.isLogarithmicEnabled == true && xAxis.isStickEnabled == true + { + if xAxis.isStickMajorEnabled == false && major == true + { + context.beginPath() + context.move(to: CGPoint(x: x, y: viewPortHandler.contentTop)) + context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom)) + context.strokePath() + } + else + { + let heightStick : CGFloat = 5.0 + context.beginPath() + context.move(to: CGPoint(x: x, y: viewPortHandler.contentTop)) + context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentTop + heightStick)) + + context.move(to: CGPoint(x: x, y: viewPortHandler.contentBottom)) + context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom - heightStick)) + context.strokePath() + } + } + else + { + context.beginPath() + context.move(to: CGPoint(x: x, y: viewPortHandler.contentTop)) + context.addLine(to: CGPoint(x: x, y: viewPortHandler.contentBottom)) + context.strokePath() + } } } @@ -440,44 +490,45 @@ open class XAxisRenderer: AxisRendererBase if limitLine.labelPosition == .rightTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x + xOffset, - y: viewPortHandler.contentTop + yOffset), - align: .left, - attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) + text: label, + point: CGPoint( + x: position.x + xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .left, + attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) } else if limitLine.labelPosition == .rightBottom { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x + xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), - align: .left, - attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) + text: label, + point: CGPoint( + x: position.x + xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .left, + attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) } else if limitLine.labelPosition == .leftTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x - xOffset, - y: viewPortHandler.contentTop + yOffset), - align: .right, - attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .right, + attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) } else { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x - xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), - align: .right, - attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .right, + attributes: [NSFontAttributeName: limitLine.valueFont, NSForegroundColorAttributeName: limitLine.valueTextColor]) } } } - } + + diff --git a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift index 200fd2d9ce..3f2bb47e9c 100644 --- a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift @@ -65,7 +65,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer guard let xAxis = self.axis as? XAxis else { return } - + let longest = xAxis.getLongestLabel() as NSString let labelSize = longest.size(attributes: [NSFontAttributeName: xAxis.labelFont]) @@ -80,7 +80,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer xAxis.labelRotatedWidth = round(labelRotatedSize.width + xAxis.xOffset * 3.5) xAxis.labelRotatedHeight = round(labelRotatedSize.height) } - + open override func renderAxisLabels(context: CGContext) { guard @@ -117,7 +117,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer drawLabels(context: context, pos: viewPortHandler.contentLeft - xoffset, anchor: CGPoint(x: 1.0, y: 0.5)) } } - + /// draws the x-labels on the specified y-position open override func drawLabels(context: CGContext, pos: CGFloat, anchor: CGPoint) { @@ -199,7 +199,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer fileprivate var _gridLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) - open override func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat) + open override func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat, major : Bool) { guard let viewPortHandler = self.viewPortHandler @@ -297,7 +297,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer clippingRect.origin.y -= l.lineWidth / 2.0 clippingRect.size.height += l.lineWidth context.clip(to: clippingRect) - + position.x = 0.0 position.y = CGFloat(l.limit) position = position.applying(trans) @@ -332,42 +332,42 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer if l.labelPosition == .rightTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentRight - xOffset, - y: position.y - yOffset), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y - yOffset), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .rightBottom { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentRight - xOffset, - y: position.y + yOffset - labelLineHeight), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y + yOffset - labelLineHeight), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .leftTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentLeft + xOffset, - y: position.y - yOffset), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y - yOffset), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentLeft + xOffset, - y: position.y + yOffset - labelLineHeight), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y + yOffset - labelLineHeight), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } } } diff --git a/Source/Charts/Renderers/YAxisRenderer.swift b/Source/Charts/Renderers/YAxisRenderer.swift index fd9604e868..6315f42b4e 100644 --- a/Source/Charts/Renderers/YAxisRenderer.swift +++ b/Source/Charts/Renderers/YAxisRenderer.swift @@ -8,7 +8,6 @@ // // https://github.com/danielgindi/Charts // - import Foundation import CoreGraphics @@ -141,26 +140,40 @@ open class YAxisRenderer: AxisRendererBase let labelFont = yAxis.labelFont let labelTextColor = yAxis.labelTextColor + if yAxis.isLogarithmicEnabled == true + { + yAxis.entries = yAxis.logAxis + } + + let rectGraph = viewPortHandler?.contentRect + let from = yAxis.isDrawBottomYLabelEntryEnabled ? 0 : 1 - let to = yAxis.isDrawTopYLabelEntryEnabled ? yAxis.entryCount : (yAxis.entryCount - 1) + let to = yAxis.isDrawTopYLabelEntryEnabled ? positions.count : (positions.count - 1) for i in stride(from: from, to: to, by: 1) { - let text = yAxis.getFormattedLabel(i) + if yAxis.isLogarithmicEnabled == true && yAxis.logLabels[i] == false + { + continue + } - ChartUtils.drawText( - context: context, - text: text, - point: CGPoint(x: fixedPosition, y: positions[i].y + offset), - align: textAlign, - attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor]) + let text = yAxis.valueFormatter?.stringForValue(yAxis.entries[i], axis: yAxis) ?? "" + if positions[i].y > (rectGraph?.minY)! && positions[i].y < (rectGraph?.maxY)! + { + ChartUtils.drawText( + context: context, + text: text, + point: CGPoint(x: fixedPosition, y: positions[i].y + offset), + align: textAlign, + attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor]) + } } } open override func renderGridLines(context: CGContext) { - guard let - yAxis = self.axis as? YAxis + guard + let yAxis = self.axis as? YAxis else { return } if !yAxis.isEnabled @@ -178,7 +191,6 @@ open class YAxisRenderer: AxisRendererBase context.setShouldAntialias(yAxis.gridAntialiasEnabled) context.setStrokeColor(yAxis.gridColor.cgColor) - context.setLineWidth(yAxis.gridLineWidth) context.setLineCap(yAxis.gridLineCap) if yAxis.gridLineDashLengths != nil @@ -192,12 +204,23 @@ open class YAxisRenderer: AxisRendererBase } // draw the grid + for i in 0 ..< positions.count { - drawGridLine(context: context, position: positions[i]) + var major = false + context.setLineWidth(yAxis.gridLineWidth ) + if yAxis.logAxis.count > 0 && yAxis.isLogarithmicEnabled == true + { + if (log10 (abs(yAxis.logAxis[i])) - floor (log10(abs(yAxis.logAxis[i])))) == 0 + { + context.setLineWidth(yAxis.gridLineWidth * 3) + major = true + } + } + drawGridLine(context: context, position: positions[i], major: major) } } - + if yAxis.drawZeroLineEnabled { // draw zero line @@ -216,16 +239,42 @@ open class YAxisRenderer: AxisRendererBase open func drawGridLine( context: CGContext, - position: CGPoint) + position: CGPoint, + major : Bool) { guard + let yAxis = self.axis as? YAxis, let viewPortHandler = self.viewPortHandler else { return } - context.beginPath() - context.move(to: CGPoint(x: viewPortHandler.contentLeft, y: position.y)) - context.addLine(to: CGPoint(x: viewPortHandler.contentRight, y: position.y)) - context.strokePath() + if yAxis.isLogarithmicEnabled == true && yAxis.isStickEnabled == true + { + if yAxis.isStickMajorEnabled == false && major == true + { + context.beginPath() + context.move(to: CGPoint(x: viewPortHandler.contentLeft, y: position.y)) + context.addLine(to: CGPoint(x: viewPortHandler.contentRight, y: position.y)) + context.strokePath() + } + else + { + let widthStick : CGFloat = 5.0 + context.beginPath() + context.move(to: CGPoint(x: viewPortHandler.contentLeft , y: position.y)) + context.addLine(to: CGPoint(x: viewPortHandler.contentLeft + widthStick, y: position.y)) + + context.move(to: CGPoint(x: viewPortHandler.contentRight, y: position.y)) + context.addLine(to: CGPoint(x: viewPortHandler.contentRight - widthStick, y: position.y)) + context.strokePath() + } + } + else + { + context.beginPath() + context.move(to: CGPoint(x: viewPortHandler.contentLeft, y: position.y)) + context.addLine(to: CGPoint(x: viewPortHandler.contentRight, y: position.y)) + context.strokePath() + } } open func transformedPositions() -> [CGPoint] @@ -238,18 +287,26 @@ open class YAxisRenderer: AxisRendererBase var positions = [CGPoint]() positions.reserveCapacity(yAxis.entryCount) - let entries = yAxis.entries + // let entries = yAxis.entries + let entries: [Double] + if yAxis.isLogarithmicEnabled == true + { + entries = yAxis.logAxis.map{log10($0)} + yAxis.entries = yAxis.logAxis + } else { + entries = yAxis.entries + } - for i in stride(from: 0, to: yAxis.entryCount, by: 1) + for i in stride(from: 0, to: entries.count, by: 1) { positions.append(CGPoint(x: 0.0, y: entries[i])) } - + transformer.pointValuesToPixel(&positions) return positions } - + /// Draws the zero line at the specified position. open func drawZeroLine(context: CGContext) { @@ -267,12 +324,12 @@ open class YAxisRenderer: AxisRendererBase clippingRect.origin.y -= yAxis.zeroLineWidth / 2.0 clippingRect.size.height += yAxis.zeroLineWidth context.clip(to: clippingRect) - + context.setStrokeColor(zeroLineColor.cgColor) context.setLineWidth(yAxis.zeroLineWidth) let pos = transformer.pixelForValues(x: 0.0, y: 0.0) - + if yAxis.zeroLineDashLengths != nil { context.setLineDash(phase: yAxis.zeroLineDashPhase, lengths: yAxis.zeroLineDashLengths!) @@ -359,46 +416,46 @@ open class YAxisRenderer: AxisRendererBase if l.labelPosition == .rightTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentRight - xOffset, - y: position.y - yOffset), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y - yOffset), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .rightBottom { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentRight - xOffset, - y: position.y + yOffset - labelLineHeight), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y + yOffset - labelLineHeight), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .leftTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentLeft + xOffset, - y: position.y - yOffset), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y - yOffset), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: viewPortHandler.contentLeft + xOffset, - y: position.y + yOffset - labelLineHeight), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y + yOffset - labelLineHeight), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } } } - context.restoreGState() } } + diff --git a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift index 621d6dd6ed..dedd06129c 100644 --- a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift @@ -22,7 +22,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer { super.init(viewPortHandler: viewPortHandler, yAxis: yAxis, transformer: transformer) } - + /// Computes the axis values. open override func computeAxis(min: Double, max: Double, inverted: Bool) { @@ -53,7 +53,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer computeAxisValues(min: min, max: max) } - + /// draws the y-axis labels to the screen open override func renderAxisLabels(context: CGContext) { @@ -133,7 +133,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer { context.setLineDash(phase: 0.0, lengths: []) } - + if yAxis.axisDependency == .left { context.beginPath() @@ -150,7 +150,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer context.restoreGState() } - + /// draws the y-labels on the specified x-position open func drawYLabels( context: CGContext, @@ -192,7 +192,8 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer open override func drawGridLine( context: CGContext, - position: CGPoint) + position: CGPoint, + major :Bool) { guard let viewPortHandler = self.viewPortHandler @@ -274,7 +275,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer else { return } var limitLines = yAxis.limitLines - + if limitLines.count <= 0 { return @@ -297,7 +298,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer context.saveGState() defer { context.restoreGState() } - + var clippingRect = viewPortHandler.contentRect clippingRect.origin.x -= l.lineWidth / 2.0 clippingRect.size.width += l.lineWidth @@ -325,7 +326,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer context.strokePath() let label = l.label - + // if drawing the limit-value label is enabled if l.drawLabelEnabled && label.characters.count > 0 { @@ -333,46 +334,46 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer let xOffset: CGFloat = l.lineWidth + l.xOffset let yOffset: CGFloat = 2.0 + l.yOffset - + if l.labelPosition == .rightTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x + xOffset, - y: viewPortHandler.contentTop + yOffset), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: position.x + xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .rightBottom { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x + xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), - align: .left, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: position.x + xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else if l.labelPosition == .leftTop { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x - xOffset, - y: viewPortHandler.contentTop + yOffset), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } else { ChartUtils.drawText(context: context, - text: label, - point: CGPoint( - x: position.x - xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), - align: .right, - attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } } } diff --git a/Source/Charts/Renderers/YAxisRendererRadarChart.swift b/Source/Charts/Renderers/YAxisRendererRadarChart.swift index bd04c08470..1d6813ee99 100644 --- a/Source/Charts/Renderers/YAxisRendererRadarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererRadarChart.swift @@ -156,6 +156,7 @@ open class YAxisRendererRadarChart: YAxisRenderer axis._axisMinimum = axis.entries[0] axis._axisMaximum = axis.entries[n-1] + print ("axis._axisMaximum = ", axis._axisMaximum) axis.axisRange = abs(axis._axisMaximum - axis._axisMinimum) } diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift index c8143e87ac..317d89e7e9 100755 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -22,10 +22,10 @@ open class ChartUtils internal struct Math { - internal static let FDEG2RAD = CGFloat(M_PI / 180.0) - internal static let FRAD2DEG = CGFloat(180.0 / M_PI) - internal static let DEG2RAD = M_PI / 180.0 - internal static let RAD2DEG = 180.0 / M_PI + internal static let FDEG2RAD = CGFloat(.pi / 180.0) + internal static let FRAD2DEG = CGFloat(180.0 / .pi) + internal static let DEG2RAD = .pi / 180.0 + internal static let RAD2DEG = 180.0 / .pi } internal class func roundToNextSignificant(number: Double) -> Double @@ -67,7 +67,7 @@ open class ChartUtils } else { - return number + DBL_EPSILON + return number + Double.ulpOfOne } } diff --git a/Source/ChartsRealm/Data/RealmBarDataSet.swift b/Source/ChartsRealm/Data/RealmBarDataSet.swift index fe76bf6e78..c9cb54120e 100644 --- a/Source/ChartsRealm/Data/RealmBarDataSet.swift +++ b/Source/ChartsRealm/Data/RealmBarDataSet.swift @@ -239,10 +239,10 @@ open class RealmBarDataSet: RealmBarLineScatterCandleBubbleDataSet, IBarChartDat return } - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -greatestFiniteMagnitude + _yMin = greatestFiniteMagnitude + _xMax = -greatestFiniteMagnitude + _xMin = greatestFiniteMagnitude for e in _cache as! [BarChartDataEntry] { diff --git a/Source/ChartsRealm/Data/RealmBaseDataSet.swift b/Source/ChartsRealm/Data/RealmBaseDataSet.swift index 43f660d117..59a7eb2731 100644 --- a/Source/ChartsRealm/Data/RealmBaseDataSet.swift +++ b/Source/ChartsRealm/Data/RealmBaseDataSet.swift @@ -224,11 +224,11 @@ open class RealmBaseDataSet: ChartBaseDataSet internal var _xValueField: String? internal var _cache = [ChartDataEntry]() - internal var _yMax: Double = -DBL_MAX - internal var _yMin: Double = DBL_MAX + internal var _yMax: Double = -greatestFiniteMagnitude + internal var _yMin: Double = greatestFiniteMagnitude - internal var _xMax: Double = -DBL_MAX - internal var _xMin: Double = DBL_MAX + internal var _xMax: Double = -greatestFiniteMagnitude + internal var _xMin: Double = greatestFiniteMagnitude /// Makes sure that the cache is populated for the specified range internal func buildCache() @@ -275,10 +275,10 @@ open class RealmBaseDataSet: ChartBaseDataSet return } - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -greatestFiniteMagnitude + _yMin = greatestFiniteMagnitude + _xMax = -greatestFiniteMagnitude + _xMin = greatestFiniteMagnitude for e in _cache { diff --git a/Source/ChartsRealm/Data/RealmBubbleDataSet.swift b/Source/ChartsRealm/Data/RealmBubbleDataSet.swift index 5a3c9665f1..38ffbdf868 100644 --- a/Source/ChartsRealm/Data/RealmBubbleDataSet.swift +++ b/Source/ChartsRealm/Data/RealmBubbleDataSet.swift @@ -108,10 +108,10 @@ open class RealmBubbleDataSet: RealmBarLineScatterCandleBubbleDataSet, IBubbleCh return } - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -greatestFiniteMagnitude + _yMin = greatestFiniteMagnitude + _xMax = -greatestFiniteMagnitude + _xMin = greatestFiniteMagnitude for e in _cache as! [BubbleChartDataEntry] { diff --git a/Source/ChartsRealm/Data/RealmCandleDataSet.swift b/Source/ChartsRealm/Data/RealmCandleDataSet.swift index 2fdf53aac8..1558b901e3 100644 --- a/Source/ChartsRealm/Data/RealmCandleDataSet.swift +++ b/Source/ChartsRealm/Data/RealmCandleDataSet.swift @@ -117,10 +117,10 @@ open class RealmCandleDataSet: RealmLineScatterCandleRadarDataSet, ICandleChartD return } - _yMax = -DBL_MAX - _yMin = DBL_MAX - _xMax = -DBL_MAX - _xMin = DBL_MAX + _yMax = -greatestFiniteMagnitude + _yMin = greatestFiniteMagnitude + _xMax = -greatestFiniteMagnitude + _xMin = greatestFiniteMagnitude for e in _cache as! [CandleChartDataEntry] { diff --git a/Tests/Charts/ChartUtilsTests.swift b/Tests/Charts/ChartUtilsTests.swift index a19b514d53..1739ceb6af 100644 --- a/Tests/Charts/ChartUtilsTests.swift +++ b/Tests/Charts/ChartUtilsTests.swift @@ -23,7 +23,7 @@ class ChartUtilsTests: XCTestCase { func testDecimalWithNaN() { - let number = Double.nan + let number = nan let actual = ChartUtils.decimals(number) let expected = 0 @@ -33,7 +33,7 @@ class ChartUtilsTests: XCTestCase { func testDecimalWithInfinite() { - let number = Double.infinity + let number = infinity let actual = ChartUtils.decimals(number) let expected = 0 @@ -53,7 +53,7 @@ class ChartUtilsTests: XCTestCase { func testDecimalWithMaxValue() { - let number = DBL_MAX + let number = greatestFiniteMagnitude let actual = ChartUtils.decimals(number) let expected = 0