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

Stop axis labels duplicating #638

Closed
wants to merge 17 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ DerivedData

Carthage
Charts.framework.zip
.DS_Store
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
3 changes: 3 additions & 0 deletions Charts/Classes/Renderers/ChartYAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ 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 = false;

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

_sliderX.value = 19.0;
_sliderY.value = 30.0;
Expand Down
5 changes: 3 additions & 2 deletions ChartsDemo/Classes/Demos/LineChart2ViewController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7519.1" systemVersion="14C1510" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7513.1"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="LineChart2ViewController">
Expand Down