olavolav / uniplot

Lightweight plotting to the terminal. 4x resolution via Unicode.
MIT License
340 stars 15 forks source link

On `force_ascii` and support for Unicode characters #32

Open NikosAlexandris opened 1 week ago

NikosAlexandris commented 1 week ago

The force_ascii option is useful, reportedly, to Force ASCII characters for plotting only. This can be useful for compatibility, for example when using uniplot inside of CI/CD systems that do not support Unicode. Defaults to False.

I am fighting with this : I still can't get a regularly looking output, executed commands from inside a markdown-exec executable code block.

Finally, and however, I got to access a docker image where I can update locales, etc. I am trying to install some fonts and set LC_ALL etc., but I still cannot get the output appear as expected. See also : https://github.com/pawamoy/markdown-exec/discussions/45#discussioncomment-9217987. What can I do to ensure uniplot/s are rendered correctly ?

olavolav commented 1 week ago

Hi @NikosAlexandris could you post an example of the uniplot function you are calling, and the output you are seeing?

With force_ascii=True and perhaps color=False you should not have any problems, but I'd be curious to see your case

NikosAlexandris commented 1 week ago

Hi @NikosAlexandris could you post an example of the uniplot function you are calling, and the output you are seeing?

With force_ascii=True and perhaps color=False you should not have any problems, but I'd be curious to see your case

Thank you for the reply. Struggling here to understand how I should set up the CI/CD environment to make things looks okay. Locally, I see no problems. "Remotely" I see things (exactly actually) like in this page : https://nikosalexandris.github.io/rekx/how_to/help/#help (see end of code block rekx --help).

I have even set now both locally and for CI/CD build (not the rekx example above, but another project)

theme:
  font: false

in mkdocs.yml.

For Uniplot/s, I use something like

    import shutil
    from functools import partial
    from uniplot import plot as default_plot

    terminal_columns, _ = shutil.get_terminal_size()  # we don't need lines!
    terminal_length = int(terminal_columns * terminal_width_fraction)
    plot = partial(default_plot, width=terminal_length)

then using this somewhere

# some code
        plot(
            # xs=timestamps,
            ys=y_series,
            legend_labels=legend_labels,
            lines=lines,
            title=title if title else supertitle,
            y_unit=' ' + str(unit),
            # force_ascii=True,
        )

to renders plots fine locally (with or without explicitly export FORCE_COLOR=1)

2024-06-25T22:11:35,176280794+03:00

but not when the documentation is build through the CI/CD image

image

Since this mis-alignment appears on other blocks too, irrelevant to Uniplot, I think it's a font / Unicode related issue. !?

olavolav commented 1 week ago

It does look like a font issue. Could you try 2 things:

  1. Use force_ascii=True, then the output should display identically. Though of course you loose the Unicode-powered high resolution.
  2. Use color=False and see what you get.

Thanks!

NikosAlexandris commented 6 days ago

It does look like a font issue. Could you try 2 things:

1. Use `force_ascii=True`, then the output should display identically. Though of course you loose the Unicode-powered high resolution.

2. Use `color=False` and see what you get.

Thanks!

@olavolav This is about uniplot and color=False, and not about the problem I am trying to resolve.

While testing locally, I get

2024-07-01T08:39:05,574824007+03:00

Maybe the "legend" slips away the color=False option ?

olavolav commented 5 days ago

@NikosAlexandris Thanks for pointing this out! Indeed, that's not correct behavior, have opened #33 to track that. I have a fix locally already.