Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sunburst): Added some options to adjust Sunburst chart view: innerRadius, outerRadius, donut, showNulls #30987

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ import {
getStandardizedControls,
} from '@superset-ui/chart-controls';
import { DEFAULT_FORM_DATA } from './types';
import { NULL_STRING } from '../constants';

const { labelType, numberFormat, showLabels } = DEFAULT_FORM_DATA;
const {
labelType,
numberFormat,
showLabels,
outerRadius,
innerRadius,
donut,
showNulls,
} = DEFAULT_FORM_DATA;

const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -108,6 +117,8 @@ const config: ControlPanelConfig = {
},
},
],
[<ControlSubSectionHeader>{t('Shape')}</ControlSubSectionHeader>],

[
{
name: 'number_format',
Expand All @@ -122,6 +133,62 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'outerRadius',
config: {
type: 'SliderControl',
label: t('Outer Radius'),
renderTrigger: true,
min: 10,
max: 100,
step: 1,
default: outerRadius,
description: t('Outer edge of Pie chart'),
},
},
],
[
{
name: 'donut',
config: {
type: 'CheckboxControl',
label: t('Donut'),
default: donut,
renderTrigger: true,
description: t('Do you want a donut or a pie?'),
},
},
],
[
{
name: 'innerRadius',
config: {
type: 'SliderControl',
label: t('Inner Radius'),
renderTrigger: true,
min: 0,
max: 100,
step: 1,
default: innerRadius,
description: t('Inner radius of donut hole'),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.donut?.value),
},
},
],
[
{
name: 'showNulls',
config: {
type: 'CheckboxControl',
label: t('Show %s values', NULL_STRING),
default: showNulls,
renderTrigger: true,
description: t('Do you want %s slices visible?', NULL_STRING),
},
},
],
['currency_format'],
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export default function transformProps(
showLabelsThreshold,
showTotal,
sliceId,
innerRadius,
outerRadius,
donut,
showNulls,
} = formData;
const { currencyFormats = {}, columnFormats = {} } = datasource;
const refs: Refs = {};
Expand Down Expand Up @@ -276,48 +280,50 @@ export default function transformProps(
path: string[],
pathRecords?: DataRecordValue[],
) =>
treeNodes.map(treeNode => {
const { name: nodeName, value, secondaryValue, groupBy } = treeNode;
const records = [...(pathRecords || []), nodeName];
let name = formatSeriesName(nodeName, {
numberFormatter,
timeFormatter: getTimeFormatter(dateFormat),
...(coltypeMapping[groupBy] && {
coltype: coltypeMapping[groupBy],
}),
});
const newPath = path.concat(name);
let item: NodeItemOption = {
records,
name,
value,
secondaryValue,
itemStyle: {
color: colorByCategory
? categoricalColorScale(name, sliceId)
: linearColorScale(secondaryValue / value),
},
};
if (treeNode.children?.length) {
item.children = traverse(treeNode.children, newPath, records);
} else {
name = newPath.join(',');
}
columnsLabelMap.set(name, newPath);
if (filterState.selectedValues?.[0]?.includes(name) === false) {
item = {
...item,
treeNodes
.map(treeNode => {
const { name: nodeName, value, secondaryValue, groupBy } = treeNode;
const records = [...(pathRecords || []), nodeName];
let name = formatSeriesName(nodeName, {
numberFormatter,
timeFormatter: getTimeFormatter(dateFormat),
...(coltypeMapping[groupBy] && {
coltype: coltypeMapping[groupBy],
}),
});
const newPath = path.concat(name);
let item: NodeItemOption = {
records,
name,
value,
secondaryValue,
itemStyle: {
...item.itemStyle,
opacity: OpacityEnum.SemiTransparent,
},
label: {
color: `rgba(0, 0, 0, ${OpacityEnum.SemiTransparent})`,
color: colorByCategory
? categoricalColorScale(name, sliceId)
: linearColorScale(secondaryValue / value),
},
};
}
return item;
});
if (treeNode.children?.length) {
item.children = traverse(treeNode.children, newPath, records);
} else {
name = newPath.join(',');
}
columnsLabelMap.set(name, newPath);
if (filterState.selectedValues?.[0]?.includes(name) === false) {
item = {
...item,
itemStyle: {
...item.itemStyle,
opacity: OpacityEnum.SemiTransparent,
},
label: {
color: `rgba(0, 0, 0, ${OpacityEnum.SemiTransparent})`,
},
};
}
return item;
})
.filter(x => showNulls || x.name !== NULL_STRING);

const echartOptions: EChartsCoreOption = {
grid: {
Expand Down Expand Up @@ -357,14 +363,14 @@ export default function transformProps(
minAngle: minShowLabelAngle,
overflow: 'breakAll',
},
radius: [radius * 0.3, radius],
radius: [`${donut ? innerRadius : 0}%`, `${outerRadius}%`],
data: traverse(treeData, []),
},
],
graphic: showTotal
? {
type: 'text',
top: 'center',
top: donut ? 'center' : 'top',
left: 'center',
style: {
text: t('Total: %s', primaryValueFormatter(totalValue)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const DEFAULT_FORM_DATA: Partial<EchartsSunburstFormData> = {
labelType: EchartsSunburstLabelType.Key,
showLabels: false,
dateFormat: 'smart_date',
innerRadius: 30,
outerRadius: 70,
donut: true,
showNulls: true,
};

export interface EchartsSunburstChartProps
Expand Down