From d01eccb1cd890c45c2972826d7323c3fa1cbbca1 Mon Sep 17 00:00:00 2001 From: Martin Woodward Date: Wed, 16 Dec 2020 09:44:18 +0000 Subject: [PATCH] Adjust height distribution --- index.html | 2 +- js/STLExporter.js | 2 +- js/contributions.js | 22 ++++++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index d2877ba..e021f98 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@
- +
diff --git a/js/STLExporter.js b/js/STLExporter.js index 273dec7..1c658d7 100644 --- a/js/STLExporter.js +++ b/js/STLExporter.js @@ -33,7 +33,7 @@ STLExporter.prototype = { if ( object.isMesh ) { - var geometry = object.geometry; + var geometry = object.geometry; if ( geometry.isGeometry ) { diff --git a/js/contributions.js b/js/contributions.js index 52d9be2..055c67b 100644 --- a/js/contributions.js +++ b/js/contributions.js @@ -12,7 +12,7 @@ const MAX_HEIGHT = 0.14 const FACE_ANGLE = 104.79 let username = "nat" -let year = "2020" +let year = "" + (new Date()).getFullYear() let json = {} let font = undefined let fontSize = 0.025 @@ -35,7 +35,7 @@ if (urlParams.has('year')) { // Import JSON data async function loadJSON(username, year) { - let url = `https://json-contributions.vercel.app/api/user?username=${username}&year=${year}` + let url = `https://json-contributions-five.vercel.app/api/user?username=${username}&year=${year}` let response = await fetch(url) if (response.ok) { json = await response.json() @@ -194,14 +194,28 @@ const init = () => { // CONTRIBUTION BARS let barGroup = new THREE.Group() - let maxCount = json.max let x = 0 let y = 0 json.contributions.forEach(week => { y = (CUBE_SIZE * 7) week.days.forEach(day => { y -= CUBE_SIZE - let height = (MAX_HEIGHT / maxCount * day.count).toFixed(4) + + // Adjust height around distribution of values + // Needed so that a large day doesn't blow out the scale + let height = (0).toFixed(4) + if (day.count === json.min) + { + height = MAX_HEIGHT * 0.1 + } else if (day.count > json.min && day.count <= json.p90) + { + height = ((MAX_HEIGHT * 0.1) + (((MAX_HEIGHT * 0.8) / json.p90) * day.count)).toFixed(4) + } + else if (day.count > json.p90) + { + height = ((MAX_HEIGHT * 0.9) + (((MAX_HEIGHT * 0.1) / json.max) * day.count)).toFixed(4) + } + let geometry = new THREE.BoxGeometry(CUBE_SIZE, CUBE_SIZE, height) let cube = new THREE.Mesh(geometry, bronzeMaterial) cube.position.x = x