Skip to content

fix(events): Sum chart tooltip showing raw floating-point value - #7846

Open
LaNinja06 wants to merge 3 commits into
masterfrom
fix/events-sum-chart-tooltip-precision
Open

fix(events): Sum chart tooltip showing raw floating-point value#7846
LaNinja06 wants to merge 3 commits into
masterfrom
fix/events-sum-chart-tooltip-precision

Conversation

@LaNinja06

@LaNinja06 LaNinja06 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The Events segmentation chart tooltip could show a sum like 303.35999999999996 instead of 303.36, while the summary tiles/table on the same page correctly rounded it. Root cause: the chart series pushed the raw accumulated float, and the tooltip's default formatter (getShortNumber) doesn't round for values in [0.1, 10000).

This rounds the sum series to 2 decimals at construction (matching the existing tile/table convention), and separately fixes a pre-existing bug in getShortNumber where .replace(".0", "") could corrupt values like 303.06 into 3036 by stripping the first mid-string .0 instead of only a trailing one.

Changes

  • countly.details.models.jsgetLineChartData and getBarChartData: round the s (sum) series to 2 decimals when building chart data.
  • countly.details.models.jsshowSumGraph in both functions now derives from the raw s values rather than the rounded series. Without this, buckets whose raw sums all round to 0.00 (e.g. 0.004) would hide the sum series entirely while the summary tile still showed a non-zero total.
  • countly.common.jsgetShortNumber: in the [0.1, 10000) branch only, .replace(".0", "").replace(/\.0$/, ""). That branch stringifies the raw float, so the digits after the decimal point are unbounded and a literal .0 could match mid-string. The K/M/B branches are deliberately left unchanged: they operate on .toFixed(1) output, which always has exactly one fractional digit, so .0 can only ever occur at the end there.

Verification

Verified against 7 cases (positive/negative sums, whole-number rounding, and the K-abbreviation boundary at 10000) — tooltip, tiles, and count/duration formatting all behave as expected with no regressions. The showSumGraph change was separately checked against the original, regressed, and fixed logic across tiny/negative/zero/null sums.

🤖 Generated with Claude Code

The Events segmentation chart tooltip could show a sum like
303.35999999999996 instead of 303.36, while the summary tiles/table
on the same page correctly rounded it. Root cause: the chart series
pushed the raw accumulated float, and the tooltip's default formatter
(getShortNumber) doesn't round for values in [0.1, 10000).

- Round the sum series to 2 decimals at construction in
  getLineChartData and getBarChartData (matching the tile/table
  convention).
- Fix a pre-existing bug in getShortNumber where
  .replace(".0", "") could corrupt values like 303.06 into "3036"
  by stripping the first mid-string ".0"; anchor to /\.0$/ so only a
  genuinely trailing ".0" (K/M/B abbreviations) is stripped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 24, 2026 17:27
@LaNinja06
LaNinja06 requested a review from kanwarujjaval July 24, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes inconsistent numeric formatting in the Events segmentation chart tooltip by rounding sum-series values to 2 decimals when constructing chart series data, aligning tooltip values with the existing tile/table rounding behavior. It also corrects a string-replacement bug in getShortNumber that could remove a mid-string .0 sequence and corrupt certain values.

Changes:

  • Round the Events “sum” series values to 2 decimals when building line and bar chart series data.
  • Fix getShortNumber to only strip a trailing .0 via replace(/\.0$/, ""), preventing mid-string corruption (e.g., 303.06).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/express/public/javascripts/countly/countly.common.js Fixes getShortNumber to only remove a trailing .0, preventing incorrect value corruption.
frontend/express/public/core/events/javascripts/countly.details.models.js Rounds sum-series values to 2 decimals when building chart series data for line/bar charts to avoid raw floating-point display.

Copilot AI review requested due to automatic review settings July 24, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Addresses review feedback on the platform counterpart of this fix:
showSumGraph was computed from the rounded series, so buckets whose raw
sums all round to 0.00 (e.g. 0.004) would hide the sum series entirely,
while the summary tiles - computed from raw chartData - still showed a
non-zero total.

Check the raw `s` values instead, which restores the pre-rounding
visibility semantics exactly while keeping the 2-decimal rounding for
display.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 27, 2026 21:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

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