mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-15 10:14:21 +01:00
Refactor code
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
var Logger = require('./logger')
|
||||
// Logger.setLogLevel(1)
|
||||
var log = Logger.Log
|
||||
var mermaidAPI = require('./mermaidAPI')
|
||||
var nextId = 0
|
||||
|
||||
@@ -36,11 +36,6 @@ var gitGraphRenderer = require('./diagrams/gitGraph/gitGraphRenderer')
|
||||
var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst')
|
||||
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
|
||||
* 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
|
||||
txt = exports.encodeEntities(txt)
|
||||
// console.warn('mermaid encode: ');
|
||||
// console.warn(txt);
|
||||
|
||||
var element = d3.select('#d' + id).node()
|
||||
var graphType = utils.detectType(txt)
|
||||
@@ -409,10 +402,6 @@ var render = function (id, txt, cb, container) {
|
||||
config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute
|
||||
gitGraphRenderer.setConf(config.gitGraph)
|
||||
gitGraphRenderer.draw(txt, id, false)
|
||||
// if(config.cloneCssStyles){
|
||||
// classes = gitGraphRenderer.getClasses(txt, false);
|
||||
// utils.cloneCssStyles(element.firstChild, classes);
|
||||
// }
|
||||
break
|
||||
case 'graph':
|
||||
config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute
|
||||
@@ -479,10 +468,6 @@ var render = function (id, txt, cb, container) {
|
||||
|
||||
svgCode = exports.decodeEntities(svgCode)
|
||||
|
||||
// console.warn('mermaid decode: ');
|
||||
// console.warn(svgCode);
|
||||
// var he = require('he');
|
||||
// svgCode = he.decode(svgCode);
|
||||
if (typeof cb !== 'undefined') {
|
||||
cb(svgCode, graph.bindFunctions)
|
||||
} else {
|
||||
|
||||
@@ -6,22 +6,11 @@
|
||||
* Created by knut on 14-11-23.
|
||||
*/
|
||||
var api = require('./mermaidAPI.js')
|
||||
// var log = require('./logger').create();
|
||||
|
||||
describe('when using mermaidAPI and ', function () {
|
||||
describe('doing initialize ', function () {
|
||||
// var main;
|
||||
// var document;
|
||||
// var window;
|
||||
beforeEach(function () {
|
||||
// var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
||||
// var mock = new MockBrowser();
|
||||
|
||||
delete global.mermaid_config
|
||||
|
||||
// and in the run-code inside some object
|
||||
// global.document = mock.getDocument();
|
||||
// global.window = mock.getWindow();
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
@@ -29,7 +18,7 @@ describe('when using mermaidAPI and ', function () {
|
||||
var orgConfig = api.getConfig()
|
||||
expect(orgConfig.testLiteral).toBe(undefined)
|
||||
|
||||
api.initialize({'testLiteral': true})
|
||||
api.initialize({ 'testLiteral': true })
|
||||
var config = api.getConfig()
|
||||
|
||||
expect(config.testLiteral).toBe(true)
|
||||
@@ -43,8 +32,8 @@ describe('when using mermaidAPI and ', function () {
|
||||
test2: false
|
||||
}
|
||||
|
||||
api.initialize({'testObject': object})
|
||||
api.initialize({'testObject': {'test3': true}})
|
||||
api.initialize({ 'testObject': object })
|
||||
api.initialize({ 'testObject': { 'test3': true } })
|
||||
var config = api.getConfig()
|
||||
|
||||
expect(config.testObject.test1).toBe(1)
|
||||
@@ -55,7 +44,7 @@ describe('when using mermaidAPI and ', function () {
|
||||
})
|
||||
describe('checking validity of input ', function () {
|
||||
it('it should return false for an invalid definiton', function () {
|
||||
global.mermaidAPI.parseError = function () {}
|
||||
global.mermaidAPI.parseError = function () { }
|
||||
spyOn(global.mermaidAPI, 'parseError')
|
||||
var res = api.parse('this is not a mermaid diagram definition')
|
||||
|
||||
|
||||
@@ -28,17 +28,14 @@ var detectType = function (text) {
|
||||
}
|
||||
|
||||
if (text.match(/^\s*digraph/)) {
|
||||
// log.debug('Detected dot syntax');
|
||||
return 'dotGraph'
|
||||
}
|
||||
|
||||
if (text.match(/^\s*info/)) {
|
||||
// log.debug('Detected info syntax');
|
||||
return 'info'
|
||||
}
|
||||
|
||||
if (text.match(/^\s*gantt/)) {
|
||||
// log.debug('Detected info syntax');
|
||||
return 'gantt'
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,8 @@
|
||||
*/
|
||||
var utils = require('./utils')
|
||||
|
||||
// var log = require('./logger').create();
|
||||
describe('when detecting chart type ', function () {
|
||||
var str
|
||||
beforeEach(function () {
|
||||
|
||||
})
|
||||
|
||||
it('should handle a graph defintion', function () {
|
||||
str = 'graph TB\nbfs1:queue'
|
||||
|
||||
@@ -40,11 +35,6 @@ describe('when detecting chart type ', function () {
|
||||
|
||||
describe('when cloning CSS ', 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 = ''
|
||||
})
|
||||
|
||||
@@ -136,7 +126,7 @@ describe('when cloning CSS ', function () {
|
||||
var svg = document.createElement('svg')
|
||||
svg.setAttribute('id', 'mermaid-01')
|
||||
|
||||
utils.cloneCssStyles(svg, {'default': {'styles': ['stroke:#fff', 'stroke-width:1.5px']}})
|
||||
utils.cloneCssStyles(svg, { 'default': { 'styles': ['stroke:#fff', 'stroke-width:1.5px'] } })
|
||||
expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#fff; stroke-width:1.5px; }'])
|
||||
// Also verify the elements around the styling
|
||||
expect(svg.innerHTML).toBe('<style type="text/css" title="mermaid-svg-internal-css">/* <![CDATA[ */\n#mermaid-01 .node>rect { stroke:#fff; stroke-width:1.5px; }\n/* ]]> */\n</style>')
|
||||
@@ -179,7 +169,7 @@ describe('when cloning CSS ', function () {
|
||||
it('should handle a default class together with stylesheet in document with classes in SVG', function () {
|
||||
var svg = generateSVG()
|
||||
addStyleToDocument()
|
||||
utils.cloneCssStyles(svg, {'default': {'styles': ['stroke:#ffffff', 'stroke-width:1.5px']}})
|
||||
utils.cloneCssStyles(svg, { 'default': { 'styles': ['stroke:#ffffff', 'stroke-width:1.5px'] } })
|
||||
expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#ffffff; stroke-width:1.5px; }', '.node { stroke: #eeeeee;}', '.node-square { stroke: #bbbbbb;}'])
|
||||
})
|
||||
|
||||
@@ -187,9 +177,9 @@ describe('when cloning CSS ', function () {
|
||||
var svg = generateSVG()
|
||||
addStyleToDocument()
|
||||
utils.cloneCssStyles(svg, {
|
||||
'default': {'styles': ['stroke:#ffffff', 'stroke-width:1.5px']},
|
||||
'node-square': {'styles': ['fill:#eeeeee', 'stroke:#aaaaaa']},
|
||||
'node-circle': {'styles': ['fill:#444444', 'stroke:#111111']}
|
||||
'default': { 'styles': ['stroke:#ffffff', 'stroke-width:1.5px'] },
|
||||
'node-square': { 'styles': ['fill:#eeeeee', 'stroke:#aaaaaa'] },
|
||||
'node-circle': { 'styles': ['fill:#444444', 'stroke:#111111'] }
|
||||
})
|
||||
expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#ffffff; stroke-width:1.5px; }',
|
||||
'.node { stroke: #eeeeee;}',
|
||||
|
||||
5
todo.md
5
todo.md
@@ -5,3 +5,8 @@
|
||||
- default theme doesn't work for class diagram
|
||||
- mermaidAPI.js cannot be required directly
|
||||
- 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?
|
||||
|
||||
Reference in New Issue
Block a user