mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
feat: add organisation relationships to network
This commit is contained in:
@@ -36,3 +36,16 @@ class RelationshipSerializer(serializers.ModelSerializer):
|
|||||||
'source',
|
'source',
|
||||||
'target',
|
'target',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class OrganisationRelationshipSerializer(serializers.ModelSerializer):
|
||||||
|
source = PersonSerializer()
|
||||||
|
target = OrganisationSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.OrganisationRelationship
|
||||||
|
fields = [
|
||||||
|
'pk',
|
||||||
|
'source',
|
||||||
|
'target',
|
||||||
|
]
|
||||||
|
|||||||
@@ -103,6 +103,26 @@ function get_network() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load organisation relationships and add to graph
|
||||||
|
relationship_set = JSON.parse(document.getElementById('organisation-relationship-set-data').textContent);
|
||||||
|
|
||||||
|
for (var relationship of relationship_set) {
|
||||||
|
console.log(relationship)
|
||||||
|
try {
|
||||||
|
cy.add({
|
||||||
|
group: 'edges',
|
||||||
|
data: {
|
||||||
|
id: 'organisation-relationship-' + relationship.pk.toString(),
|
||||||
|
source: 'person-' + relationship.source.pk.toString(),
|
||||||
|
target: 'organisation-' + relationship.target.pk.toString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
// Exception thrown if a node in the relationship does not exist
|
||||||
|
// This is probably because it's been filtered out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Optimise graph layout
|
// Optimise graph layout
|
||||||
var layout = cy.layout({
|
var layout = cy.layout({
|
||||||
name: 'cose',
|
name: 'cose',
|
||||||
|
|||||||
@@ -77,6 +77,8 @@
|
|||||||
|
|
||||||
{{ relationship_set|json_script:'relationship-set-data' }}
|
{{ relationship_set|json_script:'relationship-set-data' }}
|
||||||
|
|
||||||
|
{{ organisation_relationship_set|json_script:'organisation-relationship-set-data' }}
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.14.0/cytoscape.min.js"
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.14.0/cytoscape.min.js"
|
||||||
integrity="sha256-rI7zH7xDqO306nxvXUw9gqkeBpvvmddDdlXJjJM7rEM="
|
integrity="sha256-rI7zH7xDqO306nxvXUw9gqkeBpvvmddDdlXJjJM7rEM="
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ class NetworkView(LoginRequiredMixin, TemplateView):
|
|||||||
filter_relationships(all_forms['relationship'], relationship_at_date),
|
filter_relationships(all_forms['relationship'], relationship_at_date),
|
||||||
many=True).data
|
many=True).data
|
||||||
|
|
||||||
|
context['organisation_relationship_set'] = serializers.OrganisationRelationshipSerializer(
|
||||||
|
models.OrganisationRelationship.objects.all(), many=True
|
||||||
|
).data
|
||||||
|
|
||||||
logger.info('Found %d distinct relationships matching filters',
|
logger.info('Found %d distinct relationships matching filters',
|
||||||
len(context['relationship_set']))
|
len(context['relationship_set']))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user