#svg #vega #vega-lite #format #command-line #cli-applications

app vl-convert

将Vega-Lite可视化规范转换为Vega规范的命令行应用程序

48个版本 (14个稳定版本)

新版本 1.6.1 2024年8月24日
1.5.1 2024年7月27日
1.3.0 2024年3月13日
1.2.0 2023年12月2日
0.5.0 2022年10月29日

19可视化

Download history 197/week @ 2024-06-16 12/week @ 2024-06-23 4/week @ 2024-06-30 40/week @ 2024-07-07 86/week @ 2024-07-21 447/week @ 2024-07-28 120/week @ 2024-08-04 6/week @ 2024-08-11

每月659次 下载

BSD-3-Clause

4.5MB
4K SLoC

概述

此软件包是围绕vl-convert-rs软件包的一个薄层包装,它提供命令行界面,用于将Vega-Lite可视化规范转换为各种格式。

安装

使用cargo安装vl-convert

$ cargo install vl-convert

CLI使用

显示顶级vl-convert命令的文档

$ vl-convert --help

vl-convert: A utility for converting Vega-Lite specifications

Usage: vl-convert <COMMAND>

Commands:
  vl2vg      Convert a Vega-Lite specification to a Vega specification
  vl2svg     Convert a Vega-Lite specification to an SVG image
  vl2png     Convert a Vega-Lite specification to an PNG image
  vl2jpeg    Convert a Vega-Lite specification to an JPEG image
  vl2pdf     Convert a Vega-Lite specification to a PDF image
  vl2url     Convert a Vega-Lite specification to a URL that opens the chart in the Vega editor
  vl2html    Convert a Vega-Lite specification to an HTML file
  vg2svg     Convert a Vega specification to an SVG image
  vg2png     Convert a Vega specification to an PNG image
  vg2jpeg    Convert a Vega specification to an JPEG image
  vg2pdf     Convert a Vega specification to an PDF image
  vg2url     Convert a Vega specification to a URL that opens the chart in the Vega editor
  vg2html    Convert a Vega specification to an HTML file
  svg2png    Convert an SVG image to a PNG image
  svg2jpeg   Convert an SVG image to a JPEG image
  svg2pdf    Convert an SVG image to a PDF image
  ls-themes  List available themes
  cat-theme  Print the config JSON for a theme
  help       Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help information
  -V, --version  Print version information

上述子命令处理各种转换格式。使用--help标志显示每个子命令的文档。

vl2vg

将Vega-Lite JSON规范转换为Vega JSON规范

$ vl-convert vl2vg --help 

Convert a Vega-Lite specification to a Vega specification

