fix: graph display
This commit is contained in:
parent
9b32fec522
commit
7d47a76d21
|
@ -1,7 +1,9 @@
|
||||||
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"
|
||||||
|
|
||||||
let getlength = (number) => number.toString().length;
|
let getlength = (number) => number.toString().length;
|
||||||
|
|
||||||
export function removeOldSvg(){
|
export function removeOldSvg(){
|
||||||
d3.select("#graph").select("svg").remove();
|
d3.select("#graph").select("svg").remove();
|
||||||
}
|
}
|
||||||
|
@ -106,7 +108,7 @@ 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 start + (end-start)/2 -4*getlength(d.distance)
|
return start + (end-start)/2 //-4*getlength(d.distance)
|
||||||
})
|
})
|
||||||
.attr("y", function(d){
|
.attr("y", function(d){
|
||||||
let start = x(d.source)
|
let start = x(d.source)
|
||||||
|
@ -115,8 +117,11 @@ function drawGraphInner({nodes, links}){
|
||||||
// X position of end node
|
// X position of end node
|
||||||
return height-32-(Math.abs(start-end)/2)//height-30
|
return height-32-(Math.abs(start-end)/2)//height-30
|
||||||
})
|
})
|
||||||
.text(function(d){ return(`${d.distance}`)})
|
.text(function(d){
|
||||||
.style("text-anchor", "top")
|
return(truncateValueForDisplay(Number(d.distance)))
|
||||||
|
//return(Number(d.distance).toPrecision(2).toString())
|
||||||
|
})
|
||||||
|
.style("text-anchor", "middle")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DrawGraph({isListOrdered, orderedList, listOfElements, links}) {
|
export function DrawGraph({isListOrdered, orderedList, listOfElements, links}) {
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
import crypto from "crypto"
|
import crypto from "crypto"
|
||||||
|
|
||||||
export const hashString = (string) => crypto.createHash('md5').update(string).digest('hex');
|
export const hashString = (string) => crypto.createHash('md5').update(string).digest('hex');
|
||||||
|
|
||||||
|
export const transformSliderValueToActualValue = value => 10 ** value //>= 2 ? Math.round(10 ** value) : Math.round(10 * 10 ** value) / 10
|
||||||
|
export const toLocale = x => Number(x).toLocaleString()
|
||||||
|
export const truncateValueForDisplay = value => value > 10 ? Number(Math.round(value).toPrecision(2)) : Math.round(value * 10) / 10
|
||||||
|
export const transformSliderValueToPracticalValue = value => truncateValueForDisplay(transformSliderValueToActualValue(value))
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { DisplayAsMarkdown } from '../lib/displayAsMarkdown'
|
||||||
import { CreateTableWithDistances } from '../lib/findPaths'
|
import { CreateTableWithDistances } from '../lib/findPaths'
|
||||||
import { TextAreaForJson } from "../lib/textAreaForJson"
|
import { TextAreaForJson } from "../lib/textAreaForJson"
|
||||||
import { pushToMongo } from "../lib/pushToMongo.js"
|
import { pushToMongo } from "../lib/pushToMongo.js"
|
||||||
|
import { toLocale, transformSliderValueToPracticalValue } from "../lib/utils.js"
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
let increasingList = (n) => Array.from(Array(n).keys())
|
let increasingList = (n) => Array.from(Array(n).keys())
|
||||||
|
@ -36,11 +37,6 @@ let checkIfListIsOrdered = (arr, binaryComparisons) => {
|
||||||
return isOrdered
|
return isOrdered
|
||||||
}
|
}
|
||||||
|
|
||||||
let transformSliderValueToActualValue = value => 10 ** value //>= 2 ? Math.round(10 ** value) : Math.round(10 * 10 ** value) / 10
|
|
||||||
let toLocale = x => Number(x).toLocaleString()
|
|
||||||
let truncateValueForDisplay = value => value > 10 ? Number(Math.round(value)).toPrecision(2) : Math.round(value * 10) / 10
|
|
||||||
let transformSliderValueToPracticalValue = value => truncateValueForDisplay(transformSliderValueToActualValue(value))
|
|
||||||
|
|
||||||
let displayFunctionSlider = (value) => {
|
let displayFunctionSlider = (value) => {
|
||||||
let result
|
let result
|
||||||
if (value >= 0) {
|
if (value >= 0) {
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Categorizing Variants of Goodhart's Law",
|
"name": "Categorizing Variants of Goodhart's Law",
|
||||||
"url": "https://arxiv.org/abs/1803.04585",
|
"url": "https://arxiv.org/abs/1803.04585"
|
||||||
"isReferenceValue": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "The Vulnerable World Hypothesis",
|
"name": "The Vulnerable World Hypothesis",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user