feat: Adds Sunburst chart migration logic (#25343)

This commit is contained in:
Michael S. Molina 2023-09-22 09:44:40 -03:00 committed by GitHub
parent 9bd97ef4f2
commit 0c083bdc1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -82,7 +82,8 @@ function buildHierarchy(rows) {
let currentNode = root;
for (let level = 0; level < levels.length; level += 1) {
const children = currentNode.children || [];
const nodeName = levels[level].toString();
const node = levels[level];
const nodeName = node ? node.toString() : t('N/A');
// If the next node has the name '0', it will
const isLeafNode = level >= levels.length - 1 || levels[level + 1] === 0;
let childNode;

View File

@ -32,7 +32,7 @@ import {
} from '@superset-ui/core';
import { EChartsCoreOption } from 'echarts';
import { CallbackDataParams } from 'echarts/types/src/util/types';
import { OpacityEnum } from '../constants';
import { NULL_STRING, OpacityEnum } from '../constants';
import { defaultGrid } from '../defaults';
import { Refs } from '../types';
import { formatSeriesName, getColtypesMapping } from '../utils/series';
@ -138,7 +138,10 @@ export function formatTooltip({
color: ${theme.colors.grayscale.base}"
>`,
`<div style="font-weight: ${theme.typography.weights.bold}">
${node.name}
${(node.name || NULL_STRING)
.toString()
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')}
</div>`,
`<div">
${absolutePercentage} of total

View File

@ -28,6 +28,7 @@ class VizType(str, Enum):
DUAL_LINE = "dual_line"
AREA = "area"
PIVOT_TABLE = "pivot_table"
SUNBURST = "sunburst"
@click.group()
@ -76,6 +77,7 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None:
MigrateAreaChart,
MigrateDualLine,
MigratePivotTable,
MigrateSunburst,
MigrateTreeMap,
)
@ -84,6 +86,7 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None:
VizType.DUAL_LINE: MigrateDualLine,
VizType.AREA: MigrateAreaChart,
VizType.PIVOT_TABLE: MigratePivotTable,
VizType.SUNBURST: MigrateSunburst,
}
if is_downgrade:
migrations[viz_type].downgrade(db.session)

View File

@ -125,3 +125,9 @@ class MigrateDualLine(MigrateViz):
def _migrate_temporal_filter(self, rv_data: dict[str, Any]) -> None:
super()._migrate_temporal_filter(rv_data)
rv_data["adhoc_filters_b"] = rv_data.get("adhoc_filters") or []
class MigrateSunburst(MigrateViz):
source_viz_type = "sunburst"
target_viz_type = "sunburst_v2"
rename_keys = {"groupby": "columns"}