Repository navigation
grass.jupyter: Style vectors the same way on both backends - #8107
Valyrian-Code wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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.
|
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 |
|
@Valyrian-Code |
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.
|
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. |
Step 1 of #7626. Styling a vector meant backend specific code until now, a
style_functionfor folium or astyledict for ipyleaflet, and onlyopacitywas normalised.This adds
color,fill_color,width,opacityandfill_opacity, using the d.vect names as discussed in the issue:The translation to Leaflet names is a plain function with no backend imports, so it is tested on its own. A
style_functionor astylegiven 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. Bareopacitystill 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.