@@ -6,6 +6,13 @@ import { FileLink } from "./types";
66
77const graph = getGQMFileLinks ( ) ;
88
9+ export function getLinkUrl ( linkType : LinkType , file : string ) {
10+ // https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/goals/reduce-duplication.md
11+ const measuringUrl = "https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/" ;
12+ const url = `${ measuringUrl } /${ linkType . toLowerCase ( ) } s/${ file } `
13+ return url ;
14+ }
15+
916export function getGQMFileLinks ( ) {
1017 const graph : Graph = {
1118 nodes : [ ] ,
@@ -31,10 +38,11 @@ export function getGQMFileLinks() {
3138 return graph ;
3239}
3340
34- export function appendToGraph ( graph : Graph , goalFileLinks : FileLink [ ] ) {
35- goalFileLinks . forEach ( ( fileLink ) => {
41+ export function appendToGraph ( graph : Graph , fileLinks : FileLink [ ] ) {
42+ fileLinks . forEach ( ( fileLink ) => {
3643 const node : Node = {
3744 id : fileLink . file ,
45+ type : fileLink . linkType ,
3846 shape : NodeShape . RECT ,
3947 label : fileLink . label ,
4048 } ;
@@ -117,35 +125,64 @@ export function getLinks(parsed: Commonmark.Node) {
117125}
118126
119127export function getNodeShapeSyntax ( node : Node ) {
128+ const nodeUrl = getLinkUrl ( node . type , node . id )
129+ const nodeLabel = `<a href='${ nodeUrl } '>${ node . label } </a>` ;
120130 switch ( node . shape ) {
121131 case 'rect' :
122- return `[${ node . label } ]` ;
132+ return `[${ nodeLabel } ]` ;
123133 case 'circ' :
124- return `((${ node . label } ))` ;
134+ return `((${ nodeLabel } ))` ;
125135 case 'roundrect' :
126- return `((${ node . label } ))` ;
136+ return `((${ nodeLabel } ))` ;
127137 case 'diamond' :
128- return `{${ node . label } }` ;
138+ return `{${ nodeLabel } }` ;
129139 default :
130- return `[${ node . label } ]` ;
140+ return `[${ nodeLabel } ]` ;
131141 }
132142}
133143
134144export function generateMermaidDiagram ( graph : Graph ) {
135145 const nodes = graph . nodes ;
136146 const edges = graph . edges ;
137147
138- let mermaidSyntax = "```mermaid\ngraph TB\n" ;
139-
148+ let mermaidSyntax = `\`\`\`mermaid\n
149+ graph LR;\n
150+ subgraph GQM[Goals, Questions, Metrics]\n
151+ ` ;
152+
140153 nodes . forEach ( ( node ) => {
141- const nodeSyntax = getNodeShapeSyntax ( node ) ;
142- mermaidSyntax += `${ node . id } ${ nodeSyntax } \n` ;
154+ const nodeSyntax = getNodeShapeSyntax ( node )
155+ mermaidSyntax += ` ${ node . id } ${ nodeSyntax } \n`
143156 } ) ;
144157
145158 edges . forEach ( ( edge ) => {
146159 const arrowSyntax : string = ArrowType . ARROW ;
147160 mermaidSyntax += `${ edge . from } ${ arrowSyntax } ${ edge . to } \n` ;
148161 } ) ;
162+
163+ const goalsList = nodes . filter ( n => n . type == LinkType . GOAL ) . map ( n => `${ n . id } ` ) . join ( ',' ) ;
164+ const questionsList = nodes . filter ( n => n . type == LinkType . QUESTION ) . map ( n => `${ n . id } ` ) . join ( ',' ) ;
165+ const metricsList = nodes . filter ( n => n . type == LinkType . METRIC ) . map ( n => `${ n . id } ` ) . join ( ',' ) ;
166+
167+ mermaidSyntax += " end" ;
168+ mermaidSyntax += `
169+ subgraph Legend
170+ direction TB
171+
172+ goal[Goal]
173+ question[Question]
174+ metric[Metric]
175+
176+ classDef goals stroke:green,stroke-width:2px;
177+ class goal,${ goalsList } goals
178+
179+ classDef questions stroke:orange,stroke-width:2px;
180+ class question,${ questionsList } questions
181+
182+ classDef metrics stroke:purple,stroke-width:2px;
183+ class metric,${ metricsList } metrics
184+ end
185+ ` ;
149186 mermaidSyntax += "\n```" ;
150187 return mermaidSyntax ;
151188}
0 commit comments