/vega-lite-api-examples

A repository containing Vega-Lite-API implementations of all of the examples in the Vega-Lite gallery. Work in progress and contributors welcome!

Primary LanguageJavaScript

Vega-Lite API Examples

tests

Examples completed: 220 / 703

A repository containing Vega-Lite-API implementations of all of the examples in the Vega-Lite gallery.

Contributions welcome!

Usage

Test that all of the chart modules in src/ return their matching JSON spec defined in specs/.

npm test

Getting started

See the bar_aggregate.vl.js file as an example.

If you want to write an implementation, go to a file in the src/ folder and create a default function that exports a vega-lite spec. To test it, run npm test.

Tests are automatically generated when you run npm test. See the list below for which examples have already been created.

Notes

  1. As described in this issue and this PR, the mark field may not match the spec. This may occur when mark is nested inside a spec or a layer

spec

"spec": {
  "mark": "bar"
}

vega-lite example output

"spec": {
  "mark": { "type": "bar" }
}

To address this issue, the test template recursively finds mark fields that are strings and converts them into objects.

function convertMarkValues (obj) {
  for (const key in obj) {
    if (typeof obj[key] === 'object') {
      convertMarkValues(obj[key]);
    }
    if (key === 'mark' && typeof obj[key] === 'string') {
      obj.mark = { type: obj[key] };
    }
  }
  
  return obj;
}
  1. In the arc_pie_pyramid file, the ordinal type field is added but was not present in the spec:
"order": {
  "field": "order",
  "type": "ordinal"
}

Example list (Completed: 220 / 703)