diff --git a/lib/findPaths.js b/lib/findPaths.js index 86422d3..e1b7beb 100644 --- a/lib/findPaths.js +++ b/lib/findPaths.js @@ -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 */ diff --git a/lib/labeledgraph.js b/lib/labeledgraph.js index 11eb277..dfe0b04 100644 --- a/lib/labeledgraph.js +++ b/lib/labeledgraph.js @@ -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()) }) diff --git a/lib/utils.js b/lib/utils.js index d9059b8..1b3b4d7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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" + + } +} diff --git a/pages/index.js b/pages/index.js index 2252ab9..7babf17 100644 --- a/pages/index.js +++ b/pages/index.js @@ -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" />
{`times as valuable as ...`}