Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122052261
utils.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 15, 12:11
Size
5 KB
Mime Type
text/x-java
Expires
Thu, Jul 17, 12:11 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27399916
Attached To
R13029 webapp_nextjs
utils.js
View Options
'use client'
import * as d3 from "d3";
import {useRef} from "react";
function freeTextSearch(
searchTerm,
num_results = 30,
searchEntity = 'research',
callback,
conceptsOrVectors
) {
console.log("searchEntity", searchEntity)
let freeTextSearchURL;
if (conceptsOrVectors === 'concepts') {
// freeTextSearchURL = 'http://127.0.0.1:5000/concepts/submitAny';
freeTextSearchURL = 'https://expert-finder.epfl.ch//concepts/submitAny';
} else if (conceptsOrVectors === 'vectors') {
// freeTextSearchURL = 'http://127.0.0.1:5000/vectors/freeTextSearch';
freeTextSearchURL = 'https://expert-finder.epfl.ch//vectors/freeTextSearch';
} else {
//raise error
console.log("Error: conceptsOrVectors must be either 'concepts' or 'vectors', not ", conceptsOrVectors)
}
fetch(freeTextSearchURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: searchTerm,
num_results: num_results,
searchEntity: searchEntity
})
})
.then(response => response.json())
.then(callback)
.catch((error) => {
console.error('Error:', error);
});
}
export default freeTextSearch
export function getDataForCollab(
callback,
defineSizeOfNodes,
yearsSelected,
checkedPublicationTypes,
arrayLabInfoRef,
) {
console.log("getSimilarities");
// const similaritiesURL = 'http://127.0.0.1:5000/collaborations/similaritiesBetweenLabs'; // <-- Assuming this base URL
const similaritiesURL = 'https://expert-finder.epfl.ch//collaborations/similaritiesBetweenLabs'; // <-- Assuming this base URL
fetch(similaritiesURL, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
let localData = data;
let dicoLabInfo = localData['dicoLabInfo'];
let linksData = localData['links'];
let filteredData = {}
for (let lab in dicoLabInfo) {
if (dicoLabInfo[lab].details[0].level === 'lab' ||
dicoLabInfo[lab].details[0].level === 'institute' ||
dicoLabInfo[lab].details[0].level === 'school') {
filteredData[lab] = dicoLabInfo[lab]
}
}
let filteredData2 = {}
for (let lab in filteredData) {
if (lab === filteredData[lab].newName) {
filteredData2[lab] = filteredData[lab]
}
}
dicoLabInfo = filteredData2
for (let lab in dicoLabInfo) {
dicoLabInfo[lab].id = lab
}
let arrayLabInfo = Object.keys(dicoLabInfo).map(function (key) {
return dicoLabInfo[key];
});
defineSizeOfNodes(
arrayLabInfo,
yearsSelected,
checkedPublicationTypes
);
arrayLabInfo.forEach(function (d) {
if (d.embedding2D === null) {
console.log('failed d', d)
}
d.x = d.embedding2D[0] * 50;
d.y = d.embedding2D[1] * 50;
});
let linksDataFiltered = []
for (let i = 0; i < linksData.length; i++) {
if (linksData[i].source in dicoLabInfo && linksData[i].target in dicoLabInfo) {
linksDataFiltered.push(linksData[i])
}
}
linksData = linksDataFiltered
// ... Rest of the data processing ...
arrayLabInfoRef.current = arrayLabInfo
console.log("arrayLabInfoRef.current", arrayLabInfoRef.current)
callback(linksData); // Assuming this is what you want to pass back
})
.catch(error => {
console.error("error", error);
});
}
export function wrap(text, width) {
text.each(function () {
var gnodeParent = d3.select(this.parentNode);
// console.log("gnodeParent", gnodeParent)
var gnodeParentData = gnodeParent._groups[0][0].__data__;
// console.log("gnodeParentData", gnodeParentData)
var text = d3.select(this),
words = text.text().split(" ").reverse(),
nwords = words.length,
word,
line = [],
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = -(nwords + 1 / 2) * lineHeight / 2, //parseFloat(text.attr("dy")),
tspan = text.text(null)
.append("tspan")
.attr("x", x)
.attr("y", y)
.attr("dy", dy + "em");
while (word = words.pop()) {
// console.log("word", word)
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
// create a span with d3
tspan = text.append("tspan")
.text(word)
.attr("font-weight", "bold")
.attr("font-size", parseInt(gnodeParentData.size / 3) + "px")
.attr("dx", function () {
return -this.getComputedTextLength() / 2
})
.attr("x", 0)
.attr("y", 0)
.attr("dy", ++lineNumber * lineHeight + dy + "em");
}
}
});
}
Event Timeline
Log In to Comment