-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,305 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ const MERMAID_CONFIG_DIAGRAM_KEYS = [ | |
'block', | ||
'packet', | ||
'architecture', | ||
'euler', | ||
] as const; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<title>Mermaid Quick Test Page</title> | ||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=" /> | ||
<style> | ||
div.mermaid { | ||
font-family: 'Courier New', Courier, monospace !important; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Venn diagram demo</h1> | ||
|
||
<div class="diagrams"> | ||
<pre class="mermaid"> | ||
venn-beta | ||
title Very Basic Venn Diagram | ||
sets A | ||
sets B | ||
sets A,B label: AB | ||
</pre> | ||
<hr /> | ||
<pre class="mermaid"> | ||
venn-beta | ||
title Three overlapping circles | ||
sets A | ||
sets B | ||
sets C | ||
sets A,B label: AB, background: skyblue | ||
sets B,C label: BC, background: orange | ||
sets A,C label: AC, background: lightgreen | ||
sets A,B,C label: ABC, color: red, background: white | ||
</pre> | ||
<hr /> | ||
<pre class="mermaid"> | ||
venn-beta | ||
title Three concatenated circles and one isolated circle | ||
sets A size: 15, label: ALPHA | ||
sets B size: 5, label: BETA | ||
sets C size: 10 | ||
sets D size: 10, label: DELTA | ||
sets A,B size: 1, label: AB, background: gold | ||
sets B,D size: 1 | ||
</pre> | ||
</div> | ||
<script type="module"> | ||
import mermaid from '/mermaid.esm.mjs'; | ||
mermaid.initialize({ | ||
logLevel: 3, | ||
securityLevel: 'loose', | ||
}); | ||
</script> | ||
|
||
<style> | ||
pre { | ||
/*width: 45vw;*/ | ||
/*padding: 2em;*/ | ||
} | ||
</style> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
%lex | ||
%options case-insensitive | ||
|
||
%x string | ||
%x title | ||
%% | ||
\%\%(?!\{)[^\n]* /* skip comments */ | ||
[^\}]\%\%[^\n]* /* skip comments */ | ||
[\n\r]+ return 'NEWLINE'; | ||
\%\%[^\n]* /* do nothing */ | ||
\s+ /* skip */ | ||
<<EOF>> return 'EOF'; | ||
|
||
"title"\s[^#\n;]+ {return 'TITLE';} | ||
"venn-beta" {return 'VENN';} | ||
"sets" { return 'SETS'; } | ||
|
||
[+-]?(?:\d+(?:\.\d+)?|\.\d+) { return 'NUMERIC'; } | ||
[A-Za-z_][A-Za-z0-9\-_]* { return 'IDENTIFIER'; } | ||
[^":,]+ { return "OPT_VALUE"; } | ||
|
||
"," { return 'COMMA'; } | ||
":" { return 'COLON'; } | ||
|
||
/lex | ||
|
||
%start start | ||
|
||
%% /* language grammar */ | ||
|
||
start | ||
: VENN document 'EOF' { return $2; } | ||
; | ||
|
||
document | ||
: /* empty */ { $$ = [] } | ||
| document line {$1.push($2);$$ = $1} | ||
; | ||
|
||
line | ||
: SPACE statement { $$ = $2 } | ||
| statement { $$ = $1 } | ||
| NEWLINE { $$=[];} | ||
| EOF { $$=[];} | ||
; | ||
|
||
statement | ||
: TITLE {yy.setDiagramTitle( $1.substr(6));$$=$1.substr(6);} | ||
| SETS identifierList { yy.addSubsetData($identifierList, undefined); } | ||
| SETS identifierList stylesOpt { yy.addSubsetData($identifierList, $stylesOpt); } | ||
; | ||
|
||
stylesOpt | ||
: styleField { $$ = [$styleField] } | ||
| stylesOpt COMMA styleField { $$ = [...$stylesOpt, $styleField] } | ||
; | ||
|
||
styleField | ||
: IDENTIFIER COLON IDENTIFIER { $$ = [$1, $3] } | ||
| IDENTIFIER COLON OPT_VALUE { $$ = [$IDENTIFIER, $OPT_VALUE] } | ||
| IDENTIFIER COLON NUMERIC { $$ = [$IDENTIFIER, $NUMERIC] } | ||
; | ||
|
||
text: STR | ||
; | ||
|
||
identifierList | ||
: IDENTIFIER { $$ = [$IDENTIFIER] } | ||
| identifierList COMMA IDENTIFIER { $$ = [...$identifierList, $IDENTIFIER] } | ||
; | ||
|
||
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// @ts-ignore: jison doesn't export types | ||
import venn from './venn.jison'; | ||
import { db } from '../vennDB.js'; | ||
import { expect } from 'vitest'; | ||
|
||
describe('Venn diagram', function () { | ||
beforeEach(function () { | ||
venn.parser.yy = db; | ||
venn.parser.yy.clear(); | ||
venn.parser.yy.getLogger = () => console; | ||
}); | ||
|
||
test('simple', () => { | ||
const str = `venn-beta | ||
title foo bar | ||
sets A | ||
sets B | ||
sets A,B | ||
`; | ||
venn.parse(str); | ||
expect(db.getDiagramTitle()).toBe('foo bar'); | ||
expect(db.getSubsetData()).toEqual([ | ||
expect.objectContaining({ sets: ['A'], size: 10 }), | ||
expect.objectContaining({ sets: ['B'], size: 10 }), | ||
expect.objectContaining({ sets: ['A', 'B'], size: 2.5 }), | ||
]); | ||
}); | ||
|
||
test('with options', () => { | ||
const str = `venn-beta | ||
title foo bar | ||
sets A | ||
sets B size : 20 | ||
sets C size : 30, label : bar | ||
sets A,D size : 5.3, label : foo | ||
sets C, A,B | ||
`; | ||
venn.parse(str); | ||
expect(db.getSubsetData()).toEqual([ | ||
expect.objectContaining({ sets: ['A'], size: 10 }), | ||
expect.objectContaining({ sets: ['B'], size: 20 }), | ||
expect.objectContaining({ sets: ['C'], size: 30, label: 'bar' }), | ||
expect.objectContaining({ sets: ['A', 'D'], size: 5.3, label: 'foo' }), | ||
expect.objectContaining({ sets: ['A', 'B', 'C'], size: 1.1111111111111112 }), | ||
]); | ||
}); | ||
|
||
test('with elements', () => { | ||
const str = `venn-beta | ||
title foo bar | ||
sets A | ||
sets B size : 20 | ||
sets C size : 30, label : bar | ||
sets A,D size : 5.3, label : foo | ||
sets C, A,B | ||
`; | ||
venn.parse(str); | ||
expect(db.getSubsetData()).toEqual([ | ||
expect.objectContaining({ sets: ['A'], size: 10 }), | ||
expect.objectContaining({ sets: ['B'], size: 20 }), | ||
expect.objectContaining({ sets: ['C'], size: 30, label: 'bar' }), | ||
expect.objectContaining({ sets: ['A', 'D'], size: 5.3, label: 'foo' }), | ||
expect.objectContaining({ sets: ['A', 'B', 'C'], size: 1.1111111111111112 }), | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.