Skip to content

Commit

Permalink
added ex using node
Browse files Browse the repository at this point in the history
  • Loading branch information
fredo-dedup committed Mar 26, 2016
1 parent 0527d32 commit 216ee55
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Dolphin]
Timestamp=2016,3,24,21,53,59
Version=3
ViewMode=1
3 changes: 3 additions & 0 deletions docs/build/assets/Lapidary.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div.wy-menu-vertical ul.current li.toctree-l3 a {
font-weight: bold;
}
8 changes: 8 additions & 0 deletions docs/build/assets/mathjaxhelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MathJax.Hub.Config({
"tex2jax": { inlineMath: [ [ '$', '$' ] ] }
});
MathJax.Hub.Config({
config: ["MMLorHTML.js"],
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
extensions: ["MathMenu.js", "MathZoom.js"]
});
34 changes: 34 additions & 0 deletions docs/build/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<a id='VegaLite.jl-Documentation-1'></a>

# VegaLite.jl Documentation

<a id='Base.LinAlg.scale-Tuple{}' href='#Base.LinAlg.scale-Tuple{}'>#</a>
**`Base.LinAlg.scale`** &mdash; *Method*.

---


Sets scale properties for the scale argument within `encoding()` :

```julia
encoding_x(..., scale=scale(round=true, bandSize=12), ...)
```

* `type` (`AbstractString`) : ScaleType, one of "linear", "log", "pow", "sqrt", "quantile", "quantize", "ordinal", "time", "utc".
* `domain` (`AbstractString[]`) : The domain of the scale, representing the set of data values. For quantitative data, this can take the form of a two-element array with minimum and maximum values. For ordinal/categorical data, this may be an array of valid input values. The domain may also be specified by a reference to a data source.
* `range` (`AbstractString[]`) : The range of the scale, representing the set of visual values. For numeric values, the range can take the form of a two-element array with minimum and maximum values. For ordinal or quantized data, the range may by an array of desired output values, which are mapped to elements in the specified domain. For ordinal scales only, the range can be defined using a DataRef: the range values are then drawn dynamically from a backing data set.
* `round` (`Bool`) : If true, rounds numeric output values to integers. This can be helpful for snapping to the pixel grid.

Ordinal

* `bandSize` (`Real`) : minimum 0
* `padding` (`Real`) : Applies spacing among ordinal elements in the scale range. The actual effect depends on how the scale is configured. If the __points__ parameter is `true`, the padding value is interpreted as a multiple of the spacing between points. A reasonable value is 1.0, such that the first and last point will be offset from the minimum and maximum value by half the distance between points. Otherwise, padding is typically in the range [0, 1] and corresponds to the fraction of space in the range interval to allocate to padding. A value of 0.5 means that the range band width will be equal to the padding width. For more, see the [D3 ordinal scale documentation](https://github.com/mbostock/d3/wiki/Ordinal-Scales).

Typical

* `clamp` (`Bool`) : If true, values that exceed the data domain are clamped to either the minimum or maximum range value
* `nice` (`Union{Bool, AbstractString}`) : If specified, modifies the scale domain to use a more human-friendly value range. If specified as a true boolean, modifies the scale domain to use a more human-friendly number range (e.g., 7 instead of 6.96). If specified as a string, modifies the scale domain to use a more human-friendly value range. For time and utc scale types only, the nice value should be a string indicating the desired time interval ("second", "minute", "hour", "day", "week", "month", "year").
* `exponent` (`Real`) : Sets the exponent of the scale transformation. For pow scale types only, otherwise ignored.
* `zero` (`Bool`) : If true, ensures that a zero baseline value is included in the scale domain. This option is ignored for non-quantitative scales.

3 changes: 3 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Lapidary, VegaLite

makedocs()
4 changes: 4 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# VegaLite.jl Documentation

{docs}
scale()
58 changes: 58 additions & 0 deletions examples/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"width": 400,
"height": 400,
"data": [
{
"name": "table",
"values": [12, 23, 47, 6, 52, 19],
"transform": [{"type": "pie", "field": "data"}]
}
],
"scales": [
{
"name": "r",
"type": "sqrt",
"domain": {"data": "table", "field": "data"},
"range": [20, 100]
}
],
"marks": [
{
"type": "arc",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"startAngle": {"field": "layout_start"},
"endAngle": {"field": "layout_end"},
"innerRadius": {"value": 20},
"outerRadius": {"scale": "r", "field": "data"},
"stroke": {"value": "#fff"}
},
"update": {
"fill": {"value": "#ccc"}
},
"hover": {
"fill": {"value": "pink"}
}
}
},
{
"type": "text",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"radius": {"scale": "r", "field": "data", "offset": 8},
"theta": {"field": "layout_mid"},
"fill": {"value": "#000"},
"align": {"value": "center"},
"baseline": {"value": "middle"},
"text": {"field": "data"}
}
}
}
]
}
74 changes: 74 additions & 0 deletions examples/tst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//#!/usr/bin/env node
// Render a Vega specification to SVG
require('vega')

