|
|
|
@@ -26,7 +26,7 @@ CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.5f;
|
|
|
|
|
NSInteger static const kJBLineChartLinesViewUnselectedLineIndex = -1;
|
|
|
|
|
|
|
|
|
|
// Numerics (JBLineChartDotsView)
|
|
|
|
|
NSInteger static const kJBLineChartDotsViewRadiusFactor = 3; // 3x size of line width
|
|
|
|
|
NSInteger static const kJBLineChartDotsViewDefaultRadiusFactor = 3; // 3x size of line width
|
|
|
|
|
NSInteger static const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
|
|
|
|
|
|
|
|
|
// Numerics (JBLineSelectionView)
|
|
|
|
@@ -115,6 +115,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
|
|
|
|
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
|
|
|
|
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
|
|
|
|
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
|
|
|
|
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
|
|
|
|
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
|
|
|
|
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
|
|
|
|
|
|
|
|
@@ -406,21 +407,39 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
|
|
|
|
|
|
|
|
|
- (CGFloat)padding
|
|
|
|
|
{
|
|
|
|
|
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
|
|
|
|
CGFloat maxLineWidth = 0.0f;
|
|
|
|
|
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
|
|
|
|
|
|
|
|
|
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
|
|
|
|
{
|
|
|
|
|
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
|
|
|
|
CGFloat maxWidth = 0.0f;
|
|
|
|
|
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
|
|
|
|
BOOL showsDots = NO;
|
|
|
|
|
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
|
|
|
|
|
{
|
|
|
|
|
CGFloat lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
|
|
|
|
|
if (lineWidth > maxWidth)
|
|
|
|
|
showsDots = [self.dataSource lineChartView:self showsDotsForLineAtLineIndex:lineIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGFloat lineWidth = kJBLineChartLinesViewStrokeWidth; // default
|
|
|
|
|
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
|
|
|
|
{
|
|
|
|
|
lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineWidth];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
|
|
|
|
|
if (showsDots)
|
|
|
|
|
{
|
|
|
|
|
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
|
|
|
|
{
|
|
|
|
|
maxWidth = lineWidth;
|
|
|
|
|
dotRadius = [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ceil(maxWidth * 0.5);
|
|
|
|
|
|
|
|
|
|
CGFloat currentMaxLineWidth = MAX(dotRadius, lineWidth);
|
|
|
|
|
if (currentMaxLineWidth > maxLineWidth)
|
|
|
|
|
{
|
|
|
|
|
maxLineWidth = currentMaxLineWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ceil(kJBLineChartLinesViewStrokeWidth * 0.5);
|
|
|
|
|
return ceil(maxLineWidth * 0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)dataCount
|
|
|
|
@@ -530,6 +549,18 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
|
|
|
|
return kJBLineChartLinesViewStrokeWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
|
|
|
|
{
|
|
|
|
|
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
|
|
|
|
{
|
|
|
|
|
return [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
|
|
|
|
{
|
|
|
|
|
return [self padding];
|
|
|
|
@@ -1160,10 +1191,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *mutableDotViews = [NSMutableArray array];
|
|
|
|
|
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
|
|
|
|
|
{
|
|
|
|
|
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:widthForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex");
|
|
|
|
|
CGFloat lineWidth = [self.delegate lineChartDotsView:self widthForLineAtLineIndex:lineIndex];
|
|
|
|
|
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewRadiusFactor;
|
|
|
|
|
{
|
|
|
|
|
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex");
|
|
|
|
|
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtLineIndex:lineIndex];
|
|
|
|
|
|
|
|
|
|
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
|
|
|
|
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
|
|
|
|