Skip to content

feat(mermaid): add radar chart support - #151

Merged
nao1215 merged 2 commits into
mainfrom
feat/mermaid-radar
Aug 11, 2026
Merged

feat(mermaid): add radar chart support#151
nao1215 merged 2 commits into
mainfrom
feat/mermaid-radar

Conversation

@nao1215

@nao1215 nao1215 commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Closes #129

What

mermaid/radar builds mermaid radar charts. A radar chart is a set of axes and a set of curves, where each curve gives one value per axis in the order the axes were declared, so the builder is those two lists:

radar.NewDiagram(io.Discard, radar.WithTitle("Grades")).
    Axis("Math", "Science", "English").
    Axis("History", "Art").
    Curve("Alice", 85, 90, 80, 70, 75).
    Curve("Bob", 70, 75, 85, 80, 90).
    Max(100).
    Min(0).
    String()

Identifiers are generated

mermaid requires an identifier in front of every label: a bare axis "Math" is a parse error, which I confirmed by rendering. Nothing in a radar chart refers to those identifiers, so the package numbers them and the caller passes only labels. They keep counting across calls, because a chart with two axes named a1 is a chart with one axis, and a test pins that.

Escaping

A label is quoted, with a double quote and a backslash escaped. The backslash matters on its own: a label ending in one would otherwise swallow the closing quote. Everything else — colons, hashes, semicolons, parentheses — is text once inside the quotes, which I verified by rendering a label holding all of them.

Values use strconv.FormatFloat(v, 'f', -1, 64), because mermaid parses the token as a number and Go's exponent form above 1e21 is not one to it. NaN and both infinities are refused; negative values are not, since a radar axis can start below zero and Min exists for exactly that.

"beta" stays out of the API

mermaid still spells the keyword radar-beta. The package is radar and the keyword is an implementation detail.

The pinned renderer already supports it

The issue asked me to check whether the mermaid-cli version in CI renders radar-beta and to bump it if not. It does, so no workflow change was needed.

Tests

go test ./mermaid/radar/ reports 98.9% of statements.

  • Table driven output tests for every method and option, identifier numbering across calls, both escaping cases, punctuation that is safe inside quotes, fractional and negative values, and the exponent case.
  • A second table for everything refused: newlines and empty text in every field, an axis with no labels, a curve with no values, and NaN and infinite values in a curve, in Max and in Min.
  • The shared builder contract from internal/buildertest, a golden chart, and an output-verified godoc example.

Rendering

doc/radar/main.go generates a committed sample, drawn by the render job. Verified locally, both the sample and the edge case labels above.

Scope

Additive only. Nothing outside mermaid/radar/, doc/radar/, and README.md changed.

Summary by CodeRabbit

  • New Features

    • Added support for creating Mermaid radar charts with titles, axes, data curves, custom minimum and maximum scales, and formatted output.
    • Added validation and safe handling for invalid labels, values, and output operations.
    • Added examples for comparing data sets, including a student grade chart.
  • Documentation

    • Expanded the package overview, feature checklist, and usage guidance with radar chart examples.
  • Tests

    • Added coverage for rendering, escaping, formatting, validation, edge cases, and error handling.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d31ad9e1-aac8-4d84-86ca-2ebbcf68d397

📥 Commits

Reviewing files that changed from the base of the PR and between 4f3d26b and 471d828.

📒 Files selected for processing (12)
  • README.md
  • doc/edgecase/main.go
  • doc/edgecase/radar.md
  • doc/radar/generated.md
  • doc/radar/main.go
  • mermaid/radar/config.go
  • mermaid/radar/error_contract_test.go
  • mermaid/radar/examples_test.go
  • mermaid/radar/golden_test.go
  • mermaid/radar/radar.go
  • mermaid/radar/radar_test.go
  • mermaid/radar/testdata/golden/radar.md

📝 Walkthrough

Walkthrough

The pull request adds a new mermaid/radar package with a chainable builder, validation, rendering, tests, examples, generated fixtures, edge-case coverage, and README documentation.

Changes

Radar chart support

