vega / vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
BSD 3-Clause "New" or "Revised" License
96 stars 12 forks source link

Add support for named themes and custom config objects #39

Closed jonmmease closed 1 year ago

jonmmease commented 1 year ago

Overview

This PR adds support for converting Vega-Lite charts using named themes and custom config objects.

It also closes #18 by loading a default config object from a user settings directory (CLI only for now)

Rust updates

The Rust VlConverter struct now supports passing theme strings and config JSON objects to Vega-Lite conversion functions.

In addition, a new get_themes() function was added that returns a JSON object containing all of the built-in themes. This makes it possible to inspect the config object corresponding to built-in themes.

Python updates

The Python changes mirror the Rust changes exactly. There is a new get_themes function that returns a Python dict containing all of the built-in theme config objects.

CLI

The vl2* subcommands now accept --theme and --config options, where --theme expects a theme name and --config expects a path to a file containing a JSON object.

If a file exists at ~/.config/vl-convert/config.json, The CLI will use this path as the default value of the --config flag across all subcommands.

In addition, two new subcommands were added to get info on built in themes: ls-themes and cat-theme.

ls-themes

$ vl-convert ls-themes --help

List available themes

Usage: vl-convert ls-themes

Options:
  -h, --help  Print help information

Here is an example of listing the names of all available built-in themes.

$ vl-convert ls-themes

dark
excel
fivethirtyeight
ggplot2
googlecharts
latimes
powerbi
quartz
urbaninstitute
vox

cat-theme

$ vl-convert cat-theme --help

Print the config JSON for a theme

Usage: vl-convert cat-theme <THEME>

Arguments:
  <THEME>  Name of a theme

Options:
  -h, --help  Print help information

For example, print the config JSON associated with the built-in dark theme

$ vl-convert cat-theme dark

{
  "background": "#333",
  "title": {
    "color": "#fff",
    "subtitleColor": "#fff"
  },
  "style": {
    "guide-label": {
      "fill": "#fff"
    },
    "guide-title": {
      "fill": "#fff"
    }
  },
  "axis": {
    "domainColor": "#fff",
    "gridColor": "#888",
    "tickColor": "#fff"
  }
}
jonmmease commented 1 year ago

cc @lsh in case you're interested in taking a look