From 46d0a3afc86425edb37e00fe344aa1afbd8d07f0 Mon Sep 17 00:00:00 2001 From: knsv Date: Sat, 24 Oct 2015 09:07:18 +0200 Subject: [PATCH] Highlighted the editor in the nav --- index.html | 19 +++--- javascripts/lib/mermaid.js | 131 ++++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 34e06b5b84..3ea6b8bea0 100644 --- a/index.html +++ b/index.html @@ -132,19 +132,20 @@

An example of a flowchart

Future task in critical line :crit, 5d Create tests for renderer :2d Add to mermaid :1d

Play with mermaid using this editor or this live editor.

-

Further reading

-

Credits

Many thanks to the d3 and dagre-d3 projects for providing
the graphical layout and drawing libraries! Thanks also to the
js-sequence-diagram project for usage of the grammar for the
sequence diagrams.

Mermaid was created by Knut Sveidqvist for easier documentation.

Knut has not done all work by himself, here is the full list of the projects contributors.

+

Online live editor

+

An editor is available for creating diagrams. With it you can quickly start writing mermaid diagrams. It is possible to:

+

Usage

Installation

diff --git a/javascripts/lib/mermaid.js b/javascripts/lib/mermaid.js index d905055ca4..7bf41870d8 100644 --- a/javascripts/lib/mermaid.js +++ b/javascripts/lib/mermaid.js @@ -30976,7 +30976,7 @@ module.exports = '1.0.7'; },{}],86:[function(require,module,exports){ module.exports={ "name": "mermaid", - "version": "0.5.4", + "version": "0.5.5", "description": "Markdownish syntax for generating flowcharts, sequence diagrams and gantt charts.", "main": "src/mermaid.js", "keywords": [ @@ -35112,6 +35112,7 @@ exports.findTaskById = function (id) { }; exports.getTasks = function () { + //compileTasks(); var i; for (i = 10000; i < tasks.length; i++) { tasks[i].startTime = moment(tasks[i].startTime).format(dateFormat); @@ -35122,6 +35123,7 @@ exports.getTasks = function () { }; var getStartDate = function getStartDate(prevTime, dateFormat, str) { + //console.log('Deciding start date:'+JSON.stringify(str)); //log.debug('Deciding start date:'+str); //log.debug('with dateformat:'+dateFormat); @@ -35130,12 +35132,15 @@ var getStartDate = function getStartDate(prevTime, dateFormat, str) { // Test for after var re = /^after\s+([\d\w\-]+)/; var afterStatement = re.exec(str.trim()); + if (afterStatement !== null) { var task = exports.findTaskById(afterStatement[1]); + //console.log('xxx'+JSON.stringify(task)); if (typeof task === 'undefined') { var dt = new Date(); dt.setHours(0, 0, 0, 0); return dt; + //return undefined; } return task.endTime; } @@ -35272,7 +35277,95 @@ var compileData = function compileData(prevTask, dataStr) { return task; }; +var parseData = function parseData(dataStr) { + var ds; + + if (dataStr.substr(0, 1) === ':') { + ds = dataStr.substr(1, dataStr.length); + } else { + ds = dataStr; + } + + var data = ds.split(','); + + var task = {}; + var df = exports.getDateFormat(); + + // Get tags like active, done cand crit + var matchFound = true; + while (matchFound) { + matchFound = false; + if (data[0].match(/^\s*active\s*$/)) { + task.active = true; + data.shift(1); + matchFound = true; + } + if (data[0].match(/^\s*done\s*$/)) { + task.done = true; + data.shift(1); + matchFound = true; + } + if (data[0].match(/^\s*crit\s*$/)) { + task.crit = true; + data.shift(1); + matchFound = true; + } + } + var i; + for (i = 0; i < data.length; i++) { + data[i] = data[i].trim(); + } + + switch (data.length) { + case 1: + task.id = parseId(); + task.startTime = { type: 'prevTaskEnd' }; + task.endTime = { data: data[0] }; + break; + case 2: + task.id = parseId(); + task.startTime = { type: 'getStartDate', startData: data[0] }; + task.endTime = { data: data[1] }; + break; + case 3: + task.id = parseId(data[0]); + task.startTime = { type: 'getStartDate', startData: data[1] }; + task.endTime = { data: data[2] }; + break; + default: + + } + + return task; +}; + var lastTask; +var lastTaskID; +var rawTasks = []; +var taskDb = {}; +exports.addTaskNew = function (descr, data) { + var rawTask = { + section: currentSection, + type: currentSection, + description: descr, + processed: false, + raw: { data: data } + }; + var taskInfo = parseData(data); + rawTask.raw.startTime = taskInfo.startTime; + rawTask.raw.endTime = taskInfo.endTime; + rawTask.id = taskInfo.id; + rawTask.prevTaskId = lastTaskID; + rawTask.active = taskInfo.active; + rawTask.done = taskInfo.done; + rawTask.crit = taskInfo.crit; + var pos = rawTasks.push(rawTask); + + lastTaskID = rawTask.id; + // Store cross ref + taskDb[rawTask.id] = pos; +}; + exports.addTask = function (descr, data) { var newTask = { @@ -35292,6 +35385,40 @@ exports.addTask = function (descr, data) { tasks.push(newTask); }; +var compileTasks = function compileTasks() { + console.log('Compiling tasks' + rawTasks.length); + + var df = exports.getDateFormat(); + + var compileTask = function compileTask(pos) { + var task = rawTasks[pos]; + var startTime = ''; + switch (rawTasks[pos].raw.startTime.type) { + case 'prevTaskEnd': + rawTasks[pos].startTime = rawTasks[taskDb[pos].prevTaskId].endTime; + break; + case 'getStartDate': + var startTime = getStartDate(undefined, df, rawTasks[pos].raw.startTime.startData); + if (startTime) { + rawTasks[pos].startTime = startTime; + } + break; + } + + if (rawTasks[pos].startTime) { + rawTasks[pos].endTime = getEndDate(rawTasks[pos].startTime, df, rawTasks[pos].raw.endTime.data); + } + }; + + var i; + for (i = 0; i < rawTasks.length; i++) { + console.log('Pre ompiling: ' + JSON.stringify(rawTasks[i])); + compileTask(i); + //console.log('Compiling: '+rawTasks[taskDb[i]].id); + console.log('Compiling: ' + JSON.stringify(rawTasks[i], null, 2)); + } +}; + exports.parseError = function (err, hash) { global.mermaidAPI.parseError(err, hash); }; @@ -37502,7 +37629,7 @@ var drawMessage = function drawMessage(elem, startx, stopx, verticalPos, msg) { line.attr('stroke', 'black'); line.style('fill', 'none'); // remove any fill colour if (msg.type === sq.yy.LINETYPE.SOLID || msg.type === sq.yy.LINETYPE.DOTTED) { - line.attr('marker-end', 'url(' + url + '#crosshead)'); + line.attr('marker-end', 'url(' + url + '#arrowhead)'); } if (msg.type === sq.yy.LINETYPE.SOLID_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_CROSS) {