tweaks: Id now alphabetical strings rather than numbers
This commit is contained in:
parent
65b670c9d7
commit
b40727c9df
|
@ -1,6 +1,6 @@
|
|||
/* Imports*/
|
||||
import React from "react";
|
||||
import { toLocale, truncateValueForDisplay } from "../lib/utils.js"
|
||||
import { toLocale, truncateValueForDisplay, numToAlphabeticalString } from "../lib/utils.js"
|
||||
|
||||
/* Utilities */
|
||||
let avg = arr => arr.reduce((a,b) => (a+b)) / arr.length
|
||||
|
@ -8,9 +8,9 @@ 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)));
|
||||
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)));
|
||||
return num.toFixed(-Math.floor(Math.log(-num)/Math.log(10))+1);
|
||||
}else{
|
||||
return toLocale(num)//return "~0"
|
||||
|
||||
|
@ -99,7 +99,7 @@ export function CreateTableWithDistances({isListOrdered, orderedList, listOfElem
|
|||
} else {
|
||||
let nodes = orderedList.map(i => listOfElements[i])
|
||||
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)
|
||||
return(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
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;
|
||||
|
||||
|
@ -67,7 +67,7 @@ function drawGraphInner({nodes, links}){
|
|||
.append("text")
|
||||
.attr("x", function (d) { return (x(d.id)) })
|
||||
.attr("y", height - 10)
|
||||
.text(function(d){ return(d.id)})
|
||||
.text(function (d) { return numToAlphabeticalString(d.id) })
|
||||
.style("text-anchor", "middle")
|
||||
|
||||
// Add the links
|
||||
|
|
|
@ -20,12 +20,12 @@ export const _transformSliderValueToPracticalValue = value => truncateValueForDi
|
|||
|
||||
export function numToAlphabeticalString(num){
|
||||
// https://stackoverflow.com/questions/45787459/convert-number-to-alphabet-string-javascript/45787487
|
||||
num=num+1
|
||||
var s = '', t;
|
||||
|
||||
while (num > 0) {
|
||||
t = (num - 1) % 26;
|
||||
s = String.fromCharCode(65 + t) + s;
|
||||
num = (num - t)/26 | 0;
|
||||
}
|
||||
return s || undefined;
|
||||
return `#${s}` || undefined;
|
||||
}
|
||||
|
|
|
@ -221,9 +221,9 @@ export default function Home({ listOfElementsDefault }) {
|
|||
}
|
||||
|
||||
let nextStepSlider = ({ posList, binaryComparisons, sliderValue, element1, element2 }) => {
|
||||
if (sliderValue < 1) {
|
||||
// sliderValue = -sliderValue;
|
||||
// [element1, element2] = [element2, element1]
|
||||
if (sliderValue < 1 && sliderValue > 0) {
|
||||
sliderValue = 1/sliderValue;
|
||||
[element1, element2] = [element2, element1]
|
||||
}
|
||||
console.log(`posList@nextStepSlider:`)
|
||||
console.log(posList)
|
||||
|
|
Loading…
Reference in New Issue
Block a user