zeppelin/docs/development/writingzeppelinvisualization.md
1ambda 90e8b80b56 [ZEPPELIN-2070][DOCS] Create Docs for Spell
### What is this PR for?

Docs for Spell which was added by #1940

### What type of PR is it?
[Documentation]

### Todos
* [x] - Add docs for spell
* [x] - Fix typo in vis docs

### What is the Jira issue?

[ZEPPELIN-2070](https://issues.apache.org/jira/browse/ZEPPELIN-2070)

### How should this be tested?

- `cd docs`
- `/usr/local/bin/bundle exec jekyll serve --watch`
- Open `http://localhost:4000/development/writingzeppelinspell.html`

### Screenshots (if appropriate)

![image](https://cloud.githubusercontent.com/assets/4968473/22772190/9e6cfbfc-eede-11e6-8f36-8ee3749d4b36.png)

![image](https://cloud.githubusercontent.com/assets/4968473/22772341/703c4d54-eedf-11e6-87ba-a8446f35c862.png)

### Questions:
* Does the licenses files need update? - NO
* Is there breaking changes for older versions? - NO
* Does this needs documentation? - YES

Author: 1ambda <1amb4a@gmail.com>

Closes #1998 from 1ambda/ZEPPELIN-2070/docs-for-spell and squashes the following commits:

dbb8082 [1ambda] fix: Typo
af63ff6 [1ambda] fix: Enhance spell doc
9fd2a3b [1ambda] fix: Typo
0851ad1 [1ambda] fix: Typo in spell doc
00d5158 [1ambda] fix: Indent
c7dc9bd [1ambda] fix: Typo in writing in viz
bcc9b3e [1ambda] docs: Add docs for spell
83ee050 [1ambda] docs: Add spell doc to nav
04deb81 [1ambda] fix: Invalid desc in vis docs
2017-02-16 10:25:55 +09:00

6.9 KiB

layout title description group
page Writing a new Visualization(Experimental) Apache Zeppelin Visualization is a pluggable package that can be loaded/unloaded on runtime through Helium framework in Zeppelin. A Visualization is a javascript npm package and user can use them just like any other built-in visualization in a note. development

{% include JB/setup %}

Writing a new Visualization (Experimental)

What is Apache Zeppelin Visualization

Apache Zeppelin Visualization is a pluggable package that can be loaded/unloaded on runtime through Helium framework in Zeppelin. A Visualization is a javascript npm package and user can use them just like any other built-in visualization in notebook.

How it works

1. Load Helium package files from registry

Zeppelin needs to know what Visualization packages are available. Zeppelin will read information of packages from both online and local registry. Registries are configurable through ZEPPELIN_HELIUM_LOCALREGISTRY_DEFAULT env variable or zeppelin.helium.localregistry.default property.

2. Enable packages

Once Zeppelin loads Helium package files from registries, available packages are displayed in Helium menu.

Click 'enable' button.

3. Create and load visualization bundle on the fly

Once a Visualization package is enabled, HeliumBundleFactory creates a js bundle. The js bundle is served by helium/bundle/load rest api endpoint.

4. Run visualization

Zeppelin shows additional button for loaded Visualizations. User can use just like any other built-in visualizations.

Write new Visualization

1. Create a npm package

Create a package.json in your new Visualization directory. Normally, you can add any dependencies in package.json however Zeppelin Visualization package only allows two dependencies: zeppelin-vis and zeppelin-tabledata.

Here's an example

{
  "name": "zeppelin_horizontalbar",
  "description" : "Horizontal Bar chart",
  "version": "1.0.0",
  "main": "horizontalbar",
  "author": "",
  "license": "Apache-2.0",
  "dependencies": {
    "zeppelin-tabledata": "*",
    "zeppelin-vis": "*"
  }
}

2. Create your own visualization

To create your own visualization, you need to create a js file and import Visualization class from zeppelin-vis package and extend the class. zeppelin-tabledata package provides some useful transformations, like pivot, you can use in your visualization. (you can create your own transformation, too).

Visualization class, there're several methods that you need to override and implement. Here's simple visualization that just prints Hello world.

import Visualization from 'zeppelin-vis'
import PassthroughTransformation from 'zeppelin-tabledata/passthrough'

export default class helloworld extends Visualization {
  constructor(targetEl, config) {
    super(targetEl, config)
    this.passthrough = new PassthroughTransformation(config);
  }

  render(tableData) {
    this.targetEl.html('Hello world!')
  }

  getTransformation() {
    return this.passthrough
  }
}

To learn more about Visualization class, check visualization.js.

You can check complete visualization package example here.

Zeppelin's built-in visualization uses the same API, so you can check built-in visualizations as additional examples.

3. Create Helium package file and locally deploy

Helium Package file is a json file that provides information about the application. Json file contains the following information

{
  "type" : "VISUALIZATION",
  "name" : "zeppelin_horizontalbar",
  "description" : "Horizontal Bar chart (example)",
  "license" : "Apache-2.0",
  "artifact" : "./zeppelin-examples/zeppelin-example-horizontalbar",
  "icon" : "<i class='fa fa-bar-chart rotate90flipX'></i>"
}

Place this file in your local registry directory (default ./helium).

type

When you're creating a visualization, 'type' should be 'VISUALIZATION'. Check application type if you're interested in the other types of package.

name

Name of visualization. Should be unique. Allows [A-Za-z90-9_].

description

A short description about visualization.

artifact

Location of the visualization npm package. Support npm package with version or local filesystem path.

e.g.

When artifact exists in npm repository

artifact: "my-visualiztion@1.0.0"

When artifact exists in local file system

artifact: "/path/to/my/visualization"
license

License information.

e.g.

license: "Apache-2.0"
icon

Icon to be used in visualization select button. String in this field will be rendered as a HTML tag.

e.g.

icon: "<i class='fa fa-coffee'></i>"

4. Run in dev mode

Place your Helium package file in local registry (ZEPPELIN_HOME/helium). Run Zeppelin. And then run zeppelin-web in visualization dev mode.

cd zeppelin-web
yarn run dev:helium 

You can browse localhost:9000. Everytime refresh your browser, Zeppelin will rebuild your visualization and reload changes.

5. Publish your visualization

Once it's done, publish your visualization package using npm publish. That's it. With in an hour, your visualization will be available in Zeppelin's helium menu.