Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
#26 | Implemented render edges
Browse files Browse the repository at this point in the history
  • Loading branch information
GerwinBosch committed Oct 31, 2017
1 parent 5245ce2 commit 9a42e87
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/DataClassifyDialog.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/forbid-prop-types */
import React, { Component } from 'react';
import {
Dialog, DropDownMenu, FlatButton, IconButton, MenuItem, Step,
Expand Down Expand Up @@ -209,7 +210,7 @@ class DataClassifyDialog extends Component {
}
DataClassifyDialog.propTypes = {
open: PropTypes.bool.isRequired,
data: PropTypes.arrayOf(PropTypes.object).isRequired,
data: PropTypes.object.isRequired,
closeCallBack: PropTypes.func.isRequired,
finishCallBack: PropTypes.func.isRequired,
};
Expand Down
2 changes: 2 additions & 0 deletions src/DataLinkDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DataLinkDialog extends Component {
r: 30,
type: 'emptyEdge',
title: name,
label: name,
link: result.uri,
vocabPrefix: result.vocabPrefix,
prefix: result.prefix,
Expand Down Expand Up @@ -105,6 +106,7 @@ class DataLinkDialog extends Component {
});
};


renderDialogTableBody() {
if (!this.state.lovAvailable) {
return (<TextField
Expand Down
27 changes: 27 additions & 0 deletions src/DataLinkView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Divider from 'material-ui/Divider';
import PropTypes from 'prop-types';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import Info from 'material-ui/svg-icons/action/info-outline';
import * as d3 from 'd3';
import DataLinkDialog from './DataLinkDialog';

function doNothing() {
Expand Down Expand Up @@ -258,6 +259,31 @@ class DataLinkView extends Component {
});
this.forceUpdate();
};
// eslint-disable-next-line class-methods-use-this
renderEdge(graphView, domNode, datum) {
// For new edges, add necessary child domNodes
if (!domNode.hasChildNodes()) {
d3.select(domNode).append('path');
d3.select(domNode).append('use');
d3.select(domNode).append('text');
}

const style = graphView.getEdgeStyle(datum, graphView.props.selected);
const trans = graphView.getEdgeHandleTransformation(datum);
d3.select(domNode).attr('style', style).select('use').attr('xlink:href', d => graphView.props.edgeTypes[d.type].shapeId)
.attr('width', graphView.props.edgeHandleSize)
.attr('height', graphView.props.edgeHandleSize)
.attr('transform', trans);

d3.select(domNode).select('path').attr('d', graphView.getPathDescription);
if (datum.label) {
d3.select(domNode).select('text').attr('class', 'barsEndlineText')
.attr('text-anchor', 'middle')
.attr('transform', trans)
.text(datum.label);
}
}


renderGraph() {
const nodes = this.props.nodes;
Expand Down Expand Up @@ -296,6 +322,7 @@ class DataLinkView extends Component {
onDeleteEdge={this.onDeleteEdge}
onDeleteNode={doNothing}
onCreateNode={doNothing}
renderEdge={this.renderEdge}
/>
);
}
Expand Down
38 changes: 37 additions & 1 deletion src/TripleVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GraphView from 'react-digraph';
import { green500 } from 'material-ui/styles/colors';
import { Card, CardHeader, CardText } from 'material-ui/Card';
import Paper from 'material-ui/Paper';
import * as d3 from 'd3';
import { distribute } from './dataprocessing';

const GraphConfig = {
Expand Down Expand Up @@ -77,7 +78,6 @@ class TripleVisualizer extends React.Component {

};
}

componentWillReceiveProps(nextProps) {
if (nextProps !== this.props) {
this.dataToNodes(nextProps.data);
Expand Down Expand Up @@ -213,10 +213,13 @@ class TripleVisualizer extends React.Component {
nodes.push(endNode);
}
}
const delimiter = relation.classification.indexOf('#') !== -1 ? '#' : '/';
edges.push({
source: startNode.id,
target: endNode.id,
label: relation.classification,
title: relation.classification.substring(
relation.classification.lastIndexOf(delimiter) + 1, relation.classification.length),
type: 'emptyEdge',
});
});
Expand Down Expand Up @@ -261,9 +264,12 @@ class TripleVisualizer extends React.Component {
};
nodes.push(object);
}
const delimiter = ontology[1].value.indexOf('#') !== -1 ? '#' : '/';
edges.push({
source: subject.id,
target: object.id,
title: ontology[1].value.substring(
ontology[1].value.lastIndexOf(delimiter) + 1, ontology[1].value.length),
label: ontology[1].value,
type: 'emptyEdge',
});
Expand All @@ -273,6 +279,34 @@ class TripleVisualizer extends React.Component {
this.setState({ nodes, edges });
};
doNothing = () => {};
// {source: 0, target: 1, label: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", type: "emptyEdge"}
// eslint-disable-next-line class-methods-use-this
renderEdge(graphView, domNode, datum) {
// For new edges, add necessary child domNodes
if (!domNode.hasChildNodes()) {
d3.select(domNode).append('path');
d3.select(domNode).append('use');
d3.select(domNode).append('text');
}

const style = graphView.getEdgeStyle(datum, graphView.props.selected);
const trans = graphView.getEdgeHandleTransformation(datum);
d3.select(domNode).attr('style', style).select('use').attr('xlink:href', d => graphView.props.edgeTypes[d.type].shapeId)
.attr('width', graphView.props.edgeHandleSize)
.attr('height', graphView.props.edgeHandleSize)
.attr('transform', trans);

d3.select(domNode).select('path').attr('d', graphView.getPathDescription);
if (datum.label) {
d3.select(domNode).select('text').attr('class', 'barsEndlineText')
.attr('text-anchor', 'middle')
.attr('transform', trans)
.attr('font-size', '12px')
.text(datum.title);
}
}


renderCard = () => {
let cardText = '';
let title = '';
Expand Down Expand Up @@ -397,6 +431,7 @@ class TripleVisualizer extends React.Component {
onDeleteEdge={this.doNothing}
onDeleteNode={this.doNothing}
onCreateNode={this.doNothing}
renderEdge={this.renderEdge}
/>
{this.renderCard()}

Expand Down Expand Up @@ -429,6 +464,7 @@ class TripleVisualizer extends React.Component {
onDeleteEdge={this.doNothing}
onDeleteNode={this.doNothing}
onCreateNode={this.doNothing}
renderEdge={this.renderEdge}
/>
{this.renderClassCard()}

Expand Down

0 comments on commit 9a42e87

Please sign in to comment.