Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] Show element info on hover #130 #131

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/netjsongraph.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/css/netjsongraph.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ body {
font-weight: bold;
text-align: center;
}

.njg-tooltip {
background: rgba(251, 251, 251, 0.9) !important;
border: none !important;
}
54 changes: 37 additions & 17 deletions src/js/netjsongraph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,43 @@ class NetJSONGraphRender {
const commonOption = self.utils.deepMergeObj(
{
// Show element's detail when hover
//
// tooltip: {
// confine: true,
// formatter: params => {
// if (params.componentSubType === "graph") {
// return params.dataType === "edge"
// ? self.utils.linkInfo(params.data)
// : self.utils.nodeInfo(params.data);
// } else if (params.componentSubType === "graphGL") {
// return self.utils.nodeInfo(params.data);
// } else {
// return params.componentSubType === "lines"
// ? self.utils.linkInfo(params.data.link)
// : self.utils.nodeInfo(params.data.node);
// }
// }
// }

tooltip: {
confine: true,
position: (pos, params, dom, rect, size) => {
let position = "right";
if (size.viewSize[0] - pos[0] < size.contentSize[0]) {
position = "left";
}
if (params.componentSubType === "lines") {
position = [
pos[0] + size.contentSize[0] / 8,
pos[1] - size.contentSize[1] / 2,
];

if (size.viewSize[0] - position[0] < size.contentSize[0]) {
position[0] -= 1.25 * size.contentSize[0];
}
}
return position;
},
padding: [5, 16],
renderMode: "html",
className: "njg-tooltip",
formatter: (params) => {
if (params.componentSubType === "graph") {
return params.dataType === "edge"
? self.utils.linkInfo(params.data)
: self.utils.nodeInfo(params.data);
}
if (params.componentSubType === "graphGL") {
return self.utils.nodeInfo(params.data);
}
return params.componentSubType === "lines"
? self.utils.linkInfo(params.data.link)
: self.utils.nodeInfo(params.data.node);
},
},
},
configs.echartsOption,
);
Expand Down