#' @title Deprecated - Plot proportional symbols
#' @description
#' This function is deprecated. Please use `mf_map()` with `type = "prop"`
#' instead.
#'
#' Plot proportional symbols.
#' @eval my_params(c(
#' 'x',
#' 'var',
#' 'col',
#' 'alpha',
#' 'border',
#' 'lwd',
#' 'add' ,
#' 'inches',
#' 'val_max',
#' 'lwd_max',
#' 'symbol',
#' 'leg_pos',
#' 'leg_title',
#' 'leg_title_cex',
#' 'leg_val_cex',
#' 'leg_val_rnd',
#' 'leg_val_dec',
#' 'leg_val_big',
#' 'leg_frame',
#' 'leg_horiz',
#' 'leg_frame_border',
#' 'leg_bg',
#' 'leg_fg',
#' 'leg_size',
#' 'leg_adj'))
#' @keywords internal
#' @export
#' @return x is (invisibly) returned.
#' @examples
#' mtq <- mf_get_mtq()
#' mf_map(mtq)
#' mf_map(mtq, "POP", "prop")
#'
#' mf_map(mtq)
#' mf_map(
#'   x = mtq, var = "POP", type = "prop",
#'   inches = .4, symbol = "circle", val_max = 90000,
#'   col = "tomato1", border = "blue", lwd = 1,
#'   leg_pos = "right", leg_title = "Population",
#'   leg_title_cex = 1, leg_val_cex = .8, leg_val_rnd = 0,
#'   leg_frame = TRUE, add = TRUE
#' )
mf_prop <- function(x,
                    var,
                    inches = 0.3,
                    val_max,
                    lwd_max = 20,
                    symbol = "circle",
                    col,
                    alpha = NULL,
                    border,
                    lwd = .7,
                    extent = x,
                    bg,
                    expandBB = rep(.04, 4),
                    leg_pos = mf_get_leg_pos(x),
                    leg_title = var,
                    leg_title_cex = .8,
                    leg_val_cex = .6,
                    leg_val_rnd = 0,
                    leg_val_dec = ".",
                    leg_val_big = "",
                    leg_frame = FALSE,
                    leg_frame_border,
                    leg_horiz = FALSE,
                    leg_adj = c(0, 0),
                    leg_fg,
                    leg_bg,
                    leg_size = 1,
                    add = TRUE) {
  deprecate_direct_calls_to("mf_prop")
  # default
  op <- par(mar = getOption("mapsf.mar"), no.readonly = TRUE)
  on.exit(par(op))

  bgc <- go(bg, "background")
  col <- go(col, "highlight", "tomato4")
  border <- go(border, "background")
  leg_fg <- go(leg_fg, "highlight")
  leg_bg <- go(leg_bg, "foreground", getOption("mapsf.background"))
  leg_frame_border <- go(
    leg_frame_border, "foreground",
    getOption("mapsf.highlight")
  )
  border <- border[[1]]

  if (!is.null(alpha)) {
    col <- get_hex_pal(col, alpha)
  }

  xtype <- get_geom_type(x)
  # linestring special case
  if (xtype == "LINE") {
    xl <- x[!is.na(x[[var]]), ]
    if (!missing(val_max)) {
      maxval <- val_max
    } else {
      maxval <- max(xl[[var]])
    }
    xl$lwd <- xl[[var]] * lwd_max / maxval
    if (add == FALSE) {
      mf_init(x, expandBB = expandBB, extent = extent, bgc = bgc)
    }
    op2 <- par(lend = 1)
    mf_map(xl, lwd = xl$lwd, add = TRUE, col = col)

    val <- seq(min(xl[[var]]), max(xl[[var]]), length.out = 4)
    leg(
      type = "prop_line",
      pos = leg_pos,
      val = val,
      lwd = max(xl$lwd),
      col = col,
      title = leg_title,
      title_cex = leg_title_cex,
      val_cex = leg_val_cex,
      val_rnd = leg_val_rnd,
      val_dec = leg_val_dec,
      val_big = leg_val_big,
      frame = leg_frame,
      bg = leg_bg,
      fg = leg_fg,
      adj = leg_adj,
      frame_border = leg_frame_border,
      size = leg_size
    )

    par(op2)

    return(invisible(x))
  }


  # check merge and order
  dots <- create_dots(x = x, var = var)

  # default col
  mycols <- rep(col, nrow(dots))

  # Default max value
  if (missing(val_max)) {
    val_max <- max(dots[[var]])
  }

  # get sizes
  sizes <- get_size(
    var = dots[[var]], inches = inches,
    val_max = val_max, symbol = symbol
  )

  # size and values for legend, hollow circle (fixmax case)
  size_max <- max(sizes)
  val <- seq(sqrt(min(dots[[var]])), sqrt(max(dots[[var]])), length.out = 4)
  val <- val * val

  if (inches <= size_max) {
    inches <- size_max
    borders <- border
  } else {
    mycols <- c(NA, mycols)
    borders <- c(NA, rep(border, nrow(dots)))
    dots <- rbind(dots[1, ], dots)
    dots[1, var] <- val_max
    sizes <- c(inches, sizes)
  }

  # empty plot if needed
  if (add == FALSE) {
    mf_init(x, expandBB = expandBB, extent = extent, bgc = bgc)
  }

  # Plot the symbols
  plot_symbols(
    symbol = symbol, dots = dots, sizes = xinch(sizes),
    mycols = mycols, border = borders, lwd = lwd,
    inches = inches
  )

  # symbols size
  leg(
    type = "prop",
    pos = leg_pos,
    val = val,
    title = leg_title,
    symbol = symbol,
    inches = size_max,
    col = col,
    title_cex = leg_title_cex,
    val_cex = leg_val_cex,
    val_rnd = leg_val_rnd,
    val_dec = leg_val_dec,
    val_big = leg_val_big,
    horiz = leg_horiz,
    frame = leg_frame,
    border = border,
    lwd = lwd,
    adj = leg_adj,
    bg = leg_bg,
    fg = leg_fg,
    self_adjust = TRUE,
    mar = getOption("mapsf.mar"),
    frame_border = leg_frame_border,
    size = leg_size
  )

  return(invisible(x))
}
