mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-15 13:29:40 +02:00
Refactor code
This commit is contained in:
17
src/d3.js
vendored
17
src/d3.js
vendored
@@ -3,7 +3,6 @@ const d3 = require('d3')
|
|||||||
module.exports = d3;
|
module.exports = d3;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
D3 Text Wrap
|
D3 Text Wrap
|
||||||
By Vijith Assar
|
By Vijith Assar
|
||||||
http://www.vijithassar.com
|
http://www.vijithassar.com
|
||||||
@@ -11,7 +10,6 @@ module.exports = d3;
|
|||||||
@vijithassar
|
@vijithassar
|
||||||
|
|
||||||
Detailed instructions at http://www.github.com/vijithassar/d3textwrap
|
Detailed instructions at http://www.github.com/vijithassar/d3textwrap
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
@@ -313,8 +311,6 @@ module.exports = d3;
|
|||||||
// adjust the length by the offset we've tracked
|
// adjust the length by the offset we've tracked
|
||||||
// due to the misreported length discussed above
|
// due to the misreported length discussed above
|
||||||
|
|
||||||
// var testWidth = newWidth - totalOffset
|
|
||||||
|
|
||||||
// if our latest version of the string is too
|
// if our latest version of the string is too
|
||||||
// big for the bounds, use the previous
|
// big for the bounds, use the previous
|
||||||
// version of the string (without the newest word
|
// version of the string (without the newest word
|
||||||
@@ -363,9 +359,6 @@ module.exports = d3;
|
|||||||
textNodeSelected.text('')
|
textNodeSelected.text('')
|
||||||
for (i = 0; i < substrings.length; i++) {
|
for (i = 0; i < substrings.length; i++) {
|
||||||
substring = substrings[i].string
|
substring = substrings[i].string
|
||||||
// if (i > 0) {
|
|
||||||
// var previousSubstring = substrings[i - 1]
|
|
||||||
// }
|
|
||||||
// only append if we're sure it won't make the tspans
|
// only append if we're sure it won't make the tspans
|
||||||
// overflow the bounds.
|
// overflow the bounds.
|
||||||
if ((i) * lineHeight < bounds.height - (lineHeight * 1.5)) {
|
if ((i) * lineHeight < bounds.height - (lineHeight * 1.5)) {
|
||||||
@@ -387,15 +380,6 @@ module.exports = d3;
|
|||||||
if (padding) { xOffset += padding }
|
if (padding) { xOffset += padding }
|
||||||
return xOffset
|
return xOffset
|
||||||
})
|
})
|
||||||
// .attr('dx', function() {
|
|
||||||
// if(i == 0) {
|
|
||||||
// var render_offset = 0;
|
|
||||||
// } else if(i > 0) {
|
|
||||||
// render_offset = substrings[i - 1].width;
|
|
||||||
// render_offset = render_offset * -1;
|
|
||||||
// }
|
|
||||||
// return render_offset;
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,4 +445,3 @@ module.exports = d3;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
/* jshint ignore:end */
|
|
||||||
|
@@ -10,21 +10,6 @@
|
|||||||
* => [2011-3-3T20:24:4.810 error (5021)] booom
|
* => [2011-3-3T20:24:4.810 error (5021)] booom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// const LEVELS = {
|
|
||||||
// debug: 1,
|
|
||||||
// info: 2,
|
|
||||||
// warn: 3,
|
|
||||||
// error: 4,
|
|
||||||
// fatal: 5,
|
|
||||||
// default: 5
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var defaultLevel = LEVELS.error
|
|
||||||
|
|
||||||
// exports.setLogLevel = function (level) {
|
|
||||||
// defaultLevel = level;
|
|
||||||
// };
|
|
||||||
|
|
||||||
function formatTime (timestamp) {
|
function formatTime (timestamp) {
|
||||||
var hh = timestamp.getUTCHours()
|
var hh = timestamp.getUTCHours()
|
||||||
var mm = timestamp.getUTCMinutes()
|
var mm = timestamp.getUTCMinutes()
|
||||||
|
@@ -68,8 +68,6 @@ var init = function () {
|
|||||||
: nodes instanceof window.Node ? [nodes]
|
: nodes instanceof window.Node ? [nodes]
|
||||||
: nodes // Last case - sequence config was passed pick next
|
: nodes // Last case - sequence config was passed pick next
|
||||||
|
|
||||||
var i
|
|
||||||
|
|
||||||
if (typeof global.mermaid_config !== 'undefined') {
|
if (typeof global.mermaid_config !== 'undefined') {
|
||||||
mermaidAPI.initialize(global.mermaid_config)
|
mermaidAPI.initialize(global.mermaid_config)
|
||||||
}
|
}
|
||||||
@@ -92,7 +90,7 @@ var init = function () {
|
|||||||
bindFunctions(element)
|
bindFunctions(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nodes.length; i++) {
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
var element = nodes[i]
|
var element = nodes[i]
|
||||||
|
|
||||||
/*! Check if previously processed */
|
/*! Check if previously processed */
|
||||||
@@ -107,13 +105,8 @@ var init = function () {
|
|||||||
// Fetch the graph definition including tags
|
// Fetch the graph definition including tags
|
||||||
txt = element.innerHTML
|
txt = element.innerHTML
|
||||||
|
|
||||||
// console.warn('delivererd from the browser: ');
|
|
||||||
// console.warn(txt);
|
|
||||||
|
|
||||||
// transforms the html to pure text
|
// transforms the html to pure text
|
||||||
txt = he.decode(txt).trim()
|
txt = he.decode(txt).trim()
|
||||||
// console.warn('he decode: ');
|
|
||||||
// console.warn(txt);
|
|
||||||
|
|
||||||
mermaidAPI.render(id, txt, insertSvg, element)
|
mermaidAPI.render(id, txt, insertSvg, element)
|
||||||
}
|
}
|
||||||
@@ -226,16 +219,12 @@ exports.contentLoaded = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if(typeof global.mermaid === 'undefined' ){
|
|
||||||
if (typeof global.mermaid.startOnLoad === 'undefined') {
|
if (typeof global.mermaid.startOnLoad === 'undefined') {
|
||||||
log.debug('In start, no config')
|
log.debug('In start, no config')
|
||||||
config = mermaidAPI.getConfig()
|
config = mermaidAPI.getConfig()
|
||||||
if (config.startOnLoad) {
|
if (config.startOnLoad) {
|
||||||
global.mermaid.init()
|
global.mermaid.init()
|
||||||
}
|
}
|
||||||
// }else{
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +237,3 @@ if (typeof document !== 'undefined') {
|
|||||||
exports.contentLoaded()
|
exports.contentLoaded()
|
||||||
}, false)
|
}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Your actual module
|
|
||||||
// return module.exports;
|
|
||||||
// }));
|
|
||||||
|
@@ -5,40 +5,20 @@
|
|||||||
/**
|
/**
|
||||||
* Created by knut on 14-11-23.
|
* Created by knut on 14-11-23.
|
||||||
*/
|
*/
|
||||||
// var rewire = require('rewire');
|
|
||||||
var mermaid = require('./mermaid')
|
var mermaid = require('./mermaid')
|
||||||
// var log = require('./logger').create();
|
|
||||||
|
|
||||||
describe('when using mermaid and ', function () {
|
describe('when using mermaid and ', function () {
|
||||||
describe('when detecting chart type ', function () {
|
describe('when detecting chart type ', function () {
|
||||||
// var mermaid;
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not start rendering with mermaid_config.startOnLoad set to false', function () {
|
it('should not start rendering with mermaid_config.startOnLoad set to false', function () {
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
global.mermaid_config = {startOnLoad: false}
|
global.mermaid_config = {startOnLoad: false}
|
||||||
|
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(global.mermaid, 'init')
|
||||||
// log.debug(mermaid);
|
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).not.toHaveBeenCalled()
|
expect(global.mermaid.init).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not start rendering with mermaid.startOnLoad set to false', function () {
|
it('should not start rendering with mermaid.startOnLoad set to false', function () {
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
global.mermaid.startOnLoad = false
|
global.mermaid.startOnLoad = false
|
||||||
global.mermaid_config = {startOnLoad: true}
|
global.mermaid_config = {startOnLoad: true}
|
||||||
|
|
||||||
@@ -49,7 +29,6 @@ describe('when using mermaid and ', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering with both startOnLoad set', function () {
|
it('should start rendering with both startOnLoad set', function () {
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
global.mermaid.startOnLoad = true
|
global.mermaid.startOnLoad = true
|
||||||
global.mermaid_config = {startOnLoad: true}
|
global.mermaid_config = {startOnLoad: true}
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
@@ -59,7 +38,6 @@ describe('when using mermaid and ', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering with mermaid.startOnLoad set and no mermaid_config defined', function () {
|
it('should start rendering with mermaid.startOnLoad set and no mermaid_config defined', function () {
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
global.mermaid.startOnLoad = true
|
global.mermaid.startOnLoad = true
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(global.mermaid, 'init')
|
||||||
@@ -68,7 +46,6 @@ describe('when using mermaid and ', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering as a default with no changes performed', function () {
|
it('should start rendering as a default with no changes performed', function () {
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(global.mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
@@ -83,12 +60,8 @@ describe('when using mermaid and ', function () {
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.mermaid_config = {startOnLoad: false}
|
global.mermaid_config = {startOnLoad: false}
|
||||||
// var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
|
||||||
// var mock = new MockBrowser();
|
|
||||||
flow.parser.yy = graph
|
flow.parser.yy = graph
|
||||||
graph.clear()
|
graph.clear()
|
||||||
// global.document = mock.getDocument();
|
|
||||||
// mermaid = rewire('./mermaid');
|
|
||||||
})
|
})
|
||||||
it('it should handle edges with text', function () {
|
it('it should handle edges with text', function () {
|
||||||
flow.parser.parse('graph TD;A-->|text ex|B;')
|
flow.parser.parse('graph TD;A-->|text ex|B;')
|
||||||
|
Reference in New Issue
Block a user