fix: minor improvements

This commit is contained in:
NunoSempere 2021-11-25 15:08:20 +00:00
parent efbd28fcbf
commit e3832ad202
4 changed files with 17 additions and 16 deletions

View File

@ -1,21 +1,9 @@
/* Imports*/
import React from "react";
import { toLocale, truncateValueForDisplay, numToAlphabeticalString } from "../lib/utils.js"
import { toLocale, truncateValueForDisplay, numToAlphabeticalString, formatLargeOrSmall } from "../lib/utils.js"
/* Utilities */
let avg = arr => arr.reduce((a,b) => (a+b)) / arr.length
let formatLargeOrSmall = num => {
if(num > 1){
return toLocale(truncateValueForDisplay(num))
}else if(num > 0){
return num.toFixed(-Math.floor(Math.log(num)/Math.log(10))+1);
}else if(num > -1){
return num.toFixed(-Math.floor(Math.log(-num)/Math.log(10))+1);
}else{
return toLocale(num)//return "~0"
}
}
/* Main function */

View File

@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
import * as d3 from 'd3';
import { toLocale, truncateValueForDisplay, numToAlphabeticalString } from "../lib/utils.js"
import { toLocale, truncateValueForDisplay, numToAlphabeticalString, formatLargeOrSmall } from "../lib/utils.js"
let getlength = (number) => number.toString().length;
@ -118,7 +118,7 @@ function drawGraphInner({ nodes, links }) {
return height - 32 - (Math.abs(start - end) / 2)//height-30
})
.text(function (d) {
return Number(d.distance)
return formatLargeOrSmall(Number(d.distance))
return (truncateValueForDisplay(Number(d.distance)))
//return(Number(d.distance).toPrecision(2).toString())
})

View File

@ -29,3 +29,16 @@ export function numToAlphabeticalString(num){
}
return `#${s}` || undefined;
}
export function formatLargeOrSmall (num) {
if(num > 1){
return toLocale(truncateValueForDisplay(num))
}else if(num > 0){
return num.toFixed(-Math.floor(Math.log(num)/Math.log(10))+1);
}else if(num < -1){
return num.toFixed(-Math.floor(Math.log(-num)/Math.log(10))+1);
}else{
return toLocale(num)//return "~0"
}
}

View File

@ -287,7 +287,7 @@ export default function Home({ listOfElementsDefault }) {
//console.log(event.target.value)
setSliderValue(event.target.value)
}}
className="text-center px-2 py-1 placeholder-blueGray-300 text-blueGray-600 relative bg-white bg-white rounded text-lg border-0 shadow outline-none focus:outline-none focus:ring w-8/12 m-2"
className="text-center px-2 py-1 placeholder-blueGray-300 text-blueGray-600 relative bg-white bg-white rounded text-lg border-0 shadow outline-none focus:outline-none focus:ring w-8/12 m-2 h-10"
/>
<br />
{`times as valuable as ...`}