Skip to content

Commit

Permalink
On double click, open semantic scholar page for paper (node)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnmora committed Jan 5, 2018
1 parent 9fc047b commit fc1f5a6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let filterParams = {
authorIsActive: {}
}

var yearToPix = d3.scaleLinear()
let yearToPix = d3.scaleLinear()
.domain([minYear, maxYear])
.range([0, width]);

Expand Down Expand Up @@ -68,11 +68,10 @@ d3.select('#DBH-range-slider-min').text(minYear);
d3.select('#DBH-range-slider-max').text(maxYear);

// tooltip
var tooltip = d3.select("body").append("div")
let tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);

// 3. GET DATA AND SETUP INITIAL VIS DEPENDANT ON DATA -------------------------------------------------------------------------

const radiusFromNode = d => {
if(d.radius !== undefined) return d.radius
Expand All @@ -83,7 +82,9 @@ const radiusFromNode = d => {
return d.radius;
}

const nodeMouseOver = function(d) {
// NODE MOUSE EVENTS

const displayNodeTooltip = function(d) {
console.log(d)
tooltip.transition()
.duration(200)
Expand All @@ -93,12 +94,19 @@ const nodeMouseOver = function(d) {
.style("top", (d3.event.pageY - 28) + "px");
}

const nodeMouseOut = function(d) {
const removeNodeTooltip = function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
}

const openNodeSSPage = function(d) {
window.open(d.linkToPaper, '_blank')
}


// 3. GET DATA AND SETUP INITIAL VIS DEPENDANT ON DATA -------------------------------------------------------------------------

Promise.all([
new Promise((res,rej) => d3.json(graphDataJSON, function(error, JSONdata) { if(error) { rej(error) } else { res(JSONdata) } })),
new Promise((res,rej) => d3.json(coreAuthorsJSON, function(error, JSONdata) { if(error) { rej(error) } else { res(JSONdata) } }))
Expand Down Expand Up @@ -242,8 +250,9 @@ function updateVis() {
.append("circle")
.attr("fill", d => getCoreAuthorColor(d))
.style("opacity", d => d.coreAuthor ? 1 : nonCoreAuthorOpacity)
.on("mouseover", nodeMouseOver)
.on("mouseout", nodeMouseOut)
.on("mouseover", displayNodeTooltip)
.on("mouseout", removeNodeTooltip)
.on("dblclick", openNodeSSPage)
.call(function(node) { node.transition().duration(transitionTime).attr("r", radiusFromNode); })
.call(
d3
Expand Down

0 comments on commit fc1f5a6

Please sign in to comment.