mirror of
https://github.com/apache/superset.git
synced 2026-04-13 21:24:28 +00:00
* setup docusaurus
* rename
* add introduction content
* chore(docsV2): move content from docs to docsV2 (#17714)
* add FAQs and contribution pages
* chore: add api, security, and roadmap pages, include swaggerui in dependency for api page
* chore: move api page header below imports
* chore: change API page info alert to use built in Infima class instead of custom class
Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
* chore(docs-v2): moving more markdown content to new documentation site (#17736)
* chore: move markdown content and images for docs installation directory to docs-v2
* chore: move docs miscellaneous directory content to docs-v2
* chore(docs-v2): move over connecting to databases content and rename some files to .mdx
Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
* Update styling and logo (#17990)
* update styling
* update colors
* chore(docs-v2): remove blog and tutorial and update some styling (#17929)
* add superset logo and favicon, change styles to better match current docs, add prettierrc
* change file types to mdx
* Add simple superset dark mode freindly logo
* clean up default pages - blog and tutorial docs
Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
* Chore: moving charts and dashboard to docusaurus (#18036)
* add contributing add creating charts and dashboards
* delete extra images
* update rat-excludes
* Port homepage (#18115)
* Port community page (#18128)
* chore: add seo redirects for Docs v@ (#18092)
* fix: handle null values in time-series table (#18039)
* cleanup column_type_mappings (#17569)
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
* important change to MakeFile (#18037)
* Update superset-e2e.yml (#18041)
* Revert "Update superset-e2e.yml (#18041)" (#18051)
This reverts commit b5652739c9.
* feat: Trino Authentications (#17593)
* feat: support Trino Authentications
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
* docs: Trino Authentications
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
* chore(supeset.utils.core): move all database utils to database utils module (#18058)
* chore(plugin-chart-echarts): add types to controls (#18059)
* fix(generator): more cleanup to plugin framework (#18027)
* fix(generator): more cleanup to plugin framework
* fix typo and package name
* add docs
* fix typo
* Update superset-frontend/webpack.config.js
Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
* fix generator reference
* add steps to tutorial and fix package version
* refine docs/readme
Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
* feat(advanced analytics): support groupby in resample (#18045)
* fix(dashboard): scope of nativefilter not update (#18048)
* fix(generator): add lockfile and fix styling issues (#18073)
* fix(generator): add lockfile and fix styling issues
* fix margins and remove redundant scroll
* update tutorial
* refactor(sql_lab): SQL Lab Persistent Saved State (#17771)
* a lot of console logs
* testing
* test
* added saved_query to remoteId
* created useEffect so that title properly changes in modal
* Update superset-frontend/src/SqlLab/actions/sqlLab.js
Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
* refactor(example_data): replace the way the birth_names data is loaded to DB (#18060)
* refactor: replace the way the birth_names data is loaded to DB
* fix failed unit test
* fix failed unit test
* fix failed tests
* fix pass wrong flag of support datetime type
* remove unused fixture
* feat: add chart description in info tooltip (#17207)
* feat: add chart list description
* fix: text overflow
* fix: text-overflow with line-height
* Correction of proper names format in README (#18087)
* chore: added SEO routes
* fix can't use examples helpers on non app context based environment (#18086)
* chore: split CLI into multiple files (#18082)
* chore: split CLI into multiple files
* Update tests
* Who fixes the fixtures?
* Add subcommands dynamically
* Rebase
* fix misspelling (#18097)
* refactor: sqleditorleftbar to functional (#17807)
* Working on converting sqleditorleftbar to functional component
* Creating draft PR to address bug
* Still working on solving re rendering bug
* infinite rerender fix
* Creating draft PR to address bug
* Cleaning up in preparation for push
* Made changes suggested by Elizabeth
* Fixed issues as per Lindsey's comment
Co-authored-by: Arash <arash.afghahi@gmail.com>
* fix rat excludes and headers
* fix(docs): fix path of image for "Create New Chart" (#18089)
* Migrate Checkbox story to tsx - see #18100 (#18101)
Looks good!
* refactor: migrate RowCountLabel to TypeScript & added story (#18105)
* enable superbook for explore component
* migrate RowCountLabel to TypeScript
* add storybook for RowCountLabel
* fix: logging warning on dataframe (don't use python's warnings) (#18111)
* fix: logging warning on dataframe (don't use python's warnings)
* lint
* update changelog and updating for 1.4.0 (#18083)
* feat: Adds a key-value endpoint to store charts form data (#17882)
* feat: Adds a key-value endpoint to store charts form data
* Fixes linting problems
* Removes the query_params from the endpoints
* Refactors the commands
* Removes unused imports
* Changes the parameters to use dataclass
* Adds more access tests
* Gets the first dataset while testing
* Adds unit tests for the check_access function
* Changes the can_access check
* Always check for dataset access
* fix(explore): fix chart embed code modal glitch (#17843)
* feat(plugin-chart-echarts): support non-timeseries x-axis (#17917)
* feat(plugin-chart-echarts): support non-timeseries x-axis
* fix tests
* change formula return type from Date to number
* add x_axis test coverage
* rename func and improve coverage
* add x-axis control to bar chart
* remove redundant console.log
* fix description
* make x-axis control mandatory
* 🙃
* fix x-axis formatter
* fix showValues
* fix implicit rDTTM_ALIAS references in postProcessing
* replace TIME_COLUMN with DTTM_ALIAS
* fix remaining implicit indexes
* fix: Disable filtering on wide result sets (#18021)
* fix: handle null values in time-series table (#18039)
* cleanup column_type_mappings (#17569)
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
* important change to MakeFile (#18037)
* add missing is_timeseries to pivot op
Co-authored-by: Erik Ritter <erik.ritter@airbnb.com>
Co-authored-by: Grace Guo <grace.guo@airbnb.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
* feat(country-map): added new countries in country-chart-map (#18081)
* chore: migrating storybook jsx to typescript #18100 (#18133)
* Migrating storybook jsx to typescript #18100
* Migrating storybook jsx to typescript
Co-authored-by: Jayakrishnan Karolil <jayakrishnan.karolil@nielsen.com>
* feat(annotation): add toast feedback to annotation templates (#18116)
* feat(dashboard): add toast feedback to dashboard actions (#18114)
* feat(explore): more toast feedback on user actions in Explore (#18108)
* feat(explore): add toasts feedback when user copies chart url
* Show toast message when updating chart properties
* Change toast type to success when saving chart
* Use success toast from props
* Fix tests
* Use withToasts instead of dispatch
* Use PropertiesModalProps instead of any
* Docs: fix typo (#18125)
* fix: undefined error when adding extra sequential color scheme (#18152)
* feat: allow assets to be managed externally (#18093)
* feat: allow assets to be managed externally
* Use server_default
* chore: use pkg_resources for cleaner config (#18130)
* refactor: Moves the Explore form_data endpoint (#18151)
* refactor: Moves the Explore form_data endpoint
* Removes unused imports
* Fixes openapi schema error
* Fixes typo
* Renames and UPDATING.md
Co-authored-by: Grace Guo <grace.guo@airbnb.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
Co-authored-by: Hugh A. Miles II <hughmil3s@gmail.com>
Co-authored-by: ofekisr <35701650+ofekisr@users.noreply.github.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
Co-authored-by: Yongjie Zhao <yongjie.zhao@gmail.com>
Co-authored-by: Stephen Liu <750188453@qq.com>
Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
Co-authored-by: Adam Dobrawy <ad-m@users.noreply.github.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Emily Wu <86927881+em0227@users.noreply.github.com>
Co-authored-by: Josue Lugaro <82119536+JosueLugaro@users.noreply.github.com>
Co-authored-by: Arash <arash.afghahi@gmail.com>
Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Erik Ritter <erik.ritter@airbnb.com>
Co-authored-by: Hammad-Raza <hammadraza42@hotmail.com>
Co-authored-by: jayakrishnankk <kk.jayakrishnan@gmail.com>
Co-authored-by: Jayakrishnan Karolil <jayakrishnan.karolil@nielsen.com>
Co-authored-by: Farid Rener <proteusvacuum@users.noreply.github.com>
* remove unneeded requirement
Co-authored-by: Corbin Robb <31329271+corbinrobb@users.noreply.github.com>
Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
Co-authored-by: Daniel W <61300812+The-hyphen-user@users.noreply.github.com>
Co-authored-by: Geido <60598000+geido@users.noreply.github.com>
Co-authored-by: Srini Kadamati <skadamat@gmail.com>
Co-authored-by: Grace Guo <grace.guo@airbnb.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
Co-authored-by: ofekisr <35701650+ofekisr@users.noreply.github.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
Co-authored-by: Yongjie Zhao <yongjie.zhao@gmail.com>
Co-authored-by: Stephen Liu <750188453@qq.com>
Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
Co-authored-by: Adam Dobrawy <ad-m@users.noreply.github.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Emily Wu <86927881+em0227@users.noreply.github.com>
Co-authored-by: Josue Lugaro <82119536+JosueLugaro@users.noreply.github.com>
Co-authored-by: Arash <arash.afghahi@gmail.com>
Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Erik Ritter <erik.ritter@airbnb.com>
Co-authored-by: Hammad-Raza <hammadraza42@hotmail.com>
Co-authored-by: jayakrishnankk <kk.jayakrishnan@gmail.com>
Co-authored-by: Jayakrishnan Karolil <jayakrishnan.karolil@nielsen.com>
Co-authored-by: Farid Rener <proteusvacuum@users.noreply.github.com>
233 lines
9.8 KiB
Plaintext
233 lines
9.8 KiB
Plaintext
---
|
|
title: Building Custom Viz Plugins
|
|
hide_title: true
|
|
sidebar_position: 11
|
|
version: 1
|
|
---
|
|
|
|
import useBaseUrl from "@docusaurus/useBaseUrl";
|
|
|
|
This is a tutorial to help you build a "Hello World" viz plugin. The intent is to provide a basic
|
|
scaffolding to build any sort of data visualization, using any viz libary you'd like (e.g. ECharts,
|
|
AntV, HighCharts, VX, and D3.).
|
|
|
|
You can build the Hello World plugin by running a [Yeoman](https://yeoman.io/) generator, which
|
|
takes a few simple options, and provides this plugin scaffolding.
|
|
|
|
## Getting Set Up
|
|
|
|
### Install Yeoman and the Superset Package Generator
|
|
|
|
This Hello World plugin we'll be building is generated automatically with
|
|
[Yeoman](https://yeoman.io/). Let's first get that installed by opening up a terminal and installing
|
|
both the `yo` module and the
|
|
[superset package generator](https://github.com/apache-superset/superset-ui/tree/master/packages/generator-superset)
|
|
(`v0.14.7`) to create the new plugin.
|
|
|
|
```
|
|
npm install -g yo @superset-ui/generator-superset
|
|
```
|
|
|
|
### Install Superset
|
|
|
|
There are
|
|
[complete instructions](https://github.com/apache/superset#installation-and-configuration)
|
|
available on the [Superset Github repository](https://github.com/apache/superset). In a
|
|
nutshell, the easiest way is to:
|
|
|
|
1. Have a Mac or linux-based machine
|
|
2. Install [Docker](https://docs.docker.com/get-docker/)
|
|
3. Clone [the repository](https://github.com/apache/superset) to your computer
|
|
4. Use your terminal to `cd` into the `superset` directory
|
|
5. Run `docker-compose up`
|
|
6. Open _another_ terminal, and `cd` into `superset/superset-frontend`
|
|
7. Run `npm install` to load up all the npm packages.
|
|
8. Run `npm run dev-server` to spin up the Webpack hot-reloading server
|
|
9. Wait for it to build, and then open your browser to `http://localhost:9000` and log in with
|
|
`admin`/`admin`. You're off to the races! (Note: we'll be restarting this later)
|
|
|
|
### Install Superset-UI
|
|
|
|
1. Clone [the `superset-ui` repository](https://github.com/apache-superset/superset-ui) to your
|
|
computer. It can sit in the same parent directory as your `superset` repo
|
|
2. Use your terminal to `cd` into `superset-ui`
|
|
3. Run `yarn install` and wait for all the packages to get installed
|
|
|
|
## Build Your "Hello, World"
|
|
|
|
### ~~Write~~ _generate_ some code!
|
|
|
|
1. Using your terminal, `cd` into your local `superset-ui` repo folder and then into the `plugins`
|
|
subdirectory.
|
|
2. Make a new directory for your plugin, i.e. `mkdir plugin-chart-hello-world`. **Note:** we
|
|
_highly_ recommend following the `plugin-chart-your-plugin-name` pattern.
|
|
3. Now `cd plugin-chart-hello-world`
|
|
4. Finally, run `yo @superset-ui/superset`
|
|
5. Select `Create superset-ui chart plugin package` on the following screen:
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-1-yeoman-select.png")} />{" "}
|
|
|
|
6. Give it a name (in our case, go with the default, based on the folder name):
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-2-yeoman-package-name.png")}
|
|
/>
|
|
|
|
7. Give it a description (again, default is fine!)
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-3-yeoman-description.png")}
|
|
/>{" "}
|
|
|
|
8. Choose which type of React component you want to make (Class, or Function component).
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-4-yeoman-component-type.png")}
|
|
/>{" "}
|
|
|
|
9. Select whether you'd like your visualization to be timeseries-based or not
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-5-yeoman-timeseries.png")}
|
|
/>{" "}
|
|
|
|
10. Select whether or not you want to include badges at the top of your README file (really only
|
|
needed if you intend to contribute your plugin to the `superset-ui` repo).
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-6-yeoman-badges.png")} />{" "}
|
|
|
|
11. Admire all the files the generator has created for you. Note that EACH of these is chock full of
|
|
comments about what they're for, and how best to use them.
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-7-yeoman-files.png")} />{" "}
|
|
|
|
### Add your Plugin to Superset (with NPM Link)
|
|
|
|
Now, we want to see this thing actually RUN! To do that, we'll add your package to Superset and
|
|
embrace the magic power of `npm link` to see it in-situ, without needing to **build** the plugin, or
|
|
open any PRs on Github.
|
|
|
|
1. Add your package to the `package.json` file in `superset/superset-frontend`.
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-8-package-json.png")} />{" "}
|
|
|
|
Note: Do _not_ run `npm install`... explanation below.
|
|
|
|
2. Add your plugin to the `MainPreset.js` file (located in
|
|
`superset/superset-frontend/src/visualizations/presets/MainPreset.js`) in two places,
|
|
alongside the other plugins.
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-9-mainpreset-import.png")}
|
|
/>{" "}
|
|
|
|
{' '}
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-9-mainpreset-register.png")}
|
|
/>
|
|
|
|
3. Open a terminal window to `superset/superset-frontend`. If you did the Install Superset
|
|
steps above, you may still have webpack running there, and you can just stop it with `ctrol-c`.
|
|
If not, just open a new window and or `cd` to that directory path.
|
|
|
|
4) Use `npm link` to symlink plugin, using a relative path to `superset-ui` and your plugin folder,
|
|
e.g. `npm link ../../superset-ui/plugins/plugin-chart-hello-world`.
|
|
|
|
5. Restart your webpack dev server with `npm run dev-server`. You'll know it worked if you see a
|
|
line stating
|
|
`[Superset Plugin] Use symlink source for @superset-ui/plugin-chart-hello-world @ ^0.0.0`.
|
|
|
|
**NOTE:** If/when you do an `npm install` that erases the symlink generated by `npm link`, so you'll
|
|
have to redo those steps.
|
|
|
|
**NOTE:** Dynamic import is a work in progress. We hope you won't even need to DO this soon. We'll
|
|
be blogging again when that day comes, we assure you. In short, we have a goal to make editing
|
|
`package.json` and `MainPreset.js` unnecessary, so all the code changes are made in ONE repo.
|
|
|
|
### See it with your own eyes!
|
|
|
|
You should now be able to go to the Explore view in your local Superset and add a new chart! You'll
|
|
see your new plugin when you go to select your viz type.
|
|
|
|
<img
|
|
src={useBaseUrl("/img/custom-plugins/plugin-10-hello-thumbnail.png")}
|
|
/>{" "}
|
|
|
|
Now you can load up some data, and you'll see it appear in the plugin!
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-11-explore-view.png")} />{" "}
|
|
|
|
The plugin also outputs three things to your browser's console:
|
|
|
|
- `formData`, a.k.a. everything sent into your viz from the controls
|
|
- `props`, as output from the `transformProps` file for your plugin's consumption
|
|
- The actual HTML element, which your plugin has hooks into for any necessary DOM maniupluation
|
|
|
|
<img src={useBaseUrl("/img/custom-plugins/plugin-12-console-logs.png")} />{" "}
|
|
|
|
## Make it Your Own
|
|
|
|
Now you're free to run wild with your new plugin! Here are a few places to start digging in:
|
|
|
|
### Read the comments and docs
|
|
|
|
Take a look through the full file tree of the plugin. The Readme gives details for the job of each
|
|
file. EACH of these files has been annotated with extensive comments of what the file is for, and
|
|
the basics of what you can do with it.
|
|
|
|
### Take control!
|
|
|
|
The plugin includes a couple of example controls, but you can certainly continue to add as many as
|
|
you need to. The comments/documentation within the controls file is a start, but we recommend
|
|
looking at existing `superset-ui` plugins for more examples of how you can implement controls to
|
|
enhance your queries, work with your data, and change your visualization's display.
|
|
|
|
### Build the perfect query
|
|
|
|
The `buildQuery` file where your plugin actually fetches data from the Superset backend. This file
|
|
builds he query "context" for your plugin. For a simple plugin, this file needn't do much. There are
|
|
a couple changes that need to be made for a timeseries plugin, thus the option in the Yeoman
|
|
generator.
|
|
|
|
This file also allows you to add various post-processing operations, to have the Superset backend
|
|
process your data in various ways (pivoting, etc), but that's a whole other topic we'll cover
|
|
separately in the near future.
|
|
|
|
### Style with Emotion
|
|
|
|
Each of these methods lets you add custom CSS styles using Emotion 👩🎤(a CSS-in-JS approach) which
|
|
has access to Superset's burgeoning set of theme variables, and also automatically scopes the styles
|
|
to your plugin, so they don't "leak" to other areas of Superset.
|
|
|
|
In the Hello World plugin, we've included a few example Theme variables (`colors`, `gridUnit`s, and
|
|
typographic weights/sizes). We'll be continuing to add more variables to this theme file as we
|
|
continue to push Superset (and the viz plugins) toward the standards of the Superset redesign (see
|
|
[SIP-34](https://github.com/apache/superset/issues/8976))
|
|
|
|
### Give it a thumbnail
|
|
|
|
Because come on... that's the fun part, right?
|
|
|
|
### Build it!
|
|
|
|
In this tutorial, you built your plugin in the `superset-ui` repo. This means you can use the
|
|
built-in build scripts that the repo provides. With your terminal of choice, simply `cd` into the
|
|
root directory of `supeset-ui` and run `yarn build`. This will kick off a build of ALL the Superset
|
|
plugins and packages, including yours.
|
|
|
|
### Test early, test often!
|
|
|
|
The Hello World plugin includes some basic Jest tests to act as a starting point to add unit tests
|
|
to your plugin. These do a quick sanity check that the plugin actually loads correctly, and then run
|
|
through the basics of making sure that your controls are properly respected by modifying the
|
|
resulting data and/or props of the plugin. Running `yarn test` from the root directory of
|
|
`superset-ui` will run all the tests for plugins/packages, including your Hello World.
|
|
|
|
### Deploying Custom Visualization to Production
|
|
|
|
To deploy plugins to a production environment, you must have additional code
|
|
inside Superset that includes the npm packages of your plugins so they can be installed in the frontend.
|
|
|
|
One option is to build your Dockerfile so it contains your custom visualization packages.
|