Skip to content

Instantly share code, notes, and snippets.

@widged
Forked from widged/Agist.txt
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save widged/8720755 to your computer and use it in GitHub Desktop.
Save widged/8720755 to your computer and use it in GitHub Desktop.
== Plant Explorer in Neo4j
:neo4j-version: 2.0.0
:author: Marielle Lange
:twitter: @widged
:tags: gardening
The goal is to explore how graphgist can be used to feed data to d3js visualisations. Vegetable data have been obtained through the scrapping of various websites. They have been normalized to bring to a common scale data on different measurement units or dates from different hemispheres. Then they have been reduced, to binify any continuous data.
To avoid to overtax the console, only one plant is loaded in this example ("anise").
=== Embedded Javascript
Click any of the buttons and a call will be made to the Neo4j console through some javascript embedded within the gist. The json data returned by the script will cause the visualisation to refresh.
The visualisation is in the form of a density map. For instance, for soil ph, the values 6,7,8 are the ph values that the plant tolerates. The background color capture a custom color scale (mildly acidic in orange, neutral in yellow, alkaline in green). The bar under the number capture the relative frequency of that observation (2 observations for ph 6, 3 for ph 7 and 1 for ph 8).
Sowing months have been normalized to the Southern Hemisphere (as I live in NZ).
++++
<div id="traitDensity"></div>
<script>
// Not clear what the cause was but scripts embedded in the gist where not loaded in the order of appearance.
// A custom loader is used instead.
ScriptLoader = {};
(function(Class) {
Class.loadScripts = function(base, scripts, asyncReturn) {
function nextScript() {
if(!scripts || !scripts.length) { asyncReturn(); return; }
var script = scripts.shift();
jQuery.getScript(base + script, nextScript)
}
nextScript();
}
})(ScriptLoader)
// The files are accessible at:
// https://github.com/widged/neoconsole/tree/gh-pages/demo
ScriptLoader.loadScripts(
"http://widged.github.io/neoconsole/demo/",
[
"RequirePreloaded.js",
"CypherConsole.js",
"PlantProvider_cypher.js",
"ClassUtil.js",
"DensityMap.js",
"TraitDensity.js"
],
whenAllScripts
);
function whenAllScripts() {
// The data loaded in the graph and the statements used to query the graph can be viewed at:
// https://github.com/widged/neoconsole/blob/gh-pages/demo/PlantProvider_cypher.js
requirejs(["traitdensity"], function(TraitDensity) {
var traits = TraitDensity.instance();
traits.traits([
{id: "/soil/ph", label: "Soil PH", type: "measure", colors: "0:#CC2222,5:#FF6600,6.0:#FFDD00,7.0:#336600"},
{id: "/physiology/size/height", label: "Plant Height", type: "measure", colors: "-10:#003366,30:#336600,40:#FF6600,50:#CC2222"},
{id: "/propagate/cal", label: "Sowing Months", type: "tag", render: "months"}
]);
traits.mount(document.querySelector("#traitDensity"))
traits.actuate();
});
}
</script>
++++
=== Credits
* link:http://neo4j.org/[Neo4j] and link:http://gist.neo4j.org/[graphgist]
* link:http://d3js.org/[D3js]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment