mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
refactor: Remove dead code from the Word Cloud plugin (#29594)
This commit is contained in:
committed by
GitHub
parent
5b79752e5d
commit
85b66946ed
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user