Skip to content

feat(component): add reference lines (markLine) for bar and line charts - #173

Closed
alfredo1996 wants to merge 4 commits into
devfrom
feat/issue-136-markline
Closed

feat(component): add reference lines (markLine) for bar and line charts#173
alfredo1996 wants to merge 4 commits into
devfrom
feat/issue-136-markline

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Mar 22, 2026

Copy link
Copy Markdown
Owner

Summary

Support horizontal reference lines via ECharts markLine for goals, thresholds, and averages on bar and line charts.

Changes

  • New: parseReferenceLines(), buildMarkLineFromRefs() in chart-utils.ts
  • Updated: BarChart — referenceLines prop, markLine on first series
  • Updated: base-chart.tsx — registered MarkLineComponent
  • Updated: vitest.setup.ts + base-chart.test.tsx — mock MarkLineComponent
  • Updated: chart-options-schema — "Reference Lines (JSON)" for bar/line
  • 7 new tests

Closes #136
🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for horizontal reference lines on bar and line charts, customizable via JSON configuration with options for values, labels, and colors.
  • Tests

    • Added comprehensive test coverage for reference line parsing, validation, and ECharts configuration generation.

Add parseReferenceLines() and buildMarkLineFromRefs() to chart-utils.ts.
Wire markLine into BarChart — reference lines attach to first series.
Register MarkLineComponent in ECharts and update all test mocks.

- JSON config: [{"value":50,"label":"Target","color":"#ff0000"}]
- Chart option added to bar and line in chart-options-schema
- 7 new tests for reference line parsing

Closes #136

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alfredo1996 alfredo1996 added enhancement New feature or request pkg:component UI component library area:charts Chart rendering labels Mar 22, 2026
@coderabbitai

coderabbitai Bot commented Mar 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@alfredo1996 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e342f020-3e38-48c3-861c-d9c6891d898d

📥 Commits

Reviewing files that changed from the base of the PR and between 0672191 and e4fcf26.

📒 Files selected for processing (7)
  • app/e2e/fixtures.ts
  • component/src/charts/__tests__/base-chart.test.tsx
  • component/src/charts/__tests__/line-chart.test.tsx
  • component/src/charts/__tests__/reference-line.test.ts
  • component/src/charts/base-chart.tsx
  • component/src/charts/line-chart.tsx
  • component/vitest.setup.ts

Walkthrough

Added support for horizontal reference lines in bar and line charts via ECharts markLine. Introduced ReferenceLine type, parsing and configuration helpers, registered MarkLineComponent, integrated into BarChart with a new referenceLines prop, and updated chart options schema.

Changes

Cohort / File(s) Summary
Test Setup & Mocks
component/src/charts/__tests__/base-chart.test.tsx, component/vitest.setup.ts
Added MarkLineComponent to the echarts/components mock in test setup files.
Reference Line Tests
component/src/charts/__tests__/reference-line.test.ts
New test suite for parseReferenceLines and ReferenceLine type, covering edge cases (undefined, empty, invalid JSON) and valid multi-line parsing with field preservation and filtering.
Chart Utilities
component/src/charts/chart-utils.ts
Added ReferenceLine interface, parseReferenceLines() to safely parse JSON strings into reference line objects, and buildMarkLineFromRefs() to generate ECharts-compatible markLine configuration with labels, colors, and dashed styling.
Bar Chart Integration
component/src/charts/bar-chart.tsx
Added optional referenceLines prop (JSON string), integrated parsing and markLine building, conditionally attach markLine to first series, and updated dependency array for re-computation.
Base Chart Setup
component/src/charts/base-chart.tsx
Imported and registered MarkLineComponent from echarts/components in both static registry and component set.
Chart Options Schema
component/src/components/composed/chart-options-schema.ts
Added referenceLines text option (default "", category Annotations) to barOptions and lineOptions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements reference line support with parseReferenceLines and buildMarkLineFromRefs helpers, registers MarkLineComponent, integrates with BarChart, and updates schema. However, line chart integration is not included in the code changes. Implement reference line support for line charts to fully satisfy acceptance criteria #136 which requires 'works with both bar and line charts'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature addition: reference lines (markLine) support for bar and line charts.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing reference line functionality: utility functions, component registration, BarChart integration, test coverage, and schema updates align with issue #136 requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.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 feat/issue-136-markline

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.

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
component/src/charts/chart-utils.ts (2)

11-15: Consider extending ReferenceLine for vertical line support.

