Skip to content

Commit

Permalink
Stop axis labels duplicating.
Browse files Browse the repository at this point in the history
  • Loading branch information
noais committed Jan 4, 2016
1 parent 65e3ae9 commit bb0527f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Charts/Classes/Components/ChartYAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public class ChartYAxis: ChartAxisBase
/// **default**: 0.0 (no maximum specified)
public var maxWidth = CGFloat(0)

/// if true, axis values will be repeated
public var allowRepeatedValues = false

/// the minimum diference value of the axis values
///
/// **default**: 1
public var granuality = Double(1.0)

public override init()
{
super.init()
Expand Down
4 changes: 4 additions & 0 deletions Charts/Classes/Renderers/ChartYAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public class ChartYAxisRenderer: ChartAxisRendererBase

let rawInterval = range / Double(labelCount)
var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval))
if !_yAxis.allowRepeatedValues
{
interval = interval < _yAxis.granuality ? _yAxis.granuality : interval
}
let intervalMagnitude = pow(10.0, round(log10(interval)))
let intervalSigDigit = (interval / intervalMagnitude)
if (intervalSigDigit > 5)
Expand Down
2 changes: 2 additions & 0 deletions ChartsDemo/Classes/Demos/CombinedChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ - (void)viewDidLoad

ChartYAxis *rightAxis = _chartView.rightAxis;
rightAxis.drawGridLinesEnabled = NO;
rightAxis.granuality = 0.1;

ChartYAxis *leftAxis = _chartView.leftAxis;
leftAxis.drawGridLinesEnabled = NO;
leftAxis.granuality = 0.1;

ChartXAxis *xAxis = _chartView.xAxis;
xAxis.labelPosition = XAxisLabelPositionBothSided;
Expand Down
2 changes: 2 additions & 0 deletions ChartsDemo/Classes/Demos/LineChart2ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ - (void)viewDidLoad
leftAxis.labelTextColor = [UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f];
leftAxis.customAxisMax = 200.0;
leftAxis.drawGridLinesEnabled = YES;
leftAxis.allowRepeatedValues = NO;

ChartYAxis *rightAxis = _chartView.rightAxis;
rightAxis.labelTextColor = UIColor.redColor;
rightAxis.customAxisMax = 900.0;
rightAxis.startAtZeroEnabled = NO;
rightAxis.customAxisMin = -200.0;
rightAxis.drawGridLinesEnabled = NO;
rightAxis.allowRepeatedValues = YES;

_sliderX.value = 19.0;
_sliderY.value = 30.0;
Expand Down

0 comments on commit bb0527f

Please sign in to comment.