D3.js|Path Interpolation
How do I make an d3.js|path interpolation?
Test based, http://bl.ocks.org/mbostock/1313857 http://bl.ocks.org/mbostock/1705868 http://bl.ocks.org/mbostock/5649592. What is a d3.js|path interpolation? How do you make a d3.js|path interpolation? This script and codes were developed by NaKaz on 31 August 2022, Wednesday.
D3.js|Path Interpolation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>d3.js|Path Interpolation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="//d3js.org/d3.v3.min.js"></script>
<div id="test"> <div id="svg3" class=""></div> <hr> <div id="svg4" class=""></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
D3.js|Path Interpolation - Script Codes CSS Codes
#test { width : 100%;
}
path { fill: none; stroke: #b57f93; stroke-width: 2px;
}
.focusPath { stroke: #3db1cc; stroke-opacity:0.3; stroke-width: 7px;
}
circle { fill: #5aa37e; stroke: #fff; stroke-width: 2px;
}
D3.js|Path Interpolation - Script Codes JS Codes
(function() { "use strict"; (function($, win, doc) { var DURATION, HEIGHT, PointForLineTransition, WIDTH, circle3, circleline, line, path3, points, pointsRandX, pointsRandY, svg3, svg4, transitionLine; WIDTH = +$("#test").width() || 970; HEIGHT = 400; DURATION = 5555; pointsRandX = function() { return 150 + Math.floor(Math.random() * WIDTH - 150); }; pointsRandY = function() { return 50 + Math.floor(Math.random() * 300); }; /*points = [ [480, 150] [580, 350] [680, 50] [780, 250] [180, 250] [280, 50] [380, 350] ] */ points = [[pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()], [pointsRandX(), pointsRandY()]]; PointForLineTransition = (function() { function PointForLineTransition(circle1, path1) { this.circle = circle1; this.path = path1; this.drawCircle(this.circle, this.path); } PointForLineTransition.prototype.drawCircle = function(circle, path) { var _circle, _path; _circle = circle; _path = path; _circle.transition().duration(DURATION).attrTween("transform", this.translateAlong(_path.node())).each("end", function() { return PointForLineTransition.prototype.drawCircle(_circle, _path); }); }; PointForLineTransition.prototype.translateAlong = function(path) { var _path, length; _path = path; length = _path.getTotalLength(); return function() { return function(t) { var p; p = _path.getPointAtLength(t * length); return "translate(" + p.x + "," + p.y + ")"; }; }; }; return PointForLineTransition; })(); svg3 = d3.select("#svg3").append("svg").attr("width", WIDTH).attr("height", HEIGHT); path3 = svg3.append("path").data([points]).attr("d", d3.svg.line().tension(0).interpolate("cardinal-closed")); svg3.selectAll(".point").data(points).enter().append("circle").attr("r", 4).attr("transform", function(d) { return "translate(" + d + ")"; }); circle3 = svg3.append("circle").attr("r", 13).attr("transform", "translate(" + points[0] + ")"); new PointForLineTransition(circle3, path3); transitionLine = function(path) { var tweenDash; tweenDash = function() { var i, length; length = this.getTotalLength(); i = d3.interpolateString("0," + length, length + "," + length); return function(t) { return i(t); }; }; path.transition().duration(DURATION).attrTween("stroke-dasharray", tweenDash).each("end", function() { d3.select(this).call(transitionLine); }); }; line = d3.svg.line().tension(0).interpolate("cardinal-closed"); svg4 = d3.select("#svg4").append("svg").datum(points).attr("width", WIDTH).attr("height", HEIGHT); svg4.append("path").style("stroke", "#567F83").style("stroke-opacity", 0.5).style("stroke-dasharray", "4,4").attr("d", line); circleline = svg4.append("path").attr("d", line).attr("class", "focusPath"); return circleline.call(transitionLine); })(jQuery, this.window, this.document);
}).call(this);
Developer | NaKaz |
Username | nakakaz11 |
Uploaded | August 31, 2022 |
Rating | 3 |
Size | 3,858 Kb |
Views | 34,408 |
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 |
D3.js d3.geo.projection TEST | 7,169 Kb |
Test OMG Particles II | 2,879 Kb |
A Pen by NaKaz | 2,669 Kb |
MVC tab TEST | 4,804 Kb |
D3.js su_ji_Force | 4,348 Kb |
CountUP Class sandbox | 3,229 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 |
Minimal Menu | Achudars | 3,430 Kb |
Monochrome Form | AlienPiglet | 3,096 Kb |
Opening Reveal Modal On Document Ready | Winghouchan | 1,787 Kb |
Learning canvas drawing | Aurer | 2,204 Kb |
Random Gradients - JS | Aldlevine | 2,026 Kb |
Custom Select Element | Agrayson | 3,616 Kb |
A Pen by Paul Sullivan | Pwsm50 | 2,349 Kb |
Jochaho Skeleton | Dhanushbadge | 1,689 Kb |
Social Profiles | Lachlanjc | 1,939 Kb |
Personal Website Redesign v2.0 | DevItWithDavid | 5,168 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!