Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Commit

Permalink
mimerender-cookiecutter 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gnestor committed Mar 1, 2017
1 parent 1b26a94 commit bacc56a
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 483 deletions.
7 changes: 7 additions & 0 deletions .cookiecutter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default_context:
author_name: "Grant Nestor"
author_email: "[email protected]"
mime_type: "application/vnd.vega.v2+json"
file_extension: "vg"
mime_short_name: "Vega"
extension_name: "jupyterlab_vega"
18 changes: 14 additions & 4 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
jupyterlab_vega/static/
jupyterlab_vega/__pycache__/
jupyterlab_vega.egg-info
node_modules/
labextension/lib/
nbextension/lib/
nbextension/embed/
*/node_modules/
npm-debug.log
*.egg-info/
build/
dist/

# Compiled javascript
jupyterlab_vega/__pycache__/
jupyterlab_vega/static/

# OS X
.DS_Store
126 changes: 11 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# jupyterlab_vega

A JupyterLab and Jupyter Notebook extension for rendering Vega and Vega-lite
A JupyterLab and Jupyter Notebook extension for rendering Vega

![output renderer](http://g.recordit.co/d9dWoMUUA3.gif)
![output renderer](http://g.recordit.co/QAsC7YULcY.gif)

## Prerequisites

* JupyterLab ^0.16.0 and/or Notebook >=4.3.0
* JupyterLab ^0.17.0 and/or Notebook >=4.3.0

## Usage

Expand All @@ -16,122 +16,18 @@ To render Vega output in IPython:
from jupyterlab_vega import Vega

Vega({
"width": 400,
"height": 200,
"padding": {"top": 10, "left": 30, "bottom": 30, "right": 10},
"data": [
{
"name": "table",
"values": [
{"x": 1, "y": 28}, {"x": 2, "y": 55},
{"x": 3, "y": 43}, {"x": 4, "y": 91},
{"x": 5, "y": 81}, {"x": 6, "y": 53},
{"x": 7, "y": 19}, {"x": 8, "y": 87},
{"x": 9, "y": 52}, {"x": 10, "y": 48},
{"x": 11, "y": 24}, {"x": 12, "y": 49},
{"x": 13, "y": 87}, {"x": 14, "y": 66},
{"x": 15, "y": 17}, {"x": 16, "y": 27},
{"x": 17, "y": 68}, {"x": 18, "y": 16},
{"x": 19, "y": 49}, {"x": 20, "y": 15}
]
}
],
"scales": [
{
"name": "x",
"type": "ordinal",
"range": "width",
"domain": {"data": "table", "field": "x"}
},
{
"name": "y",
"type": "linear",
"range": "height",
"domain": {"data": "table", "field": "y"},
"nice": True
}
],
"axes": [
{"type": "x", "scale": "x"},
{"type": "y", "scale": "y"}
],
"marks": [
{
"type": "rect",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"scale": "x", "field": "x"},
"width": {"scale": "x", "band": True, "offset": -1},
"y": {"scale": "y", "field": "y"},
"y2": {"scale": "y", "value": 0}
},
"update": {
"fill": {"value": "steelblue"}
},
"hover": {
"fill": {"value": "red"}
}
}
}
]
})
```

Or Vega-lite:

```python
from jupyterlab_vega import VegaLite

spec = {
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
"string": "string",
"array": [1, 2, 3],
"bool": True,
"object": {
"foo": "bar"
}
}
data = [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
]

VegaLite(spec, data)
```

Using a pandas DataFrame:

```python
from jupyterlab_vega import VegaLite
import pandas as pd

df = pd.reada_json('cars.json')

VegaLite({
"mark": "point",
"encoding": {
"y": {"type": "quantitative","field": "Acceleration"},
"x": {"type": "quantitative","field": "Horsepower"}
}
}, df)
```

Using Altair:

```python
import altair

