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

Added support for setting a custom width that is wider than the longe… #107

Merged
merged 1 commit into from
May 27, 2015
Merged
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: 27 additions & 0 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,33 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
/// returns true if autoScaleMinMax is enabled, false if no
/// :default: false
public var isAutoScaleMinMaxEnabled : Bool { return autoScaleMinMaxEnabled; }


/// Sets a custom width to the specified y axis.
public func setXAxisWidth(which: ChartYAxis.AxisDependency, width: CGFloat)
{
if (which == .Left)
{
_leftAxis.setCustomWidth(width);
}
else
{
_rightAxis.setCustomWidth(width);
}
}

/// Returns the width of the specified y axis.
public func getXAxisWidth(which: ChartYAxis.AxisDependency) -> CGFloat
{
if (which == .Left)
{
return _leftAxis.requiredSize().width;
}
else
{
return _rightAxis.requiredSize().width;
}
}
}

/// Default formatter that calculates the position of the filled line.
Expand Down
10 changes: 10 additions & 0 deletions Charts/Classes/Components/ChartYAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public class ChartYAxis: ChartAxisBase
/// the side this axis object represents
private var _axisDependency = AxisDependency.Left

/// the width the axis should take
private var _customWidth = CGFloat(0);

public override init()
{
super.init();
Expand Down Expand Up @@ -158,6 +161,7 @@ public class ChartYAxis: ChartAxisBase
var size = label.sizeWithAttributes([NSFontAttributeName: labelFont]);
size.width += xOffset * 2.0;
size.height += yOffset * 2.0;
size.width = max(_customWidth, size.width);
return size;
}

Expand Down Expand Up @@ -202,6 +206,12 @@ public class ChartYAxis: ChartAxisBase
}
}

/// Sets a custom width to the axis that can be bigger than the requried size of the longest label. Note: narrower axis widths are not supported.
public func setCustomWidth(width: CGFloat)
{
_customWidth = width;
}

public var isInverted: Bool { return inverted; }

public var isStartAtZeroEnabled: Bool { return startAtZeroEnabled; }
Expand Down