jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
717 stars 147 forks source link

in Maps, the dashed borders have a scaling issue when zooming in and which only disappears if you hover your mouse over the lines. #818

Open mathiasleroy opened 1 month ago

mathiasleroy commented 1 month ago

image

another way to resolve the scaling after zoom is to resize the chart.

if (!require("remotes")) install.packages("remotes")
if (!require("highcharter")) remotes::install_github("jbkunst/highcharter")
library(highcharter)

### DATA

mapISR <- new("SpatialPolygonsDataFrame",
  data = structure(list(
    ISO3 = "ISR",
    ISO2 = "IL", cat = "EURO", name =
      "Israel"
  ), row.names = 37L, class = "data.frame"),
  polygons = list(new("Polygons",
    Polygons = list(new("Polygon",
      labpt = c(34.9687651840375, 31.3612675920041), area = 1.966682235,
      hole = FALSE, ringDir = 1L, coords = structure(c(
        35.115,
        35.2958, 35.3782, 35.5323, 35.563, 35.6244, 35.663, 35.6535,
        35.6468, 35.632, 35.6332, 35.629, 35.6243, 35.6231, 35.6431,
        35.6416, 35.6557, 35.6627, 35.6986, 35.68, 35.6639, 35.5644,
        35.5608, 35.4303, 35.4027, 35.2109, 35.0731, 35.0161,
        35.0302, 34.9641, 35.0018, 34.9863, 35.0393, 35.2252,
        35.2293, 35.0123, 34.8791, 34.9259, 35.2333, 35.3923,
        35.476, 35.4736, 35.4001, 35.456, 35.4019, 35.3348, 35.3404,
        35.2036, 35.1619, 35.188, 35.1458, 35.1575, 35.0754,
        35.0843, 35.013, 34.9782, 34.8829, 34.8803, 34.8286,
        34.6135, 34.5443, 34.5014, 34.4074, 34.265, 34.3671,
        34.373, 34.5657, 34.4909, 34.5787, 34.7044, 34.8226,
        34.8924, 34.9652, 35.0708, 35.115, 33.093, 33.1072, 33.055,
        33.1338, 33.2832, 33.2423, 33.1891, 33.124, 33.0627,
        33.0249, 32.9902, 32.9559, 32.9169, 32.8903, 32.8618,
        32.8343, 32.8085, 32.7771, 32.7121, 32.6976, 32.6803,
        32.6252, 32.4011, 32.4093, 32.5013, 32.5431, 32.4595,
        32.3379, 32.2641, 32.1986, 32.041, 31.9645, 31.8507,
        31.7781, 31.7719, 31.6615, 31.3977, 31.3443, 31.3763,
        31.4895, 31.4905, 31.411, 31.2429, 31.149, 30.9339, 30.8732,
        30.8157, 30.582, 30.4408, 30.3573, 30.2822, 30.1287,
        29.9504, 29.8857, 29.7112, 29.5418, 29.5291, 29.6419,
        29.8034, 30.3682, 30.4104, 30.6746, 30.8537, 31.2311,
        31.2907, 31.377, 31.5339, 31.5959, 31.7045, 31.935, 32.2364,
        32.4725, 32.8273, 32.8492, 33.093
      ), dim = c(75L, 2L))
    )),
    plotOrder = 1L, labpt = c(34.9687651840375, 31.3612675920041), ID = "37", area = 1.966682235
  )), plotOrder = 1L, bbox = structure(
    c(
      34.265,
      29.5291, 35.6986, 33.2832
    ),
    dim =
      c(2L, 2L), dimnames = list(
      c("x", "y"), c("min", "max")
    )
  ), proj4string = new("CRS",
    projargs = "+proj=longlat +datum=WGS84 +no_defs"
  )
)

