From a3f571bf4f5bff7dc4210891aa405bd736f71e7b Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Mon, 18 Sep 2023 11:53:30 -0300 Subject: [PATCH 1/5] feat: Migrates Line chart --- .../shared/migrate_viz/processors.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py index 4ff6b2a93467..3503c9cb6d65 100644 --- a/superset/migrations/shared/migrate_viz/processors.py +++ b/superset/migrations/shared/migrate_viz/processors.py @@ -131,3 +131,60 @@ class MigrateSunburst(MigrateViz): source_viz_type = "sunburst" target_viz_type = "sunburst_v2" rename_keys = {"groupby": "columns"} + + +class TimeseriesChart(MigrateViz): + has_x_axis_control = True + + def _pre_action(self) -> None: + self.data["contributionMode"] = "row" if self.data.get("contribution") else None + + show_brush = self.data.get("show_brush") + self.data["zoomable"] = False if show_brush == "no" else True + + self.data["markerEnabled"] = self.data.get("show_markers") + self.data["y_axis_showminmax"] = True + + bottom_margin = self.data.get("bottom_margin") + if self.data.get("x_axis_label") and ( + not bottom_margin or bottom_margin == "auto" + ): + self.data["bottom_margin"] = 30 + + if (rolling_type := self.data.get("rolling_type")) and rolling_type != "None": + self.data["rolling_type"] = rolling_type + + if time_compare := self.data.get("time_compare"): + self.data["time_compare"] = [value + " ago" for value in time_compare] + + comparison_type = self.data.get("comparison_type") or "values" + self.data["comparison_type"] = ( + "difference" if comparison_type == "absolute" else comparison_type + ) + + +class MigrateLineChart(TimeseriesChart): + source_viz_type = "line" + target_viz_type = "echarts_timeseries_line" + rename_keys = { + "x_axis_label": "x_axis_title", + "bottom_margin": "x_axis_title_margin", + "x_axis_format": "x_axis_time_format", + "y_axis_label": "y_axis_title", + "left_margin": "y_axis_title_margin", + "y_axis_showminmax": "truncateYAxis", + "y_log_scale": "logAxis", + } + + def _pre_action(self) -> None: + super()._pre_action() + + line_interpolation = self.data.get("line_interpolation") + if line_interpolation == "cardinal": + self.target_viz_type = "echarts_timeseries_smooth" + elif line_interpolation == "step-before": + self.target_viz_type = "echarts_timeseries_step" + self.data["seriesType"] = "start" + elif line_interpolation == "step-after": + self.target_viz_type = "echarts_timeseries_step" + self.data["seriesType"] = "end" From 8de3ebb0e62cb8f1dea504dc2932c206cf363410 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 19 Sep 2023 10:46:58 -0300 Subject: [PATCH 2/5] Adjusts time_compare --- superset/migrations/shared/migrate_viz/processors.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py index 3503c9cb6d65..78f2f7b683e2 100644 --- a/superset/migrations/shared/migrate_viz/processors.py +++ b/superset/migrations/shared/migrate_viz/processors.py @@ -16,6 +16,8 @@ # under the License. from typing import Any +from superset.utils.core import as_list + from .base import MigrateViz @@ -155,7 +157,9 @@ def _pre_action(self) -> None: self.data["rolling_type"] = rolling_type if time_compare := self.data.get("time_compare"): - self.data["time_compare"] = [value + " ago" for value in time_compare] + self.data["time_compare"] = [ + value + " ago" for value in as_list(time_compare) if value + ] comparison_type = self.data.get("comparison_type") or "values" self.data["comparison_type"] = ( From 9f1fde07fe0bd16df63c712313589dba74f88c35 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 19 Sep 2023 14:39:28 -0300 Subject: [PATCH 3/5] Adds Line to the CLI command --- superset/cli/viz_migrations.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/superset/cli/viz_migrations.py b/superset/cli/viz_migrations.py index 9e69135aea38..4f50016de8a5 100644 --- a/superset/cli/viz_migrations.py +++ b/superset/cli/viz_migrations.py @@ -29,6 +29,7 @@ class VizType(str, Enum): AREA = "area" PIVOT_TABLE = "pivot_table" SUNBURST = "sunburst" + LINE = "line" @click.group() @@ -79,6 +80,7 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None: MigratePivotTable, MigrateSunburst, MigrateTreeMap, + MigrateLineChart, ) migrations = { @@ -87,6 +89,7 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None: VizType.AREA: MigrateAreaChart, VizType.PIVOT_TABLE: MigratePivotTable, VizType.SUNBURST: MigrateSunburst, + VizType.LINE: MigrateLineChart, } if is_downgrade: migrations[viz_type].downgrade(db.session) From f09881ad80d5e1d49908c9c730fb83fcedd3db9d Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 19 Sep 2023 14:53:34 -0300 Subject: [PATCH 4/5] Fixes import order --- superset/cli/viz_migrations.py | 2 +- superset/migrations/shared/migrate_viz/processors.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/superset/cli/viz_migrations.py b/superset/cli/viz_migrations.py index 4f50016de8a5..05d2bc19ca22 100644 --- a/superset/cli/viz_migrations.py +++ b/superset/cli/viz_migrations.py @@ -77,10 +77,10 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None: from superset.migrations.shared.migrate_viz.processors import ( MigrateAreaChart, MigrateDualLine, + MigrateLineChart, MigratePivotTable, MigrateSunburst, MigrateTreeMap, - MigrateLineChart, ) migrations = { diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py index 78f2f7b683e2..c04b7f3bccdc 100644 --- a/superset/migrations/shared/migrate_viz/processors.py +++ b/superset/migrations/shared/migrate_viz/processors.py @@ -140,11 +140,8 @@ class TimeseriesChart(MigrateViz): def _pre_action(self) -> None: self.data["contributionMode"] = "row" if self.data.get("contribution") else None - - show_brush = self.data.get("show_brush") - self.data["zoomable"] = False if show_brush == "no" else True - - self.data["markerEnabled"] = self.data.get("show_markers") + self.data["zoomable"] = False if self.data.get("show_brush") == "no" else True + self.data["markerEnabled"] = self.data.get("show_markers") or False self.data["y_axis_showminmax"] = True bottom_margin = self.data.get("bottom_margin") From de6075679c961fc8aba2244c0ebfb6f236f9ed84 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Wed, 1 Nov 2023 09:33:39 -0300 Subject: [PATCH 5/5] Addresses comments --- superset/cli/viz_migrations.py | 12 ++++++------ superset/migrations/shared/migrate_viz/processors.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/superset/cli/viz_migrations.py b/superset/cli/viz_migrations.py index 05d2bc19ca22..4451580d0b0a 100644 --- a/superset/cli/viz_migrations.py +++ b/superset/cli/viz_migrations.py @@ -24,12 +24,12 @@ class VizType(str, Enum): - TREEMAP = "treemap" - DUAL_LINE = "dual_line" AREA = "area" + DUAL_LINE = "dual_line" + LINE = "line" PIVOT_TABLE = "pivot_table" SUNBURST = "sunburst" - LINE = "line" + TREEMAP = "treemap" @click.group() @@ -84,12 +84,12 @@ def migrate(viz_type: VizType, is_downgrade: bool = False) -> None: ) migrations = { - VizType.TREEMAP: MigrateTreeMap, - VizType.DUAL_LINE: MigrateDualLine, VizType.AREA: MigrateAreaChart, + VizType.DUAL_LINE: MigrateDualLine, + VizType.LINE: MigrateLineChart, VizType.PIVOT_TABLE: MigratePivotTable, VizType.SUNBURST: MigrateSunburst, - VizType.LINE: MigrateLineChart, + VizType.TREEMAP: MigrateTreeMap, } if is_downgrade: migrations[viz_type].downgrade(db.session) diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py index c04b7f3bccdc..8627e201f66f 100644 --- a/superset/migrations/shared/migrate_viz/processors.py +++ b/superset/migrations/shared/migrate_viz/processors.py @@ -140,7 +140,7 @@ class TimeseriesChart(MigrateViz): def _pre_action(self) -> None: self.data["contributionMode"] = "row" if self.data.get("contribution") else None - self.data["zoomable"] = False if self.data.get("show_brush") == "no" else True + self.data["zoomable"] = self.data.get("show_brush") != "no" self.data["markerEnabled"] = self.data.get("show_markers") or False self.data["y_axis_showminmax"] = True