Lint Fixes

This commit is contained in:
ashishj
2023-01-25 17:49:35 +01:00
parent df1e9c4117
commit 49ce5222c9
18 changed files with 188 additions and 144 deletions

View File

@@ -71,6 +71,20 @@
I am a big big big tasks I am a big big big tasks
I am not so big tasks I am not so big tasks
</pre> </pre>
<pre id="diagram" class="mermaid">
timeline
title MermaidChart 2023 Timeline
section 2023 Q1 &lt;br&gt; Release Personal Tier
Buttet 1 : sub-point 1a : sub-point 1b
: sub-point 1c
Bullet 2 : sub-point 2a : sub-point 2b
section 2023 Q2 <br> Release XYZ Tier
Buttet 3 : sub-point <br/> 3a : sub-point 3b
: sub-point 3c
Bullet 4 : sub-point 4a : sub-point 4b
</pre>
<pre id="diagram" class="mermaid2"> <pre id="diagram" class="mermaid2">
timeline timeline
title England's History Timeline title England's History Timeline
@@ -96,7 +110,7 @@
2008s : Instagram 2008s : Instagram
2010 : Pinterest 2010 : Pinterest
</pre> </pre>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid2">
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'themeVariables': { %%{init: { 'logLevel': 'debug', 'theme': 'base', 'themeVariables': {
'cScale0': '#ff0000', 'cScale0': '#ff0000',
'cScale1': '#00ff00', 'cScale1': '#00ff00',
@@ -113,7 +127,7 @@
2010 : Pinterest 2010 : Pinterest
</pre> </pre>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid2">
%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': { %%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': {
'cScale0': '#ff0000', 'cScale0': '#ff0000',
'cScale1': '#00ff00', 'cScale1': '#00ff00',
@@ -173,11 +187,11 @@ mindmap
<!-- <script src="./mermaid-example-diagram-detector.js"></script> --> <!-- <script src="./mermaid-example-diagram-detector.js"></script> -->
<!-- <script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script> --> <!-- <script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script> -->
<script type="module"> <script type="module">
import mindmap from '../../packages/mermaid-mindmap/src/detector'; //import mindmap from '../../packages/mermaid-mindmap/src/detector';
// import example from '../../packages/mermaid-example-diagram/src/detector'; // import example from '../../packages/mermaid-example-diagram/src/detector';
import timeline from '../../packages/mermaid-timeline/src/detector'; import timeline from '../../packages/mermaid-timeline/src/detector';
import mermaid from '../../packages/mermaid/src/mermaid'; import mermaid from '../../packages/mermaid/src/mermaid';
await mermaid.registerExternalDiagrams([mindmap, timeline]); await mermaid.registerExternalDiagrams([timeline]);
mermaid.parseError = function (err, hash) { mermaid.parseError = function (err, hash) {
// console.error('Mermaid error: ', err); // console.error('Mermaid error: ', err);
}; };
@@ -187,7 +201,7 @@ mindmap
logLevel: 0, logLevel: 0,
flowchart: { flowchart: {
useMaxWidth: false, useMaxWidth: false,
htmlLabels: true, htmlLabels: false,
}, },
gantt: { gantt: {
useMaxWidth: false, useMaxWidth: false,
@@ -195,7 +209,7 @@ mindmap
timeline: { timeline: {
disableMulticolor: false, disableMulticolor: false,
}, },
useMaxWidth: false, useMaxWidth: true,
lazyLoadedDiagrams: [ lazyLoadedDiagrams: [
// './mermaid-mindmap-detector.esm.mjs', // './mermaid-mindmap-detector.esm.mjs',
// './mermaid-example-diagram-detector.esm.mjs', // './mermaid-example-diagram-detector.esm.mjs',

View File

@@ -42,7 +42,7 @@ export let setupGraphViewbox: (
* @param _getConfig - getConfig from mermaid/src/diagramAPI.ts * @param _getConfig - getConfig from mermaid/src/diagramAPI.ts
* @param _sanitizeText - sanitizeText from mermaid/src/diagramAPI.ts * @param _sanitizeText - sanitizeText from mermaid/src/diagramAPI.ts
* @param _setupGraphViewbox - setupGraphViewbox from mermaid/src/diagramAPI.ts * @param _setupGraphViewbox - setupGraphViewbox from mermaid/src/diagramAPI.ts
* @param _commonDb * @param _commonDb -`commonDb` from mermaid/src/diagramAPI.ts
*/ */
export const injectUtils = ( export const injectUtils = (
_log: Record<keyof typeof LEVELS, typeof console.log>, _log: Record<keyof typeof LEVELS, typeof console.log>,
@@ -64,5 +64,4 @@ export const injectUtils = (
sanitizeText = _sanitizeText; sanitizeText = _sanitizeText;
setupGraphViewbox = _setupGraphViewbox; setupGraphViewbox = _setupGraphViewbox;
commonDb = _commonDb; commonDb = _commonDb;
}; };

View File

@@ -11,7 +11,7 @@ cytoscape.use(coseBilkent);
/** /**
* @param {any} svg The svg element to draw the diagram onto * @param {any} svg The svg element to draw the diagram onto
* @param {object} mindmap The maindmap data and hierarchy * @param {object} mindmap The mindmap data and hierarchy
* @param section * @param section
* @param {object} conf The configuration object * @param {object} conf The configuration object
*/ */
@@ -110,7 +110,7 @@ function layoutMindmap(node, conf) {
renderEl.remove(); renderEl.remove();
addNodes(node, cy, conf, 0); addNodes(node, cy, conf, 0);
// Make cytoscape care about the dimensisions of the nodes // Make cytoscape care about the dimensions of the nodes
cy.nodes().forEach(function (n) { cy.nodes().forEach(function (n) {
n.layoutDimensions = () => { n.layoutDimensions = () => {
const data = n.data(); const data = n.data();
@@ -173,7 +173,7 @@ export const draw = async (text, id, version, diagObj) => {
log.debug('Renering info diagram\n' + text); log.debug('Renering info diagram\n' + text);
const securityLevel = getConfig().securityLevel; const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sanbox mode // Handle root and Document for when rendering in sandbox mode
let sandboxElement; let sandboxElement;
if (securityLevel === 'sandbox') { if (securityLevel === 'sandbox') {
sandboxElement = select('#i' + id); sandboxElement = select('#i' + id);

View File

@@ -26,7 +26,7 @@ export let sanitizeText: (str: string) => string;
export const getCommonDb = () => localCommonDb; export const getCommonDb = () => localCommonDb;
export let parseDirective = (p: any, statement: string, context: string, type: string) => { export let parseDirective = (p: any, statement: string, context: string, type: string) => {
return; return;
} };
/** /**
* Placeholder for the real function that will be injected by mermaid. * Placeholder for the real function that will be injected by mermaid.
*/ */
@@ -38,8 +38,6 @@ export let setupGraphViewbox: (
useMaxWidth: boolean useMaxWidth: boolean
) => void; ) => void;
/** /**
* Function called by mermaid that injects utility functions that help the diagram to be a good citizen. * Function called by mermaid that injects utility functions that help the diagram to be a good citizen.
* @param _log - The log function to use * @param _log - The log function to use
@@ -71,5 +69,4 @@ export const injectUtils = (
setupGraphViewbox = _setupGraphViewbox; setupGraphViewbox = _setupGraphViewbox;
localCommonDb = _commonDb; localCommonDb = _commonDb;
parseDirective = _parseDirective; parseDirective = _parseDirective;
}; };

View File

@@ -12,7 +12,7 @@ export const drawRect = function (elem, rectData) {
rectElem.attr('rx', rectData.rx); rectElem.attr('rx', rectData.rx);
rectElem.attr('ry', rectData.ry); rectElem.attr('ry', rectData.ry);
if (typeof rectData.class !== 'undefined') { if (rectData.class !== undefined) {
rectElem.attr('class', rectData.class); rectElem.attr('class', rectData.class);
} }
@@ -117,11 +117,11 @@ export const drawCircle = function (element, circleData) {
circleElement.attr('stroke', circleData.stroke); circleElement.attr('stroke', circleData.stroke);
circleElement.attr('r', circleData.r); circleElement.attr('r', circleData.r);
if (typeof circleElement.class !== 'undefined') { if (circleElement.class !== undefined) {
circleElement.attr('class', circleElement.class); circleElement.attr('class', circleElement.class);
} }
if (typeof circleData.title !== 'undefined') { if (circleData.title !== undefined) {
circleElement.append('title').text(circleData.title); circleElement.append('title').text(circleData.title);
} }
@@ -139,7 +139,7 @@ export const drawText = function (elem, textData) {
textElem.style('text-anchor', textData.anchor); textElem.style('text-anchor', textData.anchor);
if (typeof textData.class !== 'undefined') { if (textData.class !== undefined) {
textElem.attr('class', textData.class); textElem.attr('class', textData.class);
} }
@@ -517,9 +517,7 @@ export const drawNode = function (elem, node, fullSection, conf) {
node.section = section; node.section = section;
nodeElem.attr( nodeElem.attr(
'class', 'class',
(node.class ? node.class + ' ' : '') + (node.class ? node.class + ' ' : '') + 'timeline-node ' + ('section-' + section)
'timeline-node ' +
('section-' + section)
); );
const bkgElem = nodeElem.append('g'); const bkgElem = nodeElem.append('g');
@@ -535,7 +533,8 @@ export const drawNode = function (elem, node, fullSection, conf) {
.attr('text-anchor', 'middle') .attr('text-anchor', 'middle')
.call(wrap, node.width); .call(wrap, node.width);
const bbox = txt.node().getBBox(); const bbox = txt.node().getBBox();
const fontSize = conf.fontSize && conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize; const fontSize =
conf.fontSize && conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize;
node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding; node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding;
node.height = Math.max(node.height, node.maxHeight); node.height = Math.max(node.height, node.maxHeight);
node.width = node.width + 2 * node.padding; node.width = node.width + 2 * node.padding;
@@ -545,7 +544,6 @@ export const drawNode = function (elem, node, fullSection, conf) {
// Create the background element // Create the background element
defaultBkg(bkgElem, node, section, conf); defaultBkg(bkgElem, node, section, conf);
return node; return node;
}; };
@@ -560,12 +558,12 @@ export const drawNode = function (elem, node, fullSection, conf) {
.attr('text-anchor', 'middle') .attr('text-anchor', 'middle')
.call(wrap, node.width); .call(wrap, node.width);
const bbox = txt.node().getBBox(); const bbox = txt.node().getBBox();
const fontSize = conf.fontSize && conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize; const fontSize =
conf.fontSize && conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize;
textElem.remove(); textElem.remove();
return bbox.height + fontSize * 1.1 * 0.5 + node.padding; return bbox.height + fontSize * 1.1 * 0.5 + node.padding;
}; };
const defaultBkg = function (elem, node, section) { const defaultBkg = function (elem, node, section) {
const rd = 5; const rd = 5;
elem elem

View File

@@ -1,4 +1,8 @@
import { getCommonDb as _getCommonDb, parseDirective as _parseDirective ,log } from './mermaidUtils'; import {
getCommonDb as _getCommonDb,
parseDirective as _parseDirective,
log,
} from './mermaidUtils';
let currentSection = ''; let currentSection = '';
let currentTaskId = 0; let currentTaskId = 0;
@@ -45,7 +49,6 @@ export const getTasks = function () {
}; };
export const addTask = function (period, length, event) { export const addTask = function (period, length, event) {
const rawTask = { const rawTask = {
id: currentTaskId++, id: currentTaskId++,
section: currentSection, section: currentSection,
@@ -65,7 +68,6 @@ export const addEvent = function (event) {
currentTask.events.push(event); currentTask.events.push(event);
}; };
export const addTaskOrg = function (descr) { export const addTaskOrg = function (descr) {
const newTask = { const newTask = {
section: currentSection, section: currentSection,
@@ -100,6 +102,5 @@ export default {
addTask, addTask,
addTaskOrg, addTaskOrg,
addEvent, addEvent,
parseDirective parseDirective,
}; };

View File

@@ -86,7 +86,6 @@ export const draw = function (text, id, version, diagObj) {
//calculate max task height //calculate max task height
// for loop till tasks.length // for loop till tasks.length
for (const [i, task] of tasks.entries()) { for (const [i, task] of tasks.entries()) {
const taskNode = { const taskNode = {
number: i, number: i,
descr: task, descr: task,
@@ -116,16 +115,13 @@ export const draw = function (text, id, version, diagObj) {
maxEventLineLengthTemp += svgDraw.getVirtualNodeHeight(svg, eventNode, conf); maxEventLineLengthTemp += svgDraw.getVirtualNodeHeight(svg, eventNode, conf);
} }
maxEventLineLength = Math.max(maxEventLineLength, maxEventLineLengthTemp); maxEventLineLength = Math.max(maxEventLineLength, maxEventLineLengthTemp);
} }
log.debug('maxSectionHeight before draw', maxSectionHeight); log.debug('maxSectionHeight before draw', maxSectionHeight);
log.debug('maxTaskHeight before draw', maxTaskHeight); log.debug('maxTaskHeight before draw', maxTaskHeight);
if (sections && sections.length > 0) { if (sections && sections.length > 0) {
sections.forEach((section) => { sections.forEach((section) => {
const sectionNode = { const sectionNode = {
number: sectionNumber, number: sectionNumber,
descr: section, descr: section,
@@ -139,22 +135,27 @@ export const draw = function (text, id, version, diagObj) {
const node = svgDraw.drawNode(sectionNodeWrapper, sectionNode, sectionNumber, conf); const node = svgDraw.drawNode(sectionNodeWrapper, sectionNode, sectionNumber, conf);
log.debug('sectionNode output', node); log.debug('sectionNode output', node);
sectionNodeWrapper.attr( sectionNodeWrapper.attr('transform', `translate(${masterX}, ${sectionBeginY})`);
'transform',
`translate(${masterX}, ${sectionBeginY})`
);
masterY += maxSectionHeight + 50; masterY += maxSectionHeight + 50;
//draw tasks for this section //draw tasks for this section
//filter task where tasks.section == section //filter task where tasks.section == section
const tasksForSection = tasks.filter((task) => task.section === section); const tasksForSection = tasks.filter((task) => task.section === section);
if (tasksForSection.length > 0) { if (tasksForSection.length > 0) {
drawTasks(
svg,
drawTasks(svg, tasksForSection, sectionNumber, masterX, masterY, maxTaskHeight, conf, maxEventCount,maxEventLineLength,maxSectionHeight,false); tasksForSection,
sectionNumber,
masterX,
masterY,
maxTaskHeight,
conf,
maxEventCount,
maxEventLineLength,
maxSectionHeight,
false
);
} }
// todo replace with total width of section and its tasks // todo replace with total width of section and its tasks
masterX += 200 * Math.max(tasksForSection.length, 1); masterX += 200 * Math.max(tasksForSection.length, 1);
@@ -165,7 +166,19 @@ export const draw = function (text, id, version, diagObj) {
} else { } else {
//draw tasks //draw tasks
hasSections = false; hasSections = false;
drawTasks(svg, tasks, sectionNumber, masterX, masterY, maxTaskHeight, conf, maxEventCount,maxEventLineLength,maxSectionHeight,true); drawTasks(
svg,
tasks,
sectionNumber,
masterX,
masterY,
maxTaskHeight,
conf,
maxEventCount,
maxEventLineLength,
maxSectionHeight,
true
);
} }
// Get BBox of the diagram // Get BBox of the diagram
@@ -176,7 +189,7 @@ export const draw = function (text, id, version, diagObj) {
svg svg
.append('text') .append('text')
.text(title) .text(title)
.attr('x', (box.width/2)-LEFT_MARGIN) .attr('x', box.width / 2 - LEFT_MARGIN)
.attr('font-size', '4ex') .attr('font-size', '4ex')
.attr('font-weight', 'bold') .attr('font-weight', 'bold')
.attr('y', 20); .attr('y', 20);
@@ -190,20 +203,36 @@ export const draw = function (text, id, version, diagObj) {
.append('line') .append('line')
.attr('x1', LEFT_MARGIN) .attr('x1', LEFT_MARGIN)
.attr('y1', depthY) // One section head + one task + margins .attr('y1', depthY) // One section head + one task + margins
.attr('x2', (box.width)+3*LEFT_MARGIN) // Subtract stroke width so arrow point is retained .attr('x2', box.width + 3 * LEFT_MARGIN) // Subtract stroke width so arrow point is retained
.attr('y2', depthY) .attr('y2', depthY)
.attr('stroke-width', 4) .attr('stroke-width', 4)
.attr('stroke', 'black') .attr('stroke', 'black')
.attr('marker-end', 'url(#arrowhead)'); .attr('marker-end', 'url(#arrowhead)');
// Setup the view box and size of the svg element // Setup the view box and size of the svg element
setupGraphViewbox(undefined, svg, conf.timeline.padding?conf.timeline.padding:50, conf.timeline.useMaxWidth?conf.timeline.useMaxWidth:false); setupGraphViewbox(
undefined,
svg,
conf.timeline.padding ? conf.timeline.padding : 50,
conf.timeline.useMaxWidth ? conf.timeline.useMaxWidth : false
);
// addSVGAccessibilityFields(diagObj.db, diagram, id); // addSVGAccessibilityFields(diagObj.db, diagram, id);
}; };
export const drawTasks = function (
export const drawTasks = function (diagram, tasks, sectionColor, masterX, masterY, maxTaskHeight,conf,maxEventCount,maxEventLineLength,maxSectionHeight, isWithoutSections) { diagram,
tasks,
sectionColor,
masterX,
masterY,
maxTaskHeight,
conf,
maxEventCount,
maxEventLineLength,
maxSectionHeight,
isWithoutSections
) {
// Draw the tasks // Draw the tasks
for (const task of tasks) { for (const task of tasks) {
// create node from task // create node from task
@@ -223,16 +252,11 @@ export const drawTasks = function (diagram, tasks, sectionColor, masterX, master
const taskHeight = node.height; const taskHeight = node.height;
//log task height //log task height
log.debug('taskHeight after draw', taskHeight); log.debug('taskHeight after draw', taskHeight);
taskWrapper.attr( taskWrapper.attr('transform', `translate(${masterX}, ${masterY})`);
'transform',
`translate(${masterX}, ${masterY})`
);
// update max task height // update max task height
maxTaskHeight = Math.max(maxTaskHeight, taskHeight); maxTaskHeight = Math.max(maxTaskHeight, taskHeight);
// if task has events, draw them // if task has events, draw them
if (task.events) { if (task.events) {
// draw a line between the task and the events // draw a line between the task and the events
@@ -240,7 +264,8 @@ export const drawTasks = function (diagram, tasks, sectionColor, masterX, master
let linelength = maxTaskHeight; let linelength = maxTaskHeight;
//add margin to task //add margin to task
masterY += 100; masterY += 100;
linelength = linelength+ drawEvents(diagram, task.events, sectionColor, masterX, masterY, conf); linelength =
linelength + drawEvents(diagram, task.events, sectionColor, masterX, masterY, conf);
masterY -= 100; masterY -= 100;
lineWrapper lineWrapper
@@ -248,31 +273,34 @@ export const drawTasks = function (diagram, tasks, sectionColor, masterX, master
.attr('x1', masterX + 190 / 2) .attr('x1', masterX + 190 / 2)
.attr('y1', masterY + maxTaskHeight) // One section head + one task + margins .attr('y1', masterY + maxTaskHeight) // One section head + one task + margins
.attr('x2', masterX + 190 / 2) // Subtract stroke width so arrow point is retained .attr('x2', masterX + 190 / 2) // Subtract stroke width so arrow point is retained
.attr('y2', masterY + maxTaskHeight + (isWithoutSections?maxTaskHeight:maxSectionHeight) + maxEventLineLength+ 120) .attr(
'y2',
masterY +
maxTaskHeight +
(isWithoutSections ? maxTaskHeight : maxSectionHeight) +
maxEventLineLength +
120
)
.attr('stroke-width', 2) .attr('stroke-width', 2)
.attr('stroke', 'black') .attr('stroke', 'black')
.attr('marker-end', 'url(#arrowhead)') .attr('marker-end', 'url(#arrowhead)')
.attr('stroke-dasharray', "5,5"); .attr('stroke-dasharray', '5,5');
} }
masterX = masterX + 200; masterX = masterX + 200;
if (isWithoutSections && !getConfig().timeline.disableMulticolor) { if (isWithoutSections && !getConfig().timeline.disableMulticolor) {
sectionColor++; sectionColor++;
} }
} }
// reset Y coordinate for next section // reset Y coordinate for next section
masterY= masterY -10; ; masterY = masterY - 10;
}; };
export const drawEvents = function (diagram, events, sectionColor, masterX, masterY, conf) { export const drawEvents = function (diagram, events, sectionColor, masterX, masterY, conf) {
let maxEventHeight = 0; let maxEventHeight = 0;
const eventBeginY = masterY; const eventBeginY = masterY;
masterY = masterY + 100 masterY = masterY + 100;
// Draw the events // Draw the events
for (const event of events) { for (const event of events) {
// create node from event // create node from event
@@ -289,20 +317,15 @@ export const drawEvents = function (diagram, events, sectionColor, masterX, mast
log.debug('eventNode', eventNode); log.debug('eventNode', eventNode);
// create event wrapper // create event wrapper
const eventWrapper = diagram.append('g').attr('class', 'eventWrapper'); const eventWrapper = diagram.append('g').attr('class', 'eventWrapper');
const node = svgDraw.drawNode(eventWrapper, eventNode, sectionColor, conf) const node = svgDraw.drawNode(eventWrapper, eventNode, sectionColor, conf);
const eventHeight = node.height; const eventHeight = node.height;
maxEventHeight = maxEventHeight + eventHeight; maxEventHeight = maxEventHeight + eventHeight;
eventWrapper.attr( eventWrapper.attr('transform', `translate(${masterX}, ${masterY})`);
'transform',
`translate(${masterX}, ${masterY})`
);
masterY = masterY + 10 + eventHeight; masterY = masterY + 10 + eventHeight;
} }
// set masterY back to eventBeginY // set masterY back to eventBeginY
masterY = eventBeginY; masterY = eventBeginY;
return maxEventHeight; return maxEventHeight;
}; };
export default { export default {

View File

@@ -985,8 +985,6 @@ const config: Partial<MermaidConfig> = {
*/ */
useMaxWidth: true, useMaxWidth: true,
/** /**
* | Parameter | Description | Type | Required | Values | * | Parameter | Description | Type | Required | Values |
* | ----------- | --------------------------------- | ---- | -------- | ----------- | * | ----------- | --------------------------------- | ---- | -------- | ----------- |

View File

@@ -8,7 +8,6 @@ import { DiagramDefinition, DiagramDetector } from './types';
import * as _commonDb from '../commonDb'; import * as _commonDb from '../commonDb';
import { parseDirective as _parseDirective } from '../directiveUtils'; import { parseDirective as _parseDirective } from '../directiveUtils';
/* /*
Packaging and exposing resources for external diagrams so that they can import Packaging and exposing resources for external diagrams so that they can import
diagramAPI and have access to select parts of mermaid common code required to diagramAPI and have access to select parts of mermaid common code required to
@@ -19,8 +18,11 @@ export const setLogLevel = _setLogLevel;
export const getConfig = _getConfig; export const getConfig = _getConfig;
export const sanitizeText = (text: string) => _sanitizeText(text, getConfig()); export const sanitizeText = (text: string) => _sanitizeText(text, getConfig());
export const setupGraphViewbox = _setupGraphViewbox; export const setupGraphViewbox = _setupGraphViewbox;
export const getCommonDb = () => { return _commonDb }; export const getCommonDb = () => {
export const parseDirective = (p: any, statement: string, context: string, type: string)=>_parseDirective(p, statement, context, type); return _commonDb;
};
export const parseDirective = (p: any, statement: string, context: string, type: string) =>
_parseDirective(p, statement, context, type);
const diagrams: Record<string, DiagramDefinition> = {}; const diagrams: Record<string, DiagramDefinition> = {};
export interface Detectors { export interface Detectors {
@@ -51,7 +53,15 @@ export const registerDiagram = (
addStylesForDiagram(id, diagram.styles); addStylesForDiagram(id, diagram.styles);
if (diagram.injectUtils) { if (diagram.injectUtils) {
diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox,getCommonDb(),parseDirective); diagram.injectUtils(
log,
setLogLevel,
getConfig,
sanitizeText,
setupGraphViewbox,
getCommonDb(),
parseDirective
);
} }
}; };

View File

@@ -33,7 +33,7 @@ export interface DiagramDefinition {
_sanitizeText: InjectUtils['_sanitizeText'], _sanitizeText: InjectUtils['_sanitizeText'],
_setupGraphViewbox: InjectUtils['_setupGraphViewbox'], _setupGraphViewbox: InjectUtils['_setupGraphViewbox'],
_commonDb: InjectUtils['_commonDb'], _commonDb: InjectUtils['_commonDb'],
_parseDirective: InjectUtils['_parseDirective'], _parseDirective: InjectUtils['_parseDirective']
) => void; ) => void;
} }

View File

@@ -1,5 +1,3 @@
import * as configApi from './config'; import * as configApi from './config';
import { log } from './logger'; import { log } from './logger';
@@ -7,7 +5,12 @@ import { directiveSanitizer } from './utils';
let currentDirective: { type?: string; args?: any } | undefined = {}; let currentDirective: { type?: string; args?: any } | undefined = {};
export const parseDirective = function (p: any, statement: string, context: string, type: string): void { export const parseDirective = function (
p: any,
statement: string,
context: string,
type: string
): void {
log.debug('parseDirective is being called', statement, context, type); log.debug('parseDirective is being called', statement, context, type);
try { try {
if (statement !== undefined) { if (statement !== undefined) {

View File

@@ -15,7 +15,6 @@ timeline
2006 : Twitter 2006 : Twitter
``` ```
## Syntax ## Syntax
The syntax for creating Timeline diagram is simple. You always start with the `timeline` keyword to let mermaid know that you want to create a timeline diagram. The syntax for creating Timeline diagram is simple. You always start with the `timeline` keyword to let mermaid know that you want to create a timeline diagram.
@@ -24,15 +23,18 @@ After that there is a possibility to add a title to the timeline. This is done b
Then you add the timeline data, where you always start with a time period, followed by a colon and then the text for the event. Optionally you can add a second colon and then the text for the event. So, you can have one or more events per time period. Then you add the timeline data, where you always start with a time period, followed by a colon and then the text for the event. Optionally you can add a second colon and then the text for the event. So, you can have one or more events per time period.
```json ```json
{time period} : {event} {time period} : {event}
``` ```
or or
```json ```json
{time period} : {event} : {event} {time period} : {event} : {event}
``` ```
or or
```json ```json
{time period} : {event} {time period} : {event}
: {event} : {event}
@@ -41,7 +43,6 @@ or
NOTE: Both time period and event are simple text, and not limited to numbers. NOTE: Both time period and event are simple text, and not limited to numbers.
Let us look at the syntax for the example above. Let us look at the syntax for the example above.
```mermaid-example ```mermaid-example
@@ -59,6 +60,7 @@ The sequence of time period and events is important, as it will be used to draw
Similarly, the first event will be placed at the top for that specific time period, and the last event will be placed at the bottom. Similarly, the first event will be placed at the top for that specific time period, and the last event will be placed at the bottom.
## Grouping of time periods in sections/ages ## Grouping of time periods in sections/ages
You can group time periods in sections/ages. This is done by adding a line with the keyword `section` followed by the section name. You can group time periods in sections/ages. This is done by adding a line with the keyword `section` followed by the section name.
All subsequent time periods will be placed in this section until a new section is defined. All subsequent time periods will be placed in this section until a new section is defined.
@@ -78,12 +80,13 @@ timeline
Industry 4.0 : Internet, Robotics, Internet of Things Industry 4.0 : Internet, Robotics, Internet of Things
Industry 5.0 : Artificial intelligence, Big data,3D printing Industry 5.0 : Artificial intelligence, Big data,3D printing
``` ```
As you can see, the time periods are placed in the sections, and the sections are placed in the order they are defined. As you can see, the time periods are placed in the sections, and the sections are placed in the order they are defined.
All time periods and events under a given section follow a similar color scheme. This is done to make it easier to see the relationship between time periods and events. All time periods and events under a given section follow a similar color scheme. This is done to make it easier to see the relationship between time periods and events.
## Wrapping of text for long time-periods or events ## Wrapping of text for long time-periods or events
By default, the text for time-periods and events will be wrapped if it is too long. This is done to avoid that the text is drawn outside the diagram. By default, the text for time-periods and events will be wrapped if it is too long. This is done to avoid that the text is drawn outside the diagram.
You can also use `<br>` to force a line break. You can also use `<br>` to force a line break.
@@ -120,6 +123,7 @@ However, if there is no section defined, then we have two possibilities:
2006 : Twitter 2006 : Twitter
``` ```
Note that this is no, section defined, and each time period and its corresponding events will have its own color scheme. Note that this is no, section defined, and each time period and its corresponding events will have its own color scheme.
2. Disable the multiColor option using the `disableMultiColor` option. This will make all time periods and events follow the same color scheme. 2. Disable the multiColor option using the `disableMultiColor` option. This will make all time periods and events follow the same color scheme.
@@ -139,6 +143,7 @@ mermaid.initialize({
``` ```
let us look at same example, where we have disabled the multiColor option. let us look at same example, where we have disabled the multiColor option.
```mermaid-example ```mermaid-example
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'timeline': {'disableMulticolor': true}}}%% %%{init: { 'logLevel': 'debug', 'theme': 'base', 'timeline': {'disableMulticolor': true}}}%%
timeline timeline
@@ -149,6 +154,7 @@ let us look at same example, where we have disabled the multiColor option.
2006 : Twitter 2006 : Twitter
``` ```
### Customizing Color scheme ### Customizing Color scheme
You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on. You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on.
@@ -180,8 +186,8 @@ Now let's override the default values for the `cScale0` to `cScale2` variables:
See how the colors are changed to the values specified in the theme variables. See how the colors are changed to the values specified in the theme variables.
## Themes ## Themes
Mermaid supports a bunch of pre-defined themes which you can use to find the right one for you. PS: you can actually override an existing theme's variable to get your own custom theme going. Learn more about theming your diagram [here](../config/theming.md). Mermaid supports a bunch of pre-defined themes which you can use to find the right one for you. PS: you can actually override an existing theme's variable to get your own custom theme going. Learn more about theming your diagram [here](../config/theming.md).
The following are the different pre-defined theme options: The following are the different pre-defined theme options:
@@ -270,10 +276,6 @@ Let's put them to use, and see how our sample diagram looks in different themes:
2010 : Pinterest 2010 : Pinterest
``` ```
## Integrating with your library/website. ## Integrating with your library/website.
Timeline uses the experimental lazy loading & async rendering features which could change in the future. Timeline uses the experimental lazy loading & async rendering features which could change in the future.

View File

@@ -779,7 +779,6 @@ const renderAsync = async function (
return svgCode; return svgCode;
}; };
/** /**
* @param options - Initial Mermaid options * @param options - Initial Mermaid options
*/ */