• Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Visualization Constraints and Weight Learning

Formalizing Visualization Design Knowledge as Constraints

Test Coverage Status PyPi Code style: black code style: prettier

Draco is a formal framework for representing design knowledge about effective visualization design as a collection of constraints. You can use Draco to find effective visualization visual designs in Vega-Lite. Draco's constraints are implemented in based on Answer Set Programming (ASP) and solved with the Clingo constraint solver. We also implemented a way to learn weights for the recommendation system directly from the results of graphical perception experiment.

Read our introductory blog post about Draco and our research paper for more details. Try Draco in the browser at https://uwdata.github.io/draco-editor.

We are working on an improved version of Draco at https://github.com/cmudig/draco2.

Status

There Be Dragons! This project is in active development and we are working hard on cleaning up the repository and making it easier to use the recommendation model in Draco. If you want to use this right now, please talk to us. More documentation is forthcoming.

Overview

This repository currently contains:

  • draco (pypi) The ASP programs with soft and hard constraints, a python API for running Draco, the CLI, and the python wrapper for the draco-core API. Additionally includes some helper functions that may prove useful.
  • draco-core (npm) Holds a Typescript / Javascript friendly copy of the ASP programs, and additionally, a Typescript /Javascript API for all the translation logic of Draco, as described below.

Sibling Repositories

Various functionality and extensions are in the following repositories

  • draco-vis

    • A web-friendly Draco! Including a bundled Webassembly module of Draco's solver, Clingo.
  • draco-learn

    • Runs a learning-to-rank method on results of perception experiments.
  • draco-tools

    • UI tools to create annotated datasets of pairs of visualizations, look at the recommendations, and to explore large datasets of example visualizations.
  • draco-analysis

    • Notebooks to analyze the results.

Draco API (Python)

In addition to a wrapper of the Draco-Core API describe below, the python API contains the following functions.

object Result <>

The result of a Draco run, a solution to a draco_query. User result.as_vl() to convert this solution into a Vega-Lite specification.

run (draco_query: List[str] [,constants, files, relax_hard, silence_warnings, debug, clear_cache]) -> Result: <>

Runs a draco_query, defined as a list of Draco ASP facts (strings), against given file asp programs (defaults to base Draco set). Returns a Result if the query is satisfiable. If relax_hard is set to True, hard constraints (hard.lp) will not be strictly enforced, and instead will incur an infinite cost when violated.

is_valid (draco_query: List[str] [,debug]) -> bool: <>

Runs a draco_query, defined as a list of Draco ASP facts (strings), against Draco's hard constraints. Returns true if the visualization defined by the query is a valid one (does not violate hard constraints), and false otherwise. Hard constraints can be found in hard.lp.

data_to_asp (data: List) -> List[str]: <>

Reads an array of data and returns the ASP declaration of it (a list of facts).

read_data_to_asp (file: str) -> List[str]: <>

Reads a file of data (either .json or .csv) and returns the ASP declaration of it (a list of facts).

Draco-Core API (Typescript / Javascript)

vl2asp (spec: TopLevelUnitSpec): string[] <>

Translates a Vega-Lite specification into a list of ASP Draco facts.

cql2asp (spec: any): string[] <>

Translates a CompassQL specification into a list of ASP Draco constraints.

asp2vl (facts: string[]): TopLevelUnitSpec <>

Interprets a list of ASP Draco facts as a Vega-Lite specification.

data2schema (data: any[]): Schema <>

Reads a list of rows and generates a data schema for the dataset. data should be given as a list of dictionaries.

schema2asp (schema: Schema): string[] <>

Translates a data schema into an ASP declaration of the data it describes.

constraints2json (constraintsAsp: string, weightsAsp?: string): Constraint[] <>

Translates the given ASP constraints and matching weights (i.e. for soft constraints) into JSON format.

json2constraints (constraints: Constraint[]): ConstraintAsp <>

Translates the given JSON format ASP constraints into ASP strings for definitions and weights (if applicable, i.e. for soft constraints).

User Info

Installation

Python (Draco API)

