1
0
mirror of https://github.com/taigrr/skyline synced 2025-01-18 04:33:13 -08:00

Adjust height distribution

This commit is contained in:
Martin Woodward 2020-12-16 09:44:18 +00:00
parent 3fbb8dc96c
commit d01eccb1cd
3 changed files with 20 additions and 6 deletions

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<div id="info"> <div id="info">
<button id="exportASCII">export ASCII</button> <button id="exportBinary">export binary</button> <button id="exportASCII">export ASCII</button> <button id="exportBinary">export STL</button>
</div> </div>
<script type="module" src="js/contributions.js"></script> <script type="module" src="js/contributions.js"></script>

View File

@ -12,7 +12,7 @@ const MAX_HEIGHT = 0.14
const FACE_ANGLE = 104.79 const FACE_ANGLE = 104.79
let username = "nat" let username = "nat"
let year = "2020" let year = "" + (new Date()).getFullYear()
let json = {} let json = {}
let font = undefined let font = undefined
let fontSize = 0.025 let fontSize = 0.025
@ -35,7 +35,7 @@ if (urlParams.has('year')) {
// Import JSON data // Import JSON data
async function loadJSON(username, year) { 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) let response = await fetch(url)
if (response.ok) { if (response.ok) {
json = await response.json() json = await response.json()
@ -194,14 +194,28 @@ const init = () => {
// CONTRIBUTION BARS // CONTRIBUTION BARS
let barGroup = new THREE.Group() let barGroup = new THREE.Group()
let maxCount = json.max
let x = 0 let x = 0
let y = 0 let y = 0
json.contributions.forEach(week => { json.contributions.forEach(week => {
y = (CUBE_SIZE * 7) y = (CUBE_SIZE * 7)
week.days.forEach(day => { week.days.forEach(day => {
y -= CUBE_SIZE 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 geometry = new THREE.BoxGeometry(CUBE_SIZE, CUBE_SIZE, height)
let cube = new THREE.Mesh(geometry, bronzeMaterial) let cube = new THREE.Mesh(geometry, bronzeMaterial)
cube.position.x = x cube.position.x = x