inno-diagram
Version:
It was created to develop Inno Linc.
83 lines (70 loc) • 2.72 kB
JavaScript
const activityDiagram = require('../diagrams/activity-diagram.js');
const Viz = require("../../lib/viz-lite.js");
require('./svg-utils.js')();
const fs = require("fs");
module.exports = function()
{
//Json 파일을 파싱하여 얻은 텍스트를 가지고 Diagram을 그림
this.processJson = function(text, isDark)
{
var options = { dir: "TB", generate: true, dark: isDark};
var dot = null;
var svg = null;
if (text.length == 0)
return "";
dot = activityDiagram(text, options);
if (dot === null && svg === null)
return "Error: unable to parse the yUML file";
if (dot !== null)
{
try {
svg = Viz(buildDotHeader(isDark) + dot);
svg = processEmbeddedImages(svg, isDark);
}
catch (e) {
return "Error composing the diagram";
}
}
return svg;
}
this.processDirectives = function(line, options)
{
const directions = {
leftToRight: "LR",
rightToLeft: "RL",
topDown: "TB"
};
var keyvalue = /^\/\/\s+\{\s*([\w]+)\s*:\s*([\w]+)\s*\}$/.exec(line); // extracts directives as: // {key:value}
if (keyvalue != null && keyvalue.length == 3)
{
var key = keyvalue[1];
var value = keyvalue[2];
switch (key)
{
case "type":
if (/^(class|usecase|activity|state|deployment|package|sequence)$/.test(value))
options.type = value;
else {
options.error = "Error: invalid value for 'type'. Allowed values are: class, usecase, activity, state, deployment, package.";
return;
}
break;
case "direction":
if (/^(leftToRight|rightToLeft|topDown)$/.test(value))
options.dir = directions[value];
else {
options.error = "Error: invalid value for 'direction'. Allowed values are: leftToRight, rightToLeft, topDown <i>(default)</i>.";
return;
}
break;
case "generate":
if (/^(true|false)$/.test(value))
options.generate = (value === "true");
else {
options.error = "Error: invalid value for 'generate'. Allowed values are: true, false <i>(default)</i>.";
return;
}
}
}
}
}