mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-11 11:29:42 +02:00
Add different id generators
This commit is contained in:
@@ -119,6 +119,21 @@ const config = {
|
|||||||
*/
|
*/
|
||||||
secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'],
|
secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This option controls if the generated ids of nodes in the SVG are generated randomly or based on a seed.
|
||||||
|
* If set to false, the IDs are generated based on the current date and thus are not deterministic. This is the default behaviour.
|
||||||
|
*
|
||||||
|
*## Notes**: This matters if your files are checked into sourcecontrol e.g. git and should not change unless content is changed.
|
||||||
|
***Default value: false**
|
||||||
|
*/
|
||||||
|
deterministicIds: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This option is the optional seed for deterministic ids. if set to undefined but deterministicIds is true, a simple number iterator is used.
|
||||||
|
* You can set this attribute to base the seed on a static string.
|
||||||
|
*/
|
||||||
|
deterministicIDSeed: undefined,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object containing configurations specific for flowcharts
|
* The object containing configurations specific for flowcharts
|
||||||
*/
|
*/
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
// import { decode } from 'he';
|
// import { decode } from 'he';
|
||||||
import decode from 'entity-decode/browser';
|
import decode from 'entity-decode/browser';
|
||||||
import mermaidAPI from './mermaidAPI';
|
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
|
import mermaidAPI from './mermaidAPI';
|
||||||
import utils from './utils';
|
import utils from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +78,8 @@ const init = function() {
|
|||||||
mermaidAPI.updateSiteConfig({ gantt: mermaid.ganttConfig });
|
mermaidAPI.updateSiteConfig({ gantt: mermaid.ganttConfig });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nextId = utils.initIdGeneratior(conf.deterministicIds, conf.deterministicIDSeed);
|
||||||
|
|
||||||
let txt;
|
let txt;
|
||||||
|
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
@@ -90,7 +92,7 @@ const init = function() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = `mermaid-${Date.now()}`;
|
const id = `mermaid-${nextId()}`;
|
||||||
|
|
||||||
// Fetch the graph definition including tags
|
// Fetch the graph definition including tags
|
||||||
txt = element.innerHTML;
|
txt = element.innerHTML;
|
||||||
|
13
src/utils.js
13
src/utils.js
@@ -1,3 +1,4 @@
|
|||||||
|
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||||
import {
|
import {
|
||||||
curveBasis,
|
curveBasis,
|
||||||
curveBasisClosed,
|
curveBasisClosed,
|
||||||
@@ -12,9 +13,8 @@ import {
|
|||||||
curveStepBefore,
|
curveStepBefore,
|
||||||
select
|
select
|
||||||
} from 'd3';
|
} from 'd3';
|
||||||
import { logger } from './logger';
|
|
||||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
|
||||||
import common from './diagrams/common/common';
|
import common from './diagrams/common/common';
|
||||||
|
import { logger } from './logger';
|
||||||
// import cryptoRandomString from 'crypto-random-string';
|
// import cryptoRandomString from 'crypto-random-string';
|
||||||
|
|
||||||
// Effectively an enum of the supported curve types, accessible by name
|
// Effectively an enum of the supported curve types, accessible by name
|
||||||
@@ -790,6 +790,15 @@ export const configureSvgSize = function(svgElem, height, width, useMaxWidth) {
|
|||||||
d3Attrs(svgElem, attrs);
|
d3Attrs(svgElem, attrs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const initIdGeneratior = function(deterministic, seed) {
|
||||||
|
if (!deterministic) return () => Date.now();
|
||||||
|
const iterator = function() {
|
||||||
|
return this.count++;
|
||||||
|
};
|
||||||
|
iterator.seed = seed ? seed.length : 0;
|
||||||
|
return iterator;
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
assignWithDepth,
|
assignWithDepth,
|
||||||
wrapLabel,
|
wrapLabel,
|
||||||
|
Reference in New Issue
Block a user