Skip to content

Commit

Permalink
feat(plugin-word-cloud): change how wordcloud is exported (apache#418)
Browse files Browse the repository at this point in the history
* feat(plugin-word-cloud): change how wordcloud is exported

* docs: fix storybook
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 25, 2021
1 parent 2a728d5 commit 3708ade
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { SuperChart } from '@superset-ui/chart';
import { select, withKnobs } from '@storybook/addon-knobs';
import WordCloudChartPlugin from '@superset-ui/plugin-chart-word-cloud';
import LegacyWordCloudChartPlugin from '@superset-ui/plugin-chart-word-cloud/esm/legacy';
import {
WordCloudChartPlugin,
LegacyWordCloudChartPlugin,
} from '@superset-ui/plugin-chart-word-cloud';
import data from './data';

new WordCloudChartPlugin().configure({ key: 'word-cloud2' }).register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BigNumberChartPlugin as LegacyBigNumberPlugin } from '@superset-ui/lega
import LegacySankeyPlugin from '@superset-ui/legacy-plugin-chart-sankey';
import LegacySunburstPlugin from '@superset-ui/legacy-plugin-chart-sunburst';
import LegacyWordCloudPlugin from '@superset-ui/legacy-plugin-chart-word-cloud';
import WordCloudPlugin from '@superset-ui/plugin-chart-word-cloud';
import { WordCloudChartPlugin } from '@superset-ui/plugin-chart-word-cloud';

import {
bigNumberFormData,
Expand All @@ -33,7 +33,7 @@ new LegacySunburstPlugin().configure({ key: SUNBURST }).register();
// @ts-ignore
new LegacyWordCloudPlugin().configure({ key: WORD_CLOUD_LEGACY }).register();
// @ts-ignore
new WordCloudPlugin().configure({ key: WORD_CLOUD }).register();
new WordCloudChartPlugin().configure({ key: WORD_CLOUD }).register();

const VIS_TYPES = [BIG_NUMBER, SANKEY, SUNBURST, WORD_CLOUD, WORD_CLOUD_LEGACY];
const FORM_DATA_LOOKUP = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import buildQuery from './buildQuery';
import { WordCloudFormData } from './types';
import transformProps from './transformProps';
import thumbnail from './images/thumbnail.png';

const metadata = new ChartMetadata({
credits: ['https://github.com/jasondavies/d3-cloud'],
description: '',
name: t('Word Cloud'),
thumbnail,
});

export default class WordCloudChartPlugin extends ChartPlugin<WordCloudFormData> {
constructor() {
super({
buildQuery,
loadChart: () => import('./chart/WordCloud'),
metadata,
transformProps,
});
}
}
export { default as WordCloudChartPlugin } from './plugin';
export { default as LegacyWordCloudChartPlugin } from './legacyPlugin';
export * from './types';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import buildQuery from '../buildQuery';
import buildQuery from '../plugin/buildQuery';
import transformProps from './transformProps';
import thumbnail from '../images/thumbnail.png';
import { LegacyWordCloudFormData } from './types';
Expand All @@ -13,7 +13,7 @@ const metadata = new ChartMetadata({
useLegacyApi: true,
});

export default class WordCloudChartPlugin extends ChartPlugin<LegacyWordCloudFormData> {
export default class LegacyWordCloudChartPlugin extends ChartPlugin<LegacyWordCloudFormData> {
constructor() {
super({
buildQuery,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildQueryContext } from '@superset-ui/query';
import { WordCloudFormData } from './types';
import { WordCloudFormData } from '../types';

export default function buildQuery(formData: WordCloudFormData) {
// Set the single QueryObject's groupby field with series in formData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import buildQuery from './buildQuery';
import { WordCloudFormData } from '../types';
import transformProps from './transformProps';
import thumbnail from '../images/thumbnail.png';

const metadata = new ChartMetadata({
credits: ['https://github.com/jasondavies/d3-cloud'],
description: '',
name: t('Word Cloud'),
thumbnail,
});

export default class WordCloudChartPlugin extends ChartPlugin<WordCloudFormData> {
constructor() {
super({
buildQuery,
loadChart: () => import('../chart/WordCloud'),
metadata,
transformProps,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChartProps } from '@superset-ui/chart';
import { WordCloudProps } from './chart/WordCloud';
import { WordCloudFormData } from './types';
import { WordCloudProps } from '../chart/WordCloud';
import { WordCloudFormData } from '../types';

export default function transformProps(chartProps: ChartProps): WordCloudProps {
const { width, height, formData, queryData } = chartProps;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { WordCloudChartPlugin, LegacyWordCloudChartPlugin } from '../src';

describe('plugin-chart-word-cloud', () => {
it('exports WordCloudChartPlugin', () => {
expect(WordCloudChartPlugin).toBeDefined();
});
it('exports LegacyWordCloudChartPlugin', () => {
expect(LegacyWordCloudChartPlugin).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'babel-polyfill';
import { ChartProps } from '@superset-ui/chart';
import transformProps from '../../src/legacy/transformProps';
import transformProps from '../../src/legacyPlugin/transformProps';

describe('WordCloud tranformProps', () => {
const formData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'babel-polyfill';
import buildQuery from '../src/buildQuery';
import buildQuery from '../../src/plugin/buildQuery';

describe('WordCloud buildQuery', () => {
const formData = {
Expand Down

0 comments on commit 3708ade

Please sign in to comment.