diff --git a/apiv1/serializers.py b/apiv1/serializers.py index 86f121f..2c4e08d 100644 --- a/apiv1/serializers.py +++ b/apiv1/serializers.py @@ -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 diff --git a/frontend/src/components/Graph.jsx b/frontend/src/components/Graph.jsx index 6bce589..595eb5f 100644 --- a/frontend/src/components/Graph.jsx +++ b/frontend/src/components/Graph.jsx @@ -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 (