refactor: Remove dead code from the Word Cloud plugin (#29594)

This commit is contained in:
Michael S. Molina
2024-07-19 10:37:40 -03:00
committed by GitHub
parent 5b79752e5d
commit 85b66946ed
11 changed files with 56 additions and 304 deletions

View File

@@ -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,