-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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: Add Bubble chart migration logic #26033
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,3 +184,32 @@ def _pre_action(self) -> None: | |
) | ||
|
||
self.data["opacity"] = 0.7 | ||
|
||
|
||
class MigrateBubbleChart(MigrateViz): | ||
source_viz_type = "bubble" | ||
target_viz_type = "bubble_v2" | ||
rename_keys = { | ||
"bottom_margin": "x_axis_title_margin", | ||
"left_margin": "y_axis_title_margin", | ||
"limit": "row_limit", | ||
"x_axis_format": "xAxisFormat", | ||
"x_log_scale": "logXAxis", | ||
"x_ticks_layout": "xAxisLabelRotation", | ||
"y_axis_showminmax": "truncateYAxis", | ||
"y_log_scale": "logYAxis", | ||
} | ||
remove_keys = {"x_axis_showminmax"} | ||
|
||
def _pre_action(self) -> None: | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason the bottom margin is now fix to 30 (pixels?) as opposed to being automatic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout adjustments to match the legacy version's look. |
||
|
||
if x_ticks_layout := self.data.get("x_ticks_layout"): | ||
self.data["x_ticks_layout"] = 45 if x_ticks_layout == "45°" else 0 | ||
|
||
# Truncate y-axis by default to preserve layout | ||
self.data["y_axis_showminmax"] = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, this occurs prior to the renaming of the keys? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from typing import Any | ||
|
||
from superset.migrations.shared.migrate_viz import MigrateBubbleChart | ||
from tests.unit_tests.migrations.viz.utils import migrate_and_assert | ||
|
||
SOURCE_FORM_DATA: dict[str, Any] = { | ||
"adhoc_filters": [], | ||
"bottom_margin": 20, | ||
"color_scheme": "default", | ||
"entity": "count", | ||
"left_margin": 20, | ||
"limit": 100, | ||
"max_bubble_size": 50, | ||
"series": ["region"], | ||
"show_legend": True, | ||
"size": 75, | ||
"viz_type": "bubble", | ||
"x": "year", | ||
"x_axis_format": "SMART_DATE", | ||
"x_axis_label": "Year", | ||
"x_axis_showminmax": True, | ||
"x_log_scale": True, | ||
"x_ticks_layout": "45°", | ||
"y": "country", | ||
"y_axis_bounds": [0, 100], | ||
"y_axis_format": "SMART_DATE", | ||
"y_axis_label": "Year", | ||
"y_axis_showminmax": False, | ||
"y_log_scale": True, | ||
} | ||
|
||
TARGET_FORM_DATA: dict[str, Any] = { | ||
"adhoc_filters": [], | ||
"color_scheme": "default", | ||
"entity": "count", | ||
"form_data_bak": SOURCE_FORM_DATA, | ||
"logXAxis": True, | ||
"logYAxis": True, | ||
"max_bubble_size": 50, | ||
"row_limit": 100, | ||
"series": ["region"], | ||
"show_legend": True, | ||
"size": 75, | ||
"truncateYAxis": True, | ||
"viz_type": "bubble_v2", | ||
"x": "year", | ||
"xAxisFormat": "SMART_DATE", | ||
"xAxisLabelRotation": 45, | ||
"x_axis_label": "Year", | ||
"x_axis_title_margin": 20, | ||
"y": "country", | ||
"y_axis_bounds": [0, 100], | ||
"y_axis_format": "SMART_DATE", | ||
"y_axis_label": "Year", | ||
"y_axis_title_margin": 20, | ||
} | ||
|
||
|
||
def test_migration() -> None: | ||
migrate_and_assert(MigrateBubbleChart, SOURCE_FORM_DATA, TARGET_FORM_DATA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but what's the reason we have a mix of snake- and camel-case in the chart properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always the same answer... 😏