Improved class styling for nodes

Added unit testing
classDefs are now exported to the common style of the SVG
Styling is no longer copied from other mermaid SVGs on the same webpage
This commit is contained in:
Björn Weström
2014-12-14 22:15:47 +01:00
parent 6ef6d79b48
commit f656269a50
10 changed files with 539 additions and 125 deletions

View File

@@ -37,7 +37,7 @@ exports.addVertices = function (vert, g) {
* @type {string}
*/
var classStr = '';
if(vertice.classes.length >0){
classStr = vertice.classes.join(" ");
}
@@ -138,11 +138,34 @@ exports.addEdges = function (edges, g) {
};
/**
* Returns the default style for nodes.
* @returns {string} Default style for nodes
* Returns the all the styles from classDef statements in the graph definition.
* @returns {object} classDef styles
*/
exports.defaultNodeStyle = function () {
return ".node {fill:#eaeaea; stroke:#666; stroke-width:1.5px;}";
exports.getClasses = function (text, isDot) {
var parser;
graph.clear();
if(isDot){
parser = dot.parser;
}else{
parser = flow.parser;
}
parser.yy = graph;
// Parse the graph definition
parser.parse(text);
var classDefStylesObj = {};
var classDefStyleStr = '';
var classes = graph.getClasses();
// Add default class if undefined
if(typeof classes.default === 'undefined') {
classes.default = {id:'default'};
classes.default.styles = ['fill:#eaeaea','stroke:#666','stroke-width:1.5px'];
}
return classes;
};
/**