Skip to content

Commit

Permalink
feat: Adds Sunburst chart migration logic (#25343)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Sep 22, 2023
1 parent 9bd97ef commit 0c083bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions superset/cli/viz_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class VizType(str, Enum):
DUAL_LINE = "dual_line"
AREA = "area"
PIVOT_TABLE = "pivot_table"
SUNBURST = "sunburst"


@click.group()
Expand Down Expand Up @@ -76,6 +77,7 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None:
MigrateAreaChart,
MigrateDualLine,
MigratePivotTable,
MigrateSunburst,
MigrateTreeMap,
)

Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions superset/migrations/shared/migrate_viz/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ def _pre_action(self) -> None:
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"}

0 comments on commit 0c083bd

Please sign in to comment.