Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ChartData::getDataSetByLabel always return the first IChartDataSet when ignorecase = true #4274

@PeterKaminski09

Description

@PeterKaminski09

Issue

It appears that this commit (https://github.com/danielgindi/Charts/pull/3892/files) added the comparison label.caseInsensitiveCompare(label) to ChartData::getDataSetByLabel.

This will always be true, so statements like chartData.getDataSetByLabel("myLabel", ignorecase: true) will return whatever IChartDataSet is at index 0.

Effected code

 internal func getDataSetIndexByLabel(_ label: String, ignorecase: Bool) -> Int
    {
        // TODO: Return nil instead of -1
        if ignorecase
        {
            return dataSets.firstIndex {
                guard let label = $0.label else { return false }
                return label.caseInsensitiveCompare(label) == .orderedSame
            } ?? -1
        }
        ...
    }

Follow-up

I'm happy to submit a pull-request to fix this issue 😺

Charts Environment

Charts version/Branch/Commit Number: 3.4.0
Xcode version: 11.3.1
Swift version: 5.0
Platform(s) running Charts: iOS
macOS version running Xcode: 10.15.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions