Skip to content

Commit

Permalink
refactor: Remove dead code from the Word Cloud plugin (#29594)
Browse files Browse the repository at this point in the history
(cherry picked from commit 85b6694)
  • Loading branch information
michael-s-molina authored and sadpandajoe committed Aug 12, 2024
1 parent 4369967 commit c8008e6
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

This file was deleted.

Loading

0 comments on commit c8008e6

Please sign in to comment.