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

feat: UI table formatting #950

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mattrunyon
Copy link
Collaborator

Fixes #596. Adds UI table formatting based on the spec.

Features

  • Multiple formatting rules allowed on one table
  • First matching rule for a formatting type is applied
  • Single dataclass (ui.TableFormat) which encompasses the potential formatting options
  • The cols parameter applies formatting to specific columns. The where parameter provides further filtering for rows
  • DH theme color keywords supported in addition to hex and CSS keyword colors
  • If a background color is specified with no text color, a contrasting black/white text color is applied

Missing

  • Docs
  • Unit tests (should pull out some of the model code around formatting to test it easier)
  • E2e tests
  • Testing/setting good error messages if where is bad. Other potential error points we might want to add
  • Databars through formatting option (follow-up PR?)
  • Default as a keyword for all values. Could be useful if you want to apply a background color and not a font color that may have no where clause later in the list. (follow-up PR?)
  • Regex/wildcard column name matching (follow-up PR)
  • Number formatting rules can be applied to date columns since they're actually longs. I think this is fine as just something to note instead of trying to determine if a formatting option is date/number specific

Example Code

from deephaven import ui
import deephaven.plot.express as dx

t = ui.table(
    dx.data.stocks(),
    formatting=[
        ui.TableFormat(background_color="positive", where="Sym=`DOG`", color='negative'),
        ui.TableFormat(
            cols=["Sym", "Exchange"], background_color="negative", where="Sym=`CAT`"
        ),
        ui.TableFormat(cols=["Sym", "Exchange"], alignment="center"),
        ui.TableFormat(cols="Size", color="notice", where="Size > 100"),
        ui.TableFormat(cols="Size", color="info", where="Size < 10"),
        ui.TableFormat(cols="Timestamp", value="E, dd MMM yyyy HH:mm:ss z"),
        ui.TableFormat(value="0.00%"),
    ],
)

@mattrunyon mattrunyon self-assigned this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui.table Formatting
1 participant