borderPAL <- new("SpatialLinesDataFrame", data = structure(
  list(Name = c(
    "Gaza",
    "West Bank"
  )),
  row.names = 2:3,
  class = "data.frame"
), lines = list(
  new("Lines", Lines = list(new("Line", coords = structure(c(
    34.4909000000001,
    34.5075159043102, 34.5588874747385, 34.5657000000001, 34.5325842055843,
    34.4859392403048, 34.3804316639265, 34.373, 34.3726857005768,
    34.3697741482572, 34.3671, 34.3212008492267, 34.265, 31.5959,
    31.5821274589943, 31.5395467455378, 31.5339000000001, 31.5069364912102,
    31.4689572745399, 31.3830510019205, 31.3770000000002, 31.3724027050453,
    31.3298150838271, 31.2907, 31.2639067640932, 31.2311
  ), dim = c(
    13L,
    2L
  )))), ID = "2"), new("Lines", Lines = list(new("Line",
    coords = structure(c(
      35.476, 35.3923000000001, 35.3335010862793,
      35.2791328295471, 35.2333000000002, 35.196753311771,
      35.0337402966776, 34.9775773762158, 34.9655198689783,
      34.9259000000002, 34.9158841237544, 34.8853590913363,
      34.8791, 34.9022358369817, 34.936163814819, 34.9485345716516,
      35.006477806807, 35.0123000000002, 35.0711875422847,
      35.131130354984, 35.1809327170935, 35.2023552279524,
      35.2293000000001, 35.2252, 35.1626012160908, 35.0909220588225,
      35.0556515068938, 35.04102863744, 35.0393, 34.986522705144,
      34.9863, 34.988657690641, 34.9913575235209, 35.0018,
      34.9939863610451, 34.9641, 35.0302, 35.0176165723667,
      35.0161000000002, 35.0560243733131, 35.0731000000001,
      35.2109, 35.2198804408897, 35.324668495663, 35.4027,
      35.4303000000002, 35.5155323289802, 35.5608, 31.4905000000001,
      31.4895000000001, 31.4476381318668, 31.4089306685833,
      31.3763000000001, 31.372495530178, 31.3555260556074,
      31.3496795577065, 31.3484243845391, 31.3443, 31.3557283716138,
      31.390558216296, 31.3977000000001, 31.4435200735417,
      31.5107137713909, 31.5352138138264, 31.6499692600274,
      31.6615, 31.6914593763514, 31.7219556276049, 31.7472928662081,
      31.7581916920092, 31.7719000000002, 31.7781000000002,
      31.8025468623553, 31.8305399060224, 31.8443142044087,
      31.8500249108226, 31.8507000000002, 31.9640218142385,
      31.9645000000001, 31.9761363441316, 31.9894613257642,
      32.041, 32.0736639124483, 32.1986, 32.2641, 32.3299621956988,
      32.3379000000001, 32.423071996401, 32.4595, 32.5431000000002,
      32.5411428444779, 32.5183058231561, 32.5013000000002,
      32.4093000000001, 32.4039444053822, 32.4011
    ), dim = c(
      48L,
      2L
    ))
  )), ID = "3")
), bbox = structure(c(
  34.265, 31.2311,
  35.5608, 32.5431000000002
), dim = c(2L, 2L), dimnames = list(
  c("x", "y"), c("min", "max")
)), proj4string = new("CRS",
  projargs = "+proj=longlat +datum=WGS84 +no_defs"
))

### MAP 
highchart(type = "map") |>
  hc_add_series(
    mapData = geojson_list(mapISR),
    nullColor = "grey",
    borderColor = "green"
  ) |>
  ### PALESTINE -----
  hc_add_series(
    type = "mapline",
    data = geojson_list(borderPAL),
    geojson = TRUE,
    showInLegend = FALSE,
    dashStyle = "Dash",
    lineWidth = 1,
    color = "magenta"
  ) |>
  hc_mapNavigation(enabled = TRUE) |>
  hc_title(
    text = "Title"
  )

I changed the border colors to green and magenta to see better the difference beofre and after hovering the border with the mouse: image

And also this issue doesn't disappear by adding lineWidth = 1, borderWidth = 1 to the first hc_add_series