finos / perspective

A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
https://perspective.finos.org/
Apache License 2.0
7.72k stars 1.05k forks source link

Formatting for `float` and `integer` columns via `Intl.NumberFormat` #2563

Closed texodus closed 3 months ago

texodus commented 3 months ago

Adds formatting options for integer and float columns. From #2539 which this PR supersedes:

This PR aims to create a universal number string formatter using the Intl.NumberFormat() constructor as the base datatype. This PR creates a column settings control on the viewer and integrates it into the Datagrid. Further work will integrate this control into the D3FC plugins and the OpenLayers plugin.

Screenshot 2024-03-11 at 11 53 11 PM

Things I changed from the predecessor PRs:

There are a bunch of issues remaining with this PR that I feel need to be resolved:

IMO we should be unwinding this ambiguity completely, not shuffling it around. This:

{
    version: "2.7.1",
    plugin: "Datagrid",
    plugin_config: {
        columns: {
            datetime: {
                format: "custom",
                timeZone: "America/Curacao",
                datetime_color_mode: "foreground",
            },
            "Order ID": {
                format: "link",
                string_color_mode: "foreground",
                color: "#ff0000",
            },
        },
        editable: true,
        scroll_lock: false,
    },
    columns: ["Order ID", "datetime"],
    expressions: { datetime: "datetime(100)" },
}

... is now this ...:

{
    version: "2.7.1",
    plugin: "Datagrid",
    columns_config: {
        datetime: {
            format: "custom",
            timeZone: "America/Curacao",
            datetime_color_mode: "foreground",
        },
        "Order ID": {
            format: "link",
            string_color_mode: "foreground",
            color: "#ff0000",
        },
    },
    plugin_config: {
        editable: true,
        scroll_lock: false,
    },
    columns: ["Order ID", "datetime"],
    expressions: { datetime: "datetime(100)" },
}

... but IMO this makes more sense, and mirrors how this data structure is ultimately dissected during restore():

{
    version: "2.7.1",
    plugin: "Datagrid",
    style: {
        editable: true,
        scroll_lock: false,
        columns: {
            datetime: {
                format: "custom",
                timeZone: "America/Curacao",
                datetime_color_mode: "foreground",
            },
            "Order ID": {
                format: "link",
                string_color_mode: "foreground",
                color: "#ff0000",
            },
        },
    },
    view: {
        columns: ["Order ID", "datetime"],
        expressions: { datetime: "datetime(100)" },
    }
}

Refactorings like this are costly on the Perspective community (and me), but this would be complex to do today as plugin_config is untyped and the state is managed externally, so I can accept this conceit to the structure of the code for now. It is still a fairly significant breaking change to the persistence API.