fix node sizing for instances of size 1
This commit is contained in:
parent
e2e32cf29e
commit
c8ab3f3810
|
@ -87,7 +87,7 @@ class NodeSerializer(serializers.ModelSerializer):
|
||||||
return obj.name
|
return obj.name
|
||||||
|
|
||||||
def get_size(self, obj):
|
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):
|
def get_x(self, obj):
|
||||||
return obj.x_coord
|
return obj.x_coord
|
||||||
|
|
|
@ -27,12 +27,21 @@ const SETTINGS = {
|
||||||
class GraphImpl extends React.Component {
|
class GraphImpl extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.props.graph) {
|
let graph = this.props.graph;
|
||||||
|
if (!graph) {
|
||||||
|
// TODO: error state
|
||||||
return null;
|
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 (
|
return (
|
||||||
<Sigma
|
<Sigma
|
||||||
graph={this.props.graph}
|
graph={graph}
|
||||||
renderer="webgl"
|
renderer="webgl"
|
||||||
settings={SETTINGS}
|
settings={SETTINGS}
|
||||||
style={STYLE}
|
style={STYLE}
|
||||||
|
|
Loading…
Reference in a new issue