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 graphlib from 'graphlibrary'
import * as d3 from 'd3' import * as d3 from 'd3'
import graphDb from './graphDb' import flowDb from './flowDb'
import flow from './parser/flow' import flow from './parser/flow'
import dot from './parser/dot' import dot from './parser/dot'
import dagreD3 from 'dagre-d3-renderer' import dagreD3 from 'dagre-d3-renderer'
@@ -211,18 +211,18 @@ export const addEdges = function (edges, g) {
*/ */
export const getClasses = function (text, isDot) { export const getClasses = function (text, isDot) {
let parser let parser
graphDb.clear() flowDb.clear()
if (isDot) { if (isDot) {
parser = dot.parser parser = dot.parser
} else { } else {
parser = flow.parser parser = flow.parser
} }
parser.yy = graphDb parser.yy = flowDb
// Parse the graph definition // Parse the graph definition
parser.parse(text) parser.parse(text)
const classes = graphDb.getClasses() const classes = flowDb.getClasses()
// Add default class if undefined // Add default class if undefined
if (typeof (classes.default) === 'undefined') { if (typeof (classes.default) === 'undefined') {
@@ -243,13 +243,13 @@ export const getClasses = function (text, isDot) {
export const draw = function (text, id, isDot) { export const draw = function (text, id, isDot) {
logger.debug('Drawing flowchart') logger.debug('Drawing flowchart')
let parser let parser
graphDb.clear() flowDb.clear()
if (isDot) { if (isDot) {
parser = dot.parser parser = dot.parser
} else { } else {
parser = flow.parser parser = flow.parser
} }
parser.yy = graphDb parser.yy = flowDb
// Parse the graph definition // Parse the graph definition
try { try {
@@ -259,7 +259,7 @@ export const draw = function (text, id, isDot) {
} }
// Fetch the default direction, use TD if none was found // Fetch the default direction, use TD if none was found
let dir = graphDb.getDirection() let dir = flowDb.getDirection()
if (typeof dir === 'undefined') { if (typeof dir === 'undefined') {
dir = 'TD' dir = 'TD'
} }
@@ -280,16 +280,16 @@ export const draw = function (text, id, isDot) {
}) })
let subG let subG
const subGraphs = graphDb.getSubGraphs() const subGraphs = flowDb.getSubGraphs()
for (let i = subGraphs.length - 1; i >= 0; i--) { for (let i = subGraphs.length - 1; i >= 0; i--) {
subG = subGraphs[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 // 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 let i = 0
for (i = subGraphs.length - 1; i >= 0; i--) { for (i = subGraphs.length - 1; i >= 0; i--) {
@@ -421,7 +421,7 @@ export const draw = function (text, id, isDot) {
element.selectAll('g.node') element.selectAll('g.node')
.attr('title', function () { .attr('title', function () {
return graphDb.getTooltip(this.id) return flowDb.getTooltip(this.id)
}) })
if (conf.useMaxWidth) { if (conf.useMaxWidth) {
@@ -442,7 +442,7 @@ export const draw = function (text, id, isDot) {
} }
// Index nodes // Index nodes
graphDb.indexNodes('subGraph' + i) flowDb.indexNodes('subGraph' + i)
for (i = 0; i < subGraphs.length; i++) { for (i = 0; i < subGraphs.length; i++) {
subG = subGraphs[i] subG = subGraphs[i]

View File

@@ -1,9 +1,9 @@
import graphDb from '../graphDb' import flowDb from '../flowDb'
import flow from './flow' import flow from './flow'
describe('when parsing ', function () { describe('when parsing ', function () {
beforeEach(function () { beforeEach(function () {
flow.parser.yy = graphDb flow.parser.yy = flowDb
flow.parser.yy.clear() flow.parser.yy.clear()
}) })
@@ -469,42 +469,42 @@ describe('when parsing ', function () {
describe('it should handle interaction, ', function () { describe('it should handle interaction, ', function () {
it('it should be possible to use click to a callback', 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 res = flow.parser.parse('graph TD\nA-->B\nclick A callback')
const vert = flow.parser.yy.getVertices() const vert = flow.parser.yy.getVertices()
const edges = flow.parser.yy.getEdges() 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 () { 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 res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"')
const vert = flow.parser.yy.getVertices() const vert = flow.parser.yy.getVertices()
const edges = flow.parser.yy.getEdges() 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 () { 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 res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"')
const vert = flow.parser.yy.getVertices() const vert = flow.parser.yy.getVertices()
const edges = flow.parser.yy.getEdges() 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 () { 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 res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"')
const vert = flow.parser.yy.getVertices() const vert = flow.parser.yy.getVertices()
const edges = flow.parser.yy.getEdges() 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 */ /* eslint-env jasmine */
import mermaid from './mermaid' import mermaid from './mermaid'
import graphDb from './diagrams/flowchart/graphDb' import flowDb from './diagrams/flowchart/flowDb'
import flowParser from './diagrams/flowchart/parser/flow' import flowParser from './diagrams/flowchart/parser/flow'
import flowRenderer from './diagrams/flowchart/flowRenderer' import flowRenderer from './diagrams/flowchart/flowRenderer'
@@ -40,8 +40,8 @@ describe('when using mermaid and ', function () {
describe('when calling addEdges ', function () { describe('when calling addEdges ', function () {
beforeEach(function () { beforeEach(function () {
flowParser.parser.yy = graphDb flowParser.parser.yy = flowDb
graphDb.clear() flowDb.clear()
}) })
it('it should handle edges with text', function () { it('it should handle edges with text', function () {
flowParser.parser.parse('graph TD;A-->|text ex|B;') 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 scope from 'scope-css'
import { logger, setLogLevel } from './logger' import { logger, setLogLevel } from './logger'
import graph from './diagrams/flowchart/graphDb' import flowDb from './diagrams/flowchart/flowDb'
import utils from './utils' import utils from './utils'
import flowRenderer from './diagrams/flowchart/flowRenderer' import flowRenderer from './diagrams/flowchart/flowRenderer'
import seq from './diagrams/sequenceDiagram/sequenceRenderer' import seq from './diagrams/sequenceDiagram/sequenceRenderer'
@@ -262,11 +262,11 @@ function parse (text) {
break break
case 'graph': case 'graph':
parser = flowParser parser = flowParser
parser.parser.yy = graph parser.parser.yy = flowDb
break break
case 'dotGraph': case 'dotGraph':
parser = dotParser parser = dotParser
parser.parser.yy = graph parser.parser.yy = flowDb
break break
case 'sequenceDiagram': case 'sequenceDiagram':
parser = sequenceParser parser = sequenceParser
@@ -457,7 +457,7 @@ const render = function (id, txt, cb, container) {
svgCode = decodeEntities(svgCode) svgCode = decodeEntities(svgCode)
if (typeof cb !== 'undefined') { if (typeof cb !== 'undefined') {
cb(svgCode, graph.bindFunctions) cb(svgCode, flowDb.bindFunctions)
} else { } else {
logger.warn('CB = undefined!') logger.warn('CB = undefined!')
} }