Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cleaning up the Formatter API #5787

Open
@anntzer

Description

@anntzer

Still on my offset-text rewrite spree...

Currently, the formatter API (in charge of picking the strings for the tick labels, axis offset and cursor position in the status bar) is a bit messy: the public methods available are

  • Formatter.__call__(self, val, idx): computes the label texts
  • Formatter.format_data(self, val): not publicly used
  • Formatter.format_data_short(self, val): computes the cursor position text
  • Formatter.get_offset(self): returns the offset text
  • Formatter.set_locs(self, locs): required for computing the labels
  • Formatter.fix_minus(self, s): overriden only by ScalarFormatter to use a unicode minus

FixedFormatter also provides set_offset_string.

The commonly used ScalarFormatter and LogFormatter also provide pprint_val (with different signatures, and not publicly used).

ScalarFormatter also provides a couple of getter/setters (for useOffset, useLocale, scientific, powerlimits); LogFormatter provides base and label_minor as setters for instance variables.

LogFormatterExponent and LogFormatterMathtext are variants of LogFormatter.

EngFormatter also provides format_eng (not publicly used).

There are also a bunch of instance attributes which are public but probably intended as private.

I propose simplifying the API to the following:

  • Formatter.get_label_text(self, val: float, idx: int): computes the label texts
  • Formatter.get_cursor_text(self, val: float): computes the cursor position text
  • Formatter.get_offset_text(self) and Formatter.set_offset_text(self, s: str): get/set the offset text
  • Formatter.set_locs(self, locs: array-like): because we need it
  • Formatter.set_uselocale(self, b: bool): because there's no reason only ScalarFormatter has it

(the new method names can be made to fallback on the old method names with a deprecation warning in the base class)

and drop or make private basically everything else:

  • fix_minus (let's first check if any backend doesn't support unicode)
  • pprint_val/format_eng
  • the various instance attributes which should have been private to start with (keeping: scientific, powerlimits, base, label_minor, using getter/setters)

and fold the LogFormatterExponent and LogFormatterMathText classes into options for the LogFormatter class.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions