## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----eval = FALSE-------------------------------------------------------------
# # No labels at all
# drag_map_prototype(x, "region", labels = FALSE)
# 
# # Labels follow their region but cannot be nudged independently
# drag_map_prototype(x, "region", label_col = "name", draggable_labels = FALSE)
# 
# # Text only — no visible marker behind the label text
# drag_map_prototype(x, "region", label_col = "name", label_marker_shape = "none")
# 
# # Circle markers — label_radius only applies when shape is "circle"
# drag_map_prototype(x, "region", label_col = "name",
#                    label_marker_shape = "circle",
#                    label_radius = 16, label_text_size = 14)
# 
# # Rounded-box markers (default) with explicit size
# drag_map_prototype(x, "region", label_col = "name",
#                    label_marker_shape = "rect",
#                    label_width = 80, label_height = 32, label_text_size = 12)

## -----------------------------------------------------------------------------
library(dragmapr)

hhs <- example_hhs_layout()
head(hhs$labels)

## -----------------------------------------------------------------------------
as_drag_labels(data.frame(
  label_id = "note-1",
  region = "3",
  label = "Custom note",
  x = hhs$labels$x[3],
  y = hhs$labels$y[3],
  tooltip = "Shown by a custom D3/Shiny layer"
))

## -----------------------------------------------------------------------------
note <- as_drag_annotations(data.frame(
  label_id = "region-3-note",
  region = "3",
  label = "Region 3 has a longer note that reads better in a box.",
  x = hhs$labels$x[3],
  y = hhs$labels$y[3]
), width_px = 180, height_px = 84)

note

## -----------------------------------------------------------------------------
render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = hhs$labels,
  label_offsets = hhs$label_offsets,
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  show_label_marker = FALSE,
  title = "Text-only labels"
)

## -----------------------------------------------------------------------------
render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = hhs$labels,
  label_offsets = hhs$label_offsets,
  label_values = c("1", "2", "3"),
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  title = "Only selected labels"
)

## -----------------------------------------------------------------------------
note$connector <- TRUE
note$connector_type <- "squiggle"

render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = note,
  label_offsets = data.frame(
    label_id = "region-3-note",
    region = "3",
    dx_m = 90000,
    dy_m = 70000
  ),
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  connector_linewidth = 0.9,
  connector_color = "#334155",
  connector_linetype = "dashed",
  connector_endpoint = "arrow",
  label_padding = 0.12,
  title = "Annotation box with connector"
)

## -----------------------------------------------------------------------------
label_offsets <- hhs$label_offsets
label_offsets$dx_m[label_offsets$label_id == "3"] <- -45000
label_offsets$dy_m[label_offsets$label_id == "3"] <- -30000

render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = hhs$labels,
  label_offsets = label_offsets,
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  title = "HHS regions with label nudge"
)

## -----------------------------------------------------------------------------
render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = hhs$labels,
  label_offsets = hhs$label_offsets,
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  legend_values = c("1", "2", "3"),
  title = "Selected legend keys"
)

## -----------------------------------------------------------------------------
render_dragged_map(
  hhs$states,
  region_offsets = hhs$region_offsets,
  region_col = "hhs_region",
  labels = hhs$labels,
  label_offsets = hhs$label_offsets,
  region_palette = hhs$region_colors,
  region_labels = hhs$region_names,
  show_origin_outlines = TRUE,
  show_movement_connectors = TRUE,
  movement_connector_color = "#64748b",
  movement_connector_opacity = 0.65,
  movement_connector_linetype = "dotted",
  movement_connector_endpoint = "open",
  title = "Movement context"
)

## ----eval = FALSE-------------------------------------------------------------
# render_dragged_map(
#   hhs$states,
#   region_offsets = "drag_region_offsets.csv",
#   region_col = "hhs_region",
#   labels = hhs$labels,
#   label_offsets = "drag_label_offsets.csv",
#   file = "hhs_dragged_layout.png",
#   width = 9,
#   height = 6
# )

## ----eval = FALSE-------------------------------------------------------------
# render_dragmapr_project(
#   "dragmapr-project.zip",
#   file = "hhs_dragged_layout.png",
#   width = 9,
#   height = 6,
#   dpi = 300
# )

