Your can try with https://kineviz.github.io/graphxr-iframe-example/ at first
Please refer the https://kineviz.github.io/graphxr-iframe-example/graphXR.injection.js in tag at first
<script src='graphXR.injection.js'></script>
iframeElem is a iframe dom element.
let iframeElem = document.getElementById("injection-graphXR-iframe-id");
Embed iframe
<iframe id="injection-graphXR-iframe-id" origin="*" > </iframe>
yarn && yarn start
then add graphXR share link as iframe embedGraphURL. You can change defaultEmbedGraphURL in index.html line 116
http://localhost:3000?embedGraphURL=https://graphxrdev.kineviz.com/p/602d2b0787329b003351adee/blank/6033b824378ffc0034884a58/IP-TEST
Please sure the graphXR iframe already load, please refer 3.1
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive graphData:", resData.content)
})
graphXR.injectionApiCommand(':getGraphStat', iframeElem)
.then((resData) => {
console.warn("Receive graphStat:", resData.content)
})
graphXR.injectionApiCommand(':clearGraph', iframeElem)
.then((resData) => {
console.warn("Receive clearGraph:", resData.content)
})
graphXR.injectionApiCommand(':selected', iframeElem)
.then((resData) => {
console.warn("Receive selected data:", resData.content)
})
graphXR.injectionApiCommand(':nearby', iframeElem)
.then((resData) => {
console.warn("Receive nearby data:", resData.content)
})
graphXR.injectionApiCommand('MATCH (n)-[r]-(m) RETURN * LIMIT 100', iframeElem)
.then((resData) => {
console.warn("Receive query data:", resData.content)
})
If you do not want node append to graphXR, please set ignoreAppend as true
graphXR.injectionApiCommand('MATCH (n)-[r]-(m) RETURN * LIMIT 100', iframeElem,{ignoreAppend:true})
.then((resData) => {
console.warn("Receive query data:", resData.content)
})
Please sure the graphXR iframe already load, please refer 3.1
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive all data:", resData.content)
const {nodes, edges} = resData.content;
//update twinkled
let colors =['green','yellow','red',null]
let topNode10 = (nodes ||[]).slice(0,10).map((n,i) =>{
//will can auto update the props to the node
let otherProps ={_index:i}
return{
id: n._GXRID,
rate: i%4+1,
//Must set stat as a string value
stat:"warning",
color: colors[i%4],//color is null, mean rest to bak
...otherProps
}
})
let ignoreTwinkled = true; // skip clear old twinkled
graphXR.injectionApiFunc(
"updateTwinkled",
{ nodes: topNode10, ignoreTwinkled },
iframeElem
);
})
//clear twinkled
let ignoreTwinkled = false;
graphXR.injectionApiFunc(
"updateTwinkled",
{ nodes: [], ignoreTwinkled },
iframeElem
);
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive all data:", resData.content)
const {nodes, edges} = resData.content;
let flyToNode = nodes[0];
if(!flyToNode){
return
}
graphXR.injectionApiFunc(
"flyTo",
flyToNode._GXRID,
iframeElem
);
})
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive all data:", resData.content)
const {nodes} = resData.content;
//Select all nodes
graphXR.injectionApiFunc(
"selectWithNodeIds",
{ nodeIds: nodes.map(n => n._GXRID) },
iframeElem
);
})
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive all data:", resData.content)
const {nodes, edges} = resData.content;
// highlightWithNodeIds
let top10NodeIds = (nodes ||[]).slice(0,10).map((n,i) =>{
return n._GXRID
})
graphXR.injectionApiFunc(
"highlightWithNodeIds",
{ nodeIds: top10NodeIds, nodeOnly:false },
iframeElem
);
})
graphXR.injectionApiCommand(':getGraph', iframeElem)
.then((resData) => {
console.warn("Receive all data:", resData.content)
const {nodes, edges} = resData.content;
// highlightWithEdgeIds
let top10EdgeIds = (edges ||[]).slice(0,10).map((e,i) =>{
return e._GXRID
})
graphXR.injectionApiFunc(
"highlightWithEdgeIds",
{ edgeIds: top10EdgeIds, edgeOnly:false },
iframeElem
);
})
let _GXRID = 9999999999;
graphXR.injectionApiFunc(
"getNodeWithId",
_GXRID,
iframeElem
).then( res =>{
console.warn("Got Node:", res.content)
})
//find the node where name = 'Sean'
graphXR.injectionApiFunc(
"getNodeWithProps",
{name:"Sean"},
iframeElem
).then( res =>{
console.warn("Got Node:", res.content)
})
You can use load event sure the GraphXR iframe already loaded
graphXR.injectionOn("load", (eventName, res) => {
if(res === 'init'){
console.warn("GraphXR iframe already load", res)
}else{
console.warn("GraphXR Load the view ", res)
}
}, iframeElem, "iframe-unique-name")
graphXR.injectionOn("change", () => {
console.warn("receive change event");
// Please use :getGraph got all data
// graphXR.injectionApiCommand(':getGraph', iframeElem)
// .then((resData) => {
// console.warn("Receive graphData:", resData.content)
// })
}, iframeElem, "iframe-unique-name")
graphXR.injectionOn("select", () => {
console.warn("receive select event")
//please use :selected got all selected nodes
graphXR.injectionApiCommand(':selected', iframeElem)
.then((resData) => {
console.warn("Receive selected:", resData.content)
})
}, iframeElem, "iframe-unique-name")
graphXR.injectionOn("nearby", (eventName, res) => {
console.warn("receive nearby nodes", res)
}, iframeElem, "iframe-unique-name")
InjectionCode is beta function, so do not recommand use it. Please sure the graphXR iframe already load, please refer 3.1
Support force, line, grid, circle, cube
force Layout e.g.
graphXR.injectionCode(`
_app.controller.API.setLayout("force")
` , iframeElem).then(resData => {
console.warn("use force success:", resData)
})
circle Layout e.g.
graphXR.injectionCode(`
_app.controller.API.setLayout("circle")
` , iframeElem).then(resData => {
console.warn("use circle success:", resData)
})