Published
Edited
Apr 5, 2022
Insert cell
# Sankey diagram of citation flows (fork)
Insert cell
viewof timeseries = select({
title: "Timeseries or not",
description: "Please indicate whether you want it to be dynamic or not. If True, it will show year by year; if False, it will show the aggregated result.",
options: ["True", "False"],
value: "True"
})
Insert cell
// viewof timeseries = Inputs.select(['True', 'False'], {label: "Timeseries"})
Insert cell
viewof level = radio({
title: 'Level of concept',
// description: 'Please select your preferred contact method',
options: [
{ label: 'L0', value: '0' },
{ label: 'L1', value: '1' },
{ label: 'L2', value: '2' },
{ label: 'L3', value: '3' },
],
value: '1'
})
Insert cell
// viewof level = Inputs.radio(new Map([["L0", 0], ["L1", 1], ["L2", 2], ["L3", 3]]), {value: 1, label: "Level of concept"})
Insert cell
viewof source = radio({
title: 'Source of citations',
// description: 'Please select your preferred contact method',
options: [
{ label: 'Cited papers', value: 'REF' },
{ label: 'Citing papers', value: 'VIS' },
],
value: 'REF'
})
Insert cell
// viewof source = Inputs.radio(new Map([["Cited papers", "REF"], ["Citing papers", "VIS"]]), {value: "REF", label: "Source of citation"})
Insert cell
// viewof valuecutoff = Inputs.range([0, 500], {step: 1, label: "Appear at least n times", value: 100})
Insert cell
viewof rankCutoff = slider({
min: 1,
max: 150,
step: 1,
description: "Top N pairs",
value: 100,
})
Insert cell
// viewof rankCutoff = Inputs.range([1, 150], {step: 1, label: "Top N pairs :", value: 100})
Insert cell
viewof frameWidth = slider({
min: 400,
max: 800,
step: 10,
description: "Frame width",
value: 600,
})
Insert cell
// viewof frameWidth = Inputs.range([400, 800], {step: 10, label: "Frame width", value: 600})
Insert cell
// viewof timeseriesss = select({
// title: "Link color",
// options: [
// {label: "static", value: "#aaa"},
// {label: "source-target", value: "source-target"},
// {label: "source", value: "source"},
// {label: "target", value: "target"},
// ],
// value: "source"
// })
Insert cell
viewof linkColor = Inputs.select(new Map([
["static", "#aaa"],
["source-target", "source-target"],
["source", "source"],
["target", "target"],
]), {
value: new URLSearchParams(html`<a href>`.search).get("color") || "source",
label: "Link color"
})
Insert cell
viewof nodeAlign = Inputs.select(["left", "right", "center", "justify"], {
value: "justify",
label: "Node alignment"
})
Insert cell
Insert cell
Insert cell
Insert cell
displayText = source == "REF" ? "From cited paper to VIS" : "From VIS to citing papers"
Insert cell
fromWhere = md`<h2>${displayText}</h2>`
Insert cell
year = md`<h2>Year displayed: ${currYear}</h2>`
Insert cell
tsDisaplayText = timeseries === "True" ? "Below is time-series data:" : "Below is aggregated data for VIS 1990-2021:"

// tsDisaplayText = ts_or_not === "True" ? "Below is time-series data:" : "Below is aggregated data for VIS 1990-2021:"
Insert cell
tsDisplay = md`${tsDisaplayText}`
Insert cell
chartSankey = SankeyChart({
links: data
}, {
nodeGroup: d => d.id.split(/\W/)[0], // take first word for color
nodeAlign, // e.g., d3.sankeyJustify; set by input above
linkColor, // e.g., "source" or "target"; set by input above
format: (f => d => `${f(d)} citations`)(d3.format(",.1~f")),
width: `${frameWidth}`,
height: 600
})
Insert cell
// data = (ts_or_not === "True")? sankeyTS.filter(
// d => d.year == currYear && d['source name'] == source && d.level == level && d.value >= valuecutoff) :
// sankeyAggregated.filter(d => d['source name'] == source && d.level == level && d.value >= valuecutoff)
Insert cell
data = (timeseries === "True")? sankeyTS.filter(
d => d.year == currYear && d['source name'] == source && d.level == level && d.rank <= rankCutoff) :
sankeyAggregated.filter(d => d['source name'] == source && d.level == level && d.rank <= rankCutoff)

// data = (ts_or_not === "True")? sankeyTS.filter(
// d => d.year == currYear && d['source name'] == source && d.level == level && d.rank <= rankCutoff) :
// sankeyAggregated.filter(d => d['source name'] == source && d.level == level && d.rank <= rankCutoff)
Insert cell
sankeyTS = FileAttachment("sankey_ts_df.csv").csv()
Insert cell
sankeyAggregated = FileAttachment("sankey_aggregated_df.csv").csv()
Insert cell
Insert cell
// d3Sankey = require.alias({"d3-array": d3, "d3-shape": d3, "d3-sankey": "d3-sankey@0.12.3/dist/d3-sankey.min.js"})("d3-sankey")
Insert cell
d3Sankey = require("d3-sankey@0.12")
Insert cell
// import {select, radio, slider, checkbox} from "@jashkenas/inputs"
Insert cell
import {select} from "@jashkenas/inputs"
Insert cell
import {radio} from "@jashkenas/inputs"
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {swatches} from "@d3/color-legend"
Insert cell
import {rangeSlider as rangeSlider } from '@mootari/range-slider'
Insert cell
import {Scrubber} from "@mbostock/scrubber"
Insert cell
import {howto} from "@d3/example-components"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more