Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit 5b64dfe

Browse files
committed
docs: 'hello world' visualization plugin
1 parent 484d639 commit 5b64dfe

File tree

13 files changed

+230
-0
lines changed

13 files changed

+230
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## @superset-ui/plugin-chart-hello-world
2+
3+
[![Version](https://img.shields.io/npm/v/@superset-ui/plugin-chart-word-cloud.svg?style=flat-square)](https://img.shields.io/npm/v/@superset-ui/plugin-chart-word-cloud.svg?style=flat-square)
4+
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui-plugins.svg?path=packages%2Fsuperset-ui-plugin-chart-word-cloud&style=flat-square)](https://david-dm.org/apache-superset/superset-ui-plugins?path=packages/superset-ui-plugin-chart-word-cloud)
5+
6+
This plugin provides Word Cloud for Superset.
7+
8+
### Usage
9+
10+
Configure `key`, which can be any `string`, and register the plugin. This `key` will be used to lookup this chart throughout the app.
11+
12+
```js
13+
import WordCloudChartPlugin from '@superset-ui/legacy-plugin-chart-word-cloud';
14+
15+
new WordCloudChartPlugin()
16+
.configure({ key: 'word-cloud' })
17+
.register();
18+
```
19+
20+
Then use it via `SuperChart`. See [storybook](https://apache-superset.github.io/superset-ui-plugins/?selectedKind=plugin-chart-word-cloud) for more details.
21+
22+
```js
23+
<SuperChart
24+
chartType="word-cloud"
25+
width={600}
26+
height={600}
27+
formData={...}
28+
queryData={{
29+
data: {...},
30+
}}
31+
/>
32+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@superset-ui/plugin-chart-hello-world",
3+
"version": "0.11.0",
4+
"description": "Superset Chart Plugin - Word Cloud",
5+
"sideEffects": [
6+
"*.css"
7+
],
8+
"main": "lib/index.js",
9+
"module": "esm/index.js",
10+
"files": [
11+
"esm",
12+
"lib"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/apache-superset/superset-ui-plugins.git"
17+
},
18+
"keywords": [
19+
"superset"
20+
],
21+
"author": "Superset",
22+
"license": "Apache-2.0",
23+
"bugs": {
24+
"url": "https://github.com/apache-superset/superset-ui-plugins/issues"
25+
},
26+
"homepage": "https://github.com/apache-superset/superset-ui-plugins#readme",
27+
"publishConfig": {
28+
"access": "public"
29+
},
30+
"dependencies": {
31+
"@types/d3-array": "^2.0.0",
32+
"@types/d3-cloud": "^1.2.1",
33+
"@types/d3-scale": "^2.0.2",
34+
"@types/d3-selection": "^1.3.4",
35+
"d3-array": "^2.0.2",
36+
"d3-cloud": "^1.2.5",
37+
"d3-scale": "^3.0.1",
38+
"d3-selection": "^1.3.2",
39+
"prop-types": "^15.6.2"
40+
},
41+
"peerDependencies": {
42+
"@superset-ui/chart": "^0.12.0",
43+
"@superset-ui/color": "^0.12.0",
44+
"@superset-ui/query": "^0.12.0",
45+
"@superset-ui/translation": "^0.12.0"
46+
}
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { extent as d3Extent } from 'd3-array';
2+
import { scaleLinear } from 'd3-scale';
3+
import { select as d3Select } from 'd3-selection';
4+
import cloudLayout from 'd3-cloud';
5+
import { CategoricalColorNamespace } from '@superset-ui/color';
6+
7+
function HelloWorld(element, props) {
8+
const { data, width, height, formData } = props;
9+
10+
const container = d3Select(element);
11+
container.select('*').remove();
12+
const div = container
13+
.append('div')
14+
.style('height', height)
15+
.style('width', width)
16+
.style('overflow', 'auto');
17+
div
18+
.append('h1')
19+
.text('Hello World')
20+
.append('h3')
21+
.text('props')
22+
.append('pre')
23+
.text(JSON.stringify(props, null, 2));
24+
}
25+
26+
HelloWorld.displayName = 'HelloWorld';
27+
28+
export default HelloWorld;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { reactify } from '@superset-ui/chart';
2+
import Component, { Props } from './HelloWorld';
3+
4+
export default reactify(Component);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { buildQueryContext } from '@superset-ui/query';
2+
3+
export default function buildQuery(formData) {
4+
// Set the single QueryObject's groupby field with series in formData
5+
return buildQueryContext(formData, baseQueryObject => {
6+
return [
7+
{
8+
...baseQueryObject,
9+
groupby: [formData.series],
10+
metrics: [formData.metric],
11+
},
12+
];
13+
});
14+
}
243 KB
Loading
243 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { t } from '@superset-ui/translation';
2+
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
3+
import buildQuery from './buildQuery';
4+
import transformProps from './transformProps';
5+
import thumbnail from './images/thumbnail.png';
6+
7+
const metadata = new ChartMetadata({
8+
credits: null,
9+
description: '',
10+
name: t('Hello World!'),
11+
thumbnail,
12+
});
13+
14+
export default class WordCloudChartPlugin extends ChartPlugin {
15+
constructor() {
16+
super({
17+
buildQuery,
18+
loadChart: () => import('./ReactHelloWorld'),
19+
metadata,
20+
useLegacyApi: false,
21+
transformProps,
22+
});
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ChartProps } from '@superset-ui/chart';
2+
3+
function transformData(data, formData) {
4+
const { metric, series } = formData;
5+
6+
const transformedData = data.map(datum => ({
7+
size: datum[metric.label || metric],
8+
text: datum[series],
9+
}));
10+
11+
return transformedData;
12+
}
13+
14+
export default function transformProps(chartProps) {
15+
const { width, height, formData, queryData } = chartProps;
16+
17+
return {
18+
data: transformData(queryData.data, formData),
19+
formData,
20+
height,
21+
width,
22+
};
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'babel-polyfill';
2+
import buildQuery from '../src/buildQuery';
3+
4+
describe('WordCloud buildQuery', () => {
5+
const formData = {
6+
datasource: '5__table',
7+
granularity_sqla: 'ds',
8+
series: 'foo',
9+
viz_type: 'word_cloud',
10+
};
11+
12+
it('should build groupby with series in form data', () => {
13+
const queryContext = buildQuery(formData);
14+
const [query] = queryContext.queries;
15+
expect(query.groupby).toEqual(['foo']);
16+
});
17+
});

0 commit comments

Comments
 (0)