Install Clingo

You can install Clingo with conda: conda install -c potassco clingo. On MacOS, you can alternatively run brew install clingo.

Install Draco (Python)

pip install draco

Typescript / Javascript (Draco-Core API)

STOP! If you wish to run Draco in a web browser, consider using draco-vis, which bundles the Clingo solver as a WebAssembly module. The Draco-Core API does not include this functionality by itself. It merely handles the logic of translating between the various interface languages.

yarn add draco-core or npm install draco-core

Developer Info

Installation

Install Clingo.

You can install Clingo with conda: conda install -c potassco clingo. On MacOS, you can alternatively run brew install clingo.

Install node dependencies

yarn or npm install

You might need to activate a Python 2.7 environment to compile the canvas module.

Build JS module

yarn build. We are currently using typescript version 3.2.1 and greater.

Python setup

pip install -r requirements.txt or conda install --file requirements.txt

Install Draco in editable mode. We expect Python 3.

pip install -e .

Now you can call the command line tool draco. For example draco --version or draco --help.

Tests

You should also be able to run the tests (and coverage report)

python setup.py test

Run only ansunit tests

ansunit asp/tests.yaml

Run only python tests

pytest -v

Test types

mypy draco tests --ignore-missing-imports

Running Draco

End to end example

To run Draco on a partial spec.

sh run_pipeline.sh spec

The output would be a .vl.json file (for Vega-Lite spec) and a .png file to preview the visualization (by default, outputs would be in folder __tmp__).

Use CompassQL to generate examples

Run yarn build_cql_examples.

Run Draco directly on a set of ASP constraints

You can use the helper file asp/_all.lp.

clingo asp/_all.lp test.lp

Alternatively, you can invoke Draco with draco -m asp test.lp.

Run APT example

clingo asp/_apt.lp examples/example_apt.lp --opt-mode=optN --quiet=1 --project -c max_extra_encs=0

This only prints the relevant data and restricts the extra encodings that are being generated.

Releases

  • Make sure everything works!
  • Update __version__ in draco/__init__.py and use the right version below.
  • git commit -m "bump version to 0.0.1"
  • Tag the last commit git tag -a v0.0.1.
  • git push and git push --tags
  • Run python setup.py sdist upload.

Resources

Related Repositories

Previous prototypes

For a bit of historical perspective, after building Compass and CompassQL with @kanitw, @domoritz worked with colleagues at UW on a first constraint-based prototype vis-csp in ASP, then tried Z3 in vis-constraints before going back to ASP for Draco.

Related software

Guides

More Repositories

1

visualization-curriculum

A data visualization curriculum of interactive notebooks.
Jupyter Notebook
1,275
star
2

arquero

Query processing and transformation of array-backed data tables.
JavaScript
1,251
star
3

mosaic

An extensible framework for linking databases and interactive views.
JavaScript
688
star
4

d3-tutorials

D3 Tutorials for CSE512 Data Visualization Course at University of Washington
HTML
170
star
5

imMens

Real-Time Visual Querying of Big Data
HTML
168
star
6

living-papers

Authoring tools for scholarly communication. Create interactive web pages or formal research papers from markdown source.
TeX
129
star
7

termite-data-server

Data Server for Topic Models
Python
120
star
8

errudite

An Interactive Tool for Scalable and Reproducible Error Analysis.
Python
104
star
9

gemini

A grammar and recommender system for animated transitions in Vega/Vega-Lite
JavaScript
103
star
10

vsup

Code for generating Value-Suppressing Uncertainty Palettes for use in D3 charts.
JavaScript
77
star
11

latent-space-cartography

Visual analysis of vector space embeddings
HTML
74
star
12

setcola

High-Level Constraints for Graph Layout
JavaScript
72
star
13

boba

Specifying and executing multiverse analysis
Python
62
star
14

termite-visualizations

[development moved to termite-data-server]
Python
61
star
15

rev

REV: Reverse-Engineering Visualizations
Python
60
star
16

graphscape

A directed graph model of the visualization design space, using Vega-Lite.
JavaScript
58
star
17

