-
Notifications
You must be signed in to change notification settings - Fork 0
/
elastic-list.min.js
2 lines (2 loc) · 5.51 KB
/
elastic-list.min.js
1
2
/*! elastic-list 2023-01-26 */
!function () { var a, b, c, d, e, f, g, h = ["name", "Affiliation at the time of award"], i = ["country", "gender", "year", "category", "city", "name"], j = {}, k = 25, l = 40, m = 35, n = "4px", o = !1; g = d3.select("#mytooltip").style("visibility", "hidden").style("background-color", "#333333"), i.forEach(function (a) { j[a] = {}, j[a].values = {}, j[a].filters = d3.set() }); var p = function (b, c) { console.log(c.length + " documents"), a = c, a.forEach(function (a) { a.__filtered__ = !0, i.forEach(function (b) { "" != a[b] && (a[b] in j[b].values ? j[b].values[a[b]]++ : j[b].values[a[b]] = 1) }) }), t() }, q = function (a, b) { if (j[a].filters.has(b) ? j[a].filters.remove(b) : j[a].filters.add(b), r()) { for (var c = [], d = 0; d < i.length; d++)c = c.concat(j[i[d]].filters.values()); d3.select(".elastic-list-filters").select("p").text("Filtering by: " + c.toString()) } else d3.select(".elastic-list-filters").select("p").text("No filters applied"); s() }, r = function () { for (var a = !1, b = 0; b < i.length && 0 == a; b++)a = a || !j[i[b]].filters.empty(); return a }, s = function () { i.forEach(function (a) { d3.keys(j[a].values).forEach(function (b) { j[a].values[b] = 0 }) }), r() ? a.forEach(function (a) { a.__filtered__ = !0; for (var b = 0; b < i.length && 1 == a.__filtered__; b++)j[i[b]].filters.empty() || (a.__filtered__ = a.__filtered__ && j[i[b]].filters.has(a[i[b]])); 1 == a.__filtered__ && i.forEach(function (b) { j[b].values[a[b]]++ }) }) : a.forEach(function (a) { a.__filtered__ = !0, i.forEach(function (b) { j[b].values[a[b]]++ }) }), v() }, t = function () { e = { top: 20, right: 20, bottom: 30, left: 40 }, width = 1170 - e.left - e.right, height = 400 - e.top - e.bottom + l, value_cell_padding = 1, value_cell_height = 37, d = d3.scale.ordinal().domain(i).rangeRoundBands([0, width]), c = d3.svg.axis().scale(d).orient("bottom"), b = d3.select("#elastic-list").attr("class", "elastic-list").style("width", width + "px").style("height", height + "px"), b.append("div").attr("class", "elastic-list-dimension-headers").selectAll(".elastic-list-dimension-header").data(i).enter().append("div").attr("class", "elastic-list-dimension-header").style("width", d.rangeBand() + "px").style("height", l + "px").text(function (a) { return a == h[0] ? h[1].capitalize() : a.capitalize() }), d3.select("#filtering").append("div").attr("class", "elastic-list-filters").style("height", k).append("p").text("No filters applied"), d3.select("#results").style("width", width + "px"), v() }, u = function (a, b) { var c = a.attributes.__minvalue__.value; return 0 == b.value ? n : value_cell_height + b.value / c + "px" }, v = function () { var c = 1e3, e = function (a, b) { return d3.min(d3.values(a.value.values).filter(function (a) { return a > 0 })) }, h = function (a, b) { return o ? d3.entries(a.value.values).sort(function (a, b) { return a.value > b.value ? -1 : a.value < b.value ? 1 : 0 }).filter(function (a) { return "" != a.key }) : d3.entries(a.value.values) }; f = b.selectAll(".elastic-list-dimension").data(d3.entries(j)), f.attr("__minvalue__", e), f.selectAll(".elastic-list-dimension-item").data(h).classed("filter", function (a) { return j[this.parentNode.__data__.key].filters.has(a.key) }).transition().duration(c).style("height", function (a) { return u(this.parentNode, a) }), f.enter().append("div").attr("class", "elastic-list-dimension").style("width", d.rangeBand() + "px").style("height", height - l + "px").attr("__minvalue__", e).selectAll(".elastic-list-dimension-item").data(h).enter().append("div").attr("class", "elastic-list-dimension-item").style("height", function (a) { return u(this.parentNode, a) }).style("width", d.rangeBand() + "px").style("left", 0).on("mouseover", function (a) { 0 == a.value ? g.html(a.key + ": no matchings").style("visibility", "visible") : d3.select(this).text().indexOf("...") > -1 && g.html(a.key + ": " + a.value).style("visibility", "visible"), d3.select(this).classed("elastic-list-dimension-item-hover", !0) }).on("mousemove", function (a) { (0 == a.value || d3.select(this).text().indexOf("...") > -1) && g.style("top", d3.event.pageY - 20 + "px").style("left", d3.event.pageX + 5 + "px") }).on("mouseout", function (a) { g.style("visibility", "hidden"), d3.select(this).classed("elastic-list-dimension-item-hover", !1) }).on("click", function (a) { g.style("visibility", "hidden"), q(this.parentNode.__data__.key, a.key), d3.select(this).classed("elastic-list-dimension-item-hover", !1), d3.select(this).classed("filter", function (a) { return j[this.parentNode.__data__.key].filters.has(a.key) }) }), items = b.selectAll(".elastic-list-dimension-item"), items.each(function (a, b) { d3.select(this).selectAll("p").remove(), a.value > 0 && (d3.select(this).append("p").html(a.key.length > m ? a.key.substring(0, m) + "..." : a.key).style("opacity", 0).attr("class", "key").transition().duration(c).delay(200).style("opacity", 1), d3.select(this).append("p").html("<b>" + a.value + "</b>").style("opacity", 0).attr("class", "value").transition().duration(c).delay(200).style("opacity", 1)) }); var i = ""; a.forEach(function (a) { a.__filtered__ && (i += "<p>" + a.year + " - <b>" + a.firstname + " " + a.surname + ". </b>" + a.category.capitalize() + ", " + a.country + "<span class='price-motivation'> " + a.motivation + "</span></p>") }), d3.select("#results").html(i), d3.select("#results-count").html("Found " + d3.select("#results").selectAll("p")[0].length) }; String.prototype.capitalize = function () { return this.charAt(0).toUpperCase() + this.slice(1) }, d3.csv("nobel_prizes.csv", o) }();