Visualize National Contiguity with a Force Directed Graph
How do I make an visualize national contiguity with a force directed graph?
What is a visualize national contiguity with a force directed graph? How do you make a visualize national contiguity with a force directed graph? This script and codes were developed by Codoer on 07 December 2022, Wednesday.
Visualize National Contiguity with a Force Directed Graph - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Visualize National Contiguity with a Force Directed Graph</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://c0d0er.github.io/Visualize-National-Contiguity-with-a-Force-Directed-Graph/flags1.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id='app'></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Visualize National Contiguity with a Force Directed Graph - Script Codes CSS Codes
body { display: flex; justify-content: center; align-items: center; background-color: #1e7145;
}
.flags { position: relative;
}
.links { stroke: black; stroke-width: 1px;
}
.tooltip1 { padding: 5px; background-color: white; border-radius: 2px; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4); pointer-events: none; opacity: 0.8;
}
.country { color: black;
}
.flag { position: absolute;
}
.link-active { stroke: blue; stroke-width: 3px;
}
Visualize National Contiguity with a Force Directed Graph - Script Codes JS Codes
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ForceGraph = function (_React$Component) { _inherits(ForceGraph, _React$Component); function ForceGraph() { _classCallCheck(this, ForceGraph); return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); } ForceGraph.prototype.componentDidMount = function componentDidMount() { d3.json('https://raw.githubusercontent.com/c0d0er/D3-Show-National-Contiguity-with-a-Force-Directed-Graph/master/countries.json', function (data) { var nodes = data.nodes; var links = data.links; var w = window.innerWidth; var h = window.innerHeight; var div = d3.select('.forcegraph').append('div'); var svg = d3.select('.forcegraph').append('svg').attr('width', w).attr('height', h); var forceG = d3.forceSimulation(nodes).force('link', d3.forceLink().links(links).strength(2.5)).force('charge', d3.forceManyBody().strength(440)).force('center', d3.forceCenter(w / 2, h / 2)).force('collide', d3.forceCollide(24)).on('tick', ticked); var link = svg.append('g').attr('class', 'links').selectAll('line').data(links).enter().append('line'); var node = d3.select('.forcegraph').select('.flags').append('g').selectAll('img').data(nodes).enter().append('img').attr('class', function (d) { return 'flag flag-' + d.code; }).call(d3.drag().on('start', dragstarted).on('drag', dragged).on('end', dragended)); var linkedByIndex = {}; links.forEach(function (d) { linkedByIndex[d.source.index + "," + d.target.index] = 1; }); console.log(linkedByIndex); function isConnected(a, b) { return linkedByIndex[a.index + "," + b.index] || linkedByIndex[b.index + "," + a.index]; } /* node.on("mouseover", function(d){ node.classed("node-connected", function(o) { console.log(o) return isConnected(d, o); }); link.classed("link-active", function(o) { return o.source === d || o.target === d; }); d3.select(this).classed('node-active', true); }).on("mouseout", function(d){ node.attr('class', 'node') link.classed("link-active", false); }); */ node.on('mouseover', function (d) { var tooltipCountries = ''; var connectedCountries = []; node.style('transform', function (o) { if (isConnected(d, o)) { connectedCountries.push(o.country); tooltipCountries = d.country + ', is connected to ' + connectedCountries.join(', ') + '.'; return 'scale(1.2)'; } else { return 'scale(0.7)'; } }); node.classed('node-connected', function (o) { return isConnected(d, 0); }); link.classed("link-active", function (o) { return o.source === d || o.target === d; }); d3.select(this).style('transform', 'scale(2)'); div.html('<div class="tooltip1"><span class="country">' + tooltipCountries + '</span></div>').style('left', d3.event.clientX - 24 + 'px').style('top', d3.event.clientY - 52 + 'px').style('position', 'absolute'); }).on('mouseout', function () { d3.select('.tooltip1').classed('hidden', 'true'); node.style('transform', 'scale(1)'); node.classed('node-connected', false); link.classed('link-active', false); d3.select(this).style('transform', 'scale(1)'); }); function ticked() { link.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; }); node.style("left", function (d) { return d.x - 8 + 'px'; }).style("top", function (d) { return d.y - 8 + 'px'; }); //svg.attr('width',window.innerWidth) //.attr('height', window.innerHeight); } function dragstarted(d) { if (!d3.event.active) { forceG.alphaTarget(0.3) //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) { forceG.alphaTarget(0); } d.fx = null; d.fy = null; } svg.append('text').attr("transform", "translate(" + w / 2 + " ," + 45 + ")").style("text-anchor", "middle").attr('fill', 'white').style('font-size', '1.9em').text("Show National Contiguity with a Force Directed Graph"); }); }; ForceGraph.prototype.render = function render() { return React.createElement( 'div', { className: 'forcegraph' }, React.createElement('div', { className: 'flags' }) ); }; return ForceGraph;
}(React.Component);
ReactDOM.render(React.createElement(ForceGraph, null), document.getElementById('app'));
Developer | Codoer |
Username | c0d0er |
Uploaded | December 07, 2022 |
Rating | 3 |
Size | 5,906 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Jd wiki | 3,082 Kb |
Pomodoro Clock | 3,279 Kb |
Visualize Data with a Scatterplot Graph | 6,834 Kb |
React Markdown Previewer | 3,190 Kb |
Wikipedia Viewer | 2,811 Kb |
Show the Local Weather | 2,904 Kb |
Pomodoro positions | 2,182 Kb |
Visualize Data with a Heat Map | 6,445 Kb |
React Roguelike Dungeon Crawler Game | 9,706 Kb |
Pomodoro 1 timer | 2,589 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Login-ng-modal | Heedoo | 3,566 Kb |
A Pen by Oliver Schafeld | Schafeld | 1,720 Kb |
Flat buttons for Eliassen.com | Kdooley89 | 1,737 Kb |
Vue.js Starter | Andymerskin | 1,268 Kb |
Long Shadow Button | Uixcrazy | 3,550 Kb |
About Mazano | Kiti | 2,585 Kb |
SVG hamburger menu button | Elifitch | 2,602 Kb |
Flat design iframe | Damienpm | 1,819 Kb |
Project MMetro beta | Atomicsong | 5,157 Kb |
Random Gradients - JS | Aldlevine | 2,026 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!