Skip to content
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

Support concatenation #33

Open
binste opened this issue Nov 24, 2023 · 2 comments
Open

Support concatenation #33

binste opened this issue Nov 24, 2023 · 2 comments

Comments

@binste
Copy link
Collaborator

binste commented Nov 24, 2023

See #31 (comment)

@mattijn
Copy link
Contributor

mattijn commented Nov 29, 2023

The comment in OP refers to two tile_charts next to each other.

Another concatenation issue is the following, while trying to add a basemap to the following example in the altair gallery: https://altair-viz.github.io/gallery/interval_selection_map_quakes.html

This works:

import altair as alt
import altair_tiles as til
from vega_datasets import data
import geopandas as gpd

# load data
gdf_quakies = gpd.read_file(data.earthquakes.url, driver="GeoJSON")

# defintion for interactive brush
brush = alt.selection_interval(
    encodings=["longitude"],
    empty=False,
    value={"longitude": [-50, -110]}
)

# world disk
sphere = alt.Chart(alt.sphere()).mark_geoshape(
    fill="transparent", stroke="lightgray", strokeWidth=1
)

# earthquakes as dots on map
quakes = alt.Chart(gdf_quakies).transform_calculate(
    lon="datum.geometry.coordinates[0]",
    lat="datum.geometry.coordinates[1]",
).mark_circle(opacity=0.35, tooltip=True).encode(
    longitude="lon:Q",
    latitude="lat:Q",
    color=alt.condition(brush, alt.value("goldenrod"), alt.value("steelblue")),
    size=alt.Size("mag:Q").scale(type="pow", range=[1, 1000], domain=[0, 7], exponent=4),
).add_params(brush)

# combine layers for the map
left_map = alt.layer(til.create_tiles_chart(), sphere, quakes).project(type="mercator").properties(width=300, height=300)
left_map
image

But adding bars as chart next to it, make the tile-layer disappear:

# histogram of binned earthquakes
bars = alt.Chart(gdf_quakies).mark_bar().encode(
    x=alt.X("mag:Q").bin(extent=[0,7]),
    y="count(mag):Q",
    color=alt.value("steelblue")
)

# filtered earthquakes
bars_overlay = bars.encode(color=alt.value("goldenrod")).transform_filter(brush)

# combine layers for histogram
right_bars = alt.layer(bars, bars_overlay)

left_map | right_bars
image

Increasing the width of the left_map does something:

left_map.properties(width=400) | right_bars
image

@tillnagel
Copy link

Same here. Just commenting to say this does not work independent on creation mode: when creating an independent map (through create_tiles_chart), and when adding a map to a chart (through add_tiles).

I also noticed that the tiles are not even requested. Meaning, the behavior is not: map is being rendered and then not displayed - but, I assume, the size of the map is wrongly specified due to the concatenation / some offset not being considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants