forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create
sankey
parser and integrate sankey
parser into `merm…
…aid` package
- Loading branch information
1 parent
44b93c0
commit a5b0590
Showing
26 changed files
with
905 additions
and
304 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
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { parser } from './sankeyParser.js'; | ||
import { db } from './sankeyDB.js'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
describe('sankey', () => { | ||
beforeEach(() => db.clear()); | ||
|
||
it('should parse csv', () => { | ||
const csv = path.resolve(__dirname, './parser/energy.csv'); | ||
const data = fs.readFileSync(csv, 'utf8'); | ||
const graphDefinition = 'sankey-beta\n\n ' + data; | ||
|
||
parser.parse(graphDefinition); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; | ||
import type { | ||
DiagramDetector, | ||
DiagramLoader, | ||
ExternalDiagramDefinition, | ||
} from '../../diagram-api/types.js'; | ||
|
||
const id = 'sankey'; | ||
|
||
const detector: DiagramDetector = (txt) => { | ||
return /^\s*sankey-beta/.test(txt); | ||
}; | ||
|
||
const loader = async () => { | ||
const loader: DiagramLoader = async () => { | ||
const { diagram } = await import('./sankeyDiagram.js'); | ||
return { id, diagram }; | ||
}; | ||
|
||
const plugin: ExternalDiagramDefinition = { | ||
export const sankey: ExternalDiagramDefinition = { | ||
id, | ||
detector, | ||
loader, | ||
}; | ||
|
||
export default plugin; |
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,26 @@ | ||
import type { Sankey, SankeyLink } from 'mermaid-parser'; | ||
import { parse } from 'mermaid-parser'; | ||
|
||
import { log } from '../../logger.js'; | ||
import type { ParserDefinition } from '../../diagram-api/types.js'; | ||
import { populateCommonDb } from '../common/populateCommonDb.js'; | ||
import type { SankeyDB } from './sankeyTypes.js'; | ||
import { db } from './sankeyDB.js'; | ||
|
||
function populateDb(ast: Sankey, db: SankeyDB) { | ||
populateCommonDb(ast, db); | ||
ast.links.forEach((link: SankeyLink) => { | ||
db.addLink(link); | ||
}); | ||
ast.nodes.forEach((node: string) => { | ||
db.addNode(node); | ||
}); | ||
} | ||
|
||
export const parser: ParserDefinition = { | ||
parse: (input: string): void => { | ||
const ast: Sankey = parse('sankey', input); | ||
log.debug(ast); | ||
populateDb(ast, db); | ||
}, | ||
}; |
Oops, something went wrong.