Skip to content

Commit

Permalink
Rename vegaPrint to auto, print to d3auto
Browse files Browse the repository at this point in the history
  • Loading branch information
longouyang committed Apr 11, 2016
1 parent 21bd333 commit a2f58c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ TODO: expose this functionality to end users

## Automatic function

There is currently only one automatic function: `viz.vegaPrint(erp, [options])`
There is currently only one automatic function: `viz.auto(erp, [options])`

`viz.vegaPrint` tries to automatically construct a suitable visualization based on the types of the items in the ERP support.
`viz.auto` tries to automatically construct a suitable visualization based on the types of the items in the ERP support.

Options:

Expand Down
38 changes: 19 additions & 19 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</head>
<body>
<div id="intro" style="width: 80%; margin: 5px">
note: the older version of the autoviz function (the d3 version erin wrote) is currently called <code>viz.print</code>, whereas the new version (the vega-lite version long is writing) is currently called <code>viz.vegaPrint</code>.
note: the older version of the autoviz function (the d3 version erin wrote) is currently called <code>viz.print</code>, whereas the new version (the vega-lite version long is writing) is currently called <code>viz.auto</code>.
</div>

<div class="col" style="float: left">
Expand All @@ -72,30 +72,30 @@ <h1>new (vega)</h1>
}, 500))</code></pre>

