• Stars
    star
    258
  • Rank 152,205 (Top 4 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CompassQL Query Language for visualization recommendation.

CompassQL

CompassQL is a visualization query language that powers chart specifications and recommendations in Voyager 2.

As described in our vision paper and Voyager 2 paper, a CompassQL query is a JSON object that contains the following components:

  • Specification (spec) for describing a collection of queried visualizations. This spec's syntax follows a structure similar to Vega-Lite's single view specification. However, spec in CompassQL can have enumeration specifiers (or wildcards) describing properties that can be enumerated.1

  • Grouping/Nesting method names (groupBy and nest) for grouping queried visualizations into groups or hierarchical groups.

  • Ranking method names (orderBy and chooseBy) for ordering queried visualizations or choose a top visualization from the collection.

  • Config (config) for customizing query parameters.

Internally, CompassQL engine contains a collection of constraints for enumerating a set of candidate visualizations based on the input specification, and methods for grouping and ranking visualization.

For example, the following CompassQL query has one wildcard for the mark property. The system will automatically generate different marks and choose the top visual encodings based on the effectiveness score.

{
  "spec": {
    "data": {"url": "data/cars.json"},
    "mark": "?",
    "encodings": [
      {
        "channel": "x",
        "aggregate": "mean",
        "field": "Horsepower",
        "type": "quantitative"
      },{
        "channel": "y",
        "field": "Cylinders",
        "type": "ordinal"
      }
    ]
  },
  "chooseBy": "effectiveness"
}

The examples/specs directory contains a number of example CompassQL queries.

To understand more about the structure of a CompassQL Query, look at the Query interface declaration.

  • A query's spec property implements SpecQuery interface, which follows the same structure as Vega-Lite's UnitSpec (single view specification) but most of SpecQuery's properties have -Query suffixes to hint that its instance is a query that can contain wildcards to describe a collection of specifications.
  • Since multiple encoding channels can be a wildcard, the encoding object in Vega-Lite is flatten as encodings which is an array of Encoding in CompassQL's spec.

Usage

Given a row-based array of data object, here are the steps to use CompassQL:

  1. Specify a query config (or use an empty object to use the default configs)
var opt = {}; // Use all default query configs

For all query configuration properties, see src/config.ts.

  1. Build a data schema.
var schema = cql.schema.build(data);

The data property is a row-based array of data objects where each object represents a row in the data table (e.g., [{"a": 1, "b":2}, {"a": 2, "b": 3}]).

You can reuse the same schema for querying the same dataset multiple times.

  1. Specify a query. For example, this is a query for automatically selecting a mark:
var query = {
  spec: {
    data: { url: "node_modules/vega-datasets/data/cars.json" },
    mark: "?",
    encodings: [
      {
        channel: "x",
        aggregate: "mean",
        field: "Horsepower",
        type: "quantitative",
      },
      {
        channel: "y",
        field: "Cylinders",
        type: "ordinal",
      },
    ],
  },
  chooseBy: "effectiveness",
};
  1. Execute a CompassQL query.
var output = cql.recommend(query, schema);
var result = output.result; // recommendation result

The result object is an instance of SpecQueryModelGroup (ResultGroup<SpecQueryModel>), which is a root of the output ordered tree. Its items property can be either an array of SpecQueryModel or an array of SpecQueryModelGroup (for hierarchical groupings).

The SpecQueryModel is an class instance of a SpecQuery with helper methods. Note that, in the result, all of spec query models are completely enumerated and there would be no wildcard left.

  1. Convert instances of SpecQueryModel in the tree, using SpecQueryModel's toSpec() class method and the mapLeaves method.
var vlTree = cql.result.mapLeaves(result, function (item) {
  return item.toSpec();
});
  1. Now you can use the result. In this case, the tree has only 2 levels (the root and leaves). We can just get the top visualization by accessing the 0-th item.

For a full source code, please see index.html.

var topVlSpec = vlTree.items[0];

Note for Developers

  • The root file of our project is src/cql.ts, which defines the top-level namespace cql for the compiled files. Other files under src/ reflect namespace structure. All methods for cql.xxx will be in either src/xxx.ts or src/xxx/xxx.ts. For example, cql.util.* methods are in src/util.ts, cql.query is in src/query/query.ts.

  • TODO: constraints

    • List in Vy2 paper supplement..

Development Instructions

You can install dependencies with:

yarn install

You can use the following npm commands such as

npm run build
npm run lint
npm run test
npm run cover       // see test coverage  (see coverage/lcov-report/index.html)
npm run watch       // watcher that build, lint, and test
npm run test-debug  // useful for debugging unit-test with vscode
npm run clean       // useful for wiping out js files that's created from other branch

(See package.json for Full list of commands.)

To play with latest CompassQL in the vega-editor, use branch cql-vl3 in kanitw's fork, which has been updated to use Vega-Lite 3, Vega 5, and CompassQL ^0.21.1. (For CompassQL 0.7 or older, use branch compassql, which uses Vega-Lite 1.x).

Make sure to link CompassQL to the editor

cd COMPASSQL_DIR
npm link

cd VEGA_EDITOR_DIR
npm run vendor -- -l compassql

(You might want to link your local version of Vega-Lite as well.)

Main API

The main method is cql.recommend, which is in src/recommend.ts.

Directory Structure

  • examples - Example CompassQL queries
    • examples/specs – All JSON files for CompassQL queries
    • examples/cql-examples.json - A json files listing all CompasssQL examples that should be shown in Vega-editor.
  • src/ - Main source code directory.
    • src/cql.ts is the root file for CompassQL codebase that exports the global cql object. Other files under src/ reflect namespace structure.
    • All interface for CompassQL syntax should be declared at the top-level of the src/ folder.
  • test/ - Code for unit testing. test's structure reflects src's' directory structure. For example, test/constraint/ test files inside src/constraint/.
  • typings/ - TypeScript typing declaration for dependencies. Some of them are downloaded from the TypeStrong community.

Pro-Tip

  • When you add a new source file to the project, don't forget to add the file to files in tsconfig.json.

More Repositories

1

vega

A visualization grammar.
JavaScript
10,564
star
2

vega-lite

A concise grammar of interactive graphics, built on Vega.
TypeScript
4,260
star
3

voyager

Visualization Tool for Data Exploration
TypeScript
1,405
star
4

ts-json-schema-generator

Generate JSON schema from your Typescript sources
TypeScript
1,235
star
5

lyra

An interactive, graphical Visualization Design Environment (VDE)
TypeScript
1,042
star
6

falcon

Brushing and linking for big data
Jupyter Notebook
919
star
7

datalib

JavaScript data utility library.
JavaScript
727
star
8

polestar

Lightweight Tableau-style interface for visual analysis, built on Vega-lite.
JavaScript
370
star
9

ipyvega

IPython/Jupyter notebook module for Vega and Vega-Lite
Jupyter Notebook
369
star
10

react-vega

Convert Vega spec into React class conveniently
TypeScript
363
star
11

vega-embed

Publish Vega visualizations as embedded web components with interactive parameters.
TypeScript
352
star
12

vega-datasets

Common repository for example datasets used by Vega-related projects
TypeScript
234
star
13

vega-lite-api

A JavaScript API for Vega-Lite.
JavaScript
198
star
14

editor

Editor/IDE for Vega and Vega-Lite
TypeScript
134
star
15

vega-themes

Themes for stylized Vega and Vega-Lite visualizations.
TypeScript
104
star
16

vega-desktop

App for viewing visualizations created in Vega or Vega-lite
JavaScript
87
star
17

vega-tooltip

Tooltip Plugin for Vega-Lite
TypeScript
77
star
18

vega.github.io

The Vega landing page.
HTML
70
star
19

react-vega-lite

react + vega-lite
JavaScript
68
star
20

vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
Rust
65
star
21

svelte-vega

Svelte component for Vega and Vega-Lite
Svelte
64
star
22

compass

Visualization Recommendation Engine, powered by Vega-Lite Specification Language
JavaScript
56
star
23

vega-loader-arrow

Data loader for the Apache Arrow format.
JavaScript
51
star
24

scalable-vega

A demo of scaling Vega to millions of records
TypeScript
45
star
25

vega-webgl-renderer

WebGL renderer for Vega.
JavaScript
41
star
26

vega-dataflow

Reactive dataflow processing.
JavaScript
39
star
27

vega-editor

[Deprecated] Please use https://github.com/vega/editor! (Link to deployed old editor: http://vega.github.io/vega-editor)
JavaScript
39
star
28

dataflow-api

JavaScript API for dataflow processing.
JavaScript
38
star
29

vega-plus

Make Vega charts of large datasets
TypeScript
35
star
30

vega-scenegraph

Vega scenegraph and renderers.
JavaScript
34
star
31

voyager2

Deprecated version of Voyager 2 (in Angular), please use https://github.com/vega/voyager.
JavaScript
30
star
32

schema

JSON schema for Vega and Vega-Lite
27
star
33

vega-lite-tutorials

Compilation of Vega-Lite & Altair Tutorials
Jupyter Notebook
24
star
34

vega-expression

Vega expression parser and code generator.
JavaScript
24
star
35

vega-lib

Include Vega in projects using minimal dependencies.
HTML
21
star
36

dataflow-vis

Experimental Vega Dataflow Visualization
JavaScript
20
star
37

vega-view

View component for Vega visualizations.
JavaScript
20
star
38

vega-label

Labeling algorithm for Vega.
JavaScript
19
star
39

vega-render-service

A service to render Vega visualizations
TypeScript
19
star
40

datalib-sketch

Probabilistic data structures for large or streaming data sets.
JavaScript
19
star
41

editor-backend

Backend for the Vega Editor
TypeScript
18
star
42

vega-bundler

Compile optimized Vega and Vega-Lite bundles.
JavaScript
17
star
43

vega-lite-ui

Common UI Library that powers Polestar and Voyager
JavaScript
13
star
44

vega-renderer-webgl

WebGL Renderer extension for Vega
JavaScript
13
star
45

vega-tutorials

Interactive tutorials for learning Vega.
JavaScript
13
star
46

vega-parser

Parse Vega specifications to runtime dataflows.
JavaScript
13
star
47

vega-vscode

Vega Language Plug-in for Visual Studio Code
TypeScript
12
star
48

vega-statistics

Statistical routines and probability distributions.
JavaScript
12
star
49

voyager-server

TypeScript
11
star
50

roadmap

The Vega and Vega-Lite Roadmap
9
star
51

vega-geo

Geographic data transforms for Vega dataflows.
JavaScript
8
star
52

vega-typings

Typings for Vega
TypeScript
8
star
53

vega-lite-transforms2sql

Convert extracted Vega-Lite transforms to SQL for scalable visualizations
TypeScript
6
star
54

vega-runtime

Runtime support for Vega dataflows.
JavaScript
6
star
55

vega-webgpu

WebGPU Renderer Extension for Vega
TypeScript
6
star
56

vega-crossfilter

Indexed cross-filtering for Vega dataflows.
JavaScript
6
star
57

vega-lite-to-api

Convert Vega-Lite JSON spec to Vega-Lite JS API
TypeScript
6
star
58

vega-hierarchy

Hierarchical layout transforms for Vega dataflows.
JavaScript
5
star
59

vega-logging

Vega logging utilities.
JavaScript
5
star
60

vega-util

JavaScript utilities for Vega.
JavaScript
4
star
61

vue-vega

Vue component for Vega and Vega-Lite
TypeScript
4
star
62

voyager-electron

JavaScript
4
star
63

vl-convert-service

Python
4
star
64

vega-loader

Network request and file loading utilities.
JavaScript
3
star
65

vega-wordcloud

Wordcloud layout algorithm for Vega dataflows.
JavaScript
3
star
66

vega-dataflow-examples

Example applications driven by Vega dataflows.
JavaScript
3
star
67

voyager-docs

3
star
68

vega-projection

Projections for cartographic mapping.
JavaScript
3
star
69

vega-event-selector

A CSS-inspired language to select, sequence, and compose DOM events into event streams.
JavaScript
3
star
70

vega-lite-v1

Copy of Vega-Lite 1.x website
TypeScript
2
star
71

vega-lite-params-proposal

2
star
72

vega-transforms

Data processing transforms for Vega dataflows.
JavaScript
2
star
73

vega-lite-dev-config

Version-controlled build config for easy re-use and sharing
TypeScript
2
star
74

vega-force

Force simulation transform for Vega dataflows.
JavaScript
2
star
75

vega-benchmarks

Scripts to benchmark Vega's performance
HTML
2
star
76

vega-lite-v4

Copy of the Vega-Lite 4 Website
JavaScript
2
star
77

ts-api

Typescript to API generator
TypeScript
2
star
78

vega-lite-shorthand

Shorthand Syntax for Vega-Lite
2
star
79

logos

Vega and Vega-Lite Logos
2
star
80

vega-embed-v2

Vega-Embed for Vega 2 and Vega-Lite 1
JavaScript
1
star
81

vega-gist

Client-side library for managing Vega GitHub gists.
1
star
82

vega-voronoi

Voronoi diagram transform for Vega dataflows.
JavaScript
1
star
83

vega-scale

Scales and color schemes for visual encoding.
JavaScript
1
star
84

vega-lite-v3

Copy of the Vega-Lite 3 Website
TypeScript
1
star
85

vega-view-transforms

View-specific transforms for Vega dataflows.
JavaScript
1
star
86

vega-canvas

Canvas and Image object instantiation utilities.
JavaScript
1
star
87

vega-encode

Visual encoding transforms for Vega dataflows.
JavaScript
1
star