-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59601ff
commit 878cc84
Showing
13 changed files
with
214 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useRef, useEffect } from 'react'; | ||
|
||
import { useContext } from '../../hooks/useContext'; | ||
import { brush as d3Brush } from 'd3-brush'; | ||
import { select } from 'd3-selection'; | ||
interface IBrushProps { | ||
onSelectNodes: (e: any) => void; | ||
} | ||
|
||
const Brush: React.FunctionComponent<IBrushProps> = props => { | ||
const { onSelectNodes } = props; | ||
const { id, store } = useContext(); | ||
const { graph, height, width, data } = store; | ||
const svgRef = useRef(null); | ||
const selectedNodesRef = useRef([]); | ||
|
||
useEffect(() => { | ||
if (svgRef.current) { | ||
const handleBrush = selection => { | ||
if (!selection) return; | ||
|
||
const [[x0, y0], [x1, y1]] = selection; | ||
const newSelectedNodes = data.nodes.filter(node => { | ||
//@ts-ignore | ||
const { x, y, z } = graph?.graph2ScreenCoords(node.x, node.y, 0); | ||
return x0 <= x && x <= x1 && y0 <= y && y <= y1; | ||
}); | ||
console.log(newSelectedNodes); | ||
}; | ||
const svg = select(svgRef.current); | ||
const brush = d3Brush() | ||
.extent([ | ||
[0, 0], | ||
[width, height], | ||
]) | ||
.on('start', () => { | ||
selectedNodesRef.current = []; | ||
}) | ||
.on('brush', event => handleBrush(event.selection)) | ||
.on('end', () => onSelectNodes(selectedNodesRef.current)); | ||
|
||
svg.selectAll('g.brush').remove(); // Remove any existing brush group | ||
svg | ||
.append('g') | ||
.attr('class', 'brush') | ||
.call(brush) | ||
.append('rect') | ||
.attr('width', width) | ||
.attr('height', height) | ||
.attr('fill', 'none') | ||
.attr('pointer-events', 'all'); | ||
|
||
svg.style('pointer-events', 'none'); | ||
} | ||
}, [width, height, onSelectNodes]); | ||
|
||
return <svg ref={svgRef} width={width} height={height} style={{ position: 'absolute', top: '0px' }}></svg>; | ||
}; | ||
|
||
export default Brush; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/studio-graph/src/components/ContextMenu/CommonNeighbor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as React from 'react'; | ||
import { Typography, Button, Menu } from 'antd'; | ||
import { useContext } from '../../../hooks/useContext'; | ||
import { Utils } from '@graphscope/studio-components'; | ||
import { getDataMap } from '../../Prepare/utils'; | ||
|
||
interface INeighborQueryProps { | ||
onQuery: (params: any) => Promise<any>; | ||
} | ||
|
||
const CommonNeighbor: React.FunctionComponent<INeighborQueryProps> = props => { | ||
const { onQuery } = props; | ||
const { store, updateStore } = useContext(); | ||
const { nodeStatus, schema, dataMap, emitter } = store; | ||
|
||
const selectId = | ||
Object.keys(nodeStatus).filter(key => { | ||
return nodeStatus[key].selected; | ||
})[0] || ''; | ||
const selectNode = dataMap[selectId] || {}; | ||
|
||
const relatedEdges = schema.edges.filter(item => { | ||
return item.source === selectNode.label; | ||
}); | ||
const itemChildren = relatedEdges.map(item => { | ||
const { source, target, label } = item; | ||
if (source === target) { | ||
return { | ||
key: `(a:${source})-[b:${label}]-(c:${target})`, | ||
label: `[${label}]-(${target})`, | ||
}; | ||
} | ||
return { | ||
key: `(a:${source})-[b:${label}]->(c:${target})`, | ||
label: `[${label}]->(${target})`, | ||
}; | ||
}); | ||
|
||
const items = [ | ||
{ | ||
key: 'CommonNeighbor', | ||
// icon: <ShareAltOutlined />, | ||
label: 'CommonNeighbor', | ||
children: itemChildren, | ||
}, | ||
]; | ||
|
||
const onClick = async ({ key }) => { | ||
const { name, title } = selectNode.properties; | ||
let script = ''; | ||
if (name) { | ||
script = ` | ||
MATCH ${key} | ||
WHERE a.name = "${name}" | ||
RETURN a, b, c | ||
`; | ||
} | ||
if (title) { | ||
script = ` | ||
MATCH ${key} | ||
WHERE a.title = "${title}" | ||
RETURN a, b, c | ||
`; | ||
} | ||
|
||
console.log(script); | ||
/** | ||
* | ||
* | ||
* MATCH (p1:Paper)<-[c1:Cite]-(p2:Paper) | ||
WHERE p1.title = 'Parallel Subgraph Listing in a Large-Scale Graph' | ||
RETURN p1, c1, p2 | ||
*/ | ||
const res = await onQuery({ | ||
script, | ||
language: 'cypher', | ||
}); | ||
console.log(res); | ||
if (res.nodes.length > 0) { | ||
updateStore(draft => { | ||
draft.data = Utils.handleExpand(draft.data, res); | ||
draft.dataMap = getDataMap(draft.data); | ||
}); | ||
} | ||
emitter?.emit('canvas:click'); | ||
}; | ||
return ( | ||
<Menu onClick={onClick} style={{ margin: '0px', padding: '0px', width: '103%' }} mode="vertical" items={items} /> | ||
); | ||
}; | ||
|
||
export default CommonNeighbor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.