Skip to content

feat(component): add rule-based styling for Graph and Map charts - #278

Merged
alfredo1996 merged 1 commit into
improve/charts-integrationfrom
improve/charts-graph-map-styling
Mar 30, 2026
Merged

feat(component): add rule-based styling for Graph and Map charts#278
alfredo1996 merged 1 commit into
improve/charts-integrationfrom
improve/charts-graph-map-styling

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Mar 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Graph: rule-based node color via stylingRules prop, evaluated against node.value
  • Map: rule-based marker color via stylingRules prop, evaluated against marker.value
  • Registry: supportsStyling: true for both, with stylingTargets
  • Renderer: forwards stylingRules/paramValues to Graph and Map cases
  • Closes feat(component): add styling support for Graph and Map charts #259

Test plan

  • 3 new graph styling tests (TDD)
  • 3 new map styling tests (TDD: RED first, then GREEN)
  • 4 existing tests updated for new styling support
  • Component tests pass (1200)
  • App tests pass (1559)
  • CI green
  • SonarCloud quality gate

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Graph and map visualizations now support rule-based styling to dynamically color nodes and markers based on data values and custom rules.
  • Tests

    • Added comprehensive test coverage for rule-based styling functionality in graph and map chart components.

Closes #259

Graph chart:
- Add stylingRules/paramValues props to GraphChartProps
- Evaluate rules against node.value in toNvlNode()
- Rule color takes priority over explicit node.color and label palette
- 3 new tests: rule match, priority over explicit color, no-value skip

Map chart:
- Add stylingRules/paramValues props to MapChartProps
- Evaluate rules against marker.value in marker creation loop
- Rule color takes priority over explicit marker.color
- 3 new tests (TDD: written RED first, then implemented GREEN)

Registry + renderer:
- Set supportsStyling: true for graph and map
- Add stylingTargets with "Node Color" / "Marker Color"
- Forward stylingRules/paramValues in chart-renderer.tsx
- Update 4 existing tests that expected graph/map to be unstyled

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown

Walkthrough

Added rule-based styling support to Graph and Map charts by introducing stylingRules and paramValues props. Graph nodes and map markers now resolve colors via styling rules when provided, with priority over explicit colors. Updated chart registry to declare styling targets for both chart types.

Changes

Cohort / File(s) Summary
Graph/Map Chart Implementation
component/src/charts/graph-chart.tsx, component/src/charts/map-chart.tsx
Added stylingRules and paramValues optional props. Implemented rule-based color resolution: nodes/markers evaluate their value against rules to determine fill color, with rule color taking precedence over explicit color properties. Updated dependency lists to re-render when rules change.
Chart Component Tests
component/src/charts/__tests__/graph-chart.test.tsx, component/src/charts/__tests__/map-chart.test.tsx
Added new describe("rule-based styling") test blocks validating that node/marker colors follow rule precedence: rule color > explicit color > default. Tests verify rules only apply when markers/nodes have a value property. Reformatted existing test JSX and assertions for readability.
Chart Renderer Props
app/src/components/chart-renderer.tsx
Added missing prop forwarding of stylingRules and paramValues to both GraphChart and MapChart render paths, aligning graph/map with echarts styling infrastructure.
Chart Registry Configuration
app/src/lib/chart-registry.ts
Replaced supportsStyling: false with explicit stylingTargets for graph and map entries: graph targets node color, map targets marker color. Enables styling UI exposure for these chart types.
App-Level Tests
app/src/lib/__tests__/chart-registry.test.ts, app/src/lib/__tests__/widget-actions.test.ts, app/src/stores/__tests__/widget-editor-store.test.ts
Updated test suite to reflect graph and map as supported styling chart types. Adjusted test data: changed "unsupported" reference from "graph" to "json" in widget store and actions tests. Restructured assertion formatting for consistency.

Sequence Diagram

sequenceDiagram
    participant ChartRenderer
    participant GraphChart/MapChart
    participant StylingRuleEngine
    participant RenderOutput
    
    ChartRenderer->>GraphChart/MapChart: pass stylingRules & paramValues
    GraphChart/MapChart->>GraphChart/MapChart: iterate nodes/markers
    GraphChart/MapChart->>StylingRuleEngine: resolveStylingRuleColor(value, rules, params)
    StylingRuleEngine->>StylingRuleEngine: evaluate value against rule operators
    StylingRuleEngine-->>GraphChart/MapChart: return rule color (if match)
    GraphChart/MapChart->>GraphChart/MapChart: apply color precedence:<br/>rule color → explicit color → default
    GraphChart/MapChart->>RenderOutput: render styled nodes/markers
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement, pkg:component, area:charts, pkg:app

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding rule-based styling for Graph and Map charts, which aligns with the PR's primary objectives.
Linked Issues check ✅ Passed All coding requirements from #259 are met: rule-based styling implemented for Graph (node color) and Map (marker color), StylingRule engine reused, registry updated with supportsStyling and stylingTargets, renderer forwards props, and tests added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #259: Graph and Map chart styling, registry configuration, renderer forwarding, and related test updates. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve/charts-graph-map-styling

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.

@alfredo1996
alfredo1996 changed the base branch from release/1.0 to improve/charts-integration March 30, 2026 21:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
component/src/charts/graph-chart.tsx (1)

130-133: Update stale docs to match new precedence and scope.

After this change, color priority is rule → explicit node.color → label palette, and styling here affects color (not size). Please align the comments around Line 130 and Line 227 to avoid drift.

