Skip to content

Commit

Permalink
Restored old performance (#3216)
Browse files Browse the repository at this point in the history
Temporary fix for calcMinMax frequency.
Better implementation coming for Charts 4
  • Loading branch information
jjatie authored and liuxuan30 committed Jan 31, 2018
1 parent cbaf51c commit b1191bc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ open class ChartDataSet: ChartBaseDataSet
/// - note: Calls `notifyDataSetChanged()` after setting a new value.
/// - returns: The array of y-values that this DataSet represents.
/// the entries that this dataset represents / holds together
@objc open var values: [ChartDataEntry] {
didSet {
@objc open var values: [ChartDataEntry]
{
didSet
{
if isIndirectValuesCall {
isIndirectValuesCall = false
return
}
notifyDataSetChanged()
}
}
// TODO: Temporary fix for performance. Will be removed in 4.0
private var isIndirectValuesCall = false

/// maximum y-value in the value array
internal var _yMax: Double = -Double.greatestFiniteMagnitude
Expand Down Expand Up @@ -386,7 +394,8 @@ open class ChartDataSet: ChartBaseDataSet
open override func addEntry(_ e: ChartDataEntry) -> Bool
{
calcMinMax(entry: e)


isIndirectValuesCall = true
values.append(e)

return true
Expand All @@ -401,6 +410,7 @@ open class ChartDataSet: ChartBaseDataSet
{
calcMinMax(entry: e)

isIndirectValuesCall = true
if values.count > 0 && values.last!.x > e.x
{
var closestIndex = entryIndex(x: e.x, closestToY: e.y, rounding: .up)
Expand All @@ -425,7 +435,8 @@ open class ChartDataSet: ChartBaseDataSet
open override func removeEntry(_ entry: ChartDataEntry) -> Bool
{
var removed = false

isIndirectValuesCall = true

for i in 0 ..< values.count
{
if values[i] === entry
Expand All @@ -436,6 +447,8 @@ open class ChartDataSet: ChartBaseDataSet
}
}

notifyDataSetChanged()

return removed
}

Expand Down

0 comments on commit b1191bc

Please sign in to comment.