Encode fields. example: .encode(x="field_0", y="field_1", color="field_2") .encode(x="field_0", y="SUM(field_1)")
(
self,
x: Union[str, List[str]] = "",
y: Union[str, List[str]] = "",
color: str = "",
opacity: str = "",
size: str = "",
shape: str = "",
radius: str = "",
theta: str = "",
longitude: str = "",
latitude: str = "",
geoid: str = "",
details: str = "",
text: str = "",
)
| 305 | |
| 306 | # pylint: disable=unused-argument |
| 307 | def encode( |
| 308 | self, |
| 309 | x: Union[str, List[str]] = "", |
| 310 | y: Union[str, List[str]] = "", |
| 311 | color: str = "", |
| 312 | opacity: str = "", |
| 313 | size: str = "", |
| 314 | shape: str = "", |
| 315 | radius: str = "", |
| 316 | theta: str = "", |
| 317 | longitude: str = "", |
| 318 | latitude: str = "", |
| 319 | geoid: str = "", |
| 320 | details: str = "", |
| 321 | text: str = "", |
| 322 | ) -> "Component": |
| 323 | """ |
| 324 | Encode fields. |
| 325 | example: .encode(x="field_0", y="field_1", color="field_2") |
| 326 | .encode(x="field_0", y="SUM(field_1)") |
| 327 | """ |
| 328 | all_params = { |
| 329 | key: [value] if isinstance(value, str) else value |
| 330 | for key, value in locals().items() |
| 331 | if key != "self" |
| 332 | } |
| 333 | copied_obj = self.copy() |
| 334 | params_key_map = { |
| 335 | "x": "columns", |
| 336 | "y": "rows", |
| 337 | "geoid": "geoId", |
| 338 | } |
| 339 | |
| 340 | for key, field_str_list in all_params.items(): |
| 341 | field_list = [] |
| 342 | for field_str in field_str_list: |
| 343 | if not field_str: |
| 344 | continue |
| 345 | field_info = copied_obj._convert_string_to_field_info(field_str) |
| 346 | if field_info.get("aggName"): |
| 347 | copied_obj._update_single_chart_spec("config__defaultAggregated", True) |
| 348 | field_list.append(field_info) |
| 349 | if field_info["fid"] not in copied_obj._field_map: |
| 350 | copied_obj._field_map[field_info["fid"]] = field_info |
| 351 | if field_info["analyticType"] == "dimension": |
| 352 | copied_obj._single_chart_spec["encodings"]["dimensions"].append(field_info) |
| 353 | else: |
| 354 | copied_obj._single_chart_spec["encodings"]["measures"].append(field_info) |
| 355 | copied_obj._single_chart_spec["encodings"][params_key_map.get(key, key)] = field_list |
| 356 | |
| 357 | return copied_obj |
| 358 | |
| 359 | # pylint: enable=unused-argument |
| 360 | def layout( |
no test coverage detected