Skip to content

Commit 749994b

Browse files
committed
fix #167
1 parent debc79b commit 749994b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
* **Interactive legends**: New opt-in interactivity for map legends enables direct data filtering from the legend:
66
- Categorical legends: Click legend items to toggle category visibility on the map. Disabled categories are visually indicated with reduced opacity and strikethrough text.
77
- Continuous legends: Drag dual handles on the gradient bar to filter data within a selected range. Ghost overlays indicate excluded regions, and the middle section can be dragged to pan the selection window.
8-
- New parameters `interactive = TRUE`, `filter_column`, and `classification` in legend functions
8+
- New parameters `interactive = TRUE`, `filter_column`, `filter_values`, and `classification` in legend functions
99
- Smart number formatting with K/M notation for large values in legend labels
1010
- New `interactive_legend` parameter in `maplibre_view()` and `mapboxgl_view()` for quick interactive visualizations
1111
- Full Shiny integration with filter state available via input values
1212
- Works with GeoJSON, vector tiles, and PMTiles sources
1313

14+
* **Draggable legends**: New `draggable = TRUE` parameter allows users to drag legends to any position on the map. Supports both mouse and touch interactions.
15+
1416
* **Screenshot control**: New `add_screenshot_control()` function allows users to capture and download map screenshots as PNG images. Includes `image_scale` parameter for controlling output resolution.
1517

1618
* **Globe projection for compare views**: Compare maps in MapLibre now properly respect globe projection when specified.
1719

1820
* **Bug fixes and improvements**:
21+
- Fixed floating-point precision issue in interactive legend filters that could exclude edge values
1922
- Fixed continuous legend error when values are pre-formatted character strings (e.g., from `get_legend_labels()`)
2023
- Fixed draw control source handling for better feature management (#164)
2124
- Fixed `step_expr()` to properly handle quoted column names (#148)

inst/htmlwidgets/lib/legend-interactivity/legend-interactivity.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,16 @@ function applyRangeFilter(
822822
) {
823823
var layerState = window._mapglLayerState[mapId];
824824

825+
// Add small epsilon to handle floating-point precision issues
826+
// This prevents edge values from being excluded due to tiny precision differences
827+
var epsilon = Math.abs(max - min) * 1e-10;
828+
var filterMin = min - epsilon;
829+
var filterMax = max + epsilon;
830+
825831
var interactiveFilter = [
826832
"all",
827-
[">=", ["get", column], min],
828-
["<=", ["get", column], max]
833+
[">=", ["get", column], filterMin],
834+
["<=", ["get", column], filterMax]
829835
];
830836

831837
// Combine with original filter if exists

0 commit comments

Comments
 (0)