tomroh / leaflegend

Provides extensions to the leaflet R package to customize legends with images, text styling, orientation, sizing, and symbology.
https://leaflegend.delveds.com
Other
34 stars 3 forks source link

Horizontal addLegendNumeric Has Poor Alignment Between Gradient and Labels #79

Closed CIOData closed 8 months ago

CIOData commented 8 months ago

I am using addLegendNumeric in a dynamic Shiny dashboard environment where the title may extend further than the set width. Everything adjusts accordingly with the exception of the color gradient. Is there a way to allow for dynamic widths?

Code:

  addLegendNumeric(
      layerId = 'polyLegend',
      position = 'topleft', 
      pal = pal,
      values = dat2$value,
      tickWidth = 2,
      tickLength = 6,
      naLabel = 'No Data',
      orientation = 'horizontal',
      width = 150,
      height = 20,
      title = data_title,
      numberFormat = if (unique(dat2$fmt) == 'int'){
          function(x) {
              prettyNum(x, big.mark = ",", scientific = FALSE, digits = 1)
              }
          } else {
              function(x) {
                  paste0(round(x * 100, 1), "%")
              }
              }
      ) 

Output:

Screenshot 2023-12-26 231112

tomroh commented 8 months ago

What version of leaflegend are you using and the "dynamic" here is the text header size?

CIOData commented 8 months ago

I'm using leaflegend 1.1.1. Yes, the map coloring adjusts based on user variable selection. If the title of the variable selected exceeds the pre-specified width of the legend, then it drags the upper tick mark out with it. If the title is shorter, everything renders fine.

tomroh commented 8 months ago

Can you try with the latest version on GitHub? I made changes to the backend of addLegendNumeric a couple months ago that should resolve this.

CIOData commented 8 months ago

Yes, this did resolve the issue. Thank you. I look forward to this being in the stable release, as we're currently using a hacky work around in our distributed code.

tomroh commented 8 months ago

It will be in the next release which I'll put out soon.

tomroh commented 8 months ago

On it's way to CRAN