Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Jan 10, 2024
1 parent 61ceb08 commit 756150d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/traffic/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ def geojson(self) -> dict[str, Any] | list[dict[str, Any]]:
"""
return mapping(self.shape) # type: ignore

def geoencode(self, **kwargs: Any) -> "alt.Chart": # coverage: ignore
def geoencode(
self, **kwargs: Any
) -> "alt.LayerChart | alt.Chart": # coverage: ignore
"""Returns an `altair <http://altair-viz.github.io/>`_ encoding of the
shape to be composed in an interactive visualization. Specific plot
features, such as line widths, can be passed with the kwargs argument.
Expand All @@ -433,9 +435,8 @@ def geoencode(self, **kwargs: Any) -> "alt.Chart": # coverage: ignore
"""
import altair as alt

return alt.Chart(
alt.Data(values=self.geojson()) # type: ignore
).mark_geoshape(stroke="#aaaaaa", **kwargs)
data = alt.Data(values=self.geojson()) # type: ignore
return alt.Chart(data).mark_geoshape(stroke="#aaaaaa", **kwargs)

def project_shape(
self, projection: None | pyproj.Proj | "crs.Projection" = None
Expand Down
23 changes: 11 additions & 12 deletions src/traffic/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,31 @@ def runways(self) -> Optional[RunwayAirport]:

return runways[self]

def geoencode( # type: ignore
def geoencode(
self,
footprint: Union[bool, Dict[str, Any]] = True,
runways: Union[bool, Dict[str, Any]] = True,
labels: Union[bool, Dict[str, Any]] = True,
) -> "alt.Chart": # coverage: ignore
footprint: Union[bool, Dict[str, Dict[str, Any]]] = True,
runways: Union[bool, Dict[str, Dict[str, Any]]] = True,
labels: Union[bool, Dict[str, Dict[str, Any]]] = True,
**kwargs: Any,
) -> "alt.LayerChart": # coverage: ignore
import altair as alt

base = alt.Chart(self).mark_geoshape()
cumul = []
if footprint:
params = dict(
params: Dict[str, Dict[str, Any]] = dict(
aerodrome=dict(color="gainsboro", opacity=0.5),
apron=dict(color="darkgray", opacity=0.5),
terminal=dict(color="#888888"),
hangar=dict(color="#888888"),
taxiway=dict(filled=False, color="silver", strokeWidth=1.5),
)
if isinstance(footprint, dict):
footprint = {**params, **footprint}
else:
footprint = params
params = {**params, **footprint}

for key, value in footprint.items():
for key, value in params.items():
cumul.append(
base.transform_filter( # type: ignore
base.transform_filter(
f"datum.aeroway == '{key}'"
).mark_geoshape(**value)
)
Expand All @@ -227,7 +226,7 @@ def geoencode( # type: ignore
raise TypeError(
"At least one of footprint, runways and labels must be True"
)
return alt.layer(*cumul) # type: ignore
return alt.layer(*cumul)

def plot( # type: ignore
self,
Expand Down

0 comments on commit 756150d

Please sign in to comment.