mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
#1542 Handling of config
This commit is contained in:
parent
a4bf85b1b6
commit
ecea0f90d4
@ -74,8 +74,9 @@ stateDiagram-v2
|
||||
A --> D: asd123
|
||||
</div>
|
||||
</div>
|
||||
%%{init: {'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%%
|
||||
<div class="mermaid" style="width: 50%; height: 20%;">
|
||||
%%{init: {'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%%
|
||||
%%{init: {'theme': 'base'}}%%
|
||||
|
||||
graph TB
|
||||
subgraph apa
|
||||
@ -92,7 +93,7 @@ graph TD
|
||||
C
|
||||
end
|
||||
</div>
|
||||
<div class="mermaid" style="width: 50%; height: 20%;">
|
||||
<div class="mermaid2" style="width: 50%; height: 20%;">
|
||||
sequenceDiagram
|
||||
Alice->Bob: Hello Bob, how are you?
|
||||
Note over Alice,Bob: Looks
|
||||
@ -105,8 +106,8 @@ Note over Bob,Alice: Looks back
|
||||
// console.error('Mermaid error: ', err);
|
||||
};
|
||||
mermaid.initialize({
|
||||
theme: 'base',
|
||||
// themeVariables:{primaryColor: '#ff0000'},
|
||||
// theme: 'base',
|
||||
// themeVariables:{primaryColor: '#0000ff'},
|
||||
// arrowMarkerAbsolute: true,
|
||||
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
|
||||
logLevel: 0,
|
||||
|
@ -15,20 +15,27 @@ export const updateCurrentConfig = (siteCfg, _directives) => {
|
||||
let cfg = assignWithDepth({}, siteCfg);
|
||||
|
||||
// Apply directives
|
||||
let themeVariables;
|
||||
_directives.forEach(d => {
|
||||
let themeVariables = {};
|
||||
for (let i = 0; i < _directives.length; i++) {
|
||||
const d = _directives[i];
|
||||
sanitize(d);
|
||||
cfg = assignWithDepth(cfg, d);
|
||||
if (d.themeVariables) {
|
||||
themeVariables = d.themeVariables;
|
||||
}
|
||||
});
|
||||
if (themeVariables && currentConfig.theme && theme[currentConfig.theme]) {
|
||||
const variables = theme[currentConfig.theme].getThemeVariables(themeVariables);
|
||||
}
|
||||
if (cfg.theme && theme[cfg.theme]) {
|
||||
// console.warn('cfg beeing updated main bkg', themeVariables, cfg.theme);
|
||||
const variables = theme[cfg.theme].getThemeVariables(themeVariables);
|
||||
// console.warn('cfg beeing updated 2 main bkg', variables.mainBkg);
|
||||
cfg.themeVariables = variables;
|
||||
}
|
||||
// else {
|
||||
// console.warn('cfg not beeing updated main bkg', themeVariables, cfg.theme);
|
||||
// }
|
||||
|
||||
currentConfig = cfg;
|
||||
// console.warn('cfg updated main bkg', cfg.sequence);
|
||||
return cfg;
|
||||
};
|
||||
/**
|
||||
@ -49,7 +56,6 @@ export const setSiteConfig = conf => {
|
||||
// siteConfig = { ...defaultConfig, ...conf };
|
||||
siteConfig = assignWithDepth({}, defaultConfig);
|
||||
siteConfig = assignWithDepth(siteConfig, conf);
|
||||
// console.warn(siteConfig.sequence);
|
||||
currentConfig = updateCurrentConfig(siteConfig, directives);
|
||||
return siteConfig;
|
||||
};
|
||||
@ -165,6 +171,7 @@ export const reset = () => {
|
||||
|
||||
// Replace current config with siteConfig
|
||||
directives = [];
|
||||
// console.warn(siteConfig.sequence);
|
||||
updateCurrentConfig(siteConfig, directives);
|
||||
};
|
||||
|
||||
|
@ -942,8 +942,8 @@ describe('when rendering a sequenceDiagram APA', function() {
|
||||
wrap: false,
|
||||
mirrorActors: false
|
||||
};
|
||||
console.warn('Set site config');
|
||||
configApi.setSiteConfig({ logLevel: 5, sequence: conf });
|
||||
// console.warn('Config = ', configApi.getConfig())
|
||||
});
|
||||
let conf;
|
||||
beforeEach(function() {
|
||||
|
@ -216,9 +216,10 @@ const render = function(id, _txt, cb, container) {
|
||||
const siteConfig = configApi.getSiteConfig();
|
||||
configApi.addDirective(siteConfig);
|
||||
}
|
||||
// console.warn('Render fetching config');
|
||||
|
||||
const cnf = configApi.getConfig();
|
||||
console.log('Render', cnf);
|
||||
// console.warn('Render with config after adding new directives', cnf.themeVariables.mainBkg);
|
||||
// Check the maximum allowed text size
|
||||
if (_txt.length > cnf.maxTextSize) {
|
||||
txt = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa';
|
||||
@ -294,6 +295,9 @@ const render = function(id, _txt, cb, container) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// logger.warn(cnf.themeVariables);
|
||||
|
||||
const stylis = new Stylis();
|
||||
const rules = stylis(`#${id}`, getStyles(graphType, userStyles, cnf.themeVariables));
|
||||
|
||||
@ -578,8 +582,8 @@ const mermaidAPI = Object.freeze({
|
||||
reset: () => {
|
||||
console.warn('reset');
|
||||
configApi.reset();
|
||||
const siteConfig = configApi.getSiteConfig();
|
||||
updateRendererConfigs(siteConfig);
|
||||
// const siteConfig = configApi.getSiteConfig();
|
||||
// updateRendererConfigs(siteConfig);
|
||||
},
|
||||
globalReset: () => {
|
||||
configApi.reset(configApi.defaultConfig);
|
||||
|
@ -56,6 +56,7 @@ class Theme {
|
||||
|
||||
this.nodeBkg = this.primaryColor;
|
||||
this.mainBkg = this.primaryColor;
|
||||
// console.warn('main bkg ', this.mainBkg);
|
||||
this.nodeBorder = this.primaryBorderColor;
|
||||
this.clusterBkg = this.tertiaryColor;
|
||||
this.clusterBorder = this.tertiaryBorderColor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user