cars = altair.load_dataset('cars')
altair.Chart(cars).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
)
})
```

To render a `.vg` or `.vl` (`.vg.json` and `.vl.json` are also supported) file as a tree, simply open it:
To render a `.vg` file as a tree, simply open it:

![file renderer](http://g.recordit.co/z5LF4W28nv.gif)
![file renderer](http://g.recordit.co/cbf0xnQHKn.gif)

## Install

Expand Down
9 changes: 4 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ This document guides an extension maintainer through creating and publishing a r

## Update version number

Update the version number in `setup.py` and in `package.json`.
Update the version number in `setup.py`, `labextension/package.json`, and `nbextension/package.json`.

## Remove generated files

Remove old Javascript bundle builds and delete the `dist/` folder to remove old Python package builds:
Remove old Javascript bundle and Python package builds:

```bash
npm run clean
rm -rf dist/
rm -rf jupyterlab_vega/static
```

## Build the package

Build the Javascript extension bundle, then build the Python package and wheel:

```bash
npm run build
bash build.js
python setup.py sdist
python setup.py bdist_wheel --universal
```
Expand Down
3 changes: 0 additions & 3 deletions component/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.Vega {

}
.vega-actions {
display: none;
}
54 changes: 7 additions & 47 deletions component/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
import React from 'react';
import vegaEmbed from 'vega-embed';
import './index.css';

const DEFAULT_WIDTH = 500;
const DEFAULT_HEIGHT = DEFAULT_WIDTH / 1.5;

export default class Vega extends React.Component {

static defaultProps = {
renderedCallback: () => ({}),
embedMode: 'vega-lite'
};

componentDidMount() {
this.embed(
this.el,
this.props.data,
this.props.embedMode,
this.props.renderedCallback
);
}

shouldComponentUpdate(nextProps) {
return this.props.data !== nextProps.data;
}

componentDidUpdate() {
this.embed(
this.el,
this.props.data,
this.props.embedMode,
this.props.renderedCallback
);
}
export default class VegaComponent extends React.Component {

render() {
return <div ref={el => this.el = el} />;
return (
<div className="Vega">
{JSON.stringify(this.props.data)}
</div>
);
}

embed = (el, spec, mode, cb) => {
const embedSpec = { mode, spec };
const width = DEFAULT_WIDTH;
const height = DEFAULT_HEIGHT;
if (mode === 'vega-lite') {
embedSpec.spec.config = {
...embedSpec.spec.config,
cell: { width, height }
};
}
vegaEmbed(el, embedSpec, cb);
}


}
6 changes: 1 addition & 5 deletions component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"author": "Grant Nestor <[email protected]>",
"license": "ISC",
"dependencies": {
"d3": "3.5.17",
"react": "^15.3.2",
"vega": "^2.6.1",
"vega-embed": "^2.2.0",
"vega-lite": "^1.1.3"
"react": "^15.3.2"
}
}
4 changes: 1 addition & 3 deletions labextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ A JupyterLab extension for rendering Vega

## Prerequisites

* `jupyterlab@^0.16.0`

![file renderer](http://g.recordit.co/cbf0xnQHKn.gif)
* `jupyterlab@^0.17.0`

## Development

Expand Down
41 changes: 30 additions & 11 deletions labextension/build_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@ var path = require('path');

buildExtension({
name: 'jupyterlab_vega',
entry: './src/plugin.js',
outputDir: '../jupyterlab_vega/static',
entry: path.join(__dirname, 'src', 'plugin.js'),
outputDir: path.join(
__dirname,
'..',
'jupyterlab_vega',
'static'
),
useDefaultLoaders: false,
config: {
module: {
loaders: [
{ test: /\.html$/, loader: 'file-loader' },
{ test: /\.(jpg|png|gif)$/, loader: 'file-loader' },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
{
test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
},
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' },
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.js$/,
exclude: /node_modules(?!\/jupyterlab_vega_react)/,
{
test: /\.js$/,
include: [
path.join(__dirname, 'src'),
path.join(__dirname, 'node_modules', 'jupyterlab_vega_react')
],
loader: 'babel-loader',
query: {
presets: ['latest', 'stage-0', 'react']
}
query: { presets: [ 'latest', 'stage-0', 'react' ] }
}
]
}
Expand Down
11 changes: 5 additions & 6 deletions labextension/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "jupyterlab_vega_labextension",
"version": "0.16.0",
"version": "0.17.0",
"description": "A JupyterLab extension for rendering Vega",
"author": "Grant Nestor <[email protected]>",
"main": "lib/plugin.js",
Expand All @@ -12,7 +12,7 @@
],
"scripts": {
"build": "node build_extension.js",
"watch": "watch \"npm run build\" src ../component --wait 10 --ignoreDotFiles",
"watch": "watch \"npm install\" src ../component --wait 10 --ignoreDotFiles",
"preinstall": "npm install ../component",
"prepublish": "npm run build",
"extension:install": "jupyter labextension install --symlink --py --sys-prefix jupyterlab_vega",
Expand All @@ -21,20 +21,19 @@
"extension:disable": "jupyter labextension disable --py --sys-prefix jupyterlab_vega"
},
"dependencies": {
"jupyterlab": "^0.16.0",
"phosphor": "^0.7.0",
"jupyterlab": "^0.17.0",
"@phosphor/algorithm": "^0.1.0",
"@phosphor/widgets": "^0.1.3",
"react": "^15.3.2",
"react-dom": "^15.3.2"
},
"devDependencies": {
"@jupyterlab/extension-builder": ">=0.10.0",
"@jupyterlab/services": ">=0.25.0",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"rimraf": "^2.5.4",
"watch": "^1.0.1"
}
}
Loading

0 comments on commit bacc56a

Please sign in to comment.