Skip to content

Fix packed multitext chart colors for gates#406

Open
xinaesthete wants to merge 1 commit into
mainfrom
codex/fix-gates-chart-colors
Open

Fix packed multitext chart colors for gates#406
xinaesthete wants to merge 1 commit into
mainfrom
codex/fix-gates-chart-colors

Conversation

@xinaesthete

@xinaesthete xinaesthete commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • update DataStore.getColorFunction to resolve packed multitext values by row stride instead of treating the buffer as one value per row
  • preserve existing behavior for legacy single-slot multitext columns
  • add regression tests covering both legacy tag-style and packed gates-style multitext color lookups

Testing

  • Not run (not requested)

Summary by CodeRabbit

  • Bug Fixes

    • Corrected color display behavior for fields that can contain multiple values. The updated logic now properly identifies and skips empty values, using the first meaningful value to determine the display color.
  • Tests

    • Added extensive test coverage to validate color mapping functionality across different field configurations, including both single-value and multi-value scenarios.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR modifies the color mapping logic for multitext-typed columns in DataStore. For multitext columns with capacity greater than 1, the implementation now iterates through packed values instead of using a single index, returning the color of the first non-empty semantic value or a computed fallback color. Single-capacity multitext retains legacy behavior.

Changes

Cohort / File(s) Summary
Multitext Color Mapping
src/datastore/DataStore.js
Refactored getColorFunction to handle multitext columns with special case logic: single-capacity multitext uses index-based color mapping; multi-capacity multitext iterates through packed values, skipping sentinels/null values, returning first non-empty value's color or computed fallback.
Multitext Color Tests
src/tests/datastore-color.multitext.spec.ts
Added new test suite covering getColorFunction for multitext columns, validating both legacy single-slot behavior and packed multitext value color resolution across multiple rows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through packed values with glee,
Colors dance where sentinels used to be!
Single slots stay steady, true and bright,
While multitext rows find their fallback light.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix packed multitext chart colors for gates' directly and specifically describes the main change: handling packed multitext values correctly for gate chart coloring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-gates-chart-colors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify

netlify Bot commented Apr 8, 2026

Copy link
Copy Markdown

Deploy Preview for mdv-dev ready!

Name Link
🔨 Latest commit 9508477
🔍 Latest deploy log https://app.netlify.com/projects/mdv-dev/deploys/69d67432188f08000814fb0b
😎 Deploy Preview https://deploy-preview-406--mdv-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@xinaesthete
xinaesthete marked this pull request as ready for review April 8, 2026 15:32

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/tests/datastore-color.multitext.spec.ts (1)

32-61: Add coverage for the empty-item-skip path.

The packed fixture covers “fallback only” and “real value first”, but it never exercises the branch where "N/A" is encountered before a real value. A row like [0, 2, 65535] would catch a regression that returns the fallback color too early.

Possible test extension
         const column = {
             field: "__gates__",
             name: "gates",
             datatype: "multitext" as const,
             delimiter: ",",
             stringLength: 3,
             values: ["N/A", "a", "b"],
             data: new Uint16Array([
                 0, 65535, 65535,
                 2, 65535, 65535,
-                1, 2, 65535,
+                0, 2, 65535,
+                1, 2, 65535,
             ]),
         };
@@
         expect(colorFn(0)).toBe("#999999");
         expect(colorFn(1)).toBe("#00ff00");
-        expect(colorFn(2)).toBe("#ff0000");
+        expect(colorFn(2)).toBe("#00ff00");
+        expect(colorFn(3)).toBe("#ff0000");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/datastore-color.multitext.spec.ts` around lines 32 - 61, The test
for multitext packed colors misses the path where an empty/fallback entry
appears before a real value; extend the "reads packed multitext colors using row
stride" test by adding another row in the column.data that represents [0, 2,
65535] (i.e., fallback then real value then sentinel) and assert the produced
colorFn for that row index returns the real value color (use
DataStore.prototype.getColorFunction.call(store, "__gates__", {}) to obtain
colorFn and verify the returned color matches the expected "#00ff00" instead of
the fallback "#999999"), ensuring the test exercises the empty-item-skip branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/datastore/DataStore.js`:
- Around line 1514-1517: The loop in DataStore.js that iterates "for (let offset
= 0; offset < capacity; offset++)" currently breaks when valueIndex == null ||
valueIndex === 65535, causing it to stop scanning packed rows prematurely;
change the logic in that loop so it only treats null/undefined (valueIndex ==
null) as a break/stop condition but treats the 65535 sentinel as "skip this
slot" and continues scanning (i.e., do not break on valueIndex === 65535),
matching the behavior in valueReplacementUtil.ts and the handling at line ~503;
ensure you still return the first non-sentinel semantic value found within the
packed slice or fall back appropriately if none exist.

---

Nitpick comments:
In `@src/tests/datastore-color.multitext.spec.ts`:
- Around line 32-61: The test for multitext packed colors misses the path where
an empty/fallback entry appears before a real value; extend the "reads packed
multitext colors using row stride" test by adding another row in the column.data
that represents [0, 2, 65535] (i.e., fallback then real value then sentinel) and
assert the produced colorFn for that row index returns the real value color (use
DataStore.prototype.getColorFunction.call(store, "__gates__", {}) to obtain
colorFn and verify the returned color matches the expected "#00ff00" instead of
the fallback "#999999"), ensuring the test exercises the empty-item-skip branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 18d71f2b-420f-412d-a246-5d36d394abf9

📥 Commits

Reviewing files that changed from the base of the PR and between 2561062 and 9508477.

📒 Files selected for processing (2)
  • src/datastore/DataStore.js
  • src/tests/datastore-color.multitext.spec.ts

Comment on lines +1514 to +1517
for (let offset = 0; offset < capacity; offset++) {
const valueIndex = data[start + offset];
if (valueIndex == null || valueIndex === 65535) {
break;

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.

⚠️ Potential issue | 🟡 Minor

Keep scanning past 65535 sentinels inside packed rows.

Line 1516 currently breaks on the first empty slot. That disagrees with Line 503 and src/react/utils/valueReplacementUtil.ts:100-110, which both skip 65535 values anywhere in the packed slice. A row like [0, 65535, 2] would now fall back too early instead of returning the later semantic value.

Possible fix
-                    if (valueIndex == null || valueIndex === 65535) {
-                        break;
+                    if (valueIndex == null) {
+                        break;
+                    }
+                    if (valueIndex === 65535) {
+                        continue;
                     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (let offset = 0; offset < capacity; offset++) {
const valueIndex = data[start + offset];
if (valueIndex == null || valueIndex === 65535) {
break;
for (let offset = 0; offset < capacity; offset++) {
const valueIndex = data[start + offset];
if (valueIndex == null) {
break;
}
if (valueIndex === 65535) {
continue;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/datastore/DataStore.js` around lines 1514 - 1517, The loop in
DataStore.js that iterates "for (let offset = 0; offset < capacity; offset++)"
currently breaks when valueIndex == null || valueIndex === 65535, causing it to
stop scanning packed rows prematurely; change the logic in that loop so it only
treats null/undefined (valueIndex == null) as a break/stop condition but treats
the 65535 sentinel as "skip this slot" and continues scanning (i.e., do not
break on valueIndex === 65535), matching the behavior in valueReplacementUtil.ts
and the handling at line ~503; ensure you still return the first non-sentinel
semantic value found within the packed slice or fall back appropriately if none
exist.

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