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

notifyDataSetChanged() crashes with CGAffineTransformInvert: singular matrix. #3978

Closed
marthadog opened this issue Apr 29, 2019 · 1 comment

Comments

@marthadog
Copy link

I have a macOS app that uses your Charts framework and I have tried 2 x versions, i.e. 3.2.2 and 3.3.0. I use the Swift package Manager to bring down updates of your framework and all works well albeit both these versions exhibit the same issue.

I have one Line Chart view with multiple currency (pairs) DataSets and mathematically derived datasSets i.e. moving averages and standard deviations. I have disabled the "legend" on the view as I have a seperate view of buttons outside of the chart that controls the Line Chart dataSets "visible" property to clutter or declutter the chart view for the user (me) as required.

All works perfectly.

However...

I have a left Y axis range from 0.0 to 1.0 for currency exchange rates of this range.

I have a right Y axis range from 0.0 to 100.0 for currency exchange rates of this range.

As it works out I have just one currency (pair) on the right Y axis.

I click on a button in my legend view and all works well: each dataSet loses or gains visibility in the chart although still resident as a DataSet within the view.

The error:

When all dataSets within the chart are set to being not visible, i.e. nothing is showing except the left Y axis, the right Y axis, and the X axis - the moment you switch on a right Y axis dataSet "visible" and call notifyDataSetChanged() to inform the chart view that its underlying data has changed - you get a number of exceptions as follows:

CGAffineTransformInvert: singular matrix.
CGAffineTransformInvert: singular matrix.
CGAffineTransformInvert: singular matrix.
CGAffineTransformInvert: singular matrix.
CGAffineTransformInvert: singular matrix.
CGAffineTransformInvert: singular matrix.

Charts environment: macOS Mojave 10.14.4
Charts version: 3.2.2 and also tried also 3.3.0
xCode version: 10.2.1
xCode Swift version: running 4.2

    /**
     * Change view dataSet visible
     */
    @IBAction func buttonStateChanged(sender: NSButton) {
        guard let data = lineChartView.data else {
            return
        }
        
        let visible: Bool = sender.state == .on
        
        let tag = sender.tag
        
        for dataSet in data.dataSets {
            if (dataSet as? NSObject).hashValue != tag {
                continue
            }
            
            dataSet.visible = visible
            
            let (count, leftYMin, leftYMax, rightYMin, rightYMax) = data.dataSets.getVisibleDataSetCount()
            
            if count != nil {
                lineChartView.leftAxis.axisMinimum = leftYMin.reduceByPercentage(1)
                lineChartView.leftAxis.axisMaximum = leftYMax.increaseByPercentage(1)
                lineChartView.rightAxis.axisMinimum = rightYMin.reduceByPercentage(1)
                lineChartView.rightAxis.axisMaximum = rightYMax.increaseByPercentage(1)
            } else {
                lineChartView.leftAxis.axisMinimum = ViewController.defaultLeftYMin // 0.0
                lineChartView.leftAxis.axisMaximum = ViewController.defaultLeftYMax // 1.0
                lineChartView.rightAxis.axisMinimum = ViewController.defaultRightYMin // 0.0
                lineChartView.rightAxis.axisMaximum = ViewController.defaultRightYMax // 100.0
            }
            
            lineChartView.resetZoom()
            lineChartView.fitScreen()
            
            lineChartView.notifyDataSetChanged()
            
            break
        }
    }
@marthadog
Copy link
Author

Fixed: reviewed all threads within the application and looked through the Charts source code. And seperated further data work from UI work. All done. Apologise for raising the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant