in packages/graph-explorer/src/modules/GraphViewer/renderNode.tsx [10:46]
export async function renderNode(
vtConfig: VertexIconConfig
): Promise<string | undefined> {
if (!vtConfig.iconUrl) {
return;
}
if (vtConfig.iconImageType !== "image/svg+xml") {
return vtConfig.iconUrl;
}
// To avoid multiple requests, cache icons under the same URL
if (ICONS_CACHE.get(vtConfig.iconUrl)) {
return ICONS_CACHE.get(vtConfig.iconUrl);
}
try {
const response = await fetch(vtConfig.iconUrl);
let iconText = await response.text();
iconText = updateSize(iconText);
iconText = embedSvgInsideCytoscapeSvgWrapper(iconText);
iconText = applyCurrentColor(iconText, vtConfig.color || "#128EE5");
iconText = encodeSvg(iconText);
// Save to the cache
ICONS_CACHE.set(vtConfig.iconUrl, iconText);
return iconText;
} catch (error) {
// Ignore the error and move on
console.error(
`Failed to fetch the icon data for vertex ${vtConfig.type}`,
error
);
return;
}
}