Skip to content

Commit

Permalink
feat: add basic support for packinmg chart
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 8, 2021
1 parent 6dfb754 commit d69c249
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion web/public/js/graph/cloc/circle-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function renderPacking(originData) {
})
.on("click", (event, d) => focus !== d && (zoom(d), event.stopPropagation()))
.on("contextmenu", (event, d) => {
MenuSupport.createContextMenu(event, d, MenuSupport.defaultMenuItems, svg);
console.log(event, d);
MenuSupport.createContextMenu(event, d, MenuSupport.defaultMenuItems, svg, {
width: -width / 2,
height: -height / 2
});
event.stopPropagation();
})

Expand Down
14 changes: 9 additions & 5 deletions web/public/js/support/menu-support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let MenuHandle = {
copyText: function (text) {
let ta = document.createElement("textarea");
Expand All @@ -13,13 +12,18 @@ let MenuHandle = {
}

let MenuSupport = {
menuFactory: function (x, y, menuItems, data, svg) {
menuFactory: function (x, y, menuItems, data, svg, offsetOptions) {
d3.select(".contextMenu").remove();

// Draw the menu
svg.append('g')
.attr('class', "contextMenu")
.attr('transform', 'translate(0, 10)')
.attr('transform', function (d) {
if (!!offsetOptions && offsetOptions.width) {
return 'translate(' + offsetOptions.width + ',' + offsetOptions.height + ')'
}
return 'translate(0, 10)';
})
.selectAll('tmp')
.data(menuItems).enter()
.append('g').attr('class', "menuEntry")
Expand Down Expand Up @@ -60,8 +64,8 @@ let MenuSupport = {
d3.select(".contextMenu").remove();
});
},
createContextMenu: function (event, d, menuItems, svg) {
MenuSupport.menuFactory(event.layerX, event.layerY, menuItems, d, svg);
createContextMenu: function (event, d, menuItems, svg, offsetOptions) {
MenuSupport.menuFactory(event.layerX, event.layerY, menuItems, d, svg, offsetOptions);
event.preventDefault();
},
defaultMenuItems: [
Expand Down

0 comments on commit d69c249

Please sign in to comment.