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

Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Conversation

@ZacBrownBand
Copy link
Contributor

@ZacBrownBand ZacBrownBand commented Oct 19, 2016

The remove event that is triggered in DataView and DataSet only includes the ids of the items that were removed, and since the items are no longer available, it is hard to tell what items were removed.

This pr would add an oldItems property to the object that is sent with the remove event. This is supplementary to the items containing the ids to maintain reverse compatibility.

This effects

  • Items getting removed from DataSets
  • Items getting removed from DataViews
  • Clearing a DataSet using ds.clear()
  • Setting the data for a DataView using dv.setData() or when the DataView is created

Also updates the documentation for dataset Callback section.

@mojoaxel
Copy link
Member

@ZacBrownBand Thanks! Looks complete. Could you maybe provide a simple example that demonstrates how to use this!? That would be great.

@ZacBrownBand
Copy link
Contributor Author

A simple example would be if you wanted to know how long something was in a dataset for. The item in the dataset could have a created property marking the time is was added to the dataset. When handling the remove event you would have access to that data, not just the id. While handling the remove, you could just do a simple time subtraction,

To accomplish this now, you would have to maintain a hashmap of the ids and times items were added, so when you get the remove event with the id you can look up the time.

This was inspired by an application I am working that uses vis for data management. We have an issue were we have internal and external ids since we manage data from multiple sources, this leads to use needing more than just the id in special cases. By having the full object that was removed it is much easier to do entity resolution and ensure other things are updated accordingly.

@mojoaxel
Copy link
Member

@ZacBrownBand I see. I guess you need a kind of special case to use this. But why not! Thanks!
Did you test your code? I don't want to write a test for that...

@ZacBrownBand
Copy link
Contributor Author

I wrote unit tests in my application, I'm happy to add one in here!

@mojoaxel
Copy link
Member

I wrote unit tests in my application, I'm happy to add one in here!

We don't have any unit tests. But if you want to start feel free to provide a pull request ;-)

Copy link
Member

@mojoaxel mojoaxel left a comment

Choose a reason for hiding this comment

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

Thanks!

@mojoaxel mojoaxel merged commit 776f4cc into visjs:develop Oct 20, 2016
@mojoaxel
Copy link
Member

mojoaxel commented Nov 5, 2016

Sadly this introduced an error in DataView.refresh in line 120. I'll fix it.
@ZacBrownBand That happens! Next time please run npm test before committing.

mojoaxel added a commit that referenced this pull request Nov 5, 2016
yotamberk added a commit that referenced this pull request Nov 5, 2016
fixes DataView.refresh bug introduced with #2189
@ZacBrownBand
Copy link
Contributor Author

@mojoaxel Sorry about that, thanks for catching it. I didn't realize there was npm test, I know for next time.

item = this._remove(ids[i]);
if (item) {
itemId = item[this._fieldId];
if (itemId) {

Choose a reason for hiding this comment

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

This brings in some old bugs. Like I want to remove {id: 0, from: 4, to: 5} from DataSet edges.

Copy link
Member

Choose a reason for hiding this comment

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

@P1erce Can you please create an issue so we don't forget this! If you want you also could provide a simple fix :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants