improved dpid canvas splay

This commit is contained in:
Taylor Hulsmans 2023-10-23 21:27:20 -04:00
parent 9eb96de689
commit ca2aaed66f
2 changed files with 101 additions and 8 deletions

View file

@ -7,6 +7,9 @@ import {
getNodeText getNodeText
} from '../utils/canvas-util' } from '../utils/canvas-util'
export const getDpid = async function () { export const getDpid = async function () {
console.log('this', this) console.log('this', this)
if (this.unloaded) return if (this.unloaded) return
@ -45,18 +48,105 @@ export const getDpid = async function () {
} }
) )
try { try {
const json = await requestUrl(`http://beta.dpid.org/${nodeText}?jsonld`) const res = await requestUrl(`http://beta.dpid.org/${nodeText}?jsonld`)
console.log('json: ', json) console.log(res.json)
const ipfsFetchNode = createNode(canvas, created, const metadata = res.json['@graph'].filter((leaf:any) => {
if (leaf['@id'] === './') {
return true
}
if (leaf['@id'] === 'ro-crate-metadata.json') {
return true
}
if (leaf['@type'] === 'person') {
return true
}
})
const metadataNode =createNode(canvas, created,
{ {
text: `${JSON.stringify(json)}`, text: `${JSON.stringify(
res.json['@graph'].find((leaf:any)=> {
return leaf['@id'] === 'ro-crate-metadata.json'
})
)}`,
size: { height: placeholderNoteHeight } size: { height: placeholderNoteHeight }
}, },
{ {
color: assistantColor, color: assistantColor,
chat_role: 'assistant' chat_role: 'assistant'
} },
{x: -400, y:0}
) )
const homeNode =createNode(canvas, created,
{
text: `${JSON.stringify(
res.json['@graph'].find((leaf:any)=> {
return leaf['@id'] === './'
})
)}`,
size: { height: placeholderNoteHeight }
},
{
color: assistantColor,
chat_role: 'assistant'
},
)
const rootNode =createNode(canvas, created,
{
text: `${JSON.stringify(
res.json['@graph'].find((leaf:any)=> {
return leaf['@id'] === './root'
})
)}`,
size: { height: placeholderNoteHeight }
},
{
color: assistantColor,
chat_role: 'assistant'
},
{x: 400, y:0}
)
res.json['@graph'].filter((leaf:any) => {
return leaf['@type'] === 'Person'
}).forEach((leaf:any, i) => {
const ipfsFetchNode = createNode(canvas, homeNode,
{
text: `${JSON.stringify(leaf)}`,
size: { height: placeholderNoteHeight }
},
{
color: assistantColor,
chat_role: 'assistant'
},
{x: 0, y:-100}
)
})
res.json['@graph'].filter((leaf:any) => {
if (leaf['@id'] === './root') return false
switch (leaf['@type']) {
case 'CreativeWork':
return true
case 'Dataset':
return true
case 'WebSite':
return true
default:
return false
}
}).forEach((leaf:any, i) => {
const ipfsFetchNode = createNode(canvas, rootNode,
{
text: `${JSON.stringify(leaf)}`,
size: { height: placeholderNoteHeight }
},
{
color: assistantColor,
chat_role: 'assistant'
},
{x: 0, y:-100}
)
})
} catch (e) { } catch (e) {
created.setText(`error :( ${e}`) created.setText(`error :( ${e}`)

View file

@ -109,8 +109,11 @@ export const createNode = (
canvas: Canvas, canvas: Canvas,
parentNode: CanvasNode, parentNode: CanvasNode,
nodeOptions: CreateNodeOptions, nodeOptions: CreateNodeOptions,
nodeData?: Partial<AllCanvasNodeData> nodeData?: Partial<AllCanvasNodeData>,
offset?: {x: number, y: number}
) => { ) => {
offset = offset ? offset : {x:0, y:0}
if (!canvas) { if (!canvas) {
throw new Error('Invalid arguments') throw new Error('Invalid arguments')
} }
@ -127,14 +130,14 @@ export const createNode = (
const priorSibling = siblings[siblings.length - 1] const priorSibling = siblings[siblings.length - 1]
// Position left at right of prior sibling, otherwise aligned with parent // Position left at right of prior sibling, otherwise aligned with parent
const x = siblingsRight ? siblingsRight + newNoteMargin : parentNode.x const x = siblingsRight ? siblingsRight + newNoteMargin : parentNode.x + offset.x
// Position top at prior sibling top, otherwise offset below parent // Position top at prior sibling top, otherwise offset below parent
const y = (priorSibling const y = (priorSibling
? priorSibling.y ? priorSibling.y
: (parentNode.y + parentNode.height + newNoteMargin)) : (parentNode.y + parentNode.height + newNoteMargin))
// Using position=left, y value is treated as vertical center // Using position=left, y value is treated as vertical center
+ height * 0.5 + height * 0.5 - offset.y
const newNode = canvas.createTextNode( const newNode = canvas.createTextNode(
{ {