Browse Source

made graph more usable and fixed hanging scientific name issue

master
ppound 6 years ago
parent
commit
1243c66498
  1. 8
      js/fdg.js
  2. 2
      src/Controller/GraphController.php
  3. 16
      src/Graph/GraphParser.php

8
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;

2
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'],

16
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'],

Loading…
Cancel
Save