c:
<pre><code>viz.vegaPrint(ParticleFilter(function() {
<pre><code>viz.auto(ParticleFilter(function() {
return {fruit: categorical([0.1, 0.2, 0.3, 0.4], ["apple", "banana", "orange", "grape"])}
}, 500))</code></pre>

(c):
<pre><code>viz.vegaPrint(ParticleFilter(function() {
<pre><code>viz.auto(ParticleFilter(function() {
return categorical([0.1, 0.2, 0.3, 0.4], ["apple", "banana", "orange", "grape"])
}, 500))</code></pre>


r:
<pre><code>viz.vegaPrint(ParticleFilter(function() {
<pre><code>viz.auto(ParticleFilter(function() {
return {x: beta(3,2)};
},500))</code></pre>

cc:
<pre><code>viz.vegaPrint(Enumerate(function() {
<pre><code>viz.auto(Enumerate(function() {
return {
fruit: categorical([0.1, 0.2, 0.3, 0.4], ["apple", "banana", "orange", "grape"]),
boolean: flip(0.7)
}}))</code></pre>

cr:
<pre><code>viz.vegaPrint(MH(function() {
<pre><code>viz.auto(MH(function() {
var brand = flip(0.7) ? 'coke' : 'pepsi';
return {
brand: brand,
Expand All @@ -104,7 +104,7 @@ <h1>new (vega)</h1>
}, 2000));</code></pre>

rr:
<pre><code>viz.vegaPrint(MH(function() {
<pre><code>viz.auto(MH(function() {
var x = uniform(0,1);
var y = uniform(0,1);
factor(Math.log(Math.abs(x-y)))
Expand All @@ -113,7 +113,7 @@ <h1>new (vega)</h1>


ccc:
<pre><code>viz.vegaPrint(Enumerate(function() {
<pre><code>viz.auto(Enumerate(function() {
return {
who: categorical([1, 1, 1, 1, 1, 1], ["Plum", "Peacock", "White", "Scarlet", "Mustard", "Green"]),
where: categorical([1, 3, 5, 2, 4], ["candlestick", "knife", "revolver", "rope", "poison"]),
Expand All @@ -122,7 +122,7 @@ <h1>new (vega)</h1>
}))</code></pre>

ccr:
<pre><code>viz.vegaPrint(MH(function() {
<pre><code>viz.auto(MH(function() {
var brand = flip(0.7) ? 'coke' : 'pepsi';
return {
country: uniformDraw(['usa','mexico','canada']),
Expand All @@ -132,7 +132,7 @@ <h1>new (vega)</h1>
}, 2000));</code></pre>

crr:
<pre><code>viz.vegaPrint(MH(function() {
<pre><code>viz.auto(MH(function() {
var brand = flip(0.7) ? 'coke' : 'pepsi'
var x = uniform(0,1);
var y = uniform(0,1);
Expand All @@ -141,7 +141,7 @@ <h1>new (vega)</h1>
},5000))</code></pre>

rrr:
<pre><code>viz.vegaPrint(ParticleFilter(function() {
<pre><code>viz.auto(ParticleFilter(function() {
var x = uniform(0,1);
var y = uniform(0,1);
var z = uniform(0,1);
Expand All @@ -155,13 +155,13 @@ <h1>new (vega)</h1>
<h1>old (d3)</h1>

problem - high probability => huge points:
<pre><code>viz.print(Enumerate(function(){return {
<pre><code>viz.d3auto(Enumerate(function(){return {
"a": flip(.9) ? 0 : 1,
"b": flip(.9) ? 0 : 1,
"c": flip(.99) ? 0 : 1}}))</code></pre>

problem - joint visualization can be bad (nb: problematic for new code too):
<pre><code>viz.print(ParticleFilter(function() {
<pre><code>viz.d3auto(ParticleFilter(function() {
return {
a: gaussian(0,1),
b: categorical([0.1,0.8,0.1],[1.1,2.1,3.1])
Expand All @@ -175,7 +175,7 @@ <h1>old (d3)</h1>
Z: gaussian(0,1)
}
}, 1000);
viz.print(continuous_erp_3d);
viz.d3auto(continuous_erp_3d);
</code></pre>

<pre><code>var discrete_erp_3d = Enumerate(function() {
Expand All @@ -185,7 +185,7 @@ <h1>old (d3)</h1>
with_what: categorical([1, 1, 1, 1, 1], ["dining", "kitchen", "hall", "conservatory", "library"])
}
});
viz.print(discrete_erp_3d);
viz.d3auto(discrete_erp_3d);
</code></pre>

<pre><code>var discrete_erp_2d = Enumerate(function() {
Expand All @@ -194,7 +194,7 @@ <h1>old (d3)</h1>
boolean: flip(0.7)
}
});
viz.print(discrete_erp_2d);
viz.d3auto(discrete_erp_2d);
</code></pre>

<pre><code>var continuous_erp_2d = ParticleFilter(function() {
Expand All @@ -203,15 +203,15 @@ <h1>old (d3)</h1>
Y: gaussian(0, 1)
}
}, 1000);
viz.print(continuous_erp_2d);
viz.d3auto(continuous_erp_2d);
</code></pre>

<pre><code>var continuous_erp = ParticleFilter(function() { return gaussian(0, 1); }, 1000);
viz.print(continuous_erp);
viz.d3auto(continuous_erp);
</code></pre>

<pre><code>var discrete_erp = Enumerate(function() { return flip(0.9) ? "apple" : "orange"; });
viz.print(discrete_erp);
viz.d3auto(discrete_erp);
</code></pre>
</div>

Expand Down
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ function isPseudoDataFrame(arr, strict /* default true*/) {
return _.every(columnTypesOk);
}

var print = require('./old').print;

var wait = function(ms,f) {
setTimeout(f,ms);
}
Expand Down Expand Up @@ -505,7 +503,7 @@ var parallelCoordinates = function(types, support, scores) {
}

// automatically render an ERP
var vegaPrint = function(obj) {
var auto = function(obj) {
var getColumnType = function(columnValues) {
// for now, support real, integer, and categorical
// some questions:
Expand All @@ -531,7 +529,7 @@ var vegaPrint = function(obj) {
};

if (!isErp(obj)) {
// TODO: write wpEditor.warn method, use it to inform user that vegaPrint only works on ERPs
// TODO: write wpEditor.warn method, use it to inform user that auto only works on ERPs
// (though maybe this isn't necessary since we are using __print__ decorator in wp-editor?)
return null;
}
Expand Down Expand Up @@ -795,8 +793,7 @@ function hist(obj, options) {

};

// TODO: rename to scatter after porting erin's vizPrint code to vega
var _scatter = function(xs, ys, options) {
var scatter = function(xs, ys, options) {
options = _.defaults(options || {},
{xLabel: 'x',
yLabel: 'y'});
Expand Down Expand Up @@ -1182,11 +1179,11 @@ function table(obj, options) {


global.viz = {
print: print,
vegaPrint: vegaPrint,
d3auto: require('./old').print,
auto: auto,
bar: bar,
hist: hist,
scatter: _scatter,
scatter: scatter,
density: density,
line: line,
table: table,
Expand Down

0 comments on commit a2f58c4

Please sign in to comment.