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

fixed getMinimumValue() #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions linechart/linechart/LineChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public class LineChart: UIView {
var path = UIBezierPath()
// draw x-axis
x.axis.color.setStroke()
var y0 = height - self.y.scale(0) - y.axis.inset
var y0 = height - max(self.y.scale(0), 0) - y.axis.inset
path.moveToPoint(CGPoint(x: x.axis.inset, y: y0))
path.addLineToPoint(CGPoint(x: width - x.axis.inset, y: y0))
path.stroke()
Expand Down Expand Up @@ -371,10 +371,10 @@ public class LineChart: UIView {


/**
* Get maximum value in all arrays in data store.
*/
* Get minimum value in all arrays in data store.
*/
private func getMinimumValue() -> CGFloat {
var min: CGFloat = 0
var min: CGFloat = getMaximumValue()
for data in dataStore {
var newMin = minElement(data)
if newMin < min {
Expand Down Expand Up @@ -436,7 +436,7 @@ public class LineChart: UIView {

colors[lineIndex].colorWithAlphaComponent(0.2).setFill()
// move to origin
path.moveToPoint(CGPoint(x: x.axis.inset, y: self.bounds.height - self.y.scale(0) - y.axis.inset))
path.moveToPoint(CGPoint(x: x.axis.inset, y: self.bounds.height - max(self.y.scale(0), 0) - y.axis.inset))
// add line to first data point
path.addLineToPoint(CGPoint(x: x.axis.inset, y: self.bounds.height - self.y.scale(data[0]) - y.axis.inset))
// draw whole line chart
Expand All @@ -446,9 +446,9 @@ public class LineChart: UIView {
path.addLineToPoint(CGPoint(x: x1, y: y1))
}
// move down to x axis
path.addLineToPoint(CGPoint(x: self.x.scale(CGFloat(data.count - 1)) + x.axis.inset, y: self.bounds.height - self.y.scale(0) - y.axis.inset))
path.addLineToPoint(CGPoint(x: self.x.scale(CGFloat(data.count - 1)) + x.axis.inset, y: self.bounds.height - max(self.y.scale(0), 0) - y.axis.inset))
// move to origin
path.addLineToPoint(CGPoint(x: x.axis.inset, y: self.bounds.height - self.y.scale(0) - y.axis.inset))
path.addLineToPoint(CGPoint(x: x.axis.inset, y: self.bounds.height - max(self.y.scale(0), 0) - y.axis.inset))
path.fill()
}

Expand Down