refactor: Remove dead code from the Word Cloud plugin (#29594)
This commit is contained in:
parent
5b79752e5d
commit
85b66946ed
|
|
@ -17,26 +17,12 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { SuperChart, getChartTransformPropsRegistry } from '@superset-ui/core';
|
||||
import {
|
||||
WordCloudChartPlugin,
|
||||
LegacyWordCloudChartPlugin,
|
||||
WordCloudTransformProps,
|
||||
} from '@superset-ui/plugin-chart-word-cloud';
|
||||
import { SuperChart } from '@superset-ui/core';
|
||||
import { WordCloudChartPlugin } from '@superset-ui/plugin-chart-word-cloud';
|
||||
import { withResizableChartDemo } from '../../../shared/components/ResizableChartDemo';
|
||||
import data from './data';
|
||||
|
||||
new WordCloudChartPlugin().configure({ key: 'word-cloud2' }).register();
|
||||
new LegacyWordCloudChartPlugin()
|
||||
.configure({ key: 'legacy-word-cloud2' })
|
||||
.register();
|
||||
|
||||
// Enable the new WordCloud Props to show case its full features
|
||||
// if the control panel is updated to be able to pass formData in the new format.
|
||||
getChartTransformPropsRegistry().registerValue(
|
||||
'word-cloud2',
|
||||
WordCloudTransformProps,
|
||||
);
|
||||
|
||||
export default {
|
||||
title: 'Chart Plugins/plugin-chart-word-cloud',
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
|
@ -18,7 +18,5 @@
|
|||
*/
|
||||
|
||||
export { default as WordCloudChartPlugin } from './plugin';
|
||||
export { default as WordCloudTransformProps } from './plugin/transformProps';
|
||||
export { default as LegacyWordCloudChartPlugin } from './legacyPlugin';
|
||||
export * from './types';
|
||||
export { default as configureEncodable } from './configureEncodable';
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
|
||||
import transformProps from './transformProps';
|
||||
import buildQuery from '../plugin/buildQuery';
|
||||
import thumbnail from '../images/thumbnail.png';
|
||||
import { LegacyWordCloudFormData } from './types';
|
||||
|
||||
const metadata = new ChartMetadata({
|
||||
credits: ['https://github.com/jasondavies/d3-cloud'],
|
||||
description: '',
|
||||
name: t('Word Cloud'),
|
||||
thumbnail,
|
||||
useLegacyApi: true,
|
||||
});
|
||||
|
||||
export default class LegacyWordCloudChartPlugin extends ChartPlugin<LegacyWordCloudFormData> {
|
||||
constructor() {
|
||||
super({
|
||||
buildQuery,
|
||||
loadChart: () => import('../chart/WordCloud'),
|
||||
metadata,
|
||||
transformProps,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { ChartProps, getColumnLabel } from '@superset-ui/core';
|
||||
import { WordCloudProps, WordCloudEncoding } from '../chart/WordCloud';
|
||||
import { LegacyWordCloudFormData } from './types';
|
||||
|
||||
function getMetricLabel(
|
||||
metric: LegacyWordCloudFormData['metric'],
|
||||
): string | undefined {
|
||||
if (typeof metric === 'string' || typeof metric === 'undefined') {
|
||||
return metric;
|
||||
}
|
||||
if (Array.isArray(metric)) {
|
||||
return metric.length > 0 ? getMetricLabel(metric[0]) : undefined;
|
||||
}
|
||||
|
||||
return metric.label;
|
||||
}
|
||||
|
||||
export default function transformProps(chartProps: ChartProps): WordCloudProps {
|
||||
const { width, height, formData, queriesData } = chartProps;
|
||||
const {
|
||||
colorScheme,
|
||||
metric,
|
||||
rotation,
|
||||
series,
|
||||
sizeFrom = 0,
|
||||
sizeTo,
|
||||
sliceId,
|
||||
} = formData as LegacyWordCloudFormData;
|
||||
|
||||
const metricLabel = getMetricLabel(metric);
|
||||
const seriesLabel = getColumnLabel(series);
|
||||
|
||||
const encoding: Partial<WordCloudEncoding> = {
|
||||
color: {
|
||||
field: seriesLabel,
|
||||
scale: {
|
||||
scheme: colorScheme,
|
||||
},
|
||||
type: 'nominal',
|
||||
},
|
||||
fontSize:
|
||||
typeof metricLabel === 'undefined'
|
||||
? undefined
|
||||
: {
|
||||
field: metricLabel,
|
||||
scale: {
|
||||
range: [sizeFrom, sizeTo],
|
||||
zero: true,
|
||||
},
|
||||
type: 'quantitative',
|
||||
},
|
||||
text: {
|
||||
field: seriesLabel,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
data: queriesData[0].data,
|
||||
encoding,
|
||||
height,
|
||||
rotation,
|
||||
width,
|
||||
sliceId,
|
||||
colorScheme,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { QueryFormColumn, QueryFormData } from '@superset-ui/core';
|
||||
import { RotationType } from '../chart/WordCloud';
|
||||
|
||||
export type LegacyWordCloudFormData = QueryFormData & {
|
||||
colorScheme: string;
|
||||
rotation?: RotationType;
|
||||
series: QueryFormColumn;
|
||||
sizeFrom?: number;
|
||||
sizeTo: number;
|
||||
};
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
|
||||
import transformProps from '../legacyPlugin/transformProps';
|
||||
import transformProps from './transformProps';
|
||||
import buildQuery from './buildQuery';
|
||||
import { WordCloudFormData } from '../types';
|
||||
import thumbnail from '../images/thumbnail.png';
|
||||
|
|
|
|||
|
|
@ -17,14 +17,61 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { ChartProps } from '@superset-ui/core';
|
||||
import { WordCloudProps } from '../chart/WordCloud';
|
||||
import { ChartProps, getColumnLabel } from '@superset-ui/core';
|
||||
import { WordCloudProps, WordCloudEncoding } from '../chart/WordCloud';
|
||||
import { WordCloudFormData } from '../types';
|
||||
|
||||
function getMetricLabel(
|
||||
metric: WordCloudFormData['metric'],
|
||||
): string | undefined {
|
||||
if (typeof metric === 'string' || typeof metric === 'undefined') {
|
||||
return metric;
|
||||
}
|
||||
if (Array.isArray(metric)) {
|
||||
return metric.length > 0 ? getMetricLabel(metric[0]) : undefined;
|
||||
}
|
||||
|
||||
return metric.label;
|
||||
}
|
||||
|
||||
export default function transformProps(chartProps: ChartProps): WordCloudProps {
|
||||
const { width, height, formData, queriesData } = chartProps;
|
||||
const { encoding, rotation, sliceId, colorScheme } =
|
||||
formData as WordCloudFormData;
|
||||
const {
|
||||
colorScheme,
|
||||
metric,
|
||||
rotation,
|
||||
series,
|
||||
sizeFrom = 0,
|
||||
sizeTo,
|
||||
sliceId,
|
||||
} = formData as WordCloudFormData;
|
||||
|
||||
const metricLabel = getMetricLabel(metric);
|
||||
const seriesLabel = getColumnLabel(series);
|
||||
|
||||
const encoding: Partial<WordCloudEncoding> = {
|
||||
color: {
|
||||
field: seriesLabel,
|
||||
scale: {
|
||||
scheme: colorScheme,
|
||||
},
|
||||
type: 'nominal',
|
||||
},
|
||||
fontSize:
|
||||
typeof metricLabel === 'undefined'
|
||||
? undefined
|
||||
: {
|
||||
field: metricLabel,
|
||||
scale: {
|
||||
range: [sizeFrom, sizeTo],
|
||||
zero: true,
|
||||
},
|
||||
type: 'quantitative',
|
||||
},
|
||||
text: {
|
||||
field: seriesLabel,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
data: queriesData[0].data,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { WordCloudFormData } from '../../src';
|
||||
import buildQuery from '../../src/plugin/buildQuery';
|
||||
import { WordCloudFormData } from '../src';
|
||||
import buildQuery from '../src/plugin/buildQuery';
|
||||
|
||||
describe('WordCloud buildQuery', () => {
|
||||
const formData: WordCloudFormData = {
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { WordCloudChartPlugin, LegacyWordCloudChartPlugin } from '../src';
|
||||
|
||||
describe('plugin-chart-word-cloud', () => {
|
||||
it('exports WordCloudChartPlugin', () => {
|
||||
expect(WordCloudChartPlugin).toBeDefined();
|
||||
});
|
||||
it('exports LegacyWordCloudChartPlugin', () => {
|
||||
expect(LegacyWordCloudChartPlugin).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { ChartProps, supersetTheme } from '@superset-ui/core';
|
||||
import transformProps from '../../src/legacyPlugin/transformProps';
|
||||
|
||||
describe('WordCloud transformProps', () => {
|
||||
const formData = {
|
||||
colorScheme: 'bnbColors',
|
||||
datasource: '3__table',
|
||||
granularity_sqla: 'ds',
|
||||
metric: 'sum__num',
|
||||
rotation: 'square',
|
||||
series: 'name',
|
||||
sizeFrom: 10,
|
||||
sizeTo: 70,
|
||||
};
|
||||
const chartProps = new ChartProps({
|
||||
formData,
|
||||
width: 800,
|
||||
height: 600,
|
||||
queriesData: [
|
||||
{
|
||||
data: [{ name: 'Hulk', sum__num: 1 }],
|
||||
},
|
||||
],
|
||||
theme: supersetTheme,
|
||||
});
|
||||
|
||||
it('should transform chart props for word cloud viz', () => {
|
||||
expect(transformProps(chartProps)).toEqual({
|
||||
width: 800,
|
||||
height: 600,
|
||||
encoding: {
|
||||
color: {
|
||||
field: 'name',
|
||||
scale: {
|
||||
scheme: 'bnbColors',
|
||||
},
|
||||
type: 'nominal',
|
||||
},
|
||||
fontSize: {
|
||||
field: 'sum__num',
|
||||
scale: {
|
||||
range: [10, 70],
|
||||
zero: true,
|
||||
},
|
||||
type: 'quantitative',
|
||||
},
|
||||
text: {
|
||||
field: 'name',
|
||||
},
|
||||
},
|
||||
rotation: 'square',
|
||||
colorScheme: 'bnbColors',
|
||||
data: [{ name: 'Hulk', sum__num: 1 }],
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue