# need d as global because data=d in function def does not
#  have a value assigned to d, d <- mydata does do that, even if conditional
#  generates a Note
if (getRversion() >= "3.6.0")
  globalVariables(c("d", "mydata", "l", "mylabels", "mycor"))

## zzz.R  — lessR startup ----------------------------------------------------


.onAttach <- function(libname, pkgname) {
  packageStartupMessage(
    "\n",
    "lessR 4.5.6                          feedback: gerbing@pdx.edu \n",
    "--------------------------------------------------------------\n",
    "> d <- Read(\"\")  Read data file, many formats available, e.g., Excel\n",
    "  d is the default data frame, data= in analysis routines optional\n",
    "\n",
    "Find examples of reading, writing, and manipulating data, graphics,\n",
    "testing means and proportions, regression, factor analysis,\n",
    "customization, forecasting, and aggregation to pivot tables.\n",
    "  Enter: browseVignettes(\"lessR\")\n",
    "\n",
    "Although most previous function calls still work, most\n",
    "visualization functions are now reorganized to three functions:\n",
    paste0(
      "   Chart(): form = \"bar\", \"pie\", \"radar\", \"bubble\", \"dot\",\n",
      "                   \"sunburst\", \"treemap\", \"icicle\"\n"
    ),
    "   X(): form=\"histogram\", \"density\", \"vbs\", and more\n",
    paste0(
      "   XY(): form=\"scatter\", \"contour\", \"smooth\", \"hexbin\"\n"
    ),
    "There is also Flows() for Sankey flow diagrams.\n",
    "\n",
    "View lessR updates, now including modern time series forecasting.\n",
    "  Enter: news(package=\"lessR\"), or ?Chart, ?X, or ?XY\n",
    "\n",
    "Interactive data analysis for constructing visualizations.\n",
    "  Enter: interact()\n"
  )
}


.onLoad <- function(libname, pkgname) {

  if (requireNamespace("conflicted", quietly = TRUE)) {
    conflicted::conflict_prefer("style",    "lessR", quiet=TRUE)
    conflicted::conflict_prefer("STL",      "lessR", quiet=TRUE)
    conflicted::conflict_prefer("order_by", "lessR", quiet=TRUE)
    conflicted::conflict_prefer("recode",   "lessR", quiet=TRUE)
    conflicted::conflict_prefer("rename",   "lessR", quiet=TRUE)
  }

  options(theme    = "colors")
  options(sub_theme = "default")

  options(panel_fill  = "white")
  options(window_fill = getOption("panel_fill"))
  options(panel_color = "gray45")
  options(panel_lwd   = 1.0)
  options(panel_lty   = "solid")

  options(bar_fill = NULL)
  options(bar_fill_discrete =
    c("#4398D0","#B28B2A","#5FA140","#D57388","#9A84D6","#00A898",
      "#C97E5B","#909711","#00A3BA","#D26FAF","#00A76F","#BD76CB"))
  options(bar_fill_cont      = rgb(150,170,195, maxColorValue=255))
  options(trans_bar_fill     = 0.10)
  options(bar_color          = rgb(132,150,175, maxColorValue=255))
  options(bar_color_discrete = "transparent")
  options(bar_color_cont     = rgb(132,150,175, maxColorValue=255))

  options(pt_fill       = rgb(50,78,92, maxColorValue=255))
  options(trans_pt_fill = 0.10)
  options(pt_color      = rgb(50,78,92, maxColorValue=255))

  options(out_fill   = "firebrick4")
  options(out_color  = "firebrick4")
  options(out2_fill  = "firebrick2")
  options(out2_color = "firebrick2")

  options(violin_fill  = "#7485975A")
  options(violin_color = "gray15")
  options(box_fill     = rgb(65,155,210, maxColorValue=255))
  options(box_color    = "gray15")
  options(line_color   = "gray15")

  options(bubble_text_color = "#F7F2E6")
  options(ellipse_fill      = "#92806F28")
  options(ellipse_color     = "gray20")
  options(ellipse_lwd       = 1)

  options(se_fill   = "#1A1A1A19")
  options(fit_color = rgb(92,64,50, maxColorValue=255))
  options(fit_lwd   = 2)

  options(heat          = "gray30")
  options(segment_color = "gray40")
  options(ID_color      = "gray50")

  options(main_color = "gray15")
  options(main_size   = 1.16)
  options(lab_color  = "gray15")  # axis titles
  options(lab_x_color = NULL)
  options(lab_y_color = NULL)
  options(lab_size     = 1.05)
  options(lab_x_size   = NULL)
  options(lab_y_size   = NULL)

  options(axis_color   = "gray15")  # tick labels
  options(axis_x_color = NULL)
  options(axis_y_color = NULL)
  options(axis_lwd     = 1)
  options(axis_x_lwd   = NULL)
  options(axis_y_lwd   = NULL)
  options(axis_lty     = "solid")
  options(axis_x_lty   = NULL)
  options(axis_y_lty   = NULL)
  options(axis_size     = 0.80)
  options(axis_x_size   = NULL)
  options(axis_y_size   = NULL)
  options(axis_text_color   = "gray20")
  options(axis_x_text_color = NULL)
  options(axis_y_text_color = NULL)
  options(rotate_x = 0)
  options(rotate_y = 0)
  options(offset   = 0.5)

  options(grid_color   = "gray85")
  options(grid_x_color = NULL)
  options(grid_y_color = NULL)
  options(grid_lwd     = 0.5)
  options(grid_x_lwd   = NULL)
  options(grid_y_lwd   = NULL)
  options(grid_lty     = "solid")
  options(grid_x_lty   = NULL)
  options(grid_y_lty   = NULL)

  options(strip_fill       = "#7F7F7F37")
  options(strip_color      = "gray40")
  options(strip_text_color = "gray15")

  options(add_fill  = "#D9D9D920")
  options(add_trans = 0.0)
  options(add_color = "gray10")
  options(add_size   = 1.00)
  options(add_lwd   = 0.5)
  options(add_lty   = "solid")

  options(n_cat   = 1)
  options(suggest = TRUE)
  options(note    = TRUE)
  options(quiet   = FALSE)
  options(brief   = FALSE)

  options(lessR.use_plotly = TRUE)
  options(explain   = TRUE)
  options(interpret = TRUE)
  options(results   = TRUE)
  options(document  = TRUE)
  options(code      = TRUE)

  options(out.signifstars = FALSE)
  options(scipen          = 30)

  options(mc_doScale_quiet = TRUE)
}
