grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
226 stars 7 forks source link

Should we wrap `draw_legend` in `recordGraphics`? #124

Closed grantmcdermott closed 7 months ago

grantmcdermott commented 7 months ago

Or, at least, wrap the the final return object in recordGraphics(). Would require something like changing lines 360-364 here to:

  if (isTRUE(gradient)) {
    recordGraphics(
      gradient_legend(legend.args = legend.args, lmar = lmar, outer_right = outer_right, outer_bottom = outer_bottom),
      list(legend.args = legend.args, lmar = lmar, outer_right = outer_right, outer_bottom = outer_bottom),
      getNamespace("tinyplot")
    )
  } else {
    recordGraphics(
      do.call("legend", legend.args),
      list(legend.args = legend.args),
      getNamespace("tinyplot")
    )

Reason: This would ensure that the legend spacing (e.g., gaps between groups and labels) is preserved even if we resize the plot. Right now, resizing is kind of annoying because it messes up the spacing of the current plot.