Rename graphDb to flowDb

This commit is contained in:
Tyler Long 2018-03-12 20:52:06 +08:00
parent 964bc4dc12
commit 6f43082e38
5 changed files with 30 additions and 30 deletions

View File

@ -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]

View File

@ -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')
})
})

View File

@ -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;')

View File

@ -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!')
}