Skip to content

Commit

Permalink
Allow to setHighlightEnabled on a single DataSet (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jun 2, 2015
1 parent 08730b2 commit 410e773
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 35 deletions.
15 changes: 1 addition & 14 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
}

// if highlighting is enabled
if (highlightEnabled && highlightIndicatorEnabled && valuesToHighlight())
if (valuesToHighlight())
{
renderer?.drawHighlighted(context: context, indices: _indicesToHightlight);
}
Expand Down Expand Up @@ -1216,19 +1216,6 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
return highlightPerDragEnabled;
}

/// if set to true, the highlight indicator (lines for linechart, dark bar for barchart) will be drawn upon selecting values.
public var highlightIndicatorEnabled = true

/// If set to true, the highlight indicator (vertical line for LineChart and
/// ScatterChart, dark bar overlay for BarChart) that gives visual indication
/// that an Entry has been selected will be drawn upon selecting values. This
/// does not depend on the MarkerView.
/// :default: true
public var isHighlightIndicatorEnabled: Bool
{
return highlightIndicatorEnabled;
}

/// :returns: true if drawing the grid background is enabled, false if not.
/// :default: true
public var isDrawGridBackgroundEnabled: Bool
Expand Down
21 changes: 17 additions & 4 deletions Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public class ChartViewBase: UIView, ChartAnimatorDelegate
internal var _chartXMin = Float(0.0)
internal var _chartXMax = Float(0.0)

/// if true, value highlightning is enabled
public var highlightEnabled = true

/// the legend object containing all data associated with the legend
internal var _legend: ChartLegend!;

Expand Down Expand Up @@ -837,8 +834,24 @@ public class ChartViewBase: UIView, ChartAnimatorDelegate
_sizeChangeEventActions.removeAll(keepCapacity: false);
}

/// if true, value highlighting is enabled
public var highlightEnabled: Bool
{
get
{
return _data === nil ? true : _data.highlightEnabled
}
set
{
if (_data !== nil)
{
_data.highlightEnabled = newValue;
}
}
}

/// if true, value highlightning is enabled
public var isHighlightEnabled: Bool { return highlightEnabled; }
public var isHighlightEnabled: Bool { return _data === nil ? true : _data.highlightEnabled }

/// :returns: true if chart continues to scroll after touch up, false if not.
/// :default: true
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PieChartView: PieRadarChartViewBase

renderer!.drawData(context: context);

if (self.highlightEnabled && valuesToHighlight())
if (valuesToHighlight())
{
renderer!.drawHighlighted(context: context, indices: _indicesToHightlight);
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class RadarChartView: PieRadarChartViewBase

renderer!.drawData(context: context);

if (self.highlightEnabled && valuesToHighlight())
if (valuesToHighlight())
{
renderer!.drawHighlighted(context: context, indices: _indicesToHightlight);
}
Expand Down
24 changes: 24 additions & 0 deletions Charts/Classes/Data/ChartData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ public class ChartData: NSObject
}
}

/// Enables / disables highlighting values for all DataSets this data object contains.
public var highlightEnabled: Bool
{
get
{
for set in dataSets
{
if (!set.highlightEnabled)
{
return false;
}
}

return true;
}
set
{
for set in dataSets
{
set.highlightEnabled = newValue;
}
}
}

/// Clears this data object from all DataSets and removes all Entries.
/// Don't forget to invalidate the chart after this.
public func clearValues()
Expand Down
3 changes: 3 additions & 0 deletions Charts/Classes/Data/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class ChartDataSet: NSObject
public var yMin: Float { return _yMin }
public var yMax: Float { return _yMax }

/// if true, value highlighting is enabled
public var highlightEnabled = true

public override init()
{
super.init();
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public class BarChartRenderer: ChartDataRendererBase
var dataSetIndex = h.dataSetIndex;
var set = barData.getDataSetByIndex(dataSetIndex) as! BarChartDataSet!;
if (set === nil)
if (set === nil || !set.highlightEnabled)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/BubbleChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public class BubbleChartRenderer: ChartDataRendererBase
{
let dataSet = bubbleData.getDataSetByIndex(indice.dataSetIndex) as! BubbleChartDataSet!;

if (dataSet === nil)
if (dataSet === nil || !dataSet.highlightEnabled)
{
continue
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public class CandleStickChartRenderer: ChartDataRendererBase

var set = candleData.getDataSetByIndex(indices[i].dataSetIndex) as! CandleChartDataSet!;

if (set === nil)
if (set === nil || !set.highlightEnabled)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public class LineChartRenderer: ChartDataRendererBase
{
var set = lineData.getDataSetByIndex(indices[i].dataSetIndex) as! LineChartDataSet!;

if (set === nil)
if (set === nil || !set.highlightEnabled)
{
continue;
}
Expand Down
14 changes: 7 additions & 7 deletions Charts/Classes/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ public class PieChartRenderer: ChartDataRendererBase
continue;
}

var set = _chart.data?.getDataSetByIndex(indices[i].dataSetIndex) as! PieChartDataSet!;

if (set === nil || !set.highlightEnabled)
{
continue;
}

if (xIndex == 0)
{
angle = rotationAngle;
Expand All @@ -342,13 +349,6 @@ public class PieChartRenderer: ChartDataRendererBase

var sliceDegrees = drawAngles[xIndex];

var set = _chart.data?.getDataSetByIndex(indices[i].dataSetIndex) as! PieChartDataSet!;

if (set === nil)
{
continue;
}

var shift = set.selectionShift;
var circleBox = _chart.circleBox;

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/RadarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public class RadarChartRenderer: ChartDataRendererBase
{
var set = _chart.data?.getDataSetByIndex(indices[i].dataSetIndex) as! RadarChartDataSet!;

if (set === nil)
if (set === nil || !set.highlightEnabled)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/ScatterChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public class ScatterChartRenderer: ChartDataRendererBase
{
var set = scatterData.getDataSetByIndex(indices[i].dataSetIndex) as! ScatterChartDataSet!;

if (set === nil)
if (set === nil || !set.highlightEnabled)
{
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions ChartsDemo/Classes/Demos/LineChart1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ - (void)viewDidLoad
_chartView.descriptionText = @"";
_chartView.noDataTextDescription = @"You need to provide data for the chart.";

_chartView.highlightEnabled = YES;
_chartView.highlightEnabled = NO;
_chartView.dragEnabled = YES;
[_chartView setScaleEnabled:YES];
_chartView.pinchZoomEnabled = YES;
_chartView.highlightIndicatorEnabled = NO;
_chartView.drawGridBackgroundEnabled = NO;

// x-axis limit line
Expand Down

0 comments on commit 410e773

Please sign in to comment.