feat: Show squiggle function on the graph

This commit is contained in:
NunoSempere 2022-01-31 17:30:26 -05:00
parent 21fbab054c
commit bf400502e5
3 changed files with 22 additions and 11 deletions

View File

@ -22,12 +22,15 @@ const estimatedMergeSortSteps = conservativeNumMergeSortSteps; // pander to huma
/* Misc. helpers */ /* Misc. helpers */
let buildLinks = (quantitativeComparisons) => let buildLinks = (quantitativeComparisons) =>
quantitativeComparisons.map(([element1, element2, distance, reasoning]) => ({ quantitativeComparisons.map(
source: element1, ([element1, element2, distance, reasoning, squiggleString]) => ({
target: element2, source: element1,
distance: distance, target: element2,
reasoning: reasoning, distance: distance,
})); reasoning: reasoning,
squiggleString: squiggleString,
})
);
Array.prototype.containsArray = function (val) { Array.prototype.containsArray = function (val) {
var hash = {}; var hash = {};

View File

@ -288,7 +288,7 @@ export function CreateTable({ tableRows }) {
return result; return result;
} }
return ( return (
<div> <div className="w-full">
<table className="w-full"> <table className="w-full">
<thead> <thead>
<tr> <tr>

View File

@ -7,7 +7,7 @@ import {
formatLargeOrSmall, formatLargeOrSmall,
} from "./utils.js"; } from "./utils.js";
const displayWidthPercentage = 0.85; // 0.7 const displayWidthPercentage = 0.7; // 0.85; // 0.7
let getlength = (number) => number.toString().length; let getlength = (number) => number.toString().length;
@ -29,7 +29,7 @@ function drawGraphInner({ nodes, links }) {
// let width = 900 - margin.left - margin.right; // let width = 900 - margin.left - margin.right;
let initialWindowWidth = window.innerWidth; let initialWindowWidth = window.innerWidth;
let margin = { top: 0, right: 10, bottom: 30, left: 10 }; let margin = { top: 0, right: 10, bottom: 20, left: 10 };
let width = let width =
initialWindowWidth * displayWidthPercentage - margin.left - margin.right; initialWindowWidth * displayWidthPercentage - margin.left - margin.right;
@ -142,10 +142,16 @@ function drawGraphInner({ nodes, links }) {
// X position of start node on the X axis // X position of start node on the X axis
let end = x(d.target); let end = x(d.target);
// X position of end node // X position of end node
return height - 32 - Math.abs(start - end) / 2; //height-30 return height - 36 - Math.abs(start - end) / 2; //height-30
}) })
.text(function (d) { .text(function (d) {
return formatLargeOrSmall(Number(d.distance)); let distanceFormatted = formatLargeOrSmall(Number(d.distance));
if (d.distance == d.squiggleString || !d.squiggleString) {
return distanceFormatted;
} else {
return `${d.squiggleString}${distanceFormatted}`;
}
// return (truncateValueForDisplay(Number(d.distance))) // return (truncateValueForDisplay(Number(d.distance)))
//return(Number(d.distance).toPrecision(2).toString()) //return(Number(d.distance).toPrecision(2).toString())
}) })
@ -158,6 +164,8 @@ export function DrawGraph({
listOfElements, listOfElements,
links, links,
}) { }) {
console.log("LINKS:");
console.log(links);
if (isListOrdered) { if (isListOrdered) {
let nodes = orderedList.map((id, pos) => ({ let nodes = orderedList.map((id, pos) => ({
...listOfElements[id], ...listOfElements[id],