Skip to content

grass.jupyter: Style vectors the same way on both backends - #8107

Open
Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:jupyter-vector-styling
Open

Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:jupyter-vector-styling

Conversation

@Valyrian-Code

Copy link
Copy Markdown
Contributor

Step 1 of #7626. Styling a vector meant backend specific code until now, a style_function for folium or a style dict for ipyleaflet, and only opacity was normalised.

This adds color, fill_color, width, opacity and fill_opacity, using the d.vect names as discussed in the issue:

m.add_vector("roadsmajor", color="black", width=2, fill_color="#ffff00", fill_opacity=0.4)

The translation to Leaflet names is a plain function with no backend imports, so it is tested on its own. A style_function or a style given directly still wins, so existing code keeps its behavior.

Checked on both backends with the same call: folium gets {'color': 'blue', 'weight': 3} from the generated style_function, ipyleaflet gets {'color': 'black', 'fillColor': '#ffff00', 'weight': 2, 'fillOpacity': 0.4} as its style. Bare opacity still works as before. All 50 jupyter tests pass.

@Jayant-kernel this is the interface for step 2, point styling and colouring by a column.

Suggested squash commit message

grass.jupyter: Style vectors the same way on both backends

Adds color, fill_color, width, opacity and fill_opacity to add_vector, using the d.vect names. Styling a vector meant writing backend specific code until now, a style_function for folium or a style dictionary for ipyleaflet.

The translation to Leaflet names is a plain function with no backend imports, so it can be tested on its own. Each backend then takes the result in the form it wants. Replaces the shim which did this for opacity alone. A style_function or a style given directly still wins.

Adds color, fill_color, width, opacity and fill_opacity to add_vector, using
the d.vect names. Styling a vector meant writing backend specific code until
now, a style_function for folium or a style dictionary for ipyleaflet.

The translation to Leaflet names is a plain function with no backend imports,
so it can be tested on its own. Each backend then takes the result in the
form it wants.

Replaces the shim which did this for opacity alone. A style_function or a
style given directly still wins, so existing code keeps its behavior.

This is the first step of OSGeo#7626 and covers lines and areas. Point styling and
colouring by a column come next.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite notebook labels Oct 22, 2026
@Jayant-kernel

Copy link
Copy Markdown

I’ll take a look at the translator and start working out the approach for point styling and colouring by a column and keep an eye on this PR as it goes through review

@Jayant-kernel

Copy link
Copy Markdown

@Valyrian-Code
One thing I noticed: with opacity=0.4, style={"opacity": 0.9}, ipyleaflet used to use 0.4, but this merge makes it use 0.9.
Could we keep the old behavior and add a test through Vector.add_to() to cover it?

The opacity shim set style["opacity"] from the opacity argument, so the
argument won over the same key in a style passed directly. The merge
introduced with the named options had it the other way around, which changed
what opacity=0.4 with style={"opacity": 0.9} does on ipyleaflet.

Swaps the merge order back and covers it with a test through add_to, along
with one for keys that only the style sets.

folium keeps a style_function given directly, since a callable is not
something a dictionary can merge into.
@Valyrian-Code

Copy link
Copy Markdown
Contributor Author

You were right, swapped it back. The old shim set style["opacity"] from the argument, so the argument won, and I had it the other way round. Added a test through add_to for it, which fails on the old merge order so it actually guards the thing.

folium keeps a style_function if you pass one, since a dict cannot merge into a callable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries notebook Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants