diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 60eeda2..9ed7765 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -7,6 +7,7 @@ import { DisplayElement } from './displayElement' import { DisplayAsMarkdown } from './displayAsMarkdown' import { CreateTable, buildRows } from './findPaths' import { DataSetChanger } from "./datasetChanger" +import { ComparisonsChanger } from "./comparisonsChanger" import { pushToMongo } from "./pushToMongo.js" import { increasingList, maxMergeSortSteps, expectedNumMergeSortSteps } from "./utils.js" @@ -51,6 +52,7 @@ export default function ComparisonView({ listOfElementsForView }) { let initialOrderedList = [] let initialShowAdvancedOptions = false let initialShowComparisons = false + let initialShowLoadComparisons = false let initialShowChangeDataSet = false let initialNumSteps = 0; let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length) @@ -73,6 +75,7 @@ export default function ComparisonView({ listOfElementsForView }) { let [showAdvancedOptions, changeShowAdvanceOptions] = useState(initialShowAdvancedOptions); let [showComparisons, changeShowComparisons] = useState(initialShowComparisons); + let [showLoadComparisons, changeShowLoadComparisons] = useState(initialShowLoadComparisons); let [showChangeDataSet, changeshowChangeDataSet] = useState(initialShowChangeDataSet); let [numSteps, changeNumSteps] = useState(initialNumSteps); let [maxSteps, changeMaxSteps] = useState(initialMaxSteps) @@ -80,11 +83,11 @@ export default function ComparisonView({ listOfElementsForView }) { let [tableRows, setTableRows] = useState(initialTableRows) /* Convenience utils: restart + changeDataSet */ - let restart = (posList) => { + let restart = (posList) => {//({posList, initialBinaryComparisons2, initialQuantitativeComparisons2}) => { setToComparePair([posList[posList.length - 2], posList[posList.length - 1]]) setSliderValue(initialSliderValue) - setBinaryComparisons(initialBinaryComparisons) - setQuantitativeComparisons(initialQuantitativeComparisons) + setBinaryComparisons(initialBinaryComparisons2 || initialBinaryComparisons) + setQuantitativeComparisons(initialQuantitativeComparisons2 || initialQuantitativeComparisons) setIsListOrdered(initialIsListOdered) setOrderedList(initialOrderedList) changeNumSteps(initialNumSteps) @@ -107,6 +110,28 @@ export default function ComparisonView({ listOfElementsForView }) { changeMaxSteps(maxMergeSortSteps(newListLength)) restart(newPosList) + // restart({posList: newPosList}) + } + + let changeComparisons = (links, listOfElements) => { + let quantitativeComparisons2 = [] + let binaryComparisons2 = [] + for(let link of links){ + let {source, target, distance, reasoning} = link + let searchByName = (name, candidate) => candidate.name == name + let testForSource = (candidate) => searchByName(source, candidate) + let testForTarget = (candidate) => searchByName(target, candidate) + let element1 = listOfElements.findIndex(testForSource) + let element2 = listOfElements.findIndex(testForTarget) + if(element1 == -1 || element2 == -1){ + throw new Error("Comparisons include unknown elements, please retry") + } + quantitativeComparisons2.push([element1, element2, distance, reasoning]) + binaryComparisons2.push([element1,element2]) + } + // return ({quantitativeComparisons: quantitativeComparisons2, binaryComparisons: binaryComparisons2}) + //restart({posList, initialBinaryComparisons2=initialBinaryComparisons, initialQuantitativeComparisons2=initialQuantitativeComparisons}) + restart(posList) } // Manipulations @@ -377,23 +402,32 @@ export default function ComparisonView({ listOfElementsForView }) {