#49 feat: reemplazar cytoscape por vis-network con semantica de certeza en graficos de provenance
This commit is contained in:
45
src/components/provenance/provenance-vis.js
Normal file
45
src/components/provenance/provenance-vis.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Adapta el modelo de grafo de provenance ({ id, kind, label, image, entity }
|
||||
* y { from, to, certain }) al formato de vis-network, incluyendo la semántica
|
||||
* de certeza: arista cierta = sólida, arista dudosa = discontinua.
|
||||
*/
|
||||
|
||||
const COLORS = {
|
||||
product: '#26a69a',
|
||||
supplier: '#42a5f5',
|
||||
organization: '#ffb74d',
|
||||
municipality: '#66bb6a',
|
||||
department: '#5c6bc0',
|
||||
country: '#ab47bc',
|
||||
junction: '#78909c',
|
||||
}
|
||||
|
||||
export function toVisNodes (nodes) {
|
||||
return nodes.map(node => {
|
||||
const color = COLORS[node.kind] || '#cfd8dc'
|
||||
const { image, ...rest } = node
|
||||
if (node.kind === 'junction') {
|
||||
return { ...rest, shape: 'dot', color, size: 10, label: '' }
|
||||
}
|
||||
if (image) {
|
||||
return { ...rest, image, shape: 'circularImage', borderWidth: 2 }
|
||||
}
|
||||
return { ...rest, shape: 'dot', color, borderWidth: 2 }
|
||||
})
|
||||
}
|
||||
|
||||
export function toVisEdges (edges) {
|
||||
return edges.map(edge => ({
|
||||
from: edge.from,
|
||||
to: edge.to,
|
||||
dashes: !edge.certain,
|
||||
}))
|
||||
}
|
||||
|
||||
export const chartOptions = {
|
||||
nodes: { font: { size: 13, color: '#263238' } },
|
||||
edges: { color: { color: '#546e7a' } },
|
||||
physics: {
|
||||
barnesHut: { gravitationalConstant: -4000, springLength: 120, springConstant: 0.02 },
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user