Skip to content

feat: configurable decimal precision for automatic legends [PR4] [DHIS2-18242]#3648

Open
BRaimbault wants to merge 14 commits into
feat/DHIS2-18242-PR3from
feat/DHIS2-18242-PR4
Open

feat: configurable decimal precision for automatic legends [PR4] [DHIS2-18242]#3648
BRaimbault wants to merge 14 commits into
feat/DHIS2-18242-PR3from
feat/DHIS2-18242-PR4

Conversation

@BRaimbault
Copy link
Copy Markdown
Collaborator

@BRaimbault BRaimbault commented Apr 26, 2026

Parent

Implements

  • DHIS2-3156: Decimal places option for automatic legend classification
  • DHIS2-19984: Values not displayed for NUMBER data items with option sets in data table
  • DHIS2-19983: Range column not sorted numerically in data table
  • DHIS2-19982: Color picker button too narrow in option set and boolean styles
  • DHIS2-19203: Earth Engine style select uses "Steps" instead of "Classes"

Overview

Fourth PR in the series extracted from the parent epic. Adds a legendDecimalPlaces setting that controls how many decimal places are shown in automatic legend range labels, and fixes four smaller issues surfaced during the same work.

Changes

Configurable decimal precision for automatic legends DHIS2-3156

A new DecimalPlacesSelect component (0–6 places) is added to the Classification and Single Color panels for automatic and single-color legends. The selected value is stored in Redux via a new SET_LEGEND_DECIMAL_PLACES action and persisted into layer.config JSON on save (via favorites.js) and parsed back on load (via parseJsonConfig).

getLegendItems accepts a precision option that rounds bin boundaries via getRoundToPrecisionFn. getAutomaticLegendItems accepts legendDecimalPlaces and stamps decimalPlaces onto each item. Both LegendItemRange and Bubbles.jsx read per-item decimalPlaces and pass it as precision to formatWithSeparator, so legend range labels and bubble text labels render with the configured precision. styleByDataItem.js propagates legendDecimalPlaces for event layer style-by-data-item.

legendDecimalPlaces is added to validLayerProperties so it survives the pick in cleanMapConfig.

Note that values are displayed using their stored precision; this setting only affects legend formatting. Also, range is only passed to the data table for Thematic Automatic and Prefefined legends, this behavior is not modified.

Files: src/util/classify.js, src/util/legend.js, src/util/config.js, src/util/favorites.js, src/util/styleByDataItem.js, src/components/classification/Classification.jsx, src/components/classification/DecimalPlacesSelect.jsx, src/components/classification/SingleColor.jsx, src/components/legend/Bubbles.jsx, src/components/legend/LegendItem.jsx, src/components/legend/LegendItemRange.jsx, src/loaders/thematicLoader.js, src/loaders/eventLoader.js, src/actions/layerEdit.js, src/reducers/layerEdit.js, src/constants/actionTypes.js

NUMBER data items with option sets show empty cells in the data table DHIS2-19984

When a program stage data element has valueType = NUMBER and an associated option set, the values stored in event data are option codes (strings such as "high" or "low"). eventLoader was running parseFloat() on all numeric-typed headers unconditionally — parseFloat("high") = NaN. useTableData then typed those headers as TYPE_NUMBER, and the isNaN guard rendered the cell empty.

Fixed by excluding option-set-backed headers from the parseFloat conversion in eventLoader, and by typing them as TYPE_STRING in useTableData regardless of their valueType.

Files: src/loaders/eventLoader.js, src/components/datatable/useTableData.js

Range column sorts lexicographically instead of numerically DHIS2-19983

The range column in the data table was typed as TYPE_STRING, so "10 - 20" sorted before "9 - 15". Fixed by typing it as TYPE_NUMBER and providing a custom sort key that parses the range string via parseRange and compares by startValue (with endValue as a tiebreaker).

Files: src/components/datatable/useTableData.js

Color picker button too narrow in option set and boolean styles DHIS2-19982

The color picker trigger button was clipped at small widths. Widened via CSS.

Files: src/components/optionSet/OptionStyle.jsx, src/components/optionSet/styles/OptionStyle.module.css

Earth Engine style select labels the bin count field "Steps" instead of "Classes" DHIS2-19203

Renamed to "Classes" to match the label used elsewhere in the classification UI.

Files: src/components/edit/earthEngine/StyleSelect.jsx

Tests update

  • src/util/__tests__/classify.spec.js
  • src/util/__tests__/legend.spec.js
  • src/util/__tests__/favorites.spec.js
  • src/components/datatable/__tests__/useTableData.spec.jsx

Manual testing

Netlify: https://pr-3648.maps.netlify.dhis2.org/ + Instance: https://dev.im.dhis2.org/maps-app-42-3

Quality checklist

Add N/A to items that are not applicable.

  • Jest tests added/updated
  • Docs added N/A
  • d2-ci dependencies replaced N/A
  • Include plugin in testing N/A
  • Tester approved (@edoardo)

@dhis2-bot
Copy link
Copy Markdown
Contributor

dhis2-bot commented Apr 26, 2026

🚀 Deployed on https://pr-3648.maps.netlify.dhis2.org

@dhis2-bot dhis2-bot temporarily deployed to netlify April 26, 2026 20:47 Inactive
@BRaimbault BRaimbault force-pushed the feat/DHIS2-18242-PR4 branch from 3442e70 to c520c9b Compare April 26, 2026 20:53
@dhis2-bot dhis2-bot temporarily deployed to netlify April 26, 2026 20:55 Inactive
@BRaimbault BRaimbault force-pushed the feat/DHIS2-18242-PR3 branch from 78342d0 to 070dd74 Compare April 26, 2026 20:57
@dhis2-bot dhis2-bot temporarily deployed to netlify April 26, 2026 21:00 Inactive
Copy link
Copy Markdown
Collaborator Author

@BRaimbault BRaimbault left a comment

Choose a reason for hiding this comment

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

Ready for review.

@BRaimbault BRaimbault marked this pull request as ready for review April 26, 2026 21:03
@BRaimbault BRaimbault requested a review from a team April 27, 2026 10:03
@dhis2-bot dhis2-bot temporarily deployed to netlify April 27, 2026 11:17 Inactive
@BRaimbault BRaimbault force-pushed the feat/DHIS2-18242-PR4 branch from 396fabe to 1261149 Compare April 27, 2026 12:55
@dhis2-bot dhis2-bot temporarily deployed to netlify April 27, 2026 12:57 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify April 27, 2026 13:00 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify April 27, 2026 16:11 Inactive
@sonarqubecloud
Copy link
Copy Markdown

@dhis2-bot dhis2-bot temporarily deployed to netlify May 14, 2026 13:29 Inactive
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.

3 participants