Skip to content

Make legend width responsive#148

Merged
giswqs merged 3 commits intomainfrom
legend
Nov 23, 2025
Merged

Make legend width responsive#148
giswqs merged 3 commits intomainfrom
legend

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Nov 23, 2025

image

Copilot AI review requested due to automatic review settings November 23, 2025 18:37
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 23, 2025

@github-actions github-actions Bot temporarily deployed to pull request November 23, 2025 18:39 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces responsive width behavior for legend controls in MapLibre, allowing legends to automatically adjust their width based on content while respecting min/max constraints. The changes include new parameters for auto-sizing, custom header styling, and enhanced CSS rules for better content layout.

  • Adds responsive width functionality with auto_panel_width and responsive parameters
  • Introduces header customization with header_bg and header_text_color options
  • Enhances CSS styling for improved legend item layout and text handling

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
anymap/static/maplibre_widget.js Implements auto-width logic for widget panels, including display property management and dynamic width calculation via updateAutoWidth() method
anymap/static/maplibre_widget.css Adds responsive styling rules for legend content, increases title font size, and adds widget-specific CSS for better text handling and overflow control
anymap/maplibre.py Extends add_widget_control and add_legend methods with new parameters for responsive behavior and header styling, implements logic to determine width mode based on user preferences

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread anymap/maplibre.py
Comment on lines +1329 to +1331
auto_panel_width: bool = False,
header_bg: Optional[str] = None,
header_text_color: Optional[str] = None,
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The new parameters auto_panel_width, header_bg, and header_text_color are not documented in the docstring. Please add documentation for these parameters following the existing format:

  • auto_panel_width: Whether to enable automatic panel width that adapts to content. When True, the panel width will be determined by content size within min/max constraints.
  • header_bg: Optional background color for the panel header.
  • header_text_color: Optional text color for the panel header.

Copilot uses AI. Check for mistakes.
Comment thread anymap/maplibre.py
Comment on lines +5414 to +5416
header_color: Optional[str] = None,
header_text_color: Optional[str] = None,
responsive: Optional[bool] = True,
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The new parameters header_color, header_text_color, and responsive are not documented in the docstring. Please add documentation for these parameters in the Args section:

  • header_color: Optional background color for the legend header panel.
  • header_text_color: Optional text color for the legend header panel.
  • responsive: Whether to enable responsive width behavior. Defaults to True. When True, the legend width adapts to content size within min/max constraints. When False, a fixed width is used.

Copilot uses AI. Check for mistakes.
Comment on lines +367 to +395
.maplibregl-ctrl-widget-panel .widget-panel-content .widget-vbox {
width: fit-content !important;
max-width: 100% !important;
min-width: 0 !important;
display: block !important; /* Keep block display for proper vertical stacking */
}

/* Ensure HTML widgets within legend size to content but stack vertically */
.maplibregl-ctrl-widget-panel .widget-panel-content .widget-html {
width: fit-content !important; /* Size to content, not full width */
max-width: 100% !important;
display: block !important; /* Block display for vertical stacking */
box-sizing: border-box !important;
}

/* Ensure legend items stack vertically within the VBox */
.maplibregl-ctrl-widget-panel .widget-panel-content .widget-vbox > .widget-html {
margin-bottom: 4px !important; /* Consistent spacing between items */
}

.maplibregl-ctrl-widget-panel .widget-panel-content .widget-vbox > .widget-html:last-child {
margin-bottom: 0 !important; /* No margin on last item */
}

/* Ensure the VBox itself doesn't force full width on children */
.maplibregl-ctrl-widget-panel .widget-panel-content .widget-vbox {
flex-direction: column !important; /* Force vertical stacking */
align-items: flex-start !important; /* Align items to start, not stretch */
}
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

Duplicate CSS rule for .widget-vbox. This selector is defined at both lines 367-372 and 392-395. The second definition at lines 392-395 will override the first. Consider merging these rules to avoid confusion:

.maplibregl-ctrl-widget-panel .widget-panel-content .widget-vbox {
  width: fit-content !important;
  max-width: 100% !important;
  min-width: 0 !important;
  display: block !important;
  flex-direction: column !important;
  align-items: flex-start !important;
}

Copilot uses AI. Check for mistakes.
Comment thread anymap/maplibre.py
header_color: Optional[str] = None,
header_text_color: Optional[str] = None,
responsive: Optional[bool] = True,
**kwargs: Union[str, int, float],
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The type annotation for **kwargs is overly restrictive. It only includes Union[str, int, float], but the code now passes bool values (specifically auto_panel_width). This should be updated to:

**kwargs: Union[str, int, float, bool]
Suggested change
**kwargs: Union[str, int, float],
**kwargs: Union[str, int, float, bool],

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot temporarily deployed to pull request November 23, 2025 23:05 Inactive
@github-actions github-actions Bot temporarily deployed to pull request November 23, 2025 23:53 Inactive
@giswqs giswqs merged commit 94c593d into main Nov 23, 2025
8 checks passed
@giswqs giswqs deleted the legend branch November 23, 2025 23:55
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

Successfully merging this pull request may close these issues.

2 participants