Skip to content

Commit

Permalink
Sets rdfs:label as the visible node name, if label is availabe
Browse files Browse the repository at this point in the history
Ref: #4
  • Loading branch information
shreyasnagare committed Nov 22, 2020
1 parent 6184c4b commit 5bd019f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions brick-studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ $(function() {
.nodeLabel(node => {
if(node.show){
try{

return `${minifyIRI(node.type)} : ${node.id.split('#')[node.id.split('#').length - 1]} : ${node.out.length}`
let name = node.label != "undefined" ? node.label : node.id.split('#')[node.id.split('#').length - 1];
return `${minifyIRI(node.type)} : ${name} : ${node.out.length}`
}
catch (e) {
console.log('Invalid node ID: ', node.id)
Expand Down Expand Up @@ -360,7 +360,7 @@ $(function() {
ctx.strokeStyle = "#0006"
ctx.stroke();
};
const label = minifyIRI(node.id);
const label = node.label != "undefined" ? node.label : minifyIRI(node.id);
const fontSize = 15 / globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
const textWidth = ctx.measureText(label).width;
Expand Down
13 changes: 9 additions & 4 deletions rdf-studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,20 @@ const analyze = function(store = quadStore, storeIn = 'rdf', callback = preproce

const typoOfSubject = function(subject) {
const types = quadStore.getObjects(subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
var type = types.length ? types[0].id : 'undefined';
return type;
return types.length ? types[0].id : 'undefined';
};

const getType = memoize(typoOfSubject);

const getLabel = function(subject) {
const labels = quadStore.getObjects(subject, "http://www.w3.org/2000/01/rdf-schema#label");
return labels.length ? labels[0].id : 'undefined';
};

const preprocess = function(callback = draw) {
emitter.emit('preprocessing', {
status: 'start'
})
});
console.log('START: PREPROCESSING');
exportStore.addQuads(quadStore.getQuads());

Expand Down Expand Up @@ -351,7 +355,8 @@ const preprocess = function(callback = draw) {
show: false,
collapsed: true,
out: quadStore.getQuads(node).filter(quads=>quads.predicate.id!=='http://www.w3.org/1999/02/22-rdf-syntax-ns#type').map((quad)=>quad.object.id),
type: getType(node)
type: getType(node),
label: getLabel(node),
};
}))];
// var newData = {nodes:[], links:[]}
Expand Down

0 comments on commit 5bd019f

Please sign in to comment.