Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfd() and tfb() print not formatting correctly #37

Open
m-muecke opened this issue Jan 5, 2024 · 4 comments
Open

tfd() and tfb() print not formatting correctly #37

m-muecke opened this issue Jan 5, 2024 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@m-muecke
Copy link
Collaborator

m-muecke commented Jan 5, 2024

Spacing after the commas is not working for every position and perhaps a space after the semicolon makes reading easier.

tf::tf_rgp(1, arg = seq(0, 1, length.out = 3))
#> tfd[1] on (0,1) based on 3 evaluations each
#> interpolation by tf_approx_linear 
#> [1]: (0.0, 1.064);(0.5,-1.160);(1.0,-0.075)

Created on 2024-01-05 with reprex v2.0.2

@m-muecke m-muecke changed the title tfd and tfb print not formatting correct tfd and tfb print not formatting correctly Jan 5, 2024
@m-muecke m-muecke changed the title tfd and tfb print not formatting correctly tfd() and tfb() print not formatting correctly Jan 5, 2024
@fabian-s
Copy link
Contributor

fabian-s commented Jan 8, 2024

  • the space after the comma is for the minus sign, i think
  • compactness > slight increase in legibility, IMO

not gonna do this now, but agree that a better print method would be worthwhile.

@fabian-s fabian-s added the enhancement New feature or request label Jan 8, 2024
@fabian-s
Copy link
Contributor

maybe: sparklines instead? (https://rosettacode.org/wiki/Sparkline_in_unicode)

bars <-  intToUtf8(seq(0x2581, 0x2588), multiple = T)  # ▁ ▂ ▃ ▄ ▅ ▆ ▇ █
n_chars <- length(bars)

sparkline <- function(numbers) {
  mn <- min(numbers)
  mx <- max(numbers)
  interval <- mx - mn

  bins <- sapply(
    numbers,
    function(i)
      bars[[1 + min(n_chars - 1, floor((i - mn) / interval * n_chars))]]
  )
  sparkline <- paste0(bins, collapse = "")

  return(sparkline)
}

sparkline(c(1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1))
sparkline(c(1.5, 0.5, 3.5, 2.5, 5.5, 4.5, 7.5, 6.5))
sparkline(c(0, 999, 4000, 4999, 7000, 7999))
sparkline(c(0, 0, 1, 1))
sparkline(c(0, 1, 19, 20))

[1] "▂▁▄▃▆▅█▇"
[1] "▁▂▃▄▅▆▇█▇▆▅▄▃▂▁"
[1] "▂▁▄▃▆▅█▇"
[1] "▁▁▅▅██"
[1] "▁▁██"
[1] "▁▁██"

@fabian-s fabian-s added this to the v0.4 milestone May 24, 2024
@m-muecke
Copy link
Collaborator Author

m-muecke commented May 24, 2024

The sparkbar implementation from the cli package looks quite nice https://cli.r-lib.org/reference/spark_bar.html and the implementation is quite concise to copy and paste: https://github.com/r-lib/cli/blob/HEAD/R/spark.R#L64

@fabian-s
Copy link
Contributor

Yeah, but since it's just like 20 lines I think we should copy/adjust (with attribution) and avoid the dependency.

Challenge I think will be to make this look good/show up in e.g. summary(<table>) or glimpse(<table>) as well as strand print and still be generally applicable, fast/cheap and (more) informative (than what we do now).

things to think about:

  • should sparklines show just the first few values of the function or summarize all of a potentially looooong function in like 8-10 bars? (if the latter: will this become too expensive if called as the default string representation of tf?)
  • should bar heights be relative to range of each indiv. function in a vector or range of all function values for all functions in a tf-vector? (see above re. comp. cost)
  • (how to) show irregular grids?

... what else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants