I got the following D3 playground in place. The goal for now is to create a fixed hard coded new node .on("click",..)
I understand that the node do not get the initial x and y position (i guess). The error message which gives me headache is Unexpected value NaN parsing x1 attribute
.
As a beginner I appreciate if somebody could steer my mind into the correct direction.
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<html>
<head>
<title>Play with D3</title>
<!-- favcon -->
<link rel="icon" href="https://networkrepository.com/favicon.png">
<!-- call external d3.js framework -->
<script src="https://d3js.org/d3.v4.js"></script>
<!-- load "font awesome" stylesheet https://fontawesome.com/ -->
<script src="https://kit.fontawesome.com/39094309d6.js" crossorigin="anonymous"></script>
</head>
<style>
body {
overflow: hidden;
margin: 0px;
font-family: "Open Sans", sans-serif;
}
.canvas {
background-color: rgb(220,220,220);
}
.link {
stroke: rgb(0,0,0);
stroke-width: 2px;
}
.node {
stroke: rgb(255,255,255);
stroke-width: 2px;
}
.icon {
fill: rgb(0,0,0);
pointer-events: none;
}
.node:hover{
cursor: pointer;
}
</style>
<body>
<!-- SVG area for the whole graph -->
<svg id="svg"> </svg>
<!-- call app.js where the application is written -->
<script>
// define different variables
var width = window.innerWidth
height = window.innerHeight
boolColor = true
boolOpacity = true
color = null
nodes = null
// define cavnas area to draw everything
var svg = d3.select("svg")
.attr("class", "canvas")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function() {
svg.attr("transform", d3.event.transform)
}))
.append("g")
// Removes zoom on doubleclick listener
d3.select("svg").on("dblclick.zoom", null)
var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) { return d.id; }).distance(100))
.force("charge", d3.forceManyBody().strength(-400))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("attraceForce",d3.forceManyBody().strength(70));
// load data from json file
var data_nodes = [
{
"id": "00000",
"type": "company",
"name": "Test",
"context": "",
"icon": "\uf1ad"
},
{
"id": "00100",
"type": "software",
"name": "Jira",
"context":"Jira",
"icon": "\uf7b1",
"parent" : "00000"
},
{
"id": "00200",
"type": "software",
"name": "Confluence",
"context":"Confluence",
"icon": "\uf78d",
"parent" : "00000"
},
{
"id": "00300",
"type": "software",
"name": "IVIS",
"context":"IVIS",
"icon": "\ue084",
"parent" : "00000"
},
{
"id": "00400",
"type": "software",
"name": "IPOS",
"context":"IPOS",
"icon": "\ue084",
"parent" : "00000"
},
{
"id": "00500",
"type": "software",
"name": "IDAS",
"context":"IDAS",
"icon": "\ue084",
"parent" : "00000"
},
{
"id": "99997",
"type": "hardware",
"name": "power-plug",
"context": "power-plug",
"icon": "\uf1e6",
"parent" : "00000"
},
{
"id": "99998",
"type": "hardware",
"name": "usv",
"context": "usv",
"icon": "\uf5df",
"parent" : "00000"
},
]
var data_links = [
{"source": "99998", "target": "00000"},
{"source": "99997", "target": "00000"},
{"source": "00100", "target": "00000"},
{"source": "00200", "target": "00000"},
{"source": "00300", "target": "00000"},
{"source": "00400", "target": "00000"},
{"source": "00500", "target": "00000"},
]
// create links which visualize relationships
var links = svg.selectAll("svg")
.data(data_links)
.enter()
.append("line")
.attr("class", "link")
.style("stroke-width", 3)
.style("stroke-linecap", "round")
// disable browser context menu on link
.on("contextmenu", function (d, i){
d3.event.preventDefault()
})
.on("mouseenter", function(d) {
d3.select(this)
.style("stroke", "red")
})
.on("mouseleave", function(d) {
d3.select(this)
.style("stroke", "black")
})
var nodes = svg.selectAll("svg")
.data(data_nodes)
.enter()
.append("circle")
.attr("r", 30)
.attr("class", "node")
.attr("fill", entryColor)
.call(d3.drag()
.on("start", dragStarted)
.on("drag", dragged)
.on("end", dragEnded)
)
.on("click", click)
var icons = svg.selectAll("svg")
.data(data_nodes)
.enter()
//.append("g")
.append("text")
.attr("class", "icon")
.attr("text-anchor", "middle")
.attr("dominant-baseline", "central")
.style("font-family","FontAwesome")
.style("font-size","30px")
.text(function (d) {return d.icon;})
.call(d3.drag()
.on("start", dragStarted)
.on("drag", dragged)
.on("end", dragEnded)
)
// disable browser context menu on icon
.on("contextmenu", function (d, i){
d3.event.preventDefault()
})
.on("mouseenter", function(d) {
d3.event.preventDefault()
})
simulation
.nodes(data_nodes)
.on("tick", ticked);
simulation
.force("link")
.links(data_links);
function ticked() {
// update link positions
links
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
// update node positions
nodes
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
// update icon positions
icons
.attr("x", function(d) {return d.x})
.attr("y", function(d) {return d.y})
}
function click(d) {
addNode()
}
function addNode() {
var obj = {
"id": "66000",
"type": "company",
"name": "Test1",
"context": "",
"icon": "\uf1ad"
}
data_nodes.push(obj)
}
/*
Set the color of each node in dependency of their d.name attribute.
*/
function entryColor(d) {
switch (d.name) {
case "power-plug":
return "lightgreen"
case "usv":
return "orange"
case "diesel":
return "orange"
default:
return "whitesmoke"
}
}
/*
dragStarted() / dragged() and dragEnded() controlling the drag behaviour of each
object. In case all drag events are not desired, simple comment out the .call(d3.drag())
execution during the object(node) creation
*/
function dragStarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragEnded(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
</script>
</body>
</html>
https://kamagraday.com/ how well does sildenafil work
lasix medication dosage
https://cialisbob.com/ cialis online
medicine lasix
http://wardenafil.com buy levitra germany
Good day! I could have sworn I’ve visited your blog before but after
browsing through many of the articles I realized it’s
new to me. Regardless, I’m definitely happy I found
it and I’ll be book-marking it and checking back often! http://herreramedical.org/azithromycin
lasix and diarrhea
http://himscanada.com/ cialis price comparison
http://levitraye.com levitra side effect
http://stromectolhumans.com/ ivermectina para humanos
https://iwermectin.com/ ivermectin tablets dosage
https://viagraxyu.com viagra prices
Thanks for sharing your thoughts about cialis.
Regards http://cleckleyfloors.com/
http://ivermectineffects.com/ ivermectin tablets
https://ivermectinovercounter.com/ stromectol
online viagra united states – viagra pills online canada sildenafil tabs 20mg
Attractive component of content. I simply stumbled upon your blog and in accession capital to assert
that I acquire actually loved account your weblog posts.
Anyway I will be subscribing for your augment and even I success
you get right of entry to persistently quickly. https://buszcentrum.com/zithromax.htm
Hello i am kavin, its my first occasion to commenting anyplace, when i read this article i thought i could also create comment due to this good paragraph. http://antiibioticsland.com/Zithromax.htm
http://ivermectineffects.com stromectol
cialis 40 mg – site generic cialis price
zithromax package insert
stromectol order online – stromectol 0.5 mg ivermectin 2mg
fda propecia
oregon health authority emergency first aid at work
ivermectin clinical trials https://ivermectinhome.com
best casino online – online casino games for real money san manuel casino online
salbutamol inhaler amazon
http://ivermectinus.com/ ivermectin tablets for humans
http://zithrozpack.com/ zithromax z pak
how long for levitra to work http://levitrair.com levitra erection
buy ventolin inhaler tesco
best treatment for erectile dysfunction – dr oz erectile dysfunction pills ed cures that actually work
prednisone 54 – fast shipping prednisone prednisone 20mg tablets price
can humans take ivermectin paste http://stromectolus.com ivermectina dosis en humanos
canadian discount pharmacy viagra – buy sildenafil over the counter sildenafil 50 mg prices
does anxiety cause high blood pressure what can you give a dog for arthritis pain
ivermectin otc https://ivermectinhome.com
cialis 2 5 mg online – Overnight cialis 40mg cialis
http://albuterolotc.com/ ventolin generic
find new doctor united medicare
ivermectin for humans walmart https://ivermectinhome.com
ivermectin over the counter http://stromectolus.com ivermectin tablets
stromectol in canada – stromectol tablets order ivermectin usa
top rated ed pills – erectial dysfunction new ed pill
flathead county health department what are some reasons why patients should buy health insurance
can you buy ivermetin at the counter https://ivermectinhome.com
ivermectin tablets over counter https://ivermcov.com/# ivermectin for sale
javascript-help.li vs canada online pharmacies https://pharmvolk.com over counter drugs that get you high
blutdruckmedikament lisinopril
how many singers from lawrence welk show died from aids? https://ventolinhfaer.com/ asthma inhaler
buy dapoxetine new zealand
2017 major health risks how to bring high blood pressure down
ivermectine vidal https://ivermectinhome.com
bijwerkingen lisinopril accord 10 mg
javascript-help.li recommended ivermectin http://ivermectini.com stromectol 3 mg tablets price
department of health services los angeles http://doctorkiva.com cheap soft viagra
where do healthcare managers work doctors who prescribe ivermectin at no cost https://iveramectin.com ivermectin for humans for sale
javascript-help.li recommended stromectol 3mg tablets price http://ivermectiny.com stromectol dosage chart
united healthcare find a doctor https://dapoxetineus.com/ dapoxetine
my hand just has arthritis in a thumb joint http://doctorkiva.com ordering viagra from canada
javascript-help.li with ivermectin for humans https://ivermectiny.com ivermectin tablette
sildenafil 100g
best blood pressure http://ivermectino.com stromectol ivermectin amazon
viagra without a doctor prescription certified meds https://viagrob.com buy line viagra
javascript-help.li and ivermectin ebay https://ivermectinhum.com stromectol online canada
what doterra oils can use for arthritis? stromectol http://iveramectin.com/ ivermectin for humans
buy ventolin from canada
where to buy cialis for women
javascript-help.li vs stromectol http://stromectl.com ivermectin
javascript-help.li recommended ivermectin tablets https://ivermectiny.com where to buy ivermectin
best online pharmacies canada http://canadian2pharmacy.com cigna over the counter medication D3 v4 add another node to array – JavaScript Help
is there a generic advair
lasix 10mg
buy generic cytotec online
ivermectin otc http://ivermectin1.com/ ivermectin without doctor prescription
https://stromectolo.com – ivermectina comprar
impotence is there a cure or treatment http://levitraye.com – levitra headache
http://ivrmectin.com – ivermectin dosage chart for humans parasites
stromectol over the counter https://stromectolforte.com/ ivermectin side effects ivermectin for humans
zyrtec dosage – https://allergyd.com
koupit stromectol http://stromectolforte.com/# ivermectin india ivermectin for humans
These are in fact impressive ideas in on the topic of blogging.
You have touched some fastidious points here. Any way keep up wrinting. http://antiibioticsland.com/Flagyl_ER.htm
ivermectin usa https://www.ivermecton.com/ ivermectin 12 mg tablets for sale
tadalafil 10 – cialis super active rx online pharmacy
where to buy stromectol online https://stromectoloff.com/ ivermectin lotion cost