Refactor code

This commit is contained in:
Tyler Long
2017-04-16 23:24:47 +08:00
parent 110e4ee586
commit 87c7f73245
6 changed files with 124 additions and 159 deletions

View File

@@ -4,7 +4,6 @@
*/ */
var Logger = require('./logger') var Logger = require('./logger')
// Logger.setLogLevel(1)
var log = Logger.Log var log = Logger.Log
var mermaidAPI = require('./mermaidAPI') var mermaidAPI = require('./mermaidAPI')
var nextId = 0 var nextId = 0

View File

@@ -36,11 +36,6 @@ var gitGraphRenderer = require('./diagrams/gitGraph/gitGraphRenderer')
var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst') var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst')
var d3 = require('./d3') var d3 = require('./d3')
// https://github.com/cpettitt/dagre-d3/issues/202
// window.SVGElement.prototype.getTransformToElement = window.SVGElement.prototype.getTransformToElement || function (toElement) {
// return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM())
// }
/** /**
* ## Configuration * ## Configuration
* These are the default options which can be overridden with the initialization call as in the example below: * These are the default options which can be overridden with the initialization call as in the example below:
@@ -398,8 +393,6 @@ var render = function (id, txt, cb, container) {
window.txt = txt window.txt = txt
txt = exports.encodeEntities(txt) txt = exports.encodeEntities(txt)
// console.warn('mermaid encode: ');
// console.warn(txt);
var element = d3.select('#d' + id).node() var element = d3.select('#d' + id).node()
var graphType = utils.detectType(txt) var graphType = utils.detectType(txt)
@@ -409,10 +402,6 @@ var render = function (id, txt, cb, container) {
config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute
gitGraphRenderer.setConf(config.gitGraph) gitGraphRenderer.setConf(config.gitGraph)
gitGraphRenderer.draw(txt, id, false) gitGraphRenderer.draw(txt, id, false)
// if(config.cloneCssStyles){
// classes = gitGraphRenderer.getClasses(txt, false);
// utils.cloneCssStyles(element.firstChild, classes);
// }
break break
case 'graph': case 'graph':
config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute
@@ -479,10 +468,6 @@ var render = function (id, txt, cb, container) {
svgCode = exports.decodeEntities(svgCode) svgCode = exports.decodeEntities(svgCode)
// console.warn('mermaid decode: ');
// console.warn(svgCode);
// var he = require('he');
// svgCode = he.decode(svgCode);
if (typeof cb !== 'undefined') { if (typeof cb !== 'undefined') {
cb(svgCode, graph.bindFunctions) cb(svgCode, graph.bindFunctions)
} else { } else {

View File

@@ -6,22 +6,11 @@
* Created by knut on 14-11-23. * Created by knut on 14-11-23.
*/ */
var api = require('./mermaidAPI.js') var api = require('./mermaidAPI.js')
// var log = require('./logger').create();
describe('when using mermaidAPI and ', function () { describe('when using mermaidAPI and ', function () {
describe('doing initialize ', function () { describe('doing initialize ', function () {
// var main;
// var document;
// var window;
beforeEach(function () { beforeEach(function () {
// var MockBrowser = require('mock-browser').mocks.MockBrowser;
// var mock = new MockBrowser();
delete global.mermaid_config delete global.mermaid_config
// and in the run-code inside some object
// global.document = mock.getDocument();
// global.window = mock.getWindow();
document.body.innerHTML = '' document.body.innerHTML = ''
}) })

View File

@@ -28,17 +28,14 @@ var detectType = function (text) {
} }
if (text.match(/^\s*digraph/)) { if (text.match(/^\s*digraph/)) {
// log.debug('Detected dot syntax');
return 'dotGraph' return 'dotGraph'
} }
if (text.match(/^\s*info/)) { if (text.match(/^\s*info/)) {
// log.debug('Detected info syntax');
return 'info' return 'info'
} }
if (text.match(/^\s*gantt/)) { if (text.match(/^\s*gantt/)) {
// log.debug('Detected info syntax');
return 'gantt' return 'gantt'
} }

View File

@@ -4,13 +4,8 @@
*/ */
var utils = require('./utils') var utils = require('./utils')
// var log = require('./logger').create();
describe('when detecting chart type ', function () { describe('when detecting chart type ', function () {
var str var str
beforeEach(function () {
})
it('should handle a graph defintion', function () { it('should handle a graph defintion', function () {
str = 'graph TB\nbfs1:queue' str = 'graph TB\nbfs1:queue'
@@ -40,11 +35,6 @@ describe('when detecting chart type ', function () {
describe('when cloning CSS ', function () { describe('when cloning CSS ', function () {
beforeEach(function () { beforeEach(function () {
// var MockBrowser = require('mock-browser').mocks.MockBrowser;
// var mock = new MockBrowser();
// and in the run-code inside some object
// global.document = mock.getDocument();
document.body.innerHTML = '' document.body.innerHTML = ''
}) })

View File

@@ -5,3 +5,8 @@
- default theme doesn't work for class diagram - default theme doesn't work for class diagram
- mermaidAPI.js cannot be required directly - mermaidAPI.js cannot be required directly
- compile less to css - compile less to css
- don't version control generated content, move them to outside project
- editor
- dist
- docs
- what's the correct way to change logLevel as an end user?