fix: minor improvements
This commit is contained in:
parent
efbd28fcbf
commit
e3832ad202
|
@ -1,21 +1,9 @@
|
||||||
/* Imports*/
|
/* Imports*/
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { toLocale, truncateValueForDisplay, numToAlphabeticalString } from "../lib/utils.js"
|
import { toLocale, truncateValueForDisplay, numToAlphabeticalString, formatLargeOrSmall } from "../lib/utils.js"
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
let avg = arr => arr.reduce((a,b) => (a+b)) / arr.length
|
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 */
|
/* Main function */
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import * as d3 from 'd3';
|
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;
|
let getlength = (number) => number.toString().length;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function drawGraphInner({ nodes, links }) {
|
||||||
return height - 32 - (Math.abs(start - end) / 2)//height-30
|
return height - 32 - (Math.abs(start - end) / 2)//height-30
|
||||||
})
|
})
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
return Number(d.distance)
|
return formatLargeOrSmall(Number(d.distance))
|
||||||
return (truncateValueForDisplay(Number(d.distance)))
|
return (truncateValueForDisplay(Number(d.distance)))
|
||||||
//return(Number(d.distance).toPrecision(2).toString())
|
//return(Number(d.distance).toPrecision(2).toString())
|
||||||
})
|
})
|
||||||
|
|
13
lib/utils.js
13
lib/utils.js
|
@ -29,3 +29,16 @@ export function numToAlphabeticalString(num){
|
||||||
}
|
}
|
||||||
return `#${s}` || undefined;
|
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"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ export default function Home({ listOfElementsDefault }) {
|
||||||
//console.log(event.target.value)
|
//console.log(event.target.value)
|
||||||
setSliderValue(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 />
|
<br />
|
||||||
{`times as valuable as ...`}
|
{`times as valuable as ...`}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user