diff --git a/src/diagrams/flowchart/graphDb.js b/src/diagrams/flowchart/flowDb.js similarity index 100% rename from src/diagrams/flowchart/graphDb.js rename to src/diagrams/flowchart/flowDb.js diff --git a/src/diagrams/flowchart/flowRenderer.js b/src/diagrams/flowchart/flowRenderer.js index 47fa5be3a..c0f9b110d 100644 --- a/src/diagrams/flowchart/flowRenderer.js +++ b/src/diagrams/flowchart/flowRenderer.js @@ -1,7 +1,7 @@ import graphlib from 'graphlibrary' import * as d3 from 'd3' -import graphDb from './graphDb' +import flowDb from './flowDb' import flow from './parser/flow' import dot from './parser/dot' import dagreD3 from 'dagre-d3-renderer' @@ -211,18 +211,18 @@ export const addEdges = function (edges, g) { */ export const getClasses = function (text, isDot) { let parser - graphDb.clear() + flowDb.clear() if (isDot) { parser = dot.parser } else { parser = flow.parser } - parser.yy = graphDb + parser.yy = flowDb // Parse the graph definition parser.parse(text) - const classes = graphDb.getClasses() + const classes = flowDb.getClasses() // Add default class if undefined if (typeof (classes.default) === 'undefined') { @@ -243,13 +243,13 @@ export const getClasses = function (text, isDot) { export const draw = function (text, id, isDot) { logger.debug('Drawing flowchart') let parser - graphDb.clear() + flowDb.clear() if (isDot) { parser = dot.parser } else { parser = flow.parser } - parser.yy = graphDb + parser.yy = flowDb // Parse the graph definition try { @@ -259,7 +259,7 @@ export const draw = function (text, id, isDot) { } // Fetch the default direction, use TD if none was found - let dir = graphDb.getDirection() + let dir = flowDb.getDirection() if (typeof dir === 'undefined') { dir = 'TD' } @@ -280,16 +280,16 @@ export const draw = function (text, id, isDot) { }) let subG - const subGraphs = graphDb.getSubGraphs() + const subGraphs = flowDb.getSubGraphs() for (let i = subGraphs.length - 1; i >= 0; i--) { subG = subGraphs[i] - graphDb.addVertex(subG.id, subG.title, 'group', undefined) + flowDb.addVertex(subG.id, subG.title, 'group', undefined) } // Fetch the verices/nodes and edges/links from the parsed graph definition - const vert = graphDb.getVertices() + const vert = flowDb.getVertices() - const edges = graphDb.getEdges() + const edges = flowDb.getEdges() let i = 0 for (i = subGraphs.length - 1; i >= 0; i--) { @@ -421,7 +421,7 @@ export const draw = function (text, id, isDot) { element.selectAll('g.node') .attr('title', function () { - return graphDb.getTooltip(this.id) + return flowDb.getTooltip(this.id) }) if (conf.useMaxWidth) { @@ -442,7 +442,7 @@ export const draw = function (text, id, isDot) { } // Index nodes - graphDb.indexNodes('subGraph' + i) + flowDb.indexNodes('subGraph' + i) for (i = 0; i < subGraphs.length; i++) { subG = subGraphs[i] diff --git a/src/diagrams/flowchart/parser/flow.spec.js b/src/diagrams/flowchart/parser/flow.spec.js index 66081bc36..67750061e 100644 --- a/src/diagrams/flowchart/parser/flow.spec.js +++ b/src/diagrams/flowchart/parser/flow.spec.js @@ -1,9 +1,9 @@ -import graphDb from '../graphDb' +import flowDb from '../flowDb' import flow from './flow' describe('when parsing ', function () { beforeEach(function () { - flow.parser.yy = graphDb + flow.parser.yy = flowDb 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(graphDb, 'setClickEvent') + spyOn(flowDb, 'setClickEvent') const res = flow.parser.parse('graph TD\nA-->B\nclick A callback') const vert = flow.parser.yy.getVertices() const edges = flow.parser.yy.getEdges() - expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined) + expect(flowDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined) }) it('it should be possible to use click to a callback with toolip', function () { - spyOn(graphDb, 'setClickEvent') + spyOn(flowDb, 'setClickEvent') const res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"') const vert = flow.parser.yy.getVertices() const edges = flow.parser.yy.getEdges() - expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip') + expect(flowDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip') }) it('should handle interaction - click to a link', function () { - spyOn(graphDb, 'setClickEvent') + spyOn(flowDb, 'setClickEvent') const res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"') const vert = flow.parser.yy.getVertices() const edges = flow.parser.yy.getEdges() - expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined) + expect(flowDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined) }) it('should handle interaction - click to a link with tooltip', function () { - spyOn(graphDb, 'setClickEvent') + spyOn(flowDb, 'setClickEvent') const res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"') const vert = flow.parser.yy.getVertices() const edges = flow.parser.yy.getEdges() - expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip') + expect(flowDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip') }) }) diff --git a/src/mermaid.spec.js b/src/mermaid.spec.js index 37e3c5516..30bda6a0a 100644 --- a/src/mermaid.spec.js +++ b/src/mermaid.spec.js @@ -1,6 +1,6 @@ /* eslint-env jasmine */ import mermaid from './mermaid' -import graphDb from './diagrams/flowchart/graphDb' +import flowDb from './diagrams/flowchart/flowDb' import flowParser from './diagrams/flowchart/parser/flow' import flowRenderer from './diagrams/flowchart/flowRenderer' @@ -40,8 +40,8 @@ describe('when using mermaid and ', function () { describe('when calling addEdges ', function () { beforeEach(function () { - flowParser.parser.yy = graphDb - graphDb.clear() + flowParser.parser.yy = flowDb + flowDb.clear() }) it('it should handle edges with text', function () { flowParser.parser.parse('graph TD;A-->|text ex|B;') diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index e9a6bc759..2472a1f73 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -15,7 +15,7 @@ import * as d3 from 'd3' import scope from 'scope-css' import { logger, setLogLevel } from './logger' -import graph from './diagrams/flowchart/graphDb' +import flowDb from './diagrams/flowchart/flowDb' import utils from './utils' import flowRenderer from './diagrams/flowchart/flowRenderer' import seq from './diagrams/sequenceDiagram/sequenceRenderer' @@ -262,11 +262,11 @@ function parse (text) { break case 'graph': parser = flowParser - parser.parser.yy = graph + parser.parser.yy = flowDb break case 'dotGraph': parser = dotParser - parser.parser.yy = graph + parser.parser.yy = flowDb break case 'sequenceDiagram': parser = sequenceParser @@ -457,7 +457,7 @@ const render = function (id, txt, cb, container) { svgCode = decodeEntities(svgCode) if (typeof cb !== 'undefined') { - cb(svgCode, graph.bindFunctions) + cb(svgCode, flowDb.bindFunctions) } else { logger.warn('CB = undefined!') }