Fix data selection following zooming with mouse - #48
Open
mosherubin wants to merge 1 commit into
Open
Conversation
##The Problem## Data selection works fine when the chart is unzoomed, with an app's ```selectionChanged()``` callback being invoked following data point selection. When the chart is zoomed, however, the ```selectionChanged()``` callback is not invoked. Playing with zooming shows that data selection always fails following zooming using the mouse (i.e., mouse button down + drag). When zooming using the mouse wheel, data selection works for the first few zoom-in mouse wheel works. Once the chart has been enlarged a few times, selection fails. ##Reproducing the Problem## The problem can be reproduced easily with a [minimally modified ```SelectionDemo1.java``` file](https://drive.google.com/open?id=0B09i2ZH5SsTHMmoxa3ZuMWd4WVU). ##The Technical Explanation## Examining the FSE code shows that the reason for ```SelectionChanged()``` not being called following zooming is because the hash value of the ```DatasetSelectionExtension<XYCursor>``` object registered in function ```createDemoPanel()``` is modified because of zooming. This causes the statement "registeredExtensions.get(dataset)" in ```DatasetExtensionManager.getExtension()``` to return null: ```java public <T extends DatasetExtension> T getExtension(Dataset dataset, Class<T> interfaceClass) { if (interfaceClass.isAssignableFrom(dataset.getClass())) { //the dataset supports the interface return interfaceClass.cast(dataset); } else { List<DatasetExtension> extensionList = registeredExtensions.get(dataset); if (extensionList != null) { for (DatasetExtension extension : extensionList) { if (interfaceClass.isAssignableFrom(extension.getClass())) { //the dataset does not support the extension but //a matching helper object is registered for the dataset return interfaceClass.cast(extension); } } } } return null; } ``` Drilling down further shows that the ```Calendar``` member variable ```workingCalendar``` has some of its member variables changed due to zooming. The hash returned by the ```Calendar``` class takes these into account, causing the ```HashMap get()``` to fail and return null, preventing ```selectionChanged()``` from being invoked. For an explanation complete with screen captures, [see the following PDF file](https://drive.google.com/open?id=0B09i2ZH5SsTHZ3dpTmViWW5hRm8). ##The Proposed Fix## I believe ```workCalendar``` is unsafe to include in the hash of a ```TimesSeriesCollection``` object and should be removed. I would like to propose removing it from ```TimeSeriesCollection.hashCode()```. When I made the fix locally and rebuilt FSE, data selection works perfectly on both zoomed and non-zoomed charts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
Data selection works fine when the chart is unzoomed, with an app's
selectionChanged()callback being invoked following data point selection. When the chart is zoomed, however, theselectionChanged()callback is not invoked.Playing with zooming shows that data selection always fails following zooming using the mouse (i.e., mouse button down + drag). When zooming using the mouse wheel, data selection works for the first few zoom-in mouse wheel works. Once the chart has been enlarged a few times, selection fails.
Reproducing the Problem
The problem can be reproduced easily with a minimally modified SelectionDemo1.java file.
The Technical Explanation
Examining the FSE code shows that the reason for
SelectionChanged()not being called following zooming is because the hash value of theDatasetSelectionExtension<XYCursor>object registered in functioncreateDemoPanel()is modified because of zooming. This causes the statement "registeredExtensions.get(dataset)" inDatasetExtensionManager.getExtension()to return null:Drilling down further shows that the
Calendarmember variableworkingCalendarhas some of its member variables changed due to zooming.The hash returned by the
Calendarclass takes these into account, causing theHashMap get()to fail and return null, preventingselectionChanged()from being invoked.For an explanation complete with screen captures, see the following PDF file.
The Proposed Fix
I believe
workCalendaris unsafe to include in the hash of aTimesSeriesCollectionobject and should be removed. I would like to propose removing it fromTimeSeriesCollection.hashCode(). When I made the fix locally and rebuilt FSE, data selection works perfectly on both zoomed and non-zoomed charts.