From 1243c66498548710b5d77abbd96b016474d04920 Mon Sep 17 00:00:00 2001 From: ppound Date: Wed, 7 Apr 2021 15:11:23 -0300 Subject: [PATCH] made graph more usable and fixed hanging scientific name issue --- js/fdg.js | 8 ++++---- src/Controller/GraphController.php | 2 +- src/Graph/GraphParser.php | 16 +++++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/js/fdg.js b/js/fdg.js index 5c45879..d7fec7d 100644 --- a/js/fdg.js +++ b/js/fdg.js @@ -5,16 +5,16 @@ Drupal.behaviors.islandora_herbarium_object_graph = { var svg = d3.select(".fdg"), width = +svg.attr("width"), height = +svg.attr("height"); - var radius = 15; + var radius = 25; var color = d3.scaleOrdinal(d3.schemeCategory20); var simulation = d3.forceSimulation() .force("link", d3.forceLink().id(function (d) { return d.id; - }).distance(65).strength(1)) + }).distance(250).strength(0.5)) .force("charge", d3.forceManyBody()) - .force("center", d3.forceCenter(width / 2, height / 2)) - .force("gravity",gravity(0.2)); + .force("center", d3.forceCenter(width / 2, height / 2)); + //.force("gravity",gravity(0.2)); var dataPath = "/" + settings.path.currentPath.replace('fdg', 'fdg_json'); d3.json(dataPath, function (error, graph) { if (error) throw error; diff --git a/src/Controller/GraphController.php b/src/Controller/GraphController.php index 4fca791..ca860be 100644 --- a/src/Controller/GraphController.php +++ b/src/Controller/GraphController.php @@ -17,7 +17,7 @@ class GraphController extends ControllerBase { */ public function printFdgGraph($scientificName = NULL, $municipality = NULL) { $arr = ($scientificName == 'NULL' && $municipality == 'NULL') ? ['height' => - 1400, 'width' => 1000] : ['height' => 400, 'width' => 800]; + 2400, 'width' => 1400] : ['height' => 400, 'width' => 800]; return [ '#theme' => 'fdg_graph', '#height' => $arr['height'], diff --git a/src/Graph/GraphParser.php b/src/Graph/GraphParser.php index 5e44a98..e24c31b 100644 --- a/src/Graph/GraphParser.php +++ b/src/Graph/GraphParser.php @@ -24,7 +24,6 @@ class GraphParser implements GraphInterface { $outputArr['nodes'] = []; $outputArr['links'] = []; $idArr = []; - foreach ($jsonArr['results']['bindings'] as $result) { if (!array_key_exists($result['municipality']['value'], $idArr)) { $outputArr['nodes'][] = [ @@ -35,12 +34,15 @@ class GraphParser implements GraphInterface { ]; $idArr[$result['municipality']['value']] = ''; } - $outputArr['nodes'][] = [ - 'id' => $result['name']['value'], - 'name' => $result['name']['value'], - 'uri' => $result['scientificNameIRI']['value'], - 'group' => 2, - ]; + if (!array_key_exists($result['name']['value'], $idArr)) { + $outputArr['nodes'][] = [ + 'id' => $result['name']['value'], + 'name' => $result['name']['value'], + 'uri' => $result['scientificNameIRI']['value'], + 'group' => 2, + ]; + $idArr[$result['name']['value']] = ''; + } $outputArr['links'][] = [ 'target' => $result['municipality']['value'], 'source' => $result['name']['value'],