Skip to content

Commit 965951a

Browse files
authored
Merge pull request #476 from palewire/main
Automatically handle the `group_by_column` field on the ArrowChart
2 parents 1b754fc + b4de9bc commit 965951a

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

datawrapper/charts/arrow.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ class ArrowChart(BaseChart):
169169
description="The column to label by",
170170
)
171171

172+
#: The column to group arrows by
173+
groups_column: str | None = Field(
174+
default=None,
175+
description="The column to group arrows by",
176+
)
177+
172178
#
173179
# Features
174180
#
@@ -180,13 +186,6 @@ class ArrowChart(BaseChart):
180186
description="Label on the first arrow that shows column names",
181187
)
182188

183-
#: Enables the group-by-column feature, works with "Group" field
184-
group_by_column: bool = Field(
185-
default=False,
186-
alias="group-by-column",
187-
description="Enables the group-by-column feature, works with 'Group' field",
188-
)
189-
190189
@field_validator("replace_flags")
191190
@classmethod
192191
def validate_replace_flags(
@@ -224,7 +223,7 @@ def serialize_model(self) -> dict:
224223
"range-extent": self.range_extent,
225224
"value-label-format": self.value_label_format,
226225
"color-by-column": bool(self.color_category),
227-
"group-by-column": self.group_by_column,
226+
"group-by-column": self.groups_column is not None,
228227
"replace-flags": ReplaceFlags.serialize(self.replace_flags),
229228
"show-arrow-key": self.arrow_key,
230229
}
@@ -240,6 +239,8 @@ def serialize_model(self) -> dict:
240239
axes_dict["colors"] = self.color_column
241240
if self.label_column is not None:
242241
axes_dict["labels"] = self.label_column
242+
if self.groups_column is not None:
243+
axes_dict["groups"] = self.groups_column
243244

244245
# Only add axes section if there are fields to include
245246
if axes_dict:
@@ -319,10 +320,10 @@ def deserialize_model(cls, api_response: dict[str, Any]) -> dict[str, Any]:
319320
init_data["color_column"] = axes["colors"]
320321
if "labels" in axes:
321322
init_data["label_column"] = axes["labels"]
323+
if "groups" in axes:
324+
init_data["groups_column"] = axes["groups"]
322325

323326
# Features
324-
if "group-by-column" in visualize:
325-
init_data["group_by_column"] = visualize["group-by-column"]
326327
if "show-arrow-key" in visualize:
327328
init_data["arrow_key"] = visualize["show-arrow-key"]
328329

tests/integration/test_arrow_chart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_serialize_with_features(self):
210210
data=pd.DataFrame({"x": [1, 2], "y": [10, 20], "z": [15, 25]}),
211211
start_column="y",
212212
end_column="z",
213-
group_by_column=True,
213+
groups_column="x", # Setting groups_column should enable group-by-column
214214
arrow_key=True,
215215
)
216216

@@ -289,7 +289,7 @@ def mock_get(url):
289289
# Verify features
290290
assert chart.thick_arrows is True
291291
assert chart.arrow_key is True
292-
assert chart.group_by_column is True
292+
assert chart.groups_column == "Gender"
293293

294294
# Verify sorting
295295
assert chart.sort_ranges is False

0 commit comments

Comments
 (0)