Published
Edited
Mar 10, 2022
Insert cell
# Phantom vs. Vandal 2022 Challengers
Insert cell
havenRegionData = {
let margin = {
top:110,
right: 40,
bottom: 60,
left: 95
}
let spacing = 5
let barScale = d3.scaleLinear()
.domain([0, 1])
.range([0,963-margin.left])
let textSize = d3.scaleLinear()
.domain([10, 3])
.range([26,48])
let textY = d3.scaleLinear()
.domain([3, 10])
.range([57,42])
let svg = d3.create('svg').style("background-color", 'white').attr("preserveAspectRatio", "none")
.attr("viewBox", "0 0 963 460")
svg.append("text")
.attr("class", "signature")
.attr("text-anchor", "left")
.attr("y", 2)
.attr("x", 0)
.attr("dy", ".75em")
.attr('style', "font-size: 14px; font-family: 'Bebas Neue';")
.text("Author: Sam Rosenberg");


svg.append("image")
.attr("xlink:href", "https://greblytics.com/wp-content/uploads/2021/03/cropped-Grebnesor-Analytics-SK_JRD-01.png")
.attr("x", 853)
.attr("y", 0)
.attr("width", 100)
.attr("height", 50);
var text2 = svg.append("svg:text").attr("class", "title")
.attr("text-anchor", "middle")
.attr("y", 53)
.attr("x", 963/2)
.attr('style', "font-size: 45px; font-family: 'Bebas Neue';").attr("fill", valred);
;
text2.append("svg:tspan").style("fill", "black").text("Recent Gun Choices: ");
text2.append("svg:tspan").style("fill", valblue).text('Phantom');

text2.append("svg:tspan").style("fill", "black").text(" or ");
text2.append("svg:tspan").style("fill", valred).text('Vandal');
var text3 = svg.append("svg:text").attr("class", "title")
.attr("text-anchor", "middle")
.attr("y", 60).attr("dy", "1em")
.attr("x", 963/2)
.attr('style', "font-size: 20px; font-family: 'Bebas Neue';").attr("fill", 'black').text("Percentages are of guns used across all rounds.");
var text4 = svg.append("svg:text").attr("class", "title")
.attr("text-anchor", "middle")
.attr("y", 60).attr("dy", "1em")
.attr("x", 963/2)
.attr('style', "font-size: 20px; font-family: 'Bebas Neue';").attr("fill", 'black');
text4.append("svg:tspan").attr("dy", "2em").style("fill", "black").text("While only the phantom and vandal are listed, people played rounds with other guns.");
//vandal back
svg.selectAll("vandal")
.data(regionGunData)
.join('rect')
.attr("x", margin.left)
.attr("y", function(d, i) {return margin.top + 55*i+spacing*i})
.attr("width", function(d, i) {return barScale(1)})
.attr("height", 50)
.attr("fill", valred);
//adding phantom
svg.selectAll("phantom")
.data(regionGunData)
.join('rect')
.attr("x", margin.left)
.attr("y", function(d, i) {return margin.top + 55*i+spacing*i})
.attr("width", function(d, i) {return barScale(d.find(g => g.Weapon === "Phantom")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))})
.attr("height", 50)
.attr("fill", valblue);
svg.selectAll("percentphan")
.data(regionGunData)
.join('text')
.attr("x", d => barScale(d.find(g => g.Weapon === "Phantom")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))/2 + margin.left)
.attr("y", function(d, i) {return margin.top + 55*i+45+spacing*i-1}).attr("fill", 'black').call(addWebFont, 'Bebas Neue', 'https://fonts.gstatic.com/s/bebasneue/v2/JTUSjIg69CK48gW7PXoo9WlhyyTh89Y.woff2').attr('style', "font-size: "+50+"px; font-family: 'Bebas Neue';").attr("text-anchor", "middle").attr("fill", 'white')
.text(d =>((d.find(g => g.Weapon === "Phantom")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))*100).toFixed(0)+"%");
svg.selectAll("percentvan")
.data(regionGunData)
.join('text')
.attr("x", d => barScale(d.find(g => g.Weapon === "Phantom")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))+ + margin.left + barScale(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))/2)
.attr("y", function(d, i) {return margin.top + 55*i+45+spacing*i-2}).attr("fill", 'black').call(addWebFont, 'Bebas Neue', 'https://fonts.gstatic.com/s/bebasneue/v2/JTUSjIg69CK48gW7PXoo9WlhyyTh89Y.woff2').attr('style', "font-size: "+50+"px; font-family: 'Bebas Neue';").attr("text-anchor", "middle").attr("fill", 'white')
.text(d =>((d.find(g => g.Weapon === "Vandal")["Pick Percentage"]/(Number(d.find(g => g.Weapon === "Vandal")["Pick Percentage"]) + Number(d.find(g => g.Weapon === "Phantom")["Pick Percentage"])))*100).toFixed(0)+"%");
svg.selectAll("regions")
.data(regionGunData)
.join('text')
.attr("x", margin.left-3)
.attr("y", function(d, i) {return margin.top + 55*i+textY(d.find(g => g.Weapon === "Phantom")["region"].length)+spacing*i})
.text(d => d.find(g => g.Weapon === "Phantom")["region"])
.attr("fill", 'black').call(addWebFont, 'Bebas Neue', 'https://fonts.gstatic.com/s/bebasneue/v2/JTUSjIg69CK48gW7PXoo9WlhyyTh89Y.woff2').attr('style', d => "font-size: "+textSize(d.find(g => g.Weapon === "Phantom")["region"].length)+"px; font-family: 'Bebas Neue';").attr("text-anchor", "end").attr("alignment-baseline", "ideographic");
//https://media.valorant-api.com/weapons/ee8e8d15-496b-07ac-e5f6-8fae5d4c7b1a/displayicon.png
//"https://media.valorant-api.com/weapons/9c82e19d-4575-0200-1a81-3eacf00cf872/displayicon.png"
svg.append("image")
.attr("xlink:href", "https://media.valorant-api.com/weapons/ee8e8d15-496b-07ac-e5f6-8fae5d4c7b1a/displayicon.png")
.attr("x", 0)
.attr("y", 30)
.attr("width", 150)
.attr("height", margin.top);
svg.append("image")
.attr("xlink:href", "https://media.valorant-api.com/weapons/9c82e19d-4575-0200-1a81-3eacf00cf872/displayicon.png")
.attr("x", 963-150)
.attr("y",30)
.attr("width", 150)
.attr("height", margin.top);
return svg.node();
}
Insert cell
function comparePhantom(a, b) {
console.log(a)
if (a.find(g => g.Weapon === "Phantom")["Pick Percentage"] > b.find(g => g.Weapon === "Phantom")["Pick Percentage"]) {
return 1;
}
if (a.find(g => g.Weapon === "Phantom")["Pick Percentage"] <= b.find(g => g.Weapon === "Phantom")) {
return -1;
}
}
Insert cell
regionGunData = regionGunDatapre.slice(1,7)
Insert cell
regionGunDatapre.sort(comparePhantom).unshift(regionGunDatapre[7]);
Insert cell
objects = fetch("https://valorant-api.com/v1/weapons")
.then(response => {
return response.json();
})
Insert cell
valblue = '#609faa';
Insert cell
valred = '#e83a49';
Insert cell
regionGunDatapre = {
return [gunsNA.map( x => {
x.region = "N. America"
return x
}), gunsEU.map( x => {
x.region = "Europe"
return x
}), gunsBR.map( x => {
x.region = "Brazil"
return x
}), gunsTR.map( x => {
x.region = "Turkey"
return x
}), gunsJP.map( x => {
x.region = "Japan"
return x
}), gunsKR.map( x => {
x.region = "Korea"
return x
})]
}
Insert cell
gunsNA = d3.csvParse(await FileAttachment("gundNA.csv").text())
Insert cell
gunsEU = d3.csvParse(await FileAttachment("gundEU.csv").text())
Insert cell
gunsTR = d3.csvParse(await FileAttachment("gundTR.csv").text())
Insert cell
gunsKR = d3.csvParse(await FileAttachment("gundKR.csv").text())
Insert cell
gunsJP = d3.csvParse(await FileAttachment("gundJP.csv").text())
Insert cell
gunsBR = d3.csvParse(await FileAttachment("gundBR.csv").text())
Insert cell
gunsNAFull = gunsNA.map( x => {
x.region = "NA"
return x
})

Insert cell
async function toDataURL(url) {
return new Promise(async(resolve, reject) => {
const res = await fetch(url);
if(!res.ok) return reject(`Error: ${res.status} ${res.statusText}`);
const blob = await res.blob();
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => resolve(reader.result);
});
}
Insert cell
async function addWebFont(selection, fontName, fontURL, fontType = 'woff2') {
const fontData = await toDataURL(fontURL);
return selection.append('style').text(`
@font-face {
font-family: '${fontName}';
src: url(${fontData}) format('${fontType}');
}
`);
};
Insert cell
d3 = require('d3@v6')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more