Skip to content

Commit

Permalink
refine docs/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jan 17, 2022
1 parent e240ab7 commit b262f59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
43 changes: 25 additions & 18 deletions docs/src/pages/docs/Contributing/creating-viz-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ version: 1

Visualizations in Superset are implemented in JavaScript or TypeScript. Superset
comes preinstalled with several visualizations types (hereafter "viz plugins") that
can be found under the `superset-frontend/plugins` directory. Plugins are added to
can be found under the `superset-frontend/plugins` directory. Viz plugins are added to
the application in the `superset-frontend/src/visualizations/presets/MainPreset.js`.
The Superset project is always happy to review proposals for new high quality viz
plugins. However, for highly custom viz types it is recommended to maintain a fork
of Superset, and add the custom built plugins by hand.
of Superset, and add the custom built viz plugins by hand.

### Prerequisites

In order to create a new visualization plugin, you need the following:
In order to create a new viz plugin, you need the following:

- Run MacOS or Linux (Windows is not officially supported, but may work)
- Node 16
- Node.js 16
- npm 7 or 8

### Creating a simple Hello World plugin
A general familiarity with [React](https://reactjs.org/) and the npm/Node system is
also recommended.

### Creating a simple Hello World viz plugin

To get started, you need the Superset Yeoman Generator. It is recommended to use the
version of the template that ships with the version of Superset you are using. This
Expand All @@ -33,17 +36,21 @@ can be installed by doing the following:
```bash
npm i -g yo
cd superset-frontend/packages/generator-superset
npm i
npm link
```

After this you can proceed to create your viz plugin. Create a new directory wherever
you have your repos (we'll assume under `~/src/`) with the prefix
`superset-plugin-chart` and run the Yeoman generator:
After this you can proceed to create your viz plugin. Create a new directory for your
viz plugin with the prefix `superset-plugin-chart` and run the Yeoman generator:

```bash
mkdir /tmp/superset-plugin-chart-hello-world
cd /tmp/superset-plugin-chart-hello-world
```

Initialize the viz plugin:

```bash
cd ~/src
mkdir superset-plugin-chart-hello-world
cd superset-plugin-chart-hello-world
yo @superset-ui/superset
```

Expand Down Expand Up @@ -86,26 +93,25 @@ $ yo @superset-ui/superset
create src/images/thumbnail.png
```

To build the plugin, run the following commands:
To build the viz plugin, run the following commands:

```
npm i --force
npm run build
```

Alternatively, to run the plugin in development mode (=rebuilding whenever changes
Alternatively, to run the viz plugin in development mode (=rebuilding whenever changes
are made), start the dev server with the following command:

```
npm run dev
```

To add the package to Superset, go to the `superset-frontend` subdirectory in your
Superset source folder (assuming both the `superset-plugin-chart-hello-world` plugin
and `superset` repos are in the same root directory) and run
Superset source folder run

```bash
npm i -S ../../superset-plugin-chart-hello-world
npm i -S /tmp/superset-plugin-chart-hello-world
```

If you publish your package to npm, you can naturally install directly from there, too.
Expand All @@ -116,14 +122,15 @@ and make the following changes:
import { SupersetPluginChartHelloWorld } from 'superset-plugin-chart-hello-world';
```

to import the plugin and later add the following to the array that's passed to the
to import the viz plugin and later add the following to the array that's passed to the
`plugins` property:

```js
new SupersetPluginChartHelloWorld().configure({ key: 'ext-hello-world' }),
```

After that the plugin should show up when you run Superset, e.g. the development server:
After that the viz plugin should show up when you run Superset, e.g. the development
server:

```bash
npm run dev-server
Expand Down
7 changes: 3 additions & 4 deletions superset-frontend/packages/generator-superset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ npm install -g @superset-ui/generator-superset

## Usage

Generate a new package or visualization plugin in `@superset-ui`
Generate a new package or visualization plugin:

```bash
cd superset-ui/packages
mkdir superset-ui-new-package
cd superset-ui-new-package
mkdir /tmp/superset-plugin-chart-hello-world
cd /tmp/superset-plugin-chart-hello-world
yo @superset-ui/superset
```

Expand Down

0 comments on commit b262f59

Please sign in to comment.