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

Restored old performance in ChartDataSet #3216

Merged
merged 1 commit into from
Jan 31, 2018
Merged
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
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