Support styling of subgraphs

This commit is contained in:
Josh Junon
2019-05-24 17:08:45 +02:00
parent 7d3578b31a
commit f51596eb61
7 changed files with 192 additions and 111 deletions

View File

@@ -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) {