mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 23:39:50 +02:00
Support styling of subgraphs
This commit is contained in:
@@ -7,6 +7,7 @@ let vertices = {}
|
||||
let edges = []
|
||||
let classes = []
|
||||
let subGraphs = []
|
||||
let subGraphLookup = {}
|
||||
let tooltips = {}
|
||||
let subCount = 0
|
||||
let direction
|
||||
@@ -18,8 +19,9 @@ let funs = []
|
||||
* @param text
|
||||
* @param type
|
||||
* @param style
|
||||
* @param classes
|
||||
*/
|
||||
export const addVertex = function (id, text, type, style) {
|
||||
export const addVertex = function (id, text, type, style, classes) {
|
||||
let txt
|
||||
|
||||
if (typeof id === 'undefined') {
|
||||
@@ -52,6 +54,13 @@ export const addVertex = function (id, text, type, style) {
|
||||
})
|
||||
}
|
||||
}
|
||||
if (typeof classes !== 'undefined') {
|
||||
if (classes !== null) {
|
||||
classes.forEach(function (s) {
|
||||
vertices[id].classes.push(s)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,6 +152,10 @@ export const setClass = function (ids, className) {
|
||||
if (typeof vertices[id] !== 'undefined') {
|
||||
vertices[id].classes.push(className)
|
||||
}
|
||||
|
||||
if (typeof subGraphLookup[id] !== 'undefined') {
|
||||
subGraphLookup[id].classes.push(className)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -283,6 +296,7 @@ export const clear = function () {
|
||||
funs = []
|
||||
funs.push(setupToolTips)
|
||||
subGraphs = []
|
||||
subGraphLookup = {}
|
||||
subCount = 0
|
||||
tooltips = []
|
||||
}
|
||||
@@ -297,7 +311,7 @@ export const defaultStyle = function () {
|
||||
/**
|
||||
* Clears the internal graph db so that a new graph can be parsed.
|
||||
*/
|
||||
export const addSubGraph = function (list, title) {
|
||||
export const addSubGraph = function (id, list, title) {
|
||||
function uniq (a) {
|
||||
const prims = { 'boolean': {}, 'number': {}, 'string': {} }
|
||||
const objs = []
|
||||
@@ -315,10 +329,13 @@ export const addSubGraph = function (list, title) {
|
||||
|
||||
nodeList = uniq(nodeList.concat.apply(nodeList, list))
|
||||
|
||||
const subGraph = { id: 'subGraph' + subCount, nodes: nodeList, title: title.trim() }
|
||||
subGraphs.push(subGraph)
|
||||
id = id || ('subGraph' + subCount)
|
||||
title = title || ''
|
||||
subCount = subCount + 1
|
||||
return subGraph.id
|
||||
const subGraph = { id: id, nodes: nodeList, title: title.trim(), classes: [] }
|
||||
subGraphs.push(subGraph)
|
||||
subGraphLookup[id] = subGraph
|
||||
return id
|
||||
}
|
||||
|
||||
const getPosForId = function (id) {
|
||||
|
Reference in New Issue
Block a user