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

addPolygons() now responds to crosstalk events #391

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@cpsievert
Copy link
Contributor

cpsievert commented Feb 27, 2017

For example,

library(plotly)
library(leaflet)
library(sf)

nc <- system.file("shape/nc.shp", package = "sf") %>%
  st_read() %>% 
  st_transform(4326) %>%
  highlight_key()

map <- leaflet(nc) %>%
  addTiles() %>%
  addPolygons(
    opacity = 1,
    color = 'white',
    weight = .25,
    fillOpacity = .5,
    fillColor = 'blue',
    smoothFactor = 0
  )

p <- plot_ly(nc) %>% 
  add_markers(x = ~BIR74, y = ~SID79) %>%
  layout(dragmode = "lasso") %>%
  highlight("plotly_selected")

crosstalk::bscols(map, p)

leaf

TODO:

  • Should 2D brush events on polygons emit a crosstalk event? I'm leaning towards yes, but I'm not immediately sure how to implement. If not, the brush select icon/mode should be removed to avoid confusion.
  • Implement the same for addPolylines() etc?
  • Tests?

Any feedback/input is greatly appreciated :)

@bhaskarvk

This comment has been minimized.

Copy link
Collaborator

bhaskarvk commented Feb 28, 2017

Nice! So in theory this should work for all shapes like rectangles, circles, circleMarkers, polylines, right ? provided code for each of these shapes is changed accordingly.

@jcheng5

This comment has been minimized.

Copy link
Member

jcheng5 commented Feb 28, 2017

I was originally thinking polygon brushing would be really hard to implement, because it'd either have to work by 1) any intersection between the brushing rectangle and the polygon, or 2) complete coverage of the polygon by the brushing rectangle.

But a nice easier-to-implement alternative would be 3) the brushing rectangle includes the center-of-mass of the polygon (is that the right term for it?). I believe there are fast routines to do this in R?

@jcheng5

This comment has been minimized.

Copy link
Member

jcheng5 commented Feb 28, 2017

I mean, obviously the correct term is "centroid" not center-of-mass, and obviously it's just the arithmetic mean of all of the points in the polygon. :)

@cpsievert

This comment has been minimized.

Copy link
Contributor Author

cpsievert commented Feb 28, 2017

Yea, that sounds reasonable, and maybe we could leverage sf::st_centroid()?

@bhaskarvk

This comment has been minimized.

Copy link
Collaborator

bhaskarvk commented Feb 28, 2017

For irregular polygons centroids can fall out of the polygon/s.
You may also want to evaluate https://www.mapbox.com/blog/polygon-center/. It is a JS solution, so in theory it should be easy to integrate.

@jcheng5

This comment has been minimized.

Copy link
Member

jcheng5 commented Feb 28, 2017

The mapbox solution is really interesting. I can see how it would be much better than centroid for labeling but I'd want to try out both for brushing to see how they feel.

@bhaskarvk

This comment has been minimized.

Copy link
Collaborator

bhaskarvk commented Feb 28, 2017

Yup agreed.

@mdsumner

This comment has been minimized.

Copy link

mdsumner commented Mar 13, 2017

We can decompose to triangles for finer elements, as illustrated in my sfdct package. License is a problem but in time we might get CGAL or another alternative.

@mdsumner

This comment has been minimized.

Copy link

mdsumner commented Mar 13, 2017

Also fwiw this is what I was going after here: https://twitter.com/mdsumner/status/830380049815597056

@schloerke schloerke referenced this pull request Feb 12, 2018

Merged

v2.0.0 #492

23 of 29 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.