Browse Source

pass height and width to graph so works better with a large number of objects

master
ppound 6 years ago
parent
commit
3ecdfea7b4
  1. 2
      css/fdg-graph.css
  2. 2
      islandora_herbarium_object.module
  3. 2
      js/fdg.js
  4. 4
      src/Controller/GraphController.php
  5. 2
      templates/fdg-graph.html.twig

2
css/fdg-graph.css

@ -11,7 +11,7 @@
#iho-graph { #iho-graph {
overflow: scroll; overflow: scroll;
width: 100%; width: 100%;
height: 400px; height: 1400px;
} }
text { text {

2
islandora_herbarium_object.module

@ -41,7 +41,7 @@ function islandora_herbarium_object_rdf_namespaces() {
function islandora_herbarium_object_theme($existing, $type, $theme, $path) { function islandora_herbarium_object_theme($existing, $type, $theme, $path) {
return [ return [
'fdg_graph' => [ 'fdg_graph' => [
'variables' => [], 'variables' => ['height' => NULL, 'width' => NULL],
], ],
]; ];
} }

2
js/fdg.js

@ -11,7 +11,7 @@ Drupal.behaviors.islandora_herbarium_object_graph = {
var simulation = d3.forceSimulation() var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function (d) { .force("link", d3.forceLink().id(function (d) {
return d.id; return d.id;
}).distance(100).strength(1)) }).distance(65).strength(1))
.force("charge", d3.forceManyBody()) .force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2)); .force("center", d3.forceCenter(width / 2, height / 2));
var dataPath = "/" + settings.path.currentPath.replace('fdg', 'fdg_json'); var dataPath = "/" + settings.path.currentPath.replace('fdg', 'fdg_json');

4
src/Controller/GraphController.php

@ -16,8 +16,12 @@ class GraphController extends ControllerBase {
* A renderable array. * A renderable array.
*/ */
public function printFdgGraph($scientificName = NULL, $municipality = NULL) { public function printFdgGraph($scientificName = NULL, $municipality = NULL) {
$arr = ($scientificName == 'NULL' && $municipality == 'NULL') ? ['height' =>
1400, 'width' => 1000] : ['height' => 400, 'width' => 800];
return [ return [
'#theme' => 'fdg_graph', '#theme' => 'fdg_graph',
'#height' => $arr['height'],
'#width' => $arr['width'],
'#attached' => [ '#attached' => [
'library' => [ 'library' => [
'islandora_herbarium_object/d3js', 'islandora_herbarium_object/d3js',

2
templates/fdg-graph.html.twig

@ -1,3 +1,3 @@
<div id="iho-graph"> <div id="iho-graph">
<svg class='fdg' width="800" height="400"></svg> <svg class='fdg' width={{ width }} height={{ height }}></svg>
</div> </div>
Loading…
Cancel
Save