tweaks: Id now alphabetical strings rather than numbers

This commit is contained in:
NunoSempere 2021-11-25 09:01:31 +00:00
parent 65b670c9d7
commit b40727c9df
4 changed files with 61 additions and 61 deletions

View File

@ -1,6 +1,6 @@
/* Imports*/ /* Imports*/
import React from "react"; import React from "react";
import { toLocale, truncateValueForDisplay } from "../lib/utils.js" import { toLocale, truncateValueForDisplay, numToAlphabeticalString } 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
@ -8,9 +8,9 @@ let formatLargeOrSmall = num => {
if(num > 1){ if(num > 1){
return toLocale(truncateValueForDisplay(num)) return toLocale(truncateValueForDisplay(num))
}else if(num > 0){ }else if(num > 0){
return num.toFixed(-Math.floor(Math.log(num)/Math.log(10))); return num.toFixed(-Math.floor(Math.log(num)/Math.log(10))+1);
}else if(num > -1){ }else if(num > -1){
return num.toFixed(-Math.floor(Math.log(-num)/Math.log(10))); return num.toFixed(-Math.floor(Math.log(-num)/Math.log(10))+1);
}else{ }else{
return toLocale(num)//return "~0" return toLocale(num)//return "~0"
@ -99,7 +99,7 @@ export function CreateTableWithDistances({isListOrdered, orderedList, listOfElem
} else { } else {
let nodes = orderedList.map(i => listOfElements[i]) let nodes = orderedList.map(i => listOfElements[i])
let distances = findDistancesForAllElements({nodes, links}) let distances = findDistancesForAllElements({nodes, links})
let rows = nodes.map((element, i) => ({id: element.id, name: element.name, distances: distances[i]})) let rows = nodes.map((element, i) => ({id: numToAlphabeticalString(element.id), name: element.name, distances: distances[i]}))
console.log("rows@CreateTableWithDistances") console.log("rows@CreateTableWithDistances")
console.log(rows) console.log(rows)
return( return(

View File

@ -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 } from "../lib/utils.js" import { toLocale, truncateValueForDisplay, numToAlphabeticalString } from "../lib/utils.js"
let getlength = (number) => number.toString().length; let getlength = (number) => number.toString().length;
@ -67,7 +67,7 @@ function drawGraphInner({nodes, links}){
.append("text") .append("text")
.attr("x", function (d) { return (x(d.id)) }) .attr("x", function (d) { return (x(d.id)) })
.attr("y", height - 10) .attr("y", height - 10)
.text(function(d){ return(d.id)}) .text(function (d) { return numToAlphabeticalString(d.id) })
.style("text-anchor", "middle") .style("text-anchor", "middle")
// Add the links // Add the links

View File

@ -20,12 +20,12 @@ export const _transformSliderValueToPracticalValue = value => truncateValueForDi
export function numToAlphabeticalString(num){ export function numToAlphabeticalString(num){
// https://stackoverflow.com/questions/45787459/convert-number-to-alphabet-string-javascript/45787487 // https://stackoverflow.com/questions/45787459/convert-number-to-alphabet-string-javascript/45787487
num=num+1
var s = '', t; var s = '', t;
while (num > 0) { while (num > 0) {
t = (num - 1) % 26; t = (num - 1) % 26;
s = String.fromCharCode(65 + t) + s; s = String.fromCharCode(65 + t) + s;
num = (num - t)/26 | 0; num = (num - t)/26 | 0;
} }
return s || undefined; return `#${s}` || undefined;
} }

View File

@ -221,9 +221,9 @@ export default function Home({ listOfElementsDefault }) {
} }
let nextStepSlider = ({ posList, binaryComparisons, sliderValue, element1, element2 }) => { let nextStepSlider = ({ posList, binaryComparisons, sliderValue, element1, element2 }) => {
if (sliderValue < 1) { if (sliderValue < 1 && sliderValue > 0) {
// sliderValue = -sliderValue; sliderValue = 1/sliderValue;
// [element1, element2] = [element2, element1] [element1, element2] = [element2, element1]
} }
console.log(`posList@nextStepSlider:`) console.log(`posList@nextStepSlider:`)
console.log(posList) console.log(posList)