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

Fix Type 'ChartDataSet' does not conform to protocol 'RangeReplaceabl… #4881

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class BarChartDataEntry: ChartDataEntry
private var _yVals: [Double]?

/// the ranges for the individual stack values - automatically calculated
private var _ranges: [Range]?
private var _ranges: [ChartRange]?

/// the sum of all negative values this entry (if stacked) contains
private var _negativeSum: Double = 0.0
Expand Down Expand Up @@ -145,7 +145,7 @@ open class BarChartDataEntry: ChartDataEntry

if _ranges == nil
{
_ranges = [Range]()
_ranges = [ChartRange]()
}
else
{
Expand All @@ -161,12 +161,12 @@ open class BarChartDataEntry: ChartDataEntry
{
if value < 0
{
_ranges!.append(Range(from: negRemain, to: negRemain - value))
_ranges!.append(ChartRange(from: negRemain, to: negRemain - value))
negRemain -= value
}
else
{
_ranges!.append(Range(from: posRemain, to: posRemain + value))
_ranges!.append(ChartRange(from: posRemain, to: posRemain + value))
posRemain += value
}
}
Expand All @@ -191,7 +191,7 @@ open class BarChartDataEntry: ChartDataEntry
}

/// The ranges of the individual stack-entries. Will return null if this entry is not stacked.
@objc open var ranges: [Range]?
@objc open var ranges: [ChartRange]?
{
return _ranges
}
Expand Down
10 changes: 9 additions & 1 deletion Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ extension ChartDataSet: RandomAccessCollection {
}

// MARK: RangeReplaceableCollection
extension ChartDataSet: RangeReplaceableCollection {
extension ChartDataSet: RangeReplaceableCollection {
public func append(_ newElement: Element) {
calcMinMax(entry: newElement)
entries.append(newElement)
Expand Down Expand Up @@ -571,4 +571,12 @@ extension ChartDataSet: RangeReplaceableCollection {
entries.removeAll(keepingCapacity: keepCapacity)
notifyDataSetChanged()
}

public func replaceSubrange<C>(
_ subrange: Range<Index>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we just use Swift.Range<Index> here we don't have to rename the other Range class. I think it would be a better fix for the problem.

with newElements: C
) where C : Collection, Element == C.Element {
entries.replaceSubrange(subrange, with: newElements)
notifyDataSetChanged()
}
}
2 changes: 1 addition & 1 deletion Source/Charts/Highlight/BarHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ open class BarHighlighter: ChartHighlighter
/// - entry:
/// - value:
/// - Returns: The index of the closest value inside the values array / ranges (stacked barchart) to the value given as a parameter.
@objc open func getClosestStackIndex(ranges: [Range]?, value: Double) -> Int
@objc open func getClosestStackIndex(ranges: [ChartRange]?, value: Double) -> Int
{
guard let ranges = ranges else { return 0 }
if let stackIndex = ranges.firstIndex(where: { $0.contains(value) }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import Foundation

@objc(ChartRange)
open class Range: NSObject
open class ChartRange: NSObject
{
@objc open var from: Double
@objc open var to: Double
Expand Down