Skip to content

Commit f1f4d45

Browse files
claudeDominicBurkart
authored andcommitted
docs(xychart): add changeset, documentation, and e2e tests for point labels
- Add minor changeset for the new point labels feature - Enhance xyChart.md docs with mermaid-example block for mixed labels and a note about fixed font size - Add 4 Cypress e2e snapshot tests covering: all-labeled, mixed-labels, horizontal orientation, and multi-line scenarios - Add MMLU to cspell dictionary https://claude.ai/code/session_011g3A6y2kdJnZh8YB4uJaxD
1 parent fcc6be3 commit f1f4d45

5 files changed

Lines changed: 112 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': minor
3+
---
4+
5+
feat: add per-point text labels for xychart line plots

‎.cspell/misc-terms.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Buzan
33
circo
44
handDrawn
55
KOEPF
6+
MMLU
67
neato
78
newbranch
89
validify

‎cypress/integration/rendering/xyChart.spec.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,4 +879,57 @@ describe('XY Chart', () => {
879879
});
880880
});
881881
});
882+
883+
it('should render a line chart with point labels', () => {
884+
imgSnapshotTest(
885+
`
886+
xychart
887+
title "Smallest AI models scoring above 60% on MMLU"
888+
x-axis "Date" ["Apr 2022", "Feb 2023", "Jul 2023", "Sep 2023", "Apr 2024"]
889+
y-axis "Parameters (B)" 0 --> 600
890+
line [540 "PaLM", 65 "LLaMA-65B", 34 "Llama 2 34B", 7 "Mistral 7B", 3.8 "Phi-3-mini"]
891+
`,
892+
{}
893+
);
894+
});
895+
896+
it('should render a line chart with mixed labels (some points labeled, some not)', () => {
897+
imgSnapshotTest(
898+
`
899+
xychart
900+
title "Quarterly Performance"
901+
x-axis [Q1, Q2, Q3, Q4]
902+
y-axis "Revenue ($M)" 0 --> 100
903+
line [25 "Launch", 45, 72, 90 "Target Hit"]
904+
`,
905+
{}
906+
);
907+
});
908+
909+
it('should render a horizontal line chart with point labels', () => {
910+
imgSnapshotTest(
911+
`
912+
xychart horizontal
913+
title "Model Sizes"
914+
x-axis ["Model A", "Model B", "Model C"]
915+
y-axis "Parameters" 0 --> 100
916+
line [20 "Small", 50 "Medium", 90 "Large"]
917+
`,
918+
{}
919+
);
920+
});
921+
922+
it('should render multiple lines where only one has labels', () => {
923+
imgSnapshotTest(
924+
`
925+
xychart
926+
title "Comparison"
927+
x-axis [Q1, Q2, Q3, Q4]
928+
y-axis "Value" 0 --> 100
929+
line [20, 40, 60, 80]
930+
line [30 "Start", 50, 70, 95 "Peak"]
931+
`,
932+
{}
933+
);
934+
});
882935
});

‎docs/syntax/xyChart.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,49 @@ xychart
271271
bar [12,2,20,25,17,24]
272272
```
273273

274+
## Per-point text labels for line charts (v\<MERMAID_RELEASE_VERSION>+)
275+
276+
Each data point in a `line` can optionally include a quoted string label after the numeric value. Labels render above points in vertical orientation, or to the right in horizontal orientation, using the line's stroke color.
277+
278+
```mermaid-example
279+
xychart
280+
title "Smallest AI models scoring above 60% on MMLU"
281+
x-axis "Date" ["Apr 2022", "Feb 2023", "Jul 2023", "Sep 2023", "Apr 2024"]
282+
y-axis "Parameters (B)" 0 --> 600
283+
line [540 "PaLM", 65 "LLaMA-65B", 34 "Llama 2 34B", 7 "Mistral 7B", 3.8 "Phi-3-mini"]
284+
```
285+
286+
```mermaid
287+
xychart
288+
title "Smallest AI models scoring above 60% on MMLU"
289+
x-axis "Date" ["Apr 2022", "Feb 2023", "Jul 2023", "Sep 2023", "Apr 2024"]
290+
y-axis "Parameters (B)" 0 --> 600
291+
line [540 "PaLM", 65 "LLaMA-65B", 34 "Llama 2 34B", 7 "Mistral 7B", 3.8 "Phi-3-mini"]
292+
```
293+
294+
Labels are optional per point — you can mix labeled and unlabeled values:
295+
296+
```mermaid-example
297+
xychart
298+
title "Quarterly Performance"
299+
x-axis [Q1, Q2, Q3, Q4]
300+
y-axis "Revenue ($M)" 0 --> 100
301+
line [25 "Launch", 45, 72, 90 "Target Hit"]
302+
```
303+
304+
```mermaid
305+
xychart
306+
title "Quarterly Performance"
307+
x-axis [Q1, Q2, Q3, Q4]
308+
y-axis "Revenue ($M)" 0 --> 100
309+
line [25 "Launch", 45, 72, 90 "Target Hit"]
310+
```
311+
312+
Existing syntax without labels continues to work unchanged.
313+
314+
> **Note**
315+
> Point labels use a fixed font size of 12px. In vertical charts, labels appear above each point. In horizontal charts, labels appear to the right.
316+
274317
## Example on config and theme
275318

276319
```mermaid-example

‎packages/mermaid/src/docs/syntax/xyChart.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,20 @@ xychart
225225

226226
Labels are optional per point — you can mix labeled and unlabeled values:
227227

228-
```
229-
line [10 "Start", 20, 30 "End"]
228+
```mermaid-example
229+
xychart
230+
title "Quarterly Performance"
231+
x-axis [Q1, Q2, Q3, Q4]
232+
y-axis "Revenue ($M)" 0 --> 100
233+
line [25 "Launch", 45, 72, 90 "Target Hit"]
230234
```
231235

232236
Existing syntax without labels continues to work unchanged.
233237

238+
```note
239+
Point labels use a fixed font size of 12px. In vertical charts, labels appear above each point. In horizontal charts, labels appear to the right.
240+
```
241+
234242
## Example on config and theme
235243

236244
```mermaid-example

0 commit comments

Comments
 (0)