mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
Replace require with import
This commit is contained in:
@@ -7,7 +7,7 @@ import { logger } from '../../logger'
|
||||
|
||||
var conf = {
|
||||
}
|
||||
module.exports.setConf = function (cnf) {
|
||||
export const setConf = function (cnf) {
|
||||
var keys = Object.keys(cnf)
|
||||
var i
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
@@ -20,7 +20,7 @@ module.exports.setConf = function (cnf) {
|
||||
* @param vert Object containing the vertices.
|
||||
* @param g The graph that is to be drawn.
|
||||
*/
|
||||
module.exports.addVertices = function (vert, g) {
|
||||
export const addVertices = function (vert, g) {
|
||||
var keys = Object.keys(vert)
|
||||
|
||||
var styleFromStyleArr = function (styleStr, arr) {
|
||||
@@ -135,7 +135,7 @@ module.exports.addVertices = function (vert, g) {
|
||||
* @param {Object} edges The edges to add to the graph
|
||||
* @param {Object} g The graph object
|
||||
*/
|
||||
module.exports.addEdges = function (edges, g) {
|
||||
export const addEdges = function (edges, g) {
|
||||
var cnt = 0
|
||||
|
||||
var defaultStyle
|
||||
@@ -215,7 +215,7 @@ module.exports.addEdges = function (edges, g) {
|
||||
* Returns the all the styles from classDef statements in the graph definition.
|
||||
* @returns {object} classDef styles
|
||||
*/
|
||||
module.exports.getClasses = function (text, isDot) {
|
||||
export const getClasses = function (text, isDot) {
|
||||
var parser
|
||||
graph.clear()
|
||||
if (isDot) {
|
||||
@@ -246,7 +246,7 @@ module.exports.getClasses = function (text, isDot) {
|
||||
* @param text
|
||||
* @param id
|
||||
*/
|
||||
module.exports.draw = function (text, id, isDot) {
|
||||
export const draw = function (text, id, isDot) {
|
||||
logger.debug('Drawing flowchart')
|
||||
var parser
|
||||
graph.clear()
|
||||
@@ -310,8 +310,8 @@ module.exports.draw = function (text, id, isDot) {
|
||||
g.setParent(subG.nodes[j], subG.id)
|
||||
}
|
||||
}
|
||||
module.exports.addVertices(vert, g)
|
||||
module.exports.addEdges(edges, g)
|
||||
addVertices(vert, g)
|
||||
addEdges(edges, g)
|
||||
|
||||
// Create the renderer
|
||||
var Render = dagreD3.render
|
||||
|
@@ -18,7 +18,7 @@ var funs = []
|
||||
* @param type
|
||||
* @param style
|
||||
*/
|
||||
exports.addVertex = function (id, text, type, style) {
|
||||
export const addVertex = function (id, text, type, style) {
|
||||
var txt
|
||||
|
||||
if (typeof id === 'undefined') {
|
||||
@@ -63,7 +63,7 @@ exports.addVertex = function (id, text, type, style) {
|
||||
* @param type
|
||||
* @param linktext
|
||||
*/
|
||||
exports.addLink = function (start, end, type, linktext) {
|
||||
export const addLink = function (start, end, type, linktext) {
|
||||
logger.info('Got edge...', start, end)
|
||||
var edge = { start: start, end: end, type: undefined, text: '' }
|
||||
linktext = type.text
|
||||
@@ -89,7 +89,7 @@ exports.addLink = function (start, end, type, linktext) {
|
||||
* @param pos
|
||||
* @param interpolate
|
||||
*/
|
||||
exports.updateLinkInterpolate = function (pos, interp) {
|
||||
export const updateLinkInterpolate = function (pos, interp) {
|
||||
if (pos === 'default') {
|
||||
edges.defaultInterpolate = interp
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ exports.updateLinkInterpolate = function (pos, interp) {
|
||||
* @param pos
|
||||
* @param style
|
||||
*/
|
||||
exports.updateLink = function (pos, style) {
|
||||
export const updateLink = function (pos, style) {
|
||||
if (pos === 'default') {
|
||||
edges.defaultStyle = style
|
||||
} else {
|
||||
@@ -113,7 +113,7 @@ exports.updateLink = function (pos, style) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.addClass = function (id, style) {
|
||||
export const addClass = function (id, style) {
|
||||
if (typeof classes[id] === 'undefined') {
|
||||
classes[id] = { id: id, styles: [] }
|
||||
}
|
||||
@@ -131,7 +131,7 @@ exports.addClass = function (id, style) {
|
||||
* Called by parser when a graph definition is found, stores the direction of the chart.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setDirection = function (dir) {
|
||||
export const setDirection = function (dir) {
|
||||
direction = dir
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ exports.setDirection = function (dir) {
|
||||
* Called by parser when a graph definition is found, stores the direction of the chart.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setClass = function (id, className) {
|
||||
export const setClass = function (id, className) {
|
||||
if (id.indexOf(',') > 0) {
|
||||
id.split(',').forEach(function (id2) {
|
||||
if (typeof vertices[id2] !== 'undefined') {
|
||||
@@ -190,7 +190,7 @@ var setLink = function (id, linkStr) {
|
||||
})
|
||||
}
|
||||
}
|
||||
exports.getTooltip = function (id) {
|
||||
export const getTooltip = function (id) {
|
||||
return tooltips[id]
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ exports.getTooltip = function (id) {
|
||||
* Called by parser when a graph definition is found, stores the direction of the chart.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setClickEvent = function (id, functionName, link, tooltip) {
|
||||
export const setClickEvent = function (id, functionName, link, tooltip) {
|
||||
if (id.indexOf(',') > 0) {
|
||||
id.split(',').forEach(function (id2) {
|
||||
setTooltip(id2, tooltip)
|
||||
@@ -212,19 +212,19 @@ exports.setClickEvent = function (id, functionName, link, tooltip) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.bindFunctions = function (element) {
|
||||
export const bindFunctions = function (element) {
|
||||
funs.forEach(function (fun) {
|
||||
fun(element)
|
||||
})
|
||||
}
|
||||
exports.getDirection = function () {
|
||||
export const getDirection = function () {
|
||||
return direction
|
||||
}
|
||||
/**
|
||||
* Retrieval function for fetching the found nodes after parsing has completed.
|
||||
* @returns {{}|*|vertices}
|
||||
*/
|
||||
exports.getVertices = function () {
|
||||
export const getVertices = function () {
|
||||
return vertices
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ exports.getVertices = function () {
|
||||
* Retrieval function for fetching the found links after parsing has completed.
|
||||
* @returns {{}|*|edges}
|
||||
*/
|
||||
exports.getEdges = function () {
|
||||
export const getEdges = function () {
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ exports.getEdges = function () {
|
||||
* Retrieval function for fetching the found class definitions after parsing has completed.
|
||||
* @returns {{}|*|classes}
|
||||
*/
|
||||
exports.getClasses = function () {
|
||||
export const getClasses = function () {
|
||||
return classes
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ funs.push(setupToolTips)
|
||||
/**
|
||||
* Clears the internal graph db so that a new graph can be parsed.
|
||||
*/
|
||||
exports.clear = function () {
|
||||
export const clear = function () {
|
||||
vertices = {}
|
||||
classes = {}
|
||||
edges = []
|
||||
@@ -301,14 +301,14 @@ exports.clear = function () {
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
exports.defaultStyle = function () {
|
||||
export const defaultStyle = function () {
|
||||
return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;'
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the internal graph db so that a new graph can be parsed.
|
||||
*/
|
||||
exports.addSubGraph = function (list, title) {
|
||||
export const addSubGraph = function (list, title) {
|
||||
function uniq (a) {
|
||||
var prims = { 'boolean': {}, 'number': {}, 'string': {} }
|
||||
var objs = []
|
||||
@@ -343,7 +343,7 @@ var getPosForId = function (id) {
|
||||
}
|
||||
var secCount = -1
|
||||
var posCrossRef = []
|
||||
var indexNodes = function (id, pos) {
|
||||
var indexNodes2 = function (id, pos) {
|
||||
var nodes = subGraphs[pos].nodes
|
||||
secCount = secCount + 1
|
||||
if (secCount > 2000) {
|
||||
@@ -364,7 +364,7 @@ var indexNodes = function (id, pos) {
|
||||
var childPos = getPosForId(nodes[count])
|
||||
// Ignore regular nodes (pos will be -1)
|
||||
if (childPos >= 0) {
|
||||
var res = indexNodes(id, childPos)
|
||||
var res = indexNodes2(id, childPos)
|
||||
if (res.result) {
|
||||
return {
|
||||
result: true,
|
||||
@@ -383,16 +383,16 @@ var indexNodes = function (id, pos) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.getDepthFirstPos = function (pos) {
|
||||
export const getDepthFirstPos = function (pos) {
|
||||
return posCrossRef[pos]
|
||||
}
|
||||
exports.indexNodes = function () {
|
||||
export const indexNodes = function () {
|
||||
secCount = -1
|
||||
if (subGraphs.length > 0) {
|
||||
indexNodes('none', subGraphs.length - 1, 0)
|
||||
indexNodes2('none', subGraphs.length - 1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
exports.getSubGraphs = function () {
|
||||
export const getSubGraphs = function () {
|
||||
return subGraphs
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import graph from '../graphDb'
|
||||
import graphDb from '../graphDb'
|
||||
import flow from './flow'
|
||||
|
||||
describe('when parsing ', function () {
|
||||
beforeEach(function () {
|
||||
flow.parser.yy = require('../graphDb')
|
||||
flow.parser.yy = graphDb
|
||||
flow.parser.yy.clear()
|
||||
})
|
||||
|
||||
@@ -469,42 +469,42 @@ describe('when parsing ', function () {
|
||||
|
||||
describe('it should handle interaction, ', function () {
|
||||
it('it should be possible to use click to a callback', function () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A callback')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined)
|
||||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined)
|
||||
})
|
||||
|
||||
it('it should be possible to use click to a callback with toolip', function () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip')
|
||||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip')
|
||||
})
|
||||
|
||||
it('should handle interaction - click to a link', function () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined)
|
||||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined)
|
||||
})
|
||||
it('should handle interaction - click to a link with tooltip', function () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip')
|
||||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip')
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user