D3.js|Path Interpolation

Developer
Size
3,858 Kb
Views
34,408

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 Previews

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);
D3.js|Path Interpolation - Script Codes
D3.js|Path Interpolation - Script Codes
Home Page Home
Developer NaKaz
Username nakakaz11
Uploaded August 31, 2022
Rating 3
Size 3,858 Kb
Views 34,408
Do you need developer help for D3.js|Path Interpolation?

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!

NaKaz (nakakaz11) Script Codes
Create amazing web content with AI!

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!