var helpText =
'Render a Vega specification to SVG.\n\n' +
'Usage: vg2svg vega_json_file [output_svg_file]\n' +
' If output_svg_file is not provided, writes to stdout.\n\n' +
'To load data, you may need to set a base directory:\n' +
' For web retrieval, use `-b http://host/data/`. \n' +
' For files, use `-b file:///dir/data/` (absolute) or `-b data/` (relative).';

var svgHeader =
'<?xml version="1.0" encoding="utf-8"?>\n' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ' +
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n';

// import required libraries
var path = require('path'),
fs = require('fs'),
vg = require('../index');

// arguments
var args = require('yargs')
.usage(helpText)
.demand(1)
.string('b').alias('b', 'base')
.describe('b', 'Base directory for data loading.')
.boolean('h').alias('h', 'header')
.describe('h', 'Include XML header and SVG doctype.')
.argv;

// set baseURL if provided on command line
var base = 'file://' + process.cwd() + path.sep;
if (args.b) {
// if no protocol, assume files, relative to current dir
base = /^[A-Za-z]+\:\/\//.test(args.b) ? args.b + path.sep
: 'file://' + process.cwd() + path.sep + args.b + path.sep;
}
vg.config.load.baseURL = base;

// input / output files
var header = args.h ? svgHeader : '',
specFile = args._[0],
outputFile = args._[1] || null;

// load spec, render to svg
fs.readFile(specFile, 'utf8', function(err, text) {
if (err) throw err;
var spec = JSON.parse(text);
render(spec);
});

// ---

function writeSVG(svg, file) {
svg = header + svg;
if (file) { // write to file
fs.writeFile(file, svg, function(err) { if (err) throw err; });
} else { // write to stdout
process.stdout.write(svg);
}
}

function render(spec) {
vg.parse.spec(spec, function(err, chart) {
if (err) { throw err; }

var view = chart({ renderer: 'svg' })
.update();

writeSVG(view.svg(), outputFile);
});
}
77 changes: 77 additions & 0 deletions examples/tst2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//#!/usr/bin/env node
// Render a Vega specification to SVG
vg = require('vega')


var spec = {
"width": 400,
"height": 400,
"data": [
{
"name": "table",
"values": [12, 23, 47, 6, 52, 19],
"transform": [{"type": "pie", "field": "data"}]
}
],
"scales": [
{
"name": "r",
"type": "sqrt",
"domain": {"data": "table", "field": "data"},
"range": [20, 100]
}
],
"marks": [
{
"type": "arc",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"startAngle": {"field": "layout_start"},
"endAngle": {"field": "layout_end"},
"innerRadius": {"value": 20},
"outerRadius": {"scale": "r", "field": "data"},
"stroke": {"value": "#fff"}
},
"update": {
"fill": {"value": "#ccc"}
},
"hover": {
"fill": {"value": "pink"}
}
}
},
{
"type": "text",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"radius": {"scale": "r", "field": "data", "offset": 8},
"theta": {"field": "layout_mid"},
"fill": {"value": "#000"},
"align": {"value": "center"},
"baseline": {"value": "middle"},
"text": {"field": "data"}
}
}
}
]
}

render(spec);

function render(spec) {
vg.parse.spec(spec, function(chart) {
var view = chart({ renderer: "svg" })
.update();

var svg = view.svg()
process.stdout.write(svg);
});
// var canvas = view.canvas();
// do something with the node-canvas instance...
}

0 comments on commit 216ee55

Please sign in to comment.