skokenes / D3-Lasso-Plugin

A lasso selection tool for D3
BSD 3-Clause "New" or "Revised" License
79 stars 25 forks source link

Lasso for maps #2

Closed whatwehaveunlearned closed 9 years ago

whatwehaveunlearned commented 9 years ago

Hi again. I am trying to use your plugin now to select elements inside a map graph. I have assumed from the beginning that the type of graph was not important for the lasso to work. Just by specifying the lassoItems correctly I expected it to work.

So it seems that the lasso gets initialized correctly the lasso items are correctly specified. I am able to see the elements when I check lasso.items(), but the selection is not working properly. When doing a lasso the elements inside it don't get selected. I need to draw the lasso on top of an specific element in order to make it selected. The code still works perfectly when used in scatterplots. Do the lasso.items need to be on the top layer of the svg or that does not matter? Can you think or do you know why this is not working?

I can send you a small code so that you can test this issue if you are willing to. Please let me know.

Thank you for your help again! :)

skokenes commented 9 years ago

Hey, if you can post some sample code that would be great. You are right - there should be no issue with the type of graph that the lasso is used with; it is designed to work with any d3 element.

whatwehaveunlearned commented 9 years ago

I will try to extract a simple code to show this issue today with this to show it to you.

Thank you :)

whatwehaveunlearned commented 9 years ago

Sorry for the delay. I made a simple setup that plots a map of the Hawaiian islands and implements a lasso. The selected array in the lasso function is always empty.

One file is the map in topojson format and the other is the main html. Let me know.

I sent you the code in an email I can not attach it here because somehow it does not show up completely. Thank you so much for your time!

whatwehaveunlearned commented 9 years ago

This is the code for test.html (link to your lasso library I have a local link)

<!DOCTYPE html>

