chord.js | Javascript library to render images
kandi X-RAY | chord.js Summary
kandi X-RAY | chord.js Summary
Javascript library to render images of guitar and ukulele chords
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of chord.js
chord.js Key Features
chord.js Examples and Code Snippets
Community Discussions
Trending Discussions on chord.js
QUESTION
I am trying to implement an animation effect using svg circle elements on the mouse-over event of a chord path in D3 chord diagram.
The inspiration for this trial is the following implementation of a sankey diagram:
https://bl.ocks.org/micahstubbs/ed0ae1c70256849dab3e35a0241389c9
I have managed to insert the circle elements on the mouse-over event for the chords. However, I am having difficulty in figuring out how to make them follow the path of the chord. (Line 69-106 in the following JS code).
My JS code (chord.js)
...ANSWER
Answered 2018-Dec-12 at 13:57//*******************************************************************
// CREATE MATRIX AND MAP
//*******************************************************************
var matrix, mmap, rdr;
d3.csv('data/out.csv', function(error, data) {
var mpr = chordMpr(data);
mpr
.addValuesToMap('Source')
.setFilter(function(row, a, b) {
return (row.Source === a.name && row.Destination === b.name)
})
.setAccessor(function(recs, a, b) {
if (!recs[0]) return 0;
return +recs[0].Count;
});
matrix = mpr.getMatrix();
mmap = mpr.getMap();
rdr = chordRdr(matrix, mmap);
drawChords();
});
//*******************************************************************
// DRAW THE CHORD DIAGRAM
//*******************************************************************
function drawChords() {
var w = window.innerWidth || document.body.clientWidth,
h = 700,
r1 = h / 2,
r0 = r1 - 150;
var svg = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.attr("id", "circle")
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
var chord = d3.layout.chord()
.padding(.15)
.sortChords(d3.descending);
chord.matrix(matrix);
var arc = d3.svg.arc()
.innerRadius(r0*1.03)
.outerRadius(r0*1.03 + 20);
var path = d3.svg.chord()
.radius(r0);
var g = svg.selectAll("g.group")
.data(chord.groups())
.enter()
.append("g")
.attr("class", "group");
var paths = g.append("svg:path")
.style("stroke", function(d) { return fillcolor(rdr(d).gname); })
.style("fill", function(d) { return fillcolor(rdr(d).gname); })
.attr("d", arc)
.attr("class", "arcs");
var chordPaths = svg.selectAll("path.chord")
.data(chord.chords(),function(d,i){return i;})
.enter().append("svg:path")
.attr("class", "chord")
.attr("id", function(d,i){return "chord"+i})
.on("mouseover", function(d,i) {
this.classList.add("hovered");
currentpath = this;
startPoint = pathStartPoint(currentpath);
function loop(thispath) {
if (!thispath.classList.contains("hovered")) return;
setTimeout(function () {
particle = svg.insert("circle")
.attr("class",function(){return currentpath.getAttribute("id")+"-circle"})
.attr("r",2)
.style("stroke-opacity", 1)
.style("fill", currentpath.style.fill)
.attr("transform", "translate(" + startPoint[0] + "," + startPoint[1] + ")")
.transition()
.duration(2000)
.attrTween("transform", translateAlong(currentpath))
.remove();
loop(thispath);
}, 300);
}
loop(this);
})
.on("mouseout",function(d,i){
this.classList.remove("hovered");
})
.style("fill", function(d) { return fillcolor(rdr(d.target).gname); })
.attr("d", path);
}
//Get path start point for placing marker
function pathStartPoint(path) {
var d = path.getAttribute("d");
var dsplitted = d.split(" ");
return dsplitted[1].split(",");
};
function translateAlong(path) {
var l = path.getTotalLength();
var t0 = 0;
return function(i) {
return function(t) {
var p0 = path.getPointAtLength(t0 * l);//previous point
var p = path.getPointAtLength(t * l);////current point
t0 = t;
var centerX = p.x,
centerY = p.y;
return "translate(" + centerX + "," + centerY + ")"//rotate(" + angle + " 24" + " 12" +")";
}
}
}
function fillcolor(segmentvalue){
if (segmentvalue.includes("Segment A")) {
return '#ff3a21'
} else if (segmentvalue.includes("Segment C")) {
return '#26bde2'
} else if (segmentvalue.includes("Segment D")) {
return '#fcc30b'
} else if (segmentvalue.includes("Segment B")) {
return '#dd1367'
} else if (segmentvalue.includes("Segment E")) {
return '#a1e972'
} else {
return '#72e8a4'
}
}
QUESTION
I'm trying to modify my code to load a Json file from an URL rather than to use from a local file. Can anyone please explain me how to resolve this issue
...ANSWER
Answered 2018-Mar-27 at 07:41React doesn't mind how you do API(URL) call. you can choose whatever kind of AJAX library you like for this task. The simplest way is this.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install chord.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page