Layer / File(s) Summary
Radar builder API and rendering
mermaid/radar/config.go, mermaid/radar/radar.go
Adds radar chart options and a chainable builder for titles, axes, curves, bounds, escaping, validation, error retention, and Markdown output.
Builder validation and output verification
mermaid/radar/*_test.go, mermaid/radar/testdata/golden/radar.md
Adds unit, contract, example, and golden tests for valid output, invalid values, formatting, escaping, and retained errors.
Radar examples and documentation
doc/radar/..., doc/edgecase/..., README.md
Adds radar generators and committed fixtures, registers radar edge cases, and documents radar chart usage and support.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Diagram
  participant Writer
  Caller->>Diagram: NewDiagram and configure radar chart
  Caller->>Diagram: Build
  Diagram->>Writer: Write Mermaid radar output
Loading

Possibly related PRs

  • nao1215/markdown#74: Adds a separate Mermaid diagram package with a similar fluent builder, options, documentation, generators, and tests.
  • nao1215/markdown#135: Adds related Mermaid golden-output testing infrastructure.
  • nao1215/markdown#147: Modifies the shared edge-case document generator used by this radar integration.
🚥 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 clearly identifies the primary change: adding radar chart support to Mermaid.
Linked Issues check ✅ Passed The changes satisfy issue #129 by adding the radar builder, options, validation, tests, documentation, and generated samples.
Out of Scope Changes check ✅ Passed All changes remain within the allowed radar package, documentation, samples, and README scope defined by issue #129.
Docstring Coverage ✅ Passed Docstring coverage is 86.67% which is sufficient. The required threshold is 80.00%.
✨ 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 feat/mermaid-radar

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.

@github-actions

This comment has been minimized.

Comment thread mermaid/radar/radar.go
return d.scale("max", value)
}

// Min sets the centre of the chart, the value an axis is empty at.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[misspell] reported by reviewdog 🐶
"centre" is a misspelling of "center"

@nao1215
nao1215 force-pushed the feat/mermaid-radar branch from c290a6b to 3b1debb Compare August 11, 2026 16:40
@github-actions

This comment has been minimized.

A radar chart is a set of axes and a set of curves, where each curve gives one
value per axis in the order the axes were declared. Axis takes as many labels
as you give it and Curve takes the values, so a chart reads as the two lists
it is.

mermaid wants an identifier in front of every label, and nothing in a radar
chart refers to one, so the package numbers them and the caller passes only
labels. The identifiers keep counting across calls, because a chart with two
axes named a1 is a chart with one axis.

A label is quoted, with a double quote and a backslash escaped; a trailing
backslash would otherwise swallow the closing quote. Everything else, colons
and hashes included, is text once inside the quotes, which was verified by
rendering. Values are written in plain decimal notation, since mermaid parses
the token as a number and Go's exponent form is not one to it, and NaN and the
infinities are refused.

"beta" is kept out of the API. mermaid still spells the keyword that way, and
the package should not have to change its name when mermaid settles it.
The render harness landed after this branch started. radar quotes every
label, so its entry holds every character in the probe set; a line break is
the only thing left out, since one label is one line.
@nao1215
nao1215 force-pushed the feat/mermaid-radar branch from 3b1debb to 471d828 Compare August 11, 2026 22:58
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (4f3d26b) #151 (086784d) +/-
Coverage 96.1% 96.2% +0.0%
Test Execution Time 9s 9s 0s
Details
  |                     | main (4f3d26b) | #151 (086784d) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          96.1% |          96.2% | +0.0% |
  |   Files             |             61 |             63 |    +2 |
  |   Lines             |           2805 |           2893 |   +88 |
+ |   Covered           |           2697 |           2784 |   +87 |
  | Test Execution Time |             9s |             9s |    0s |

Code coverage of files in pull request scope (0.0% → 98.8%)

Files Coverage +/- Status
mermaid/radar/config.go 100.0% +100.0% added
mermaid/radar/radar.go 98.8% +98.8% added

Reported by octocov

@nao1215
nao1215 merged commit 9a01221 into main Aug 11, 2026
21 of 22 checks passed
@nao1215
nao1215 deleted the feat/mermaid-radar branch August 11, 2026 23:03
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.

feat(mermaid): add radar chart support (mermaid/radar)

1 participant