Skip to content

Commit

Permalink
add leaf node click function
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-zqwang committed Oct 20, 2024
1 parent 28a5a43 commit c6ec02c
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions static/js/taxonomy_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function buildHierarchy(data) {
}
childNode = {
name: levelName,
originalName: levelName.replace(/\s+/g, '_'), // Store original name
children: [],
color: i === 0 ? baseColor : lightenColor(baseColor, (i) * 8)
};
Expand Down Expand Up @@ -265,24 +266,40 @@ function createChart(hierarchicalData) {

}

// function setupLeafNodeClick(series) {
// series.slices.template.events.on("click", function(ev) {
// var dataItem = ev.target.dataItem;
// if (dataItem && dataItem.get("children").length === 0) {
// // This is a leaf node
// window.open("", "_blank"); // probably add link to each task (an html page)
// }
// });

// // Change cursor to pointer for leaf nodes
// series.slices.template.adapters.add("cursorOverStyle", function(cursorOverStyle, target) {
// var dataItem = target.dataItem;
// if (dataItem && dataItem.get("children").length === 0) {
// return "pointer";
// }
// return cursorOverStyle;
// });
// }
function setupLeafNodeClick(series) {
series.slices.template.events.on("click", function(ev) {
var dataItem = ev.target.dataItem;
if (dataItem && dataItem.get("children").length === 0) {
// This is a leaf node
var path = buildPath(dataItem);

// @TODO: Jiacheng; change to the actual url
var url = `https://github.com/woodfrog/megabench-eval-mock/tree/master/taxonomy_example/${path}`;
window.open(url, "_blank");
}
});

// Change cursor to pointer for leaf nodes
series.slices.template.adapters.add("cursorOverStyle", function(cursorOverStyle, target) {
var dataItem = target.dataItem;
if (dataItem && dataItem.get("children").length === 0) {
return "pointer";
}
return cursorOverStyle;
});
}

function buildPath(dataItem) {
var path = [];
var currentItem = dataItem;

while (currentItem && currentItem.get("depth") > 0) {
path.unshift(currentItem.dataContext.originalName || currentItem.get("category"));
currentItem = currentItem.get("parent");
}

return path.join('/');
}


function customBreakWords(text, maxLength) {
Expand Down

0 comments on commit c6ec02c

Please sign in to comment.