mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-22 04:55:10 +00:00
Add check for elem existance to interactive SVG; reindent JS-code
This commit is contained in:
parent
f3e7e97fe8
commit
0cb778b063
@ -5,12 +5,12 @@
|
||||
* (C) Copyright 2009-2020, Arnaud Roques
|
||||
*
|
||||
* Project Info: http://plantuml.com
|
||||
*
|
||||
*
|
||||
* If you like this project or if you find it useful, you can support us at:
|
||||
*
|
||||
*
|
||||
* http://plantuml.com/patreon (only 1$ per month!)
|
||||
* http://plantuml.com/paypal
|
||||
*
|
||||
*
|
||||
* This file is part of PlantUML.
|
||||
*
|
||||
* PlantUML is free software; you can redistribute it and/or modify it
|
||||
@ -30,7 +30,7 @@
|
||||
*
|
||||
*
|
||||
* Original Author: Arnaud Roques
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package net.sourceforge.plantuml.svg;
|
||||
@ -184,111 +184,115 @@ public class SvgGraphics {
|
||||
final Element script = document.createElement("script");
|
||||
script.setTextContent(
|
||||
"function addItemToMapOfLists(mapOfLists, name, item) {" + "\n" +
|
||||
" // mapOfLists = {" + "\n" +
|
||||
" // 'key1': [item1, item2, ...]," + "\n" +
|
||||
" // 'key2': [item3, item4, ...]," + "\n" +
|
||||
" // }" + "\n" +
|
||||
" if (mapOfLists[name].length > 0) {" + "\n" +
|
||||
" if (!mapOfLists[name].includes(item)) {" + "\n" +
|
||||
" mapOfLists[name].push(item);" + "\n" +
|
||||
" }" + "\n" +
|
||||
" } else {" + "\n" +
|
||||
" mapOfLists[name] = [item];" + "\n" +
|
||||
" }" + "\n" +
|
||||
"}" + "\n" +
|
||||
" // mapOfLists = {" + "\n" +
|
||||
" // 'key1': [item1, item2, ...]," + "\n" +
|
||||
" // 'key2': [item3, item4, ...]," + "\n" +
|
||||
" // }" + "\n" +
|
||||
" if (mapOfLists[name].length > 0) {" + "\n" +
|
||||
" if (!mapOfLists[name].includes(item)) {" + "\n" +
|
||||
" mapOfLists[name].push(item);" + "\n" +
|
||||
" }" + "\n" +
|
||||
" } else {" + "\n" +
|
||||
" mapOfLists[name] = [item];" + "\n" +
|
||||
" }" + "\n" +
|
||||
"}" + "\n" +
|
||||
"" + "\n" +
|
||||
"function main() {" + "\n" +
|
||||
" let elems = Array.from(document.getElementsByClassName('elem'));" + "\n" +
|
||||
" let links = Array.from(document.getElementsByClassName('link'));" + "\n" +
|
||||
"function main() {" + "\n" +
|
||||
" let elems = Array.from(document.getElementsByClassName('elem'));" + "\n" +
|
||||
" let links = Array.from(document.getElementsByClassName('link'));" + "\n" +
|
||||
"" + "\n" +
|
||||
" let elemsMap = {};" + "\n" +
|
||||
" let linkedElems = {};" + "\n" +
|
||||
" let linkedLinks = {};" + "\n" +
|
||||
" let elemsMap = {};" + "\n" +
|
||||
" let linkedElems = {};" + "\n" +
|
||||
" let linkedLinks = {};" + "\n" +
|
||||
"" + "\n" +
|
||||
" elems.forEach(elem => {" + "\n" +
|
||||
" let name = elem.classList[1];" + "\n" +
|
||||
" elemsMap[name] = elem;" + "\n" +
|
||||
" linkedElems[name] = [];" + "\n" +
|
||||
" linkedLinks[name] = [];" + "\n" +
|
||||
" });" + "\n" +
|
||||
" elems.forEach(elem => {" + "\n" +
|
||||
" let name = elem.classList[1];" + "\n" +
|
||||
" elemsMap[name] = elem;" + "\n" +
|
||||
" linkedElems[name] = [];" + "\n" +
|
||||
" linkedLinks[name] = [];" + "\n" +
|
||||
" });" + "\n" +
|
||||
"" + "\n" +
|
||||
" links.forEach(link => {" + "\n" +
|
||||
" let name1 = link.classList[1];" + "\n" +
|
||||
" let name2 = link.classList[2];" + "\n" +
|
||||
" links.forEach(link => {" + "\n" +
|
||||
" let name1 = link.classList[1];" + "\n" +
|
||||
" let name2 = link.classList[2];" + "\n" +
|
||||
"" + "\n" +
|
||||
" let elem1 = elemsMap[name1];" + "\n" +
|
||||
" let elem2 = elemsMap[name2];" + "\n" +
|
||||
" if (elemsMap[name1]) {" + "\n" +
|
||||
" if (elemsMap[name2]) {" + "\n" +
|
||||
" let elem1 = elemsMap[name1];" + "\n" +
|
||||
" let elem2 = elemsMap[name2];" + "\n" +
|
||||
"" + "\n" +
|
||||
" addItemToMapOfLists(linkedElems, name1, elem2);" + "\n" +
|
||||
" addItemToMapOfLists(linkedElems, name2, elem1);" + "\n" +
|
||||
" addItemToMapOfLists(linkedElems, name1, elem2);" + "\n" +
|
||||
" addItemToMapOfLists(linkedElems, name2, elem1);" + "\n" +
|
||||
"" + "\n" +
|
||||
" addItemToMapOfLists(linkedLinks, name1, link);" + "\n" +
|
||||
" addItemToMapOfLists(linkedLinks, name2, link);" + "\n" +
|
||||
" });" + "\n" +
|
||||
" addItemToMapOfLists(linkedLinks, name1, link);" + "\n" +
|
||||
" addItemToMapOfLists(linkedLinks, name2, link);" + "\n" +
|
||||
" }" + "\n" +
|
||||
" }" + "\n" +
|
||||
" });" + "\n" +
|
||||
"" + "\n" +
|
||||
" let selectedElems = [];" + "\n" +
|
||||
" let selectedLinks = [];" + "\n" +
|
||||
" let selectedElemName = null;" + "\n" +
|
||||
" let selectedElems = [];" + "\n" +
|
||||
" let selectedLinks = [];" + "\n" +
|
||||
" let selectedElemName = null;" + "\n" +
|
||||
"" + "\n" +
|
||||
" function clearSelected() {" + "\n" +
|
||||
" selectedElems.forEach(item => {" + "\n" +
|
||||
" item.classList.remove('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" selectedElems = [];" + "\n" +
|
||||
" function clearSelected() {" + "\n" +
|
||||
" selectedElems.forEach(item => {" + "\n" +
|
||||
" item.classList.remove('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" selectedElems = [];" + "\n" +
|
||||
"" + "\n" +
|
||||
" selectedLinks.forEach(item => {" + "\n" +
|
||||
" item.classList.remove('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" selectedLinks = [];" + "\n" +
|
||||
" }" + "\n" +
|
||||
" selectedLinks.forEach(item => {" + "\n" +
|
||||
" item.classList.remove('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" selectedLinks = [];" + "\n" +
|
||||
" }" + "\n" +
|
||||
"" + "\n" +
|
||||
" function selectAll() {" + "\n" +
|
||||
" selectedElemName = null;" + "\n" +
|
||||
" function selectAll() {" + "\n" +
|
||||
" selectedElemName = null;" + "\n" +
|
||||
"" + "\n" +
|
||||
" selectedElems = Array.from(elems);" + "\n" +
|
||||
" selectedElems.forEach(item => {" + "\n" +
|
||||
" item.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" selectedElems = Array.from(elems);" + "\n" +
|
||||
" selectedElems.forEach(item => {" + "\n" +
|
||||
" item.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
"" + "\n" +
|
||||
" selectedLinks = Array.from(links);" + "\n" +
|
||||
" selectedLinks.forEach(item => {" + "\n" +
|
||||
" item.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" }" + "\n" +
|
||||
" selectedLinks = Array.from(links);" + "\n" +
|
||||
" selectedLinks.forEach(item => {" + "\n" +
|
||||
" item.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" }" + "\n" +
|
||||
"" + "\n" +
|
||||
" function selectElem(elemName) {" + "\n" +
|
||||
" if (elemName === selectedElemName) {" + "\n" +
|
||||
" selectAll();" + "\n" +
|
||||
" function selectElem(elemName) {" + "\n" +
|
||||
" if (elemName === selectedElemName) {" + "\n" +
|
||||
" selectAll();" + "\n" +
|
||||
"" + "\n" +
|
||||
" } else {" + "\n" +
|
||||
" clearSelected();" + "\n" +
|
||||
" selectedElemName = elemName;" + "\n" +
|
||||
" } else {" + "\n" +
|
||||
" clearSelected();" + "\n" +
|
||||
" selectedElemName = elemName;" + "\n" +
|
||||
"" + "\n" +
|
||||
" elemsMap[elemName].classList.add('selected');" + "\n" +
|
||||
" selectedElems.push(elemsMap[elemName]);" + "\n" +
|
||||
" elemsMap[elemName].classList.add('selected');" + "\n" +
|
||||
" selectedElems.push(elemsMap[elemName]);" + "\n" +
|
||||
"" + "\n" +
|
||||
" linkedElems[elemName].forEach(linkedElem => {" + "\n" +
|
||||
" selectedElems.push(linkedElem);" + "\n" +
|
||||
" linkedElem.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" linkedElems[elemName].forEach(linkedElem => {" + "\n" +
|
||||
" selectedElems.push(linkedElem);" + "\n" +
|
||||
" linkedElem.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
"" + "\n" +
|
||||
" linkedLinks[elemName].forEach(linkedLink => {" + "\n" +
|
||||
" selectedLinks.push(linkedLink);" + "\n" +
|
||||
" linkedLink.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" }" + "\n" +
|
||||
" }" + "\n" +
|
||||
" linkedLinks[elemName].forEach(linkedLink => {" + "\n" +
|
||||
" selectedLinks.push(linkedLink);" + "\n" +
|
||||
" linkedLink.classList.add('selected');" + "\n" +
|
||||
" });" + "\n" +
|
||||
" }" + "\n" +
|
||||
" }" + "\n" +
|
||||
"" + "\n" +
|
||||
" Object.keys(elemsMap).forEach(name => {" + "\n" +
|
||||
" elemsMap[name].onclick = () => { selectElem(name); };" + "\n" +
|
||||
" });" + "\n" +
|
||||
" Object.keys(elemsMap).forEach(name => {" + "\n" +
|
||||
" elemsMap[name].onclick = () => { selectElem(name); };" + "\n" +
|
||||
" });" + "\n" +
|
||||
"" + "\n" +
|
||||
" selectAll();" + "\n" +
|
||||
"}" + "\n" +
|
||||
" selectAll();" + "\n" +
|
||||
"}" + "\n" +
|
||||
"" + "\n" +
|
||||
"document.addEventListener('DOMContentLoaded', (event) => {" + "\n" +
|
||||
" main();" + "\n" +
|
||||
"});"
|
||||
"document.addEventListener('DOMContentLoaded', (event) => {" + "\n" +
|
||||
" main();" + "\n" +
|
||||
"});"
|
||||
);
|
||||
return script;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user