fix node sizing for instances of size 1

This commit is contained in:
Tao Bojlen 2018-09-05 17:55:43 +02:00
parent e2e32cf29e
commit c8ab3f3810
2 changed files with 12 additions and 3 deletions

View File

@ -87,7 +87,7 @@ class NodeSerializer(serializers.ModelSerializer):
return obj.name
def get_size(self, obj):
return math.log(obj.user_count) if obj.user_count else 1
return math.log(obj.user_count) if (obj.user_count and (obj.user_count > 1)) else 1
def get_x(self, obj):
return obj.x_coord

View File

@ -27,12 +27,21 @@ const SETTINGS = {
class GraphImpl extends React.Component {
render() {
if (!this.props.graph) {
let graph = this.props.graph;
if (!graph) {
// TODO: error state
return null;
}
// Check that all nodes have size & coordinates; otherwise the graph will look messed up
const lengthBeforeFilter = graph.nodes.length;
graph = {...graph, nodes: graph.nodes.filter(n => n.size && n.x && n.y)};
if (graph.nodes.length !== lengthBeforeFilter) {
// tslint:disable-next-line:no-console
console.error("Some nodes were missing details: " + this.props.graph.nodes.filter(n => !n.size || !n.x || !n.y).map(n => n.label));
}
return (
<Sigma
graph={this.props.graph}
graph={graph}
renderer="webgl"
settings={SETTINGS}
style={STYLE}