fix: consistent value-to-legend-item matching and small fixes [PR1] [DHIS2-18242]#3645
Open
BRaimbault wants to merge 6 commits into
Open
fix: consistent value-to-legend-item matching and small fixes [PR1] [DHIS2-18242]#3645BRaimbault wants to merge 6 commits into
BRaimbault wants to merge 6 commits into
Conversation
Contributor
|
🚀 Deployed on https://pr-3645.maps.netlify.dhis2.org |
BRaimbault
commented
Apr 24, 2026
Collaborator
Author
BRaimbault
left a comment
There was a problem hiding this comment.
Ready for review.
edoardo
approved these changes
Apr 27, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Parent
Overview
Foundational refactor and small bug fixes extracted from the parent epic, landing first as a prerequisite for the classification and legend work to follow. No user-visible feature change (except the clamp fix, see below); mostly internal plumbing.
Changes
Thread
valueFormatthrough value-to-legend-item matchinggetLegendItemsand its helpers (getEqualIntervals,getQuantiles) now return{ items, valueFormat }instead of a bare array.getAutomaticLegendItemspropagates thevalueFormat, and both callers (thematicLoader.jsandstyleByDataItem.js) pass it togetLegendItemForValue. Incoming values are rounded to the same precision as bin boundaries before comparison, eliminating a class of off-by-epsilon mismatches at bin edges.Files:
src/util/classify.js,src/util/legend.js,src/loaders/thematicLoader.js,src/util/styleByDataItem.jsNamed args for
getAutomaticLegendItemsSwitched from positional to named parameters; removes the
eslint-disable max-paramsoverride.Unified clamp behavior between thematic and event layers
Event style-by-data-item with automatic classification didn't clamp out-of-range values while thematic layer did — a pre-existing asymmetry in master. Both callers now use
clamp: method !== CLASSIFICATION_PREDEFINED.Consequence: events with values slightly outside the auto-classified range (typically a rounding-gap artefact) are now pulled into the nearest bin instead of being dropped to the "Other" colour. The "Other" bucket still catches values that genuinely have no data.
Files:
src/loaders/thematicLoader.js,src/util/styleByDataItem.jsFix min/max calculation in
thematicLoader.jsfor legend setsWhen a predefined legendSet was used,
minValue/maxValuewere read fromlegend.items[0]andlegend.items[legend.items.length - 1]. If anoDataitem was present at either end, its sentinel value was pickedup and corrupted the bubble-radius
scaleSqrtdomain. Fixed by filteringnoDataitems first. The.at(-1)rewrite is cosmetic.Files:
src/loaders/thematicLoader.jsRobust legend-item sorting
sortLegendItemsrewritten:[...items].sort(...)){ from, to }and{ startValue, endValue }shapes on both sides of the comparator (previously onlyawas inspected)Files:
src/util/legend.jsFilter noData items by flag in
styleByDataItem.jsReplaced
config.legend.items.slice(0, -1)withlegend.items.filter((item) => !item.noData). The "Other" legend itemnow carries
noData: trueso the filter captures it. Mirrors the pattern already used inthematicLoader.js; forward-compatible with additional noData items that later PRs may introduce.Files:
src/util/styleByDataItem.jsLocal variable renames and dead-guard removal in
classify.jsPure readability cleanup in
getQuantiles/getEqualIntervals:bins→items,binSize→classSize,binCount→valuesCount,binLastValPos→lastValuePosition. Dropped the unreachablebinCount === 0 ? 0 : binCountguard (always equivalent tobinCountbecause the enclosingif (values.length > 0)is skipped when it would matter). Added?? {}fallback ingetLegendItemsfor unknown methods.Files:
src/util/classify.jsDrive-by modernisations
String.prototype.replace(/…/g, …)→replaceAll(…, …)in 9 filesisNaN(x)→Number.isNaN(x)inPeriodSelect.jsxandRadiusSelect.jsxNo behaviour change. Addresses SonarQube findings.
Tests update
src/util/__tests__/classify.spec.jssrc/util/__tests__/legend.spec.jsQuality checklist
Add N/A to items that are not applicable.