mapdeck icon indicating copy to clipboard operation
mapdeck copied to clipboard

binary path layer

Open dcooley opened this issue 5 years ago • 2 comments

working fiddle

TODO

  • [x] stroke_width needs replicating for each waypoint (when stroke_width = 10, for example, not a column of data)
  • [x] check my path.cpp is creating the correct start_indices
  • [x] implement list columns form here )
  • [ ] stroke colours are the number of edges, not vertices, so only n - 1 colours are used. Can this be handled?
  • [x] support dashed lines (there's an issue with my size value)
  • [x] tooltip
  • [x] brushing
  • [ ] encoded polylines
  • [x] all data needs to be 'unlisted' (especially colour arrays)
  • [x] tooltip data isn't / shouldn't be repeated for each coordinate pair, it should only exist for each geometry
  • [x] needs to work on a vector of hex strings
  • [x] don't expand columns if they've been passed in as a list
  • [x] example of different dashes for different lines
  • [ ] rewrite all tests
  • [x] apply to trips layer
    • [x] must use getTimestamps() prop, because if we only use getPath() it, only allows 3 coordinates (lon, lat, time), so elevation is ignored in this instance.

  • [x] alpha in colour should be [0,1]
  • [x] test & remove the sf_cast(, "LINESTRING"), because now interleave works on any geometry

List columns

the call to sfheaders::api::sf_to_df( data, sfc, sfc_column, sfc_coordinates, true ) will need to supply the list columns. Which can be worked out by seeing if any of the fill / stroke / etc. properties reference a list-column (in R)


  • [x] non-list columns need to be expanded / repeated. For example, this currently doens't work.
df <- data.frame(
	x = 1:10
	, y = 10:1
	, z = letters[1:10]
	, a = rnorm(10)
	, id = c(1,1,1,1,1,2,2,2,2,2)
)

sf <- sfheaders::sf_linestring(
  x = "x"
  , y = "y"
  , obj = df
  , list_columns = c("z","a")
  , keep = T
  , linestring_id = "id"
)

mapdeck() %>%
  add_path(
    data = sf
    , stroke_width = "id"
  )

dcooley avatar Mar 20 '20 10:03 dcooley

A couple of benchmarks showing listing and colouring

n <- 1e6
df <- data.frame(
	id = rep(1:(n/10), each = 10)
	, x = rnorm( n )
	, y = rnorm( n )
	, z = rnorm( n )
	, val = rnorm( n )
)

sf <- sfheaders::sf_linestring(
	obj = df
	, x = "x"
	, y = "y"
	, linestring_id = "id"
	, keep = TRUE 
)

sf2 <- sf

microbenchmark(
	one = {
                ## colouring a list, then unnesting
		sf2$col <- colourvalues::colour_values( sf$val )
		df2 <- sfheaders::sf_to_df( sf = sf2, fill = TRUE, unlist = "col")
	},
	two = {
                ## unnesting, then colouring
		df3 <- sfheaders::sf_to_df( sf = sf, fill = TRUE, unlist = "val" )
		df3$val <- colourvalues::colour_values( df3$val )
	},
	times = 25
)

# Unit: milliseconds
# expr       min        lq     mean   median       uq      max neval
#  one 1107.2474 1185.0316 1538.977 1244.534 1500.936 4105.763    25
#  two  900.0465  937.2211 1115.096 1000.710 1217.072 1632.342    25

dcooley avatar Apr 02 '20 09:04 dcooley

microbenchmark(
	one = {
                ## colouring a vector, then "unnesting" the vector
		sf2$col <- colourvalues::colour_values( sf$z )
		df2 <- sfheaders::sf_to_df( sf = sf2, fill = TRUE, unlist = "col")
	},
	two = {
                ## "unnesting" the vector, then colouring
		df3 <- sfheaders::sf_to_df( sf = sf, fill = TRUE, unlist = "z" )
		df3$val <- colourvalues::colour_values( df3$z )
	},
	times = 25
)

# Unit: milliseconds
# expr      min       lq     mean   median        uq      max neval
#  one 574.2571 603.5079  725.375 619.6853  783.5886 1286.826    25
#  two 855.9342 903.8275 1018.179 934.8218 1047.9458 1600.117    25

dcooley avatar Apr 02 '20 09:04 dcooley