mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
1473 Updated config handling
This commit is contained in:
parent
5677523800
commit
bd0210cdce
@ -21,6 +21,14 @@
|
||||
<body>
|
||||
<h1>info below</h1>
|
||||
<div class="mermaid" style="width: 50%; height: 20%;">
|
||||
graph TD
|
||||
A[Christmas] -->|Get money| B(Go shopping)
|
||||
B --> C{Let me think}
|
||||
C -->|One| D[Laptop]
|
||||
C -->|Two| E[iPhone]
|
||||
C -->|Three| F[fa:fa-car Car]
|
||||
</div>
|
||||
<div class="mermaid2" style="width: 50%; height: 20%;">
|
||||
flowchart TB
|
||||
subgraph 1
|
||||
A --> B;
|
||||
@ -64,13 +72,14 @@ flowchart TB
|
||||
// arrowMarkerAbsolute: true,
|
||||
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
|
||||
logLevel: 0,
|
||||
flowchart: { curve: 'linear', "htmlLabels": false },
|
||||
flowchart: { curve: 'linear',htmlLabels: false },
|
||||
// gantt: { axisFormat: '%m/%d/%Y' },
|
||||
sequence: { actorMargin: 50, showSequenceNumbers: true },
|
||||
// sequenceDiagram: { actorMargin: 300 } // deprecated
|
||||
fontFamily: '"arial", sans-serif',
|
||||
curve: 'linear',
|
||||
securityLevel: 'loose'
|
||||
securityLevel: 'loose',
|
||||
htmlLabels: false
|
||||
});
|
||||
function callback(){alert('It worked');}
|
||||
</script>
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { logger } from './logger';
|
||||
let config = {};
|
||||
|
||||
const setConf = function(cnf) {
|
||||
@ -13,10 +14,18 @@ const setConf = function(cnf) {
|
||||
if (typeof config[lvl1Keys[i]] === 'undefined') {
|
||||
config[lvl1Keys[i]] = {};
|
||||
}
|
||||
// logger.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]])
|
||||
// logger.debug(
|
||||
// 'Setting config: ' +
|
||||
// lvl1Keys[i] +
|
||||
// ' ' +
|
||||
// lvl2Keys[j] +
|
||||
// ' to ' +
|
||||
// cnf[lvl1Keys[i]][lvl2Keys[j]]
|
||||
// );
|
||||
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
|
||||
}
|
||||
} else {
|
||||
// logger.debug('Setting config: ' + lvl1Keys[i] + ' to ' + cnf[lvl1Keys[i]]);
|
||||
config[lvl1Keys[i]] = cnf[lvl1Keys[i]];
|
||||
}
|
||||
}
|
||||
|
@ -1351,7 +1351,7 @@ describe('when rendering a sequenceDiagram with directives', function() {
|
||||
renderer.setConf(conf);
|
||||
});
|
||||
|
||||
it('it should handle one actor, when theme is dark and logLevel is 1', function() {
|
||||
it('it should handle one actor, when theme is dark and logLevel is 1 DX1', function() {
|
||||
renderer.bounds.init();
|
||||
const str = `
|
||||
%%{init: { "theme": "dark", "logLevel": 1 } }%%
|
||||
|
@ -122,6 +122,9 @@ const init = function() {
|
||||
};
|
||||
|
||||
const initialize = function(config) {
|
||||
mermaidAPI.reset();
|
||||
|
||||
// logger.debug('Initializing mermaid 1', config);
|
||||
if (typeof config.mermaid !== 'undefined') {
|
||||
if (typeof config.mermaid.startOnLoad !== 'undefined') {
|
||||
mermaid.startOnLoad = config.mermaid.startOnLoad;
|
||||
@ -131,7 +134,7 @@ const initialize = function(config) {
|
||||
}
|
||||
}
|
||||
mermaidAPI.initialize(config);
|
||||
logger.debug('Initializing mermaid ');
|
||||
logger.debug('Initializing mermaid ', config);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -699,6 +699,7 @@ export const decodeEntities = function(text) {
|
||||
* completed.
|
||||
*/
|
||||
const render = function(id, _txt, cb, container) {
|
||||
const config = getConfig();
|
||||
// Check the maximum allowed text size
|
||||
let txt = _txt;
|
||||
if (_txt.length > config.maxTextSize) {
|
||||
@ -925,61 +926,35 @@ const render = function(id, _txt, cb, container) {
|
||||
return svgCode;
|
||||
};
|
||||
|
||||
const setConf = function(cnf) {
|
||||
// console.log('set conf ', cnf);
|
||||
// Top level initially mermaid, gflow, sequenceDiagram and gantt
|
||||
const lvl1Keys = Object.keys(cnf);
|
||||
for (let i = 0; i < lvl1Keys.length; i++) {
|
||||
if (typeof cnf[lvl1Keys[i]] === 'object' && cnf[lvl1Keys[i]] != null) {
|
||||
const lvl2Keys = Object.keys(cnf[lvl1Keys[i]]);
|
||||
|
||||
for (let j = 0; j < lvl2Keys.length; j++) {
|
||||
logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]);
|
||||
if (typeof config[lvl1Keys[i]] === 'undefined') {
|
||||
config[lvl1Keys[i]] = {};
|
||||
}
|
||||
logger.debug(
|
||||
'Setting config: ' +
|
||||
lvl1Keys[i] +
|
||||
' ' +
|
||||
lvl2Keys[j] +
|
||||
' to ' +
|
||||
cnf[lvl1Keys[i]][lvl2Keys[j]]
|
||||
);
|
||||
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
|
||||
}
|
||||
} else {
|
||||
config[lvl1Keys[i]] = cnf[lvl1Keys[i]];
|
||||
}
|
||||
}
|
||||
// console.log('set conf done', config);
|
||||
};
|
||||
|
||||
function reinitialize(options) {
|
||||
// console.log('re-initialize ', options.logLevel, config.logLevel, getConfig().logLevel);
|
||||
if (typeof options === 'object') {
|
||||
setConf(options);
|
||||
// setConf(options);
|
||||
setConfig(options);
|
||||
}
|
||||
setConfig(config);
|
||||
setLogLevel(config.logLevel);
|
||||
// setConfig(config);
|
||||
setLogLevel(getConfig().logLevel);
|
||||
logger.debug('RE-Initializing mermaidAPI ', { version: pkg.version, options, config });
|
||||
}
|
||||
|
||||
let firstInit = true;
|
||||
function initialize(options) {
|
||||
// console.log('initialize ', options, config, getConfig());
|
||||
let _config = getConfig();
|
||||
// Set default options
|
||||
if (typeof options === 'object') {
|
||||
setConf(_config);
|
||||
setConfig(_config);
|
||||
if (firstInit) {
|
||||
firstInit = false;
|
||||
setConfig(config);
|
||||
}
|
||||
setConfig(options);
|
||||
}
|
||||
logger.debug('Initializing mermaidAPI ', { version: pkg.version, options, _config });
|
||||
// Update default config with options supplied at initialization
|
||||
if (typeof options === 'object') {
|
||||
_config = Object.assign(_config, options);
|
||||
setConf(_config);
|
||||
}
|
||||
setConfig(_config);
|
||||
setLogLevel(_config.logLevel);
|
||||
logger.warn('Initializing mermaidAPI theme', {
|
||||
version: pkg.version,
|
||||
options,
|
||||
config,
|
||||
current: getConfig().theme
|
||||
});
|
||||
|
||||
setLogLevel(getConfig().logLevel);
|
||||
}
|
||||
|
||||
// function getConfig () {
|
||||
@ -992,7 +967,10 @@ const mermaidAPI = {
|
||||
parse,
|
||||
initialize,
|
||||
reinitialize,
|
||||
getConfig
|
||||
getConfig,
|
||||
reset: () => {
|
||||
firstInit = true;
|
||||
}
|
||||
};
|
||||
|
||||
export default mermaidAPI;
|
||||
|
@ -26,8 +26,13 @@ describe('when using mermaidAPI and ', function() {
|
||||
};
|
||||
|
||||
mermaidAPI.initialize({ testObject: object });
|
||||
let config = mermaidAPI.getConfig();
|
||||
|
||||
console.log('1:', config);
|
||||
expect(config.testObject.test1).toBe(1);
|
||||
mermaidAPI.initialize({ testObject: { test3: true } });
|
||||
const config = mermaidAPI.getConfig();
|
||||
config = mermaidAPI.getConfig();
|
||||
console.log(config);
|
||||
|
||||
expect(config.testObject.test1).toBe(1);
|
||||
expect(config.testObject.test2).toBe(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user