Usage: vl-convert vl2vg [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>            Path to input Vega-Lite file
  -o, --output <OUTPUT>          Path to output Vega file to be created
  -v, --vl-version <VL_VERSION>  Vega-Lite Version. One of 4.17, 5.8, 5.9, 5.13, 5.14, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20 [default: 5.20]
  -t, --theme <THEME>            Named theme provided by the vegaThemes package (e.g. "dark")
  -c, --config <CONFIG>          Path to Vega-Lite config file. Defaults to ~/.config/vl-convert/config.json
  -p, --pretty                   Pretty-print JSON in output file
      --show-warnings            Whether to show Vega-Lite compilation warnings
  -h, --help                     Print help

例如,将名为in.vl.json的Vega-Lite规范文件转换为名为out.vg.json的Vega规范文件。使用Vega-Lite JavaScript库的5.5版本执行转换,并美化打印结果JSON。

$ vl-convert vl2vg -i ./in.vl.json -o ./out.vg.json --vl-version 5.8 --pretty

vl2svg

将Vega-Lite规范转换为SVG图像

$ vl-convert vl2svg --help 

Convert a Vega-Lite specification to an SVG image

Usage: vl-convert vl2svg [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega-Lite file
  -o, --output <OUTPUT>
          Path to output SVG file to be created
  -v, --vl-version <VL_VERSION>
          Vega-Lite Version. One of 4.17, 5.8, 5.13, 5.14, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20 [default: 5.20]
      --theme <THEME>
          Named theme provided by the vegaThemes package (e.g. "dark")
  -c, --config <CONFIG>
          Path to Vega-Lite config file. Defaults to ~/.config/vl-convert/config.json
      --show-warnings
          Whether to show Vega-Lite compilation warnings
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为in.vl.json的Vega-Lite规范文件转换为名为out.svg的SVG文件。使用Vega-Lite JavaScript库的5.5版本执行转换,并应用dark主题(可用主题可通过以下ls-themes子命令获得)。

$ vl-convert vl2svg -i ./in.vl.json -o ./out.svg --vl-version 5.8 --theme dark

vl2png

将Vega-Lite规范转换为PNG图像

$ vl-convert vl2png --help

Convert a Vega-Lite specification to an PNG image

Usage: vl-convert vl2png [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega-Lite file
  -o, --output <OUTPUT>
          Path to output PNG file to be created
  -v, --vl-version <VL_VERSION>
          Vega-Lite Version. One of 4.17, 5.8, 5.13, 5.14, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20 [default: 5.20]
      --theme <THEME>
          Named theme provided by the vegaThemes package (e.g. "dark")
  -c, --config <CONFIG>
          Path to Vega-Lite config file. Defaults to ~/.config/vl-convert/config.json
      --scale <SCALE>
          Image scale factor [default: 1.0]
  -p, --ppi <PPI>
          Pixels per inch [default: 72.0]
      --show-warnings
          Whether to show Vega-Lite compilation warnings
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为in.vl.json的Vega-Lite规范文件转换为名为out.png的PNG文件,缩放因子为2。使用Vega-Lite JavaScript库的5.5版本执行转换,并应用位于~/my-config.json的配置文件。

$ vl-convert vl2png -i ./in.vl.json -o ./out.png --vl-version 5.8 --scale 2 --config ~/my-config.json

vl2pdf

将 Vega-Lite 规范转换为 PDF 图像

$ vl-convert vl2pdf --help

Convert a Vega-Lite specification to a PDF image

Usage: vl-convert vl2pdf [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega-Lite file
  -o, --output <OUTPUT>
          Path to output PDF file to be created
  -v, --vl-version <VL_VERSION>
          Vega-Lite Version. One of 4.17, 5.8, 5.13, 5.14, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20 [default: 5.20]
      --theme <THEME>
          Named theme provided by the vegaThemes package (e.g. "dark")
  -c, --config <CONFIG>
          Path to Vega-Lite config file. Defaults to ~/.config/vl-convert/config.json
      --scale <SCALE>
          Image scale factor [default: 1.0]
      --show-warnings
          Whether to show Vega-Lite compilation warnings
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为 in.vl.json 的 Vega-Lite 规范文件转换为名为 out.pdf 的 PNG 文件,缩放因子为 2。

$ vl-convert vl2pdf -i ./in.vl.json -o ./out.pdf --scale 2

vl2url

将 Vega-Lite 规范转换为 URL,该 URL 在 Vega 编辑器中打开图表

$ vl-convert vl2url --help

Convert a Vega-Lite specification to a URL that opens the chart in the Vega editor

Usage: vl-convert vl2url --input <INPUT>

Options:
  -i, --input <INPUT>  Path to input Vega-Lite file
      --fullscreen     Open chart in fullscreen mode
  -h, --help           Print help

vl2html

将 Vega-Lite 规范转换为 HTML 文件

$ vl-convert vl2html --help

Convert a Vega-Lite specification to an HTML file

Usage: vl-convert vl2html [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega-Lite file
  -o, --output <OUTPUT>
          Path to output HTML file to be created
  -v, --vl-version <VL_VERSION>
          Vega-Lite Version. One of 4.17, 5.8, 5.13, 5.14, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20 [default: 5.20]
      --theme <THEME>
          Named theme provided by the vegaThemes package (e.g. "dark")
  -c, --config <CONFIG>
          Path to Vega-Lite config file. Defaults to ~/.config/vl-convert/config.json
  -b, --bundle
          Whether to bundle JavaScript dependencies in the HTML file instead of loading them from a CDN
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

vg2svg

将 Vega 规范转换为 SVG 图像

$ vl-convert vg2svg --help

Convert a Vega specification to an SVG image

Usage: vl-convert vg2svg [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega file
  -o, --output <OUTPUT>
          Path to output SVG file to be created
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为 in.vg.json 的 Vega 规范文件转换为名为 out.svg 的 SVG 文件。

$ vl-convert vg2svg -i ./in.vg.json -o ./out.svg

vg2png

$ vl-convert vg2png --help

Convert a Vega specification to an PNG image

Usage: vl-convert vg2png [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega file
  -o, --output <OUTPUT>
          Path to output PNG file to be created
      --scale <SCALE>
          Image scale factor [default: 1.0]
  -p, --ppi <PPI>
          Pixels per inch [default: 72.0]
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为 in.vg.json 的 Vega 规范文件转换为名为 out.png 的 PNG 文件,缩放因子为 2。

$ vl-convert vg2png -i ./in.vg.json -o ./out.png --scale 2

vg2pdf

$ vl-convert vg2pdf --help

Convert a Vega specification to an PDF image

Usage: vl-convert vg2pdf [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega file
  -o, --output <OUTPUT>
          Path to output PDF file to be created
  -s, --scale <SCALE>
          Image scale factor [default: 1.0]
      --font-dir <FONT_DIR>
          Additional directory to search for fonts
  -a, --allowed-base-url <ALLOWED_BASE_URL>
          Allowed base URL for external data requests. Default allows any base URL
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

例如,将名为 in.vg.json 的 Vega 规范文件转换为名为 out.pdf 的 PDF 文件,缩放因子为 2。

$ vl-convert vg2pdf -i ./in.vg.json -o ./out.pdf --scale 2

vg2url

将 Vega-Lite 规范转换为 URL,该 URL 在 Vega 编辑器中打开图表

$ vl-convert vg2url --help

Convert a Vega specification to a URL that opens the chart in the Vega editor

Usage: vl-convert vg2url --input <INPUT>

Options:
  -i, --input <INPUT>  Path to input Vega file
      --fullscreen     Open chart in fullscreen mode
  -h, --help           Print help

vg2html

将 Vega 规范转换为 HTML 文件

$ vl-convert vg2html --help

Convert a Vega specification to an HTML file

Usage: vl-convert vg2html [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          Path to input Vega file
  -o, --output <OUTPUT>
          Path to output HTML file to be created
  -b, --bundle
          Whether to bundle JavaScript dependencies in the HTML file instead of loading them from a CDN
      --format-locale <FORMAT_LOCALE>
          d3-format locale name or file with .json extension
      --time-format-locale <TIME_FORMAT_LOCALE>
          d3-time-format locale name or file with .json extension
  -h, --help
          Print help

svg2png

将 SVG 图像转换为 PNG 图像

Convert an SVG image to a PNG image

Usage: vl-convert svg2png [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>        Path to input SVG file
  -o, --output <OUTPUT>      Path to output PNG file to be created
      --scale <SCALE>        Image scale factor [default: 1.0]
  -p, --ppi <PPI>            Pixels per inch [default: 72.0]
      --font-dir <FONT_DIR>  Additional directory to search for fonts
  -h, --help                 Print help

svg2jpeg

将 SVG 图像转换为 JPEG 图像

Convert an SVG image to a JPEG image

Usage: vl-convert svg2jpeg [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>        Path to input SVG file
  -o, --output <OUTPUT>      Path to output JPEG file to be created
      --scale <SCALE>        Image scale factor [default: 1.0]
  -q, --quality <QUALITY>    JPEG Quality between 0 (worst) and 100 (best) [default: 90]
      --font-dir <FONT_DIR>  Additional directory to search for fonts
  -h, --help                 Print help

svg2pdf

将 SVG 图像转换为 PDF 图像

Convert an SVG image to a PDF image

Usage: vl-convert svg2pdf [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>        Path to input SVG file
  -o, --output <OUTPUT>      Path to output PDF file to be created
      --scale <SCALE>        Image scale factor [default: 1.0]
      --font-dir <FONT_DIR>  Additional directory to search for fonts
  -h, --help                 Print help

ls-themes

$ vl-convert ls-themes --help

List available themes

Usage: vl-convert ls-themes

Options:
  -h, --help  Print help information

以下是列出所有可用内置主题名称的示例。

$ 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

例如,打印与内置 dark 主题相关的配置 JSON

$ 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"
  }
}

用户级配置文件

如果存在 ~/.config/vl-convert/config.json 文件,则 vl-convert 将将此路径用作所有子命令的 --config 标志的默认值。

依赖关系

~203MB
~4.5M SLoC