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

Highlight sync #2285

Open
moon47usaco opened this issue Mar 27, 2017 · 14 comments
Open

Highlight sync #2285

moon47usaco opened this issue Mar 27, 2017 · 14 comments

Comments

@moon47usaco
Copy link

moon47usaco commented Mar 27, 2017

Please refer to old issue #1424

I am getting the -1 dataIndex problem again with 3.0.1

This is the print out from clicking in the combined chart (upper chart):

Highlight, x: 2019.0, y: 2371.375, dataIndex (combined charts): 1, dataSetIndex: 0, stackIndex (only stacked barentry): -1

This is the print from highlight when clicking in the (lower) line chart:

Highlight, x: 1977.0, y: 39.6849736241028, dataIndex (combined charts): -1, dataSetIndex: 0, stackIndex (only stacked barentry): -1

dataIndex for the line chart is -1... =[

Clicking in the line chart then throws a "fatal error: Index out of range"

code is now:

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {

        if chartView == combinedChartView {
            print(highlight)
            lineChartView.highlightValue(highlight)
            
        } else {
            print(highlight)
            combinedChartView.highlightValue(highlight)
        }
    }
@liuxuan30
Copy link
Member

basically v3 has redesigned x axis, so you have to figure out a way to sync the correct dataSet index calculation. Sorry it's kind of beyond the current scope of this library and I can't tell you what's wrong. But I do know you could sit down and spend sometime to understand what's changed and use the new calculation.

@moon47usaco
Copy link
Author

moon47usaco commented Mar 28, 2017

If you see my post from Sep 15, 2016 you can see that this was working with version 3 before the official release of 3.0.1

Why does it work from the combined to the lower line but not from the line to the upper combined?

Again this was not an issue in the pre-released V3.

I think > dataIndex (combined charts): -1< is a bug as it did not behave this way in September before the official release.

@liuxuan30
Copy link
Member

Are you able to track down what causes it to be -1? A lot of things can change and for your case, we don't know where it goes off.

@liuxuan30 liuxuan30 reopened this Mar 28, 2017
@moon47usaco
Copy link
Author

Here is the console output below.

I am unsure as to why it is -1.

It is stopped at line 278 of CombinedChartData.swift

let data = dataObjects[highlight.dataIndex]

This seems similar to issue #2076

Same line of code, same error just arrived at differently in the approach.

Console output:

fatal error: Index out of range
2017-03-28 16:23:38.811145 Fib_Test-06[17665:652431] fatal error: Index out of range
Current stack trace:
0 libswiftCore.dylib 0x0000000100a41ce0 swift_reportError + 132
1 libswiftCore.dylib 0x0000000100a5f090 _swift_stdlib_reportFatalError + 61
2 libswiftCore.dylib 0x00000001008550c0 specialized specialized StaticString.withUTF8Buffer ((UnsafeBufferPointer) -> A) -> A + 355
3 libswiftCore.dylib 0x00000001009d1230 partial apply for (_fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never).(closure #2) + 109
4 libswiftCore.dylib 0x00000001008550c0 specialized specialized StaticString.withUTF8Buffer ((UnsafeBufferPointer) -> A) -> A + 355
5 libswiftCore.dylib 0x00000001009893f0 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never + 96
6 libswiftCore.dylib 0x000000010083ce00 _ArrayBuffer._checkInoutAndNativeTypeCheckedBounds(Int, wasNativeTypeChecked : Bool) -> () + 300
7 libswiftCore.dylib 0x000000010084daa0 Array.subscript.getter + 103
8 Charts 0x0000000100370c50 CombinedChartData.entryForHighlight(Highlight) -> ChartDataEntry? + 215
9 Charts 0x0000000100364740 ChartViewBase.highlightValue(Highlight?, callDelegate : Bool) -> () + 651
10 Charts 0x0000000100364690 ChartViewBase.highlightValue(Highlight?) -> () + 73
11 Fib_Test-06 0x000000010001b130 ViewController.chartValueSelected(ChartViewBase, entry : ChartDataEntry, highlight : Highlight) -> () + 5609
12 Fib_Test-06 0x000000010001c880 @objc ViewController.chartValueSelected(ChartViewBase, entry : ChartDataEntry, highlight : Highlight) -> () + 100
13 Charts 0x0000000100365400 partial apply + 64
14 Charts 0x00000001003654b0 thunk + 34
15 Charts 0x00000001003655a0 thunk + 51
16 Charts 0x0000000100365620 partial apply for thunk + 81
17 Charts 0x0000000100364740 ChartViewBase.highlightValue(Highlight?, callDelegate : Bool) -> () + 3049
18 Charts 0x0000000100302be0 BarLineChartViewBase.tapGestureRecognized(NSClickGestureRecognizer) -> () + 1735
19 Charts 0x0000000100303360 @objc BarLineChartViewBase.tapGestureRecognized(NSClickGestureRecognizer) -> () + 58
20 libsystem_trace.dylib 0x00007fffdc102c00 _os_activity_initiate + 61
21 AppKit 0x00007fffc4b8aad4 -[NSApplication(NSResponder) sendAction:to:from:] + 456
22 AppKit 0x00007fffc4e61a35 _NSGestureRecognizerSendActions + 194
23 AppKit 0x00007fffc4e61006 -[NSGestureRecognizer _updateGestureWithEvent:] + 1466
24 AppKit 0x00007fffc4e61d32 -[NSGestureRecognizer _delayedUpdateGesture] + 60
25 AppKit 0x00007fffc4e6459b ___NSGestureRecognizerUpdate_block_invoke + 51
26 AppKit 0x00007fffc4e643fe _NSGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 300
27 AppKit 0x00007fffc4e5dd35 _NSGestureRecognizerUpdate + 1518
28 AppKit 0x00007fffc4d03961 -[NSWindow(NSGestureRecognizer_Routing) _sendEventToGestureRecognizers:requireAcceptsFirstMouse:] + 3299
29 AppKit 0x00007fffc4cfe0a1 -[NSWindow(NSEventRouting) sendEvent:] + 512
30 AppKit 0x00007fffc4b8677c -[NSApplication(NSEvent) sendEvent:] + 1145
31 AppKit 0x00007fffc4402b97 -[NSApplication run] + 1002
32 AppKit 0x00007fffc43cd37b NSApplicationMain + 1237
33 Fib_Test-06 0x0000000100025600 main + 84
34 libdyld.dylib 0x00007fffdbed0254 start + 1
(lldb)

@moon47usaco
Copy link
Author

FYI this is the version that was working:

Version 3.0, synced to MPAndroidChart #1b9b3da

I am going to try and clone this project and change the charts library to this one as I still have it on hard drive. I will let you know the results when finished copying and testing the project with the old charts version.

@liuxuan30
Copy link
Member

could you check the calculation code? The combinedData is just an array of sub data like bar data, line data, so it will do a mapping.

On the other side, were you able to reproduce it with ChartsDemo, so we can take a look?

@moon47usaco
Copy link
Author

Not sure what you are referring to specifically for the calculation code. The combined is a collection of candlesticks and line charts.

I will try to simplify and replicate with the demo code and do some digging around to see what I can come up with.

Hopefully over the weekend.

@liuxuan30
Copy link
Member

@moon47usaco what I mean is, let data = dataObjects[highlight.dataIndex] has oob crash, and this is fetching sub chartData from combinedData.

First, we must know why highlight.dataIndex is -1.

highlgiht.dataIndex is -1 by default, however, to get the real dataIndex, it should be updated, for example, in getHighlights() of CombinedHighlighter

You can add some breakpoints or just search "dataIndex =" in the library to see where it gets updated, and if dataIndex is not set at all, or it mistakenly is set to -1 due to some errors.

I did a quick check, but can't find any clues yet.

@moon47usaco
Copy link
Author

moon47usaco commented Mar 30, 2017 via email

@moon47usaco
Copy link
Author

moon47usaco commented Mar 30, 2017

FYI - I was able to dig up the old V3 that was working before. With the same code and data set these are the values I get from printing the highlight.

Clicking in the combined chart gives:

Highlight, x: 1403.0, y: 2343.75, dataIndex (combined charts): 1, dataSetIndex: 0, stackIndex (only stacked barentry): -1

While clicking in the lower line chart (the one that throws the index out of range in 3.0.1) gives:

Highlight, x: 1445.0, y: 45.9635099725202, dataIndex (combined charts): -1, dataSetIndex: 0, stackIndex (only stacked barentry): -1

These are the same values but the old V3 is not throwing an error while V3.0.1 is.

Again this is the "Charts-Swift3.0-ChartV3" from when 2.2.5 was the current release.

Version 3.0, synced to MPAndroidChart #1b9b3da

@liuxuan30
Copy link
Member

Wait, are you saying your "lower line chart" is not in the combined chart? I looked at your old posts, it looks like there are one upper combined chart and one lower line chart.

If so, dataIndex is supposed to be used only in combined chart, other types will not use it and keep a '-1' default value, and if you apply this dataIndex from a line chart to a combined chart, that will cause issue for sure.

You need to figure out a mapping that can map your lower line chart into your combined chart by using the highlight class

@moon47usaco
Copy link
Author

moon47usaco commented Apr 1, 2017

I am not specifically using the dataIndex I just remembered it was an issue with 2.2.5 so I though it might be causing the out of bounds error here in 3.0.1.

After recompiling the version 3 that did work i realized that the values reported by the highlight were most likely correct.

I am using this code below to sync the highlight and it was working in V3 pre release but is broken in version 3.0.1. Yes lower is line and upper is combined.

       func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {

        if chartView == combinedChartView {
            print(highlight)
            lineChartView.highlightValue(highlight)
            
        } else {
            print(highlight)
            combinedChartView.highlightValue(highlight)
        }
    }

I am now not sure what is causing the out of bounds but I will try to reproduce the error with the demo on 3.0.1 soon.

@moon47usaco
Copy link
Author

moon47usaco commented Apr 2, 2017

I was able to reproduce the error with Charts Demo.

Below link is a repo with three examples:
• ChartsDemo-OSX-HL-02 - This is a highlight sync between a separate line and bar chart. It works as expected between both charts.
• ChartsDemo-OSX-HL-03 - This is a highlight sync between a candlestick/line combined chart and a separate line chart. It is broken when trying to sync the line chart to the combined chart.
• ChartsDemo-OSX-HL-04 - This is the same thing but with a line/bar combined just incase it was the candlestick data that was causing an issue. It is broken at the same point that syncing other charts to a combined chart is the issue.

I did not have time to set breakpoints and trace/debug the issue yet but I can try next weekend if I have time.

https://github.com/moon47usaco/Charts-3.0.1-Highlight-Sync-Issues

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 5, 2017

If you are not using dataIndex specifically, but when you pass a line chart highlight object into combined chart, it will call let data = dataObjects[highlight.dataIndex] even you don't need it in CombinedChartData.entryForHighlight()

One quick workround is set it to -1 and try, if you do not rely on dataIndex

I checked

    open override func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry?
    {
        let dataObjects = allData
        
        if highlight.dataIndex >= dataObjects.count
        {
            return nil
        }
        
        let data = dataObjects[highlight.dataIndex]

this code snippet was added on May 3, 2016 in commit 0e7c26b, when Chart 3.0 is not released, so it's old code. It's weird that you said an early V3 chart does not crash...

I need to check more things when I am free.

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

2 participants