Per issue #136 acceptance criteria ("Support both horizontal and vertical lines"), consider adding an optional axis?: 'x' | 'y' field to enable vertical reference lines via xAxis positioning.

 export interface ReferenceLine {
   value: number;
   label?: string;
   color?: string;
+  /** 'y' for horizontal lines (default), 'x' for vertical lines */
+  axis?: 'x' | 'y';
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@component/src/charts/chart-utils.ts` around lines 11 - 15, Extend the
ReferenceLine interface to support vertical lines by adding an optional axis?:
'x' | 'y' property so consumers can specify axis orientation; update any
consumers of ReferenceLine (e.g., chart rendering logic that uses value and
xAxis/yAxis) to treat axis === 'x' as a vertical line anchored to the xAxis and
axis === 'y' (or undefined) as the existing horizontal behavior, and adjust type
annotations and tests accordingly to accept the new field.

41-58: buildMarkLineFromRefs only supports horizontal lines.

Currently hardcodes yAxis positioning. To support vertical lines per issue #136:

♻️ Proposed refactor for axis flexibility
 export function buildMarkLineFromRefs(lines: ReferenceLine[]) {
   if (!lines.length) return undefined;
   return {
     silent: true,
     symbol: "none",
     data: lines.map((line) => ({
-      yAxis: line.value,
+      ...(line.axis === 'x' ? { xAxis: line.value } : { yAxis: line.value }),
       label: {
         formatter: line.label ?? String(line.value),
         position: "insideEndTop" as const,
       },
       lineStyle: {
         color: line.color ?? "#888",
         type: "dashed" as const,
       },
     })),
   };
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@component/src/charts/chart-utils.ts` around lines 41 - 58,
buildMarkLineFromRefs currently hardcodes horizontal lines by always emitting
yAxis; update buildMarkLineFromRefs to support vertical lines by reading an
axis/orientation property on each ReferenceLine (e.g., axis: 'x' | 'y' or
orientation: 'vertical' | 'horizontal') and conditionally emitting xAxis:
line.value for verticals and yAxis: line.value for horizontals (default to 'y'
for backward compatibility). Adjust the per-line label.position (choose a
sensible default per axis) and keep existing lineStyle/label.formatter logic;
ensure the function still returns undefined for empty arrays and preserves the
overall returned object shape.
component/src/charts/__tests__/reference-line.test.ts (1)

1-47: Missing test coverage for buildMarkLineFromRefs.

parseReferenceLines has solid coverage, but buildMarkLineFromRefs contains non-trivial logic (empty array → undefined, default color #888, label fallback, dashed style) with zero tests.

Would you like me to generate test cases for buildMarkLineFromRefs?

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

In `@component/src/charts/__tests__/reference-line.test.ts` around lines 1 - 47,
The test suite is missing coverage for buildMarkLineFromRefs which contains
important branching (returns undefined for empty input, applies default color
"#888", uses label fallback, and sets dashed style) — add unit tests that call
buildMarkLineFromRefs with (1) undefined/empty array and assert it returns
undefined, (2) a single ReferenceLine without color and without label to verify
default color "#888" and correct label fallback, (3) multiple reference lines to
verify the produced markLine object contains expected data entries, and (4) an
entry with dashed=true to assert the style is dashed; reference the
buildMarkLineFromRefs function in the tests to locate the implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@component/src/charts/bar-chart.tsx`:
- Around line 39-40: The current referenceLines prop only produces horizontal
marks via yAxis in buildMarkLineFromRefs; add an axis (or direction) field to
the ReferenceLine shape (accepting 'x'|'y' or 'vertical'|'horizontal') and
update buildMarkLineFromRefs to branch on that field: when axis === 'y' keep the
existing yAxis positioning for horizontal lines, and when axis === 'x' generate
a mark line positioned on xAxis (vertical line) using the provided value and
label/color handling; also validate/backward-compatibly default missing axis to
'y' so existing JSON strings still render as horizontal lines. Ensure you
reference the referenceLines prop parsing and the buildMarkLineFromRefs function
to locate and modify the logic.

In `@component/src/components/composed/chart-options-schema.ts`:
- Line 49: The schema exposes referenceLines but LineChart lacks support; update
the LineChart component to accept and process a referenceLines prop (same shape
as BarChart's referenceLines) by adding the prop to its props/type (e.g., in the
LineChart component signature and lineOptions handling), parse/validate the JSON
if required, and render horizontal reference lines (mirror the implementation
pattern used in BarChart) so configured lines appear on the chart; ensure
defaulting when referenceLines is empty and reuse any existing helper/util used
by BarChart for consistency.

---

Nitpick comments:
In `@component/src/charts/__tests__/reference-line.test.ts`:
- Around line 1-47: The test suite is missing coverage for buildMarkLineFromRefs
which contains important branching (returns undefined for empty input, applies
default color "#888", uses label fallback, and sets dashed style) — add unit
tests that call buildMarkLineFromRefs with (1) undefined/empty array and assert
it returns undefined, (2) a single ReferenceLine without color and without label
to verify default color "#888" and correct label fallback, (3) multiple
reference lines to verify the produced markLine object contains expected data
entries, and (4) an entry with dashed=true to assert the style is dashed;
reference the buildMarkLineFromRefs function in the tests to locate the
implementation.

In `@component/src/charts/chart-utils.ts`:
- Around line 11-15: Extend the ReferenceLine interface to support vertical
lines by adding an optional axis?: 'x' | 'y' property so consumers can specify
axis orientation; update any consumers of ReferenceLine (e.g., chart rendering
logic that uses value and xAxis/yAxis) to treat axis === 'x' as a vertical line
anchored to the xAxis and axis === 'y' (or undefined) as the existing horizontal
behavior, and adjust type annotations and tests accordingly to accept the new
field.
- Around line 41-58: buildMarkLineFromRefs currently hardcodes horizontal lines
by always emitting yAxis; update buildMarkLineFromRefs to support vertical lines
by reading an axis/orientation property on each ReferenceLine (e.g., axis: 'x' |
'y' or orientation: 'vertical' | 'horizontal') and conditionally emitting xAxis:
line.value for verticals and yAxis: line.value for horizontals (default to 'y'
for backward compatibility). Adjust the per-line label.position (choose a
sensible default per axis) and keep existing lineStyle/label.formatter logic;
ensure the function still returns undefined for empty arrays and preserves the
overall returned object shape.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e161b6a4-226c-4a66-ba38-bd09bf97785a

📥 Commits

Reviewing files that changed from the base of the PR and between 59e78c2 and 0672191.

📒 Files selected for processing (7)
  • component/src/charts/__tests__/base-chart.test.tsx
  • component/src/charts/__tests__/reference-line.test.ts
  • component/src/charts/bar-chart.tsx
  • component/src/charts/base-chart.tsx
  • component/src/charts/chart-utils.ts
  • component/src/components/composed/chart-options-schema.ts
  • component/vitest.setup.ts

Comment on lines +39 to +40
/** JSON string of reference lines: [{ value, label?, color? }] */
referenceLines?: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Issue #136 requires vertical lines support.

The acceptance criteria states "Support both horizontal and vertical lines." Current implementation only supports horizontal lines (yAxis positioning in buildMarkLineFromRefs).

Consider adding an axis or direction field to ReferenceLine to support xAxis positioning for vertical lines.

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

In `@component/src/charts/bar-chart.tsx` around lines 39 - 40, The current
referenceLines prop only produces horizontal marks via yAxis in
buildMarkLineFromRefs; add an axis (or direction) field to the ReferenceLine
shape (accepting 'x'|'y' or 'vertical'|'horizontal') and update
buildMarkLineFromRefs to branch on that field: when axis === 'y' keep the
existing yAxis positioning for horizontal lines, and when axis === 'x' generate
a mark line positioned on xAxis (vertical line) using the provided value and
label/color handling; also validate/backward-compatibly default missing axis to
'y' so existing JSON strings still render as horizontal lines. Ensure you
reference the referenceLines prop parsing and the buildMarkLineFromRefs function
to locate and modify the logic.

Comment thread component/src/components/composed/chart-options-schema.ts
alfredorubin96 and others added 3 commits March 23, 2026 01:45
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Wire up referenceLines prop in LineChart following the same pattern
  as BarChart (buildMarkLineFromRefs → markLine option)
- Add unit tests for buildMarkLineFromRefs covering empty input,
  defaults, custom colors, and label text
- Increases new code coverage toward 80% target

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The typeInEditor fixture was retrying until timeout when CM6's
internal view.state.readOnly was true. Now falls through to the
keyboard fallback strategy instead of throwing.

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

Copy link
Copy Markdown

alfredo1996 pushed a commit that referenced this pull request Mar 24, 2026
…els, markLine, pie donut)

Merges PRs #169, #170, #171, #173, #174 into a single release branch.
Resolves merge conflicts in chart-utils.ts, bar-chart.tsx, line-chart.tsx,
and chart-options-schema.ts.

Includes:
- Number formatting for single-value and tooltips (#169)
- DataZoom support for bar and line charts (#170)
- Auto-rotate and truncate axis labels (#171)
- Reference lines (markLine) for bar and line charts (#173)
- Donut center text and Top-N grouping for pie chart (#174)

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

Copy link
Copy Markdown
Owner Author

Superseded by consolidated PR #185 (release/chart-improvements)

@alfredo1996
alfredo1996 deleted the feat/issue-136-markline branch March 29, 2026 22:22
alfredo1996 pushed a commit that referenced this pull request May 10, 2026
…els, markLine, pie donut)

Merges PRs #169, #170, #171, #173, #174 into a single release branch.
Resolves merge conflicts in chart-utils.ts, bar-chart.tsx, line-chart.tsx,
and chart-options-schema.ts.

Includes:
- Number formatting for single-value and tooltips (#169)
- DataZoom support for bar and line charts (#170)
- Auto-rotate and truncate axis labels (#171)
- Reference lines (markLine) for bar and line charts (#173)
- Donut center text and Top-N grouping for pie chart (#174)

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

area:charts Chart rendering enhancement New feature or request pkg:component UI component library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(component): add reference lines (markLine) for bar and line charts

2 participants