Skip to content

Instantly share code, notes, and snippets.

View afrinc's full-sized avatar
📜
Being

Afrin Chakure afrinc

📜
Being
  • Pune, India
View GitHub Profile
@afrinc
afrinc / index.html
Last active April 21, 2020 12:57
A Composite Node with d3 v5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>A Composite Node with d3 v5</title>
<link
rel="stylesheet"
href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
/>
<style>
@afrinc
afrinc / index.html
Created April 21, 2020 13:08
adding d3 library to html
<body>
<script src="https://d3js.org/d3.v5.min.js"></script>
</body>
@afrinc
afrinc / index.html
Created April 21, 2020 13:10
script adding svg element
<script>
var width = 500, height = 400;
const nodes = [
{
id: 0,
name: "ServiceGroup",
description: "Port : 80",
connection_count: 3
}
];
@afrinc
afrinc / index.js
Last active April 21, 2020 13:12
inserting data into nodes
let circle = svg
.append("svg:g")
.selectAll("g")
.data(nodes, d => d.id);
const g = circle.enter();
@afrinc
afrinc / index.js
Created April 21, 2020 13:13
appending rectangular node
const rectangularNode = g
.append("svg:rect")
.attr("class", "node")
.attr("x", d => {
return 0;
})
.attr("y", d => {
return 0;
});
@afrinc
afrinc / index.js
Created April 21, 2020 13:14
Retrieving coordinates of the created node
var outerNodebbox = rectangularNode.node().getBBox();
@afrinc
afrinc / index.js
Created April 21, 2020 13:15
Appending image inside rectangular node
const images = g
.append("svg:image")
.attr(
"xlink:href",
"https://img.icons8.com/ios-glyphs/30/000000/superman.png"
)
.attr("x", function(d) {
let X = outerNodebbox.x;
return X + 10;
})
@afrinc
afrinc / index.js
Created April 21, 2020 13:16
adding text inside rectangular node
const label = g
.append("svg:text")
.attr("class", "name")
.attr("dx", function(d) {
return outerNodebbox.width / 3;
})
.attr("dy", function(d) {
return outerNodebbox.height / 3;
})
.attr("dominant-baseline", "central")
@afrinc
afrinc / index.js
Created April 21, 2020 13:17
adding description text inside rectangular node
const description = g
.append("svg:text")
.attr("class", "description")
.attr("dx", function(d) {
return outerNodebbox.width / 3;
})
.attr("dy", function(d) {
return (2 * outerNodebbox.height) / 3;
})
.attr("dominant-baseline", "central")
@afrinc
afrinc / index.js
Created April 21, 2020 13:17
adding circle inside rectangular node
const count_circle = g
.append("svg:circle")
.attr("class", "countCircle")
.style("visibility", "unset")
.attr("r", 10)
.attr("cx", function(d) {
let X = outerNodebbox.x;
let WIDTH = outerNodebbox.width;
return X + (2.5 * WIDTH) / 3;
})