Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Add onNodeClick callback function #40

Merged
merged 2 commits into from
Aug 5, 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
3 changes: 2 additions & 1 deletion dist/esm/happi-graph.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ class HappiGraph extends React.Component {
})
}, () => {
const { zoom } = this.state;
const { onNodeClick } = this.props;
svg
.call(zoom)
.on('dblclick.zoom', null);
addNodes(nodes, nodesGroup, graphDirection);
addNodes(nodes, nodesGroup, graphDirection, onNodeClick);
addLinks(links, linksGroup, graphDirection, nodes);
centerGraph(allGroup, svg, zoom);
});
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/happi-graph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const addHeader = (nodeGroup) => {
.classed('label', true)
.text((d) => d.label);
};
const addNodes = (nodes, nodesGroup, graphDirection) => {
const addNodes = (nodes, nodesGroup, graphDirection, onNodeClick) => {
let _nodesGroup = nodesGroup
.selectAll()
.data(nodes)
Expand All @@ -163,7 +163,7 @@ const addNodes = (nodes, nodesGroup, graphDirection) => {
.append('g')
.classed('node-group', true)
.attr('id', (d) => d.id)
.on('click', () => { console.log('CLICKED'); })
.on('click', (d) => { onNodeClick ? onNodeClick(d.target.__data__) : console.log('ON_NODE_CLICK_NOT_IMPLEMENTED'); })
.attr('transform', (d) => `translate(${d.x}, ${d.y})`)
.call(d3.drag()
.on('start', (d) => {
Expand Down
1 change: 1 addition & 0 deletions dist/types/happi-graph.component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface Props {
actions: any;
algorithm?: string;
selectedNodeId: string;
onNodeClick?: Function;
rawData: any;
debug?: boolean;
graphDirection?: string;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/happi-graph.render.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { iconsMap, linksTypeIconMap, itemGroupIconMap } from "egeria-js-commons"
export declare const simpleSquareIcon = "<svg width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M0 0H20V20H0V0Z\" fill=\"white\"/></svg>";
export declare const addProperties: (nodeGroup: any) => void;
export declare const addIcon: (nodeGroup: any, iconsMap: any) => void;
declare const addNodes: (nodes: any, nodesGroup: any, graphDirection: string) => void;
declare const addNodes: (nodes: any, nodesGroup: any, graphDirection: string, onNodeClick?: Function) => void;
declare const centerGraph: (allGroup: any, svg: any, zoom: any) => void;
declare const customZoom: (value: number, zoom: any, svg: any) => void;
declare const customZoomIn: (zoom: any, svg: any) => void;
Expand Down
3 changes: 2 additions & 1 deletion src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function App() {
debug={false}
graphDirection={"VERTICAL"}
selectedNodeId={"term@68e36496-7167-4af7-abdd-a0cd36e24084:6662c0f2.e1b1ec6c.66k78i6du.uchsna1.rn2epa.rfn2fjqf7h4qvmt5lflm8"}
actions={<HappiGraphActions rawData={{...rawData}}/>} />
actions={<HappiGraphActions rawData={{...rawData}}/>}
onNodeClick={(d: any) => console.log(d)} />
</div>
</>;
}
4 changes: 3 additions & 1 deletion src/components/HappiGraph/happi-graph.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Props {
actions: any;
algorithm?: string;
selectedNodeId: string;
onNodeClick?: Function;
rawData: any;
debug?: boolean;
graphDirection?: string;
Expand Down Expand Up @@ -188,12 +189,13 @@ class HappiGraph extends React.Component<Props, State> {
})
}, () => {
const { zoom } = this.state;
const { onNodeClick } = this.props;

svg
.call(zoom)
.on('dblclick.zoom', null);

addNodes(nodes, nodesGroup, graphDirection);
addNodes(nodes, nodesGroup, graphDirection, onNodeClick);
addLinks(links, linksGroup, graphDirection, nodes);

centerGraph(allGroup, svg, zoom);
Expand Down
4 changes: 2 additions & 2 deletions src/components/HappiGraph/happi-graph.render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const addHeader = (nodeGroup: any) => {
.text((d: any) => d.label);
};

const addNodes = (nodes: any, nodesGroup: any, graphDirection: string) => {
const addNodes = (nodes: any, nodesGroup: any, graphDirection: string, onNodeClick?: Function) => {
let _nodesGroup: any = nodesGroup
.selectAll()
.data(nodes)
Expand All @@ -208,7 +208,7 @@ const addNodes = (nodes: any, nodesGroup: any, graphDirection: string) => {
.append('g')
.classed('node-group', true)
.attr('id', (d: any) => d.id)
.on('click', () => { console.log('CLICKED'); })
.on('click', (d: any) => { onNodeClick ? onNodeClick(d.target.__data__) : console.log('ON_NODE_CLICK_NOT_IMPLEMENTED'); })
.attr('transform', (d: any) => `translate(${d.x}, ${d.y})`)
.call(
d3.drag()
Expand Down