Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit aligment #186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Classes/Drawing/ReferenceLineDrawingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal class ReferenceLineDrawingView : UIView {
private var currentRange: (min: Double, max: Double) = (0,100)
private var topMargin: CGFloat = 10
private var bottomMargin: CGFloat = 10
private var unitsAligment: UnitsAligment {
return self.settings.unitsAligment
}

private var lineWidth: CGFloat {
get {
Expand All @@ -26,7 +29,7 @@ internal class ReferenceLineDrawingView : UIView {
private var units: String {
get {
if let units = self.settings.referenceLineUnits {
return " \(units)"
return "\(units)"
} else {
return ""
}
Expand Down Expand Up @@ -82,8 +85,20 @@ internal class ReferenceLineDrawingView : UIView {

let numberFormatter = referenceNumberFormatter()

let maxString = numberFormatter.string(from: self.currentRange.max as NSNumber)! + units
let minString = numberFormatter.string(from: self.currentRange.min as NSNumber)! + units
var maxString = numberFormatter.string(from: self.currentRange.max as NSNumber)!
if self.unitsAligment == .left {
maxString = self.units + maxString
} else {
maxString += self.units
}

var minString = numberFormatter.string(from: self.currentRange.min as NSNumber)!

if self.unitsAligment == .left {
minString = self.units + minString
} else {
minString += self.units
}

addLine(withTag: maxString, from: maxLineStart, to: maxLineEnd, in: referenceLinePath)
addLine(withTag: minString, from: minLineStart, to: minLineEnd, in: referenceLinePath)
Expand Down Expand Up @@ -157,7 +172,11 @@ internal class ReferenceLineDrawingView : UIView {
var valueString = numberFormatter.string(from: value as NSNumber)!

if(self.settings.shouldAddUnitsToIntermediateReferenceLineLabels) {
valueString += " \(units)"
if self.unitsAligment == .right {
valueString += "\(self.units)"
} else {
valueString = "\(self.units) \(valueString)"
}
}

addLine(withTag: valueString, from: lineStart, to: lineEnd, in: path)
Expand Down
6 changes: 6 additions & 0 deletions Classes/Reference/ReferenceLines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ open class ReferenceLines {
@IBInspectable open var dataPointLabelBottomMargin: CGFloat = 0
/// The font for the data point labels.
@IBInspectable open var dataPointLabelColor: UIColor = UIColor.black
@IBInspectable open var unitsAligment: UnitsAligment = .right
/// The colour for the data point labels.
open var dataPointLabelFont: UIFont? = UIFont.systemFont(ofSize: 10)
/// Used to force the graph to show every n-th dataPoint label
Expand All @@ -88,3 +89,8 @@ open class ReferenceLines {
@objc public enum ScrollableGraphViewReferenceLineType : Int {
case cover
}


@objc public enum UnitsAligment: Int {
case left, right
}
10 changes: 6 additions & 4 deletions GraphView/GraphView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
TargetAttributes = {
2918399D1C72E6A400753A45 = {
CreatedOnToolsVersion = 7.2.1;
DevelopmentTeam = MX8X2BSFQH;
LastSwiftMigration = 1000;
};
};
Expand All @@ -296,6 +297,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -505,11 +507,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = MX8X2BSFQH;
INFOPLIST_FILE = GraphView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode;
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode.fork;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.2;
Expand All @@ -522,11 +524,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = MX8X2BSFQH;
INFOPLIST_FILE = GraphView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode;
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode.fork;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.2;
Expand Down