fast-kde

Fast, approximate Gaussian kernel density estimation.
JavaScript
56
star
18

bayesian-surprise

Bayesian Weighting for De-Biasing Thematic Maps
TeX
54
star
19

gestrec

A JavaScript implementation of the Protractor gesture recognizer.
JavaScript
36
star
20

perceptual-kernels

Data & source code for the perceptual kernels study
HTML
33
star
21

ellipsis

Visualization Storytelling Components
JavaScript
31
star
22

visual-embedding

Data & source code for the visual embedding model
MATLAB
31
star
23

boba-visualizer

A visual analysis tool for exploring multiverse outcomes
JavaScript
31
star
24

color-naming-in-different-languages

JavaScript
27
star
25

papers-vsup

Visualize uncertainty
TeX
27
star
26

arquero-sql

Database backend support for Arquero
JavaScript
24
star
27

arquero-worker

Worker thread support for Arquero.
JavaScript
22
star
28

living-papers-template

A Living Papers article starter template.
22
star
29

mosaic-framework-example

Using Mosaic and DuckDB within Observable Framework
TypeScript
22
star
30

dziban

Context-Aware, Recommender-Powered Visualization Authoring
Jupyter Notebook
21
star
31

draco-vis

Draco on the web
TypeScript
18
star
32

flechette

Fast, lightweight access to Apache Arrow data.
JavaScript
18
star
33

diagnostics

Topic Model Diagnostics
JavaScript
14
star
34

vegaserver

A simple node server that renders vega specs to SVG or PNG.
JavaScript
13
star
35

visual-encoding-effectiveness-data

Supplement material for "Assessing Effects of Task and Data Distribution on the Effectiveness of Visual Encodings".
JavaScript
13
star
36

divi

Automatically interact with SVG charts.
JavaScript
10
star
37

quantitative-color-data

Data for quantitative colormap study
R
10
star
38

citation-query

Retrieve paper citatation data from doi.org and Semantic Scholar.
JavaScript
10
star
39

arquero-arrow

Arrow serialization support for Arquero.
JavaScript
9
star
40

verp

The VERP Explorer
JavaScript
8
star
41

termite-stm

[development moved to termite-data-server]
Python
8
star
42

code-augmentation

Code augmentation editor
JavaScript
7
star
43

aggregate-animation-data

Supplement material for "Designing Animated Transitions to Convey Aggregate Operations"
JavaScript
7
star
44

vega-dataflow

Reactive dataflow processing.
JavaScript
7
star
45

trend-bias

Experiments on trend-fitting
TeX
6
star
46

termite-treetm

[development moved to termite-data-server]
Python
6
star
47

flights-arrow

Flight Dataset as Apache Arrow in Different Sizes
6
star
48

living-papers-paper

The UIST'23 Living Papers research paper and supplemental material.
JavaScript
5
star
49

fast-kde-benchmarks

Research archive of methods and benchmarks for fast, approximate Gaussian kernel density estimation.
JavaScript
5
star
50

gemini-supplemental-material

Supplemental material for "Gemini: A Grammar and Recommender System for Animated Transitions in Statistical Graphics"
HTML
5
star
51

uwdata.github.io

UW Interactive Data Lab web page
Svelte
5
star
52

palette-analyzer

Analyzes the local and global distances in [RGB, LAB, UCS, Color Names] model, given a palette.
HTML
5
star
53

draco-learn

Learning Weights for Draco
Python
4
star
54

draco-editor

The Draco Online Editor
CSS
4
star
55

datalib

We've moved! Please see https://github.com/vega/datalib
3
star
56

file-cache

File-based cache for JSON-serializable data.
JavaScript
3
star
57

istc-explorer

JavaScript
2
star
58

draco-analysis

Notebooks for Draco
Jupyter Notebook
2
star
59

draco-tools

Tools for Draco
JavaScript
2
star
60

living-papers-examples

Example Living Papers Articles
JavaScript
2
star
61

draco-tuner

An interactive application to modify Draco's knowledge base
TypeScript
1
star