Skip to content

Commit

Permalink
onNodeClick
Browse files Browse the repository at this point in the history
  • Loading branch information
evc29 committed Jul 31, 2024
1 parent dc0901b commit e5e4051
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/Graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Graph: React.FC<GraphProps> = ({
legendEdgeLabel,
order,
fontFamily = 'Arial',
onNodeClick,
}) => {
const cyRef = useRef<Core | null>(null);

Expand Down Expand Up @@ -363,6 +364,15 @@ const Graph: React.FC<GraphProps> = ({
content.style.fontFamily = fontFamily;
const tip = popperFactory(ref, content, {});
node.on('mouseover', () => tip.show());
if (onNodeClick) {
const c = {
accession: node.style('label'),
start: 0,
end: 0,
chromosome: '',
};
node.on('click', onNodeClick(c));
}
node.on('mouseout', () => tip.hide());
});

Expand Down
1 change: 1 addition & 0 deletions src/components/Graph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Edge {
legendEdgeLabel?: string,
order?: string[],
fontFamily?: string,
onNodeClick?: (n: { accession: string; start: number; end: number; chromosome: string }) => any,
}


Expand Down
6 changes: 6 additions & 0 deletions stories/Graph.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ SampleGraph.args = {
getColor: setColor3,
legendToggle: convertToSimple2,
order: ['P', 'R', 'B'],
onNodeClick: (n: {
accession: string;
start: number;
end: number;
chromosome: string;
}) => console.log('Accession: ' + n.accession),
};
export const PilotDataWithCentered = Template.bind({});
PilotDataWithCentered.args = {
Expand Down

0 comments on commit e5e4051

Please sign in to comment.