Skip to content

Commit

Permalink
Allow a nil label for a DataSet
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed May 21, 2015
1 parent 1b3daa1 commit 8b115eb
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Charts/Classes/Data/BarChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BarChartDataSet: BarLineScatterCandleChartDataSet
/// array of labels used to describe the different values of the stacked bars
public var stackLabels: [String] = ["Stack"]

public override init(yVals: [ChartDataEntry]?, label: String)
public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label);

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/CandleChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CandleChartDataSet: BarLineScatterCandleChartDataSet
/// Are increasing values drawn as filled?
public var increasingFilled = true

public override init(yVals: [ChartDataEntry]?, label: String)
public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label);
}
Expand Down
14 changes: 12 additions & 2 deletions Charts/Classes/Data/ChartData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ public class ChartData: NSObject
{
for (var i = 0; i < dataSets.count; i++)
{
if (label.caseInsensitiveCompare(dataSets[i].label) == NSComparisonResult.OrderedSame)
if (dataSets[i].label == nil)
{
continue;
}

if (label.caseInsensitiveCompare(dataSets[i].label!) == NSComparisonResult.OrderedSame)
{
return i;
}
Expand Down Expand Up @@ -388,7 +393,12 @@ public class ChartData: NSObject

for (var i = 0; i < _dataSets.count; i++)
{
types[i] = _dataSets[i].label;
if (_dataSets[i].label == nil)
{
continue;
}

types.append(_dataSets[i].label!);
}

return types;
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Data/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ChartDataSet: NSObject
internal var _yMax = Float(0.0)
internal var _yMin = Float(0.0)
internal var _yValueSum = Float(0.0)
public var label = "DataSet"
public var label: String? = "DataSet"
public var visible = true;
public var drawValuesEnabled = true;

Expand All @@ -48,7 +48,7 @@ public class ChartDataSet: NSObject
super.init();
}

public init(yVals: [ChartDataEntry]?, label: String)
public init(yVals: [ChartDataEntry]?, label: String?)
{
super.init();

Expand Down Expand Up @@ -374,7 +374,7 @@ public class ChartDataSet: NSObject

public override var description: String
{
return String(format: "ChartDataSet, label: %@, %i entries", arguments: [self.label, _yVals.count]);
return String(format: "ChartDataSet, label: %@, %i entries", arguments: [self.label ?? "", _yVals.count]);
}

public override var debugDescription: String
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/LineChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LineChartDataSet: LineRadarChartDataSet
circleColors.append(UIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0));
}

public override init(yVals: [ChartDataEntry]?, label: String)
public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label);
circleColors.append(UIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0));
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Data/PieChartData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public class PieChartData: ChartData

public override func getDataSetByLabel(label: String, ignorecase: Bool) -> ChartDataSet?
{
if (dataSets.count == 0)
if (dataSets.count == 0 || dataSets[0].label == nil)
{
return nil;
}

if (ignorecase)
{
if (label.caseInsensitiveCompare(dataSets[0].label) == NSComparisonResult.OrderedSame)
if (label.caseInsensitiveCompare(dataSets[0].label!) == NSComparisonResult.OrderedSame)
{
return dataSets[0];
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/PieChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PieChartDataSet: ChartDataSet
self.valueFont = UIFont.systemFontOfSize(13.0);
}

public override init(yVals: [ChartDataEntry]?, label: String)
public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label);

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Data/RadarChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class RadarChartDataSet: LineRadarChartDataSet
self.valueFont = UIFont.systemFontOfSize(13.0);
}

public override init(yVals: [ChartDataEntry]?, label: String)
public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label);

Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Renderers/ChartLegendRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ public class ChartLegendRenderer: ChartRendererBase

if (!wasStacked)
{
drawLabel(context, x: x, y: posY - _legend.textHeightMax / 2.0, label: _legend.getLabel(i)!, font: labelFont, textColor: labelTextColor);
drawLabel(context, x: x, y: posY - _legend.textHeightMax / 2.0, label: labels[i]!, font: labelFont, textColor: labelTextColor);

posY += textDrop;
}
else
{
posY += _legend.textHeightMax * 3.0;
drawLabel(context, x: x, y: posY - _legend.textHeightMax * 2.0, label: _legend.getLabel(i)!, font: labelFont, textColor: labelTextColor);
drawLabel(context, x: x, y: posY - _legend.textHeightMax * 2.0, label: labels[i]!, font: labelFont, textColor: labelTextColor);
}

// make a step down
Expand Down

0 comments on commit 8b115eb

Please sign in to comment.