########################################################################################################## code for topojson object: {"type":"Topology","objects":{"filterMap":{"type":"GeometryCollection","geometries":[{"type":"MultiPolygon","properties":{"name":"Hawaii"},"id":"USH","arcs":[[[0]],[[1]],[[2]],[[3]],[[4]],[[5]],[[6]],[[7]],[[8]],[[9]],[[10]],[[11]],[[12]],[[13]]]}]},"hawaiiPlaces":{"type":"GeometryCollection","geometries":[{"type":"Point","properties":{"name":"Lihue"},"coordinates":[8059,3238]},{"type":"Point","properties":{"name":"Wahiawa"},"coordinates":[8633,2735]},{"type":"Point","properties":{"name":"Wailuku"},"coordinates":[9279,2091]},{"type":"Point","properties":{"name":"Kailua-Kona"},"coordinates":[9501,786]},{"type":"Point","properties":{"name":"Hilo"},"coordinates":[9882,836]},{"type":"Point","properties":{"name":"Honolulu"},"coordinates":[8702,2530]}]}},"arcs":[[[9662,1297],[8,-16],[10,6],[15,-2],[16,-14],[30,-24],[37,-46],[50,-75],[20,-30],[23,-53],[12,-38],[0,-42],[-1,-55],[2,-43],[11,1],[17,18],[12,-20],[6,-22],[-2,-45],[6,-28],[7,-26],[22,-47],[22,-23],[9,-19],[5,-22],[-1,-28],[-6,-16],[-19,-54],[-19,-17],[-27,-61],[-18,-12],[0,-12],[-16,-9],[-13,-23],[-25,-18],[-22,-14],[-17,10],[-11,1],[-9,-7],[-10,-14],[-13,-22],[-8,-23],[-9,-3],[-6,-7],[-10,-14],[-6,-11],[-22,-29],[-6,-5],[-19,-42],[-3,-17],[1,-38],[-8,-20],[-13,-31],[-7,-44],[-7,-16],[-7,-15],[-10,-21],[-4,5],[0,23],[-9,17],[-17,22],[-20,29],[-11,17],[-18,11],[-8,5],[-2,20],[-3,19],[-6,4],[-3,28],[-4,45],[5,53],[10,153],[-1,26],[-6,25],[-5,33],[-7,50],[-3,21],[-4,13],[-4,21],[1,23],[-5,22],[-3,24],[-4,30],[-8,26],[-6,11],[-9,26],[-10,67],[4,30],[5,25],[9,18],[9,14],[4,11],[2,20],[6,11],[18,16],[8,35],[5,12],[9,40],[10,25],[6,0],[3,33],[2,14],[-3,20],[-7,16],[-15,53],[-6,47],[-1,37],[0,34],[8,37],[6,12],[15,0],[28,-15],[12,-5],[2,-6],[1,-8],[1,-10],[7,-27],[16,-15],[11,-14],[7,-21],[11,-11]],[[9267,1712],[-5,-20],[-12,0],[-11,5],[-8,-4],[-12,-6],[-14,-4],[-9,22],[5,16],[9,18],[12,19],[13,16],[11,10],[9,-2],[11,-29],[-6,-31],[7,-10]],[[9105,1926],[-20,-3],[-9,29],[-2,24],[-1,20],[0,25],[-1,22],[-7,10],[-18,16],[-5,20],[3,23],[10,12],[18,5],[41,-15],[19,-39],[7,-17],[7,-20],[4,-17],[1,-13],[-2,-18],[-10,-34],[-19,-20],[-16,-10]],[[9243,2234],[4,-10],[4,-2],[7,-8],[5,-6],[2,-13],[5,-3],[2,-14],[0,-13],[5,-12],[4,-14],[3,-16],[5,-19],[8,2],[4,12],[9,0],[6,3],[12,1],[5,3],[14,23],[6,6],[7,1],[7,0],[7,-2],[6,-6],[2,-1],[1,0],[1,-3],[1,-4],[6,4],[7,-10],[2,-12],[3,-6],[3,-8],[4,-13],[8,-12],[5,-12],[1,-10],[5,-1],[2,0],[2,6],[5,-10],[3,-14],[2,-9],[15,-5],[14,-16],[21,-16],[10,-46],[-2,-41],[-8,-34],[-11,-7],[-8,-30],[-12,0],[-23,-28],[-15,1],[-9,2],[-8,-1],[-21,-23],[-13,-16],[-8,-8],[-10,6],[-4,1],[-7,5],[-5,-4],[-18,-2],[-12,26],[-1,11],[-6,14],[4,8],[0,18],[-4,70],[-3,19],[0,21],[-2,18],[-2,3],[-3,7],[-5,6],[-6,-1],[-6,-6],[-3,-15],[-5,-2],[-6,8],[-6,11],[-10,4],[-9,13],[-6,-1],[-5,17],[-10,25],[-12,37],[-1,23],[-4,12],[2,22],[2,29],[4,25],[5,17],[5,1],[3,9],[1,8],[4,6],[3,-1],[5,-1],[4,3],[1,5],[3,0],[3,-5]],[[8963,2438],[6,-2],[10,1],[6,-4],[3,-12],[7,0],[40,-14],[22,-8],[16,-2],[3,12],[1,10],[2,8],[4,3],[6,-18],[2,-20],[9,-7],[12,-6],[22,1],[9,3],[6,5],[5,4],[3,-2],[8,2],[6,-5],[4,-2],[5,2],[2,-4],[-1,-5],[3,-4],[7,1],[3,-5],[-8,-35],[-13,-30],[-17,-20],[-16,-16],[-16,-8],[-17,4],[-16,8],[-33,20],[-20,17],[-29,-6],[-20,-2],[-15,-6],[-12,2],[-10,-1],[-8,8],[-5,15],[0,20],[3,16],[5,13],[8,7],[7,19],[2,20],[-6,16],[0,8],[5,-1]],[[8688,2835],[3,-18],[4,-6],[2,-7],[1,-12],[3,2],[4,-3],[3,-9],[4,-15],[1,-16],[0,-8],[-4,0],[-2,-6],[1,-18],[1,-11],[1,-18],[4,-3],[5,-5],[4,-12],[4,-13],[6,-5],[1,-8],[4,-4],[3,8],[4,13],[-6,10],[0,12],[5,5],[10,-3],[6,3],[1,-8],[-6,-14],[-2,-19],[1,-15],[7,-10],[6,-13],[1,-9],[-2,-12],[2,-12],[4,-17],[9,-14],[9,-11],[3,-6],[-5,-14],[-11,-22],[-4,-10],[-4,-4],[-2,7],[1,9],[-4,8],[-11,-7],[-10,-3],[-7,-8],[-6,-11],[-7,0],[-3,3],[-2,9],[-3,12],[-14,14],[-7,8],[-5,15],[-1,10],[0,10],[-3,-3],[-6,-13],[4,-11],[-18,-3],[1,5],[2,3],[-3,7],[-7,-1],[0,11],[-1,8],[1,7],[-2,7],[5,5],[4,5],[5,6],[2,9],[-5,10],[-5,4],[-3,4],[-1,-4],[-2,-13],[-4,4],[-3,9],[-2,7],[0,-14],[2,-17],[-2,-3],[-9,18],[-4,8],[3,-18],[7,-17],[5,-10],[4,-8],[-2,-16],[-8,-7],[-10,-4],[-15,-8],[-8,-2],[-7,-5],[-2,2],[-2,4],[-5,6],[-4,36],[-4,28],[-6,16],[-4,14],[-8,10],[-2,28],[-3,15],[-7,15],[-5,7],[-5,19],[0,21],[-1,31],[-3,9],[-18,36],[3,3],[15,7],[18,2],[12,-1],[7,0],[6,3],[6,-3],[2,13],[2,6],[8,10],[8,16],[4,7],[-1,6],[3,12],[4,20],[7,13],[9,19],[13,8],[6,0],[3,-5],[2,-6],[3,-9],[7,-13],[0,-12],[4,-4],[0,-9],[4,-9],[-2,-19],[5,-18],[6,-13]],[[7707,3030],[-5,-4],[-6,10],[-5,4],[-5,37],[1,24],[5,25],[16,39],[14,24],[17,23],[3,14],[2,13],[-1,19],[8,8],[7,-1],[8,-6],[4,-19],[-4,-9],[-5,-16],[-3,-22],[3,-29],[-6,-18],[-7,-8],[-6,-8],[-9,-6],[-9,-14],[-6,-11],[-3,-16],[-5,-31],[-3,-22]],[[8052,3499],[6,-7],[7,0],[8,-10],[3,-16],[6,-12],[2,-2],[2,-14],[2,-10],[1,-11],[4,-5],[0,-11],[-1,-30],[-4,-12],[-6,-40],[-7,-9],[0,-29],[1,-19],[0,-20],[0,-20],[-1,-8],[-6,0],[-5,-6],[4,-8],[1,-9],[-2,-7],[-5,1],[-8,-14],[-3,-13],[-3,-7],[-7,-11],[-1,-8],[-5,-1],[-2,-6],[-2,-5],[-19,15],[-12,3],[-8,0],[-16,7],[-7,2],[-3,7],[-2,-1],[-1,-7],[-3,-2],[-2,8],[-6,6],[-5,9],[-3,10],[-2,9],[-2,9],[-5,2],[-1,9],[-5,5],[-8,3],[-7,6],[-5,6],[-8,4],[-7,5],[-4,18],[-1,10],[-4,5],[-3,10],[0,15],[1,12],[0,13],[-1,9],[5,4],[11,30],[6,18],[1,11],[0,9],[0,7],[3,3],[1,3],[3,12],[10,6],[11,6],[12,17],[8,16],[10,11],[3,11],[6,5],[4,0],[3,7],[5,-2],[3,-6],[1,-7],[4,-1],[5,-4],[4,-6],[4,1],[-2,8],[2,7],[7,7],[8,-3],[10,1],[5,-8],[4,2],[5,7],[3,7],[5,-7]],[[6964,4353],[-2,-2],[1,4],[0,3],[1,2],[2,-1],[-1,-4],[0,-1],[-1,-1]],[[5789,4921],[2,-9],[-3,2],[-1,2],[1,2],[1,3]],[[4388,6422],[0,-4],[-3,15],[1,1],[2,-5],[0,-4],[0,-3]],[[2802,7231],[-3,-22],[-4,4],[-1,14],[8,4]],[[1850,7533],[-1,-5],[-2,4],[0,3],[0,5],[0,5],[1,-5],[1,-4],[1,-3]],[[3,9984],[-2,-1],[-1,2],[3,3],[1,4],[1,3],[1,4],[1,-9],[-2,-3],[-2,-3]]],"transform":{"scale":[0.002349265186218617,0.00094965110831083],"translate":[-178.30436616299988,18.906117143000117]}} Alberto González Martínez whatwehaveunlearned@gmail.com > On Mar 31, 2015, at 2:08 AM, Speros Kokenes notifications@github.com wrote: > > Hey, if you can post some sample code that would be great. You are right - there should be no issue with the type of graph that the lasso is used with; it is designed to work with any d3 element. > > — > Reply to this email directly or view it on GitHub https://github.com/skokenes/D3-Lasso-Plugin/issues/2#issuecomment-88062712.
whatwehaveunlearned commented 9 years ago

Hi how are you doing? Did you receive the email I sent you with the files? I don't know if it was the correct email address

skokenes commented 9 years ago

Hey Alberto, sorry for the delay. I have been making some updates of my own to the lasso to fix some bugs. I am going to upload this latest version today. Can you test your solution with the latest version when it is available, then let me know if your problem still exists?

Thanks

Speros

On Friday, April 17, 2015, Alberto Gonzalez notifications@github.com wrote:

Reopened #2 https://github.com/skokenes/D3-Lasso-Plugin/issues/2.

— Reply to this email directly or view it on GitHub https://github.com/skokenes/D3-Lasso-Plugin/issues/2#event-283818737.

skokenes commented 9 years ago

Hey Alberto,

This is an issue with your code and not the library, so I am going to close this item.

I did work with your code and produced a working version based on what you sent me: http://bl.ocks.org/skokenes/498a150f94cd21e2270f

The two issues that I fixed: 1) The pins were not being properly classed to ".pin". I am not sure I have seen d3's append() method take a second parameter. Regardless, I set the class attr to "pin" instead so that the dots would be properly classed for selection. 2) You are passing the selection of pins into the lasso item list before the pins are created. The pins are created via an asynchronous function that runs after you have loaded your data. Your lasso.items() declaration was outside of this asynchronous statement and was being executed before the data ever loaded, meaning that the pins did not exist yet. I moved the lasso.items() declaration inside the asynchronous function, after the pins have been created.

I also added some CSS for the lasso just so you could see that it's working.

Thanks

Speros

whatwehaveunlearned commented 9 years ago

Thank you!

I am sorry it was my mistake. I am looking at the code now and it seems I confused when copy pasting to send you the test file. In my code I pass the lasso items inside the asynchronous call as you did. I changed the class of the elements in my code as “.dot” instead of “.pin", but I assume it does not matter, if you send the correct objects to the lasso is it? It works for scatterplots where I have the same setup, with the elements declared as “.dot”.

In my complete setup I have multiple graphs so the elements for the lasso have 2 different classes, one to address all the elements in each graph and the other to address each of the individual elements inside a determined graph.

For example: “graphArea1 dot1” —> element 1 of graph 1

So I create the elements with a selectAll(“graphArea1”) and lasso.items(d3.selectAll(“.graphArea1"));

With the new version the selection does not work on the scatterplot unless I hover over the dots, but if you where able to do it, it has to be some typo in my code, I will continue debugging the issue and see if I find whats wrong.

thank you so much.

Alberto González Martínez whatwehaveunlearned@gmail.com

On Apr 23, 2015, at 7:26 AM, Speros Kokenes notifications@github.com wrote:

Closed #2 https://github.com/skokenes/D3-Lasso-Plugin/issues/2.

— Reply to this email directly or view it on GitHub https://github.com/skokenes/D3-Lasso-Plugin/issues/2#event-288539279.