diff --git a/cypress/platform/current.html b/cypress/platform/current.html index b95b8c19e..fa0477414 100644 --- a/cypress/platform/current.html +++ b/cypress/platform/current.html @@ -21,6 +21,14 @@

info below

+ 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] +
+
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');} diff --git a/src/config.js b/src/config.js index 1a81cc38e..5e556795b 100644 --- a/src/config.js +++ b/src/config.js @@ -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]]; } } diff --git a/src/diagrams/sequence/sequenceDiagram.spec.js b/src/diagrams/sequence/sequenceDiagram.spec.js index df3fcb238..4a95fad5f 100644 --- a/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/src/diagrams/sequence/sequenceDiagram.spec.js @@ -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 } }%% diff --git a/src/mermaid.js b/src/mermaid.js index 616ff40e4..97f412222 100644 --- a/src/mermaid.js +++ b/src/mermaid.js @@ -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); }; /** diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index b392e83aa..bb85e36d4 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -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; diff --git a/src/mermaidAPI.spec.js b/src/mermaidAPI.spec.js index a5114356f..916763b44 100644 --- a/src/mermaidAPI.spec.js +++ b/src/mermaidAPI.spec.js @@ -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);