Also applies to: 227-229, 256-263

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@component/src/charts/graph-chart.tsx` around lines 130 - 133, Update the
stale JSDoc/comments to reflect the new styling precedence and scope: change the
comment for stylingRules to state that these rule-based styling entries now
affect node color only (not size) and that color precedence is rule → explicit
node.color → label palette; update the paramValues comment to note these are
resolved parameter values used during rule evaluation; then apply the same
wording changes to the other comment blocks around the styling-related docs (the
blocks currently at the second location and the third location) so all
descriptions consistently state color-only effect and the new precedence order.
app/src/lib/chart-registry.ts (1)

744-753: Registry update looks correct; consider syncing interface docs.

graph/map now expose styling targets, but the supportsStyling doc comment at Line 61-64 still lists them as unsupported.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/lib/chart-registry.ts` around lines 744 - 753, The supportsStyling
doc comment is out of sync with the registry: chart types graph and map now
expose stylingTargets, so update the supportsStyling comment to list graph and
map as supporting styling; specifically edit the supportsStyling docblock (the
comment above the supportsStyling definition) to mention "graph" and "map"
alongside any other supported types, and ensure the description references
stylingTargets on the ChartRegistry entries (e.g., the graph and map objects
with stylingTargets) so the docs reflect the current registry behavior.
component/src/charts/map-chart.tsx (1)

43-46: Tighten prop docs: rules currently affect marker color, not size.

The comment says “marker color/size,” but this change only resolves color (Lines 205-214). Please update wording to avoid API confusion.

Proposed doc-only fix
-  /** Rule-based styling rules for marker color/size */
+  /** Rule-based styling rules for marker color */
   stylingRules?: StylingRule[];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@component/src/charts/map-chart.tsx` around lines 43 - 46, The prop
documentation is misleading: update the comment on stylingRules in map-chart.tsx
to remove "size" and state that rules control marker color only (e.g., change
"Rule-based styling rules for marker color/size" to "Rule-based styling rules
for marker color"); also ensure the paramValues comment still clarifies they are
"Resolved parameter values for styling rule evaluation" and reference the
stylingRules symbol so readers know these values are used when evaluating
stylingRules.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/src/lib/chart-registry.ts`:
- Around line 744-753: The supportsStyling doc comment is out of sync with the
registry: chart types graph and map now expose stylingTargets, so update the
supportsStyling comment to list graph and map as supporting styling;
specifically edit the supportsStyling docblock (the comment above the
supportsStyling definition) to mention "graph" and "map" alongside any other
supported types, and ensure the description references stylingTargets on the
ChartRegistry entries (e.g., the graph and map objects with stylingTargets) so
the docs reflect the current registry behavior.

In `@component/src/charts/graph-chart.tsx`:
- Around line 130-133: Update the stale JSDoc/comments to reflect the new
styling precedence and scope: change the comment for stylingRules to state that
these rule-based styling entries now affect node color only (not size) and that
color precedence is rule → explicit node.color → label palette; update the
paramValues comment to note these are resolved parameter values used during rule
evaluation; then apply the same wording changes to the other comment blocks
around the styling-related docs (the blocks currently at the second location and
the third location) so all descriptions consistently state color-only effect and
the new precedence order.

In `@component/src/charts/map-chart.tsx`:
- Around line 43-46: The prop documentation is misleading: update the comment on
stylingRules in map-chart.tsx to remove "size" and state that rules control
marker color only (e.g., change "Rule-based styling rules for marker color/size"
to "Rule-based styling rules for marker color"); also ensure the paramValues
comment still clarifies they are "Resolved parameter values for styling rule
evaluation" and reference the stylingRules symbol so readers know these values
are used when evaluating stylingRules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7a3d9cab-342a-470e-8343-77448e19690a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed0468 and 6fb28d5.

📒 Files selected for processing (9)
  • app/src/components/chart-renderer.tsx
  • app/src/lib/__tests__/chart-registry.test.ts
  • app/src/lib/__tests__/widget-actions.test.ts
  • app/src/lib/chart-registry.ts
  • app/src/stores/__tests__/widget-editor-store.test.ts
  • component/src/charts/__tests__/graph-chart.test.tsx
  • component/src/charts/__tests__/map-chart.test.tsx
  • component/src/charts/graph-chart.tsx
  • component/src/charts/map-chart.tsx

@sonarqubecloud

Copy link
Copy Markdown

@alfredo1996
alfredo1996 merged commit ecaa460 into improve/charts-integration Mar 30, 2026
12 checks passed
@alfredo1996
alfredo1996 deleted the improve/charts-graph-map-styling branch April 7, 2026 11:47
alfredo1996 added a commit that referenced this pull request May 10, 2026
Closes #259

Graph chart:
- Add stylingRules/paramValues props to GraphChartProps
- Evaluate rules against node.value in toNvlNode()
- Rule color takes priority over explicit node.color and label palette
- 3 new tests: rule match, priority over explicit color, no-value skip

Map chart:
- Add stylingRules/paramValues props to MapChartProps
- Evaluate rules against marker.value in marker creation loop
- Rule color takes priority over explicit marker.color
- 3 new tests (TDD: written RED first, then implemented GREEN)

Registry + renderer:
- Set supportsStyling: true for graph and map
- Add stylingTargets with "Node Color" / "Marker Color"
- Forward stylingRules/paramValues in chart-renderer.tsx
- Update 4 existing tests that expected graph/map to be unstyled

Co-authored-by: alfredorubin96 <alfredo.rubin@neotechnology.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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