Skip to content

Commit

Permalink
More features.
Browse files Browse the repository at this point in the history
  • Loading branch information
naelstrof committed Mar 19, 2016
1 parent 1686c65 commit ce703ab
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A goonchem helper that creates and displays dependency graphs of specified chemi

### Linux

* Requires dub package manager and dlang.
* Requires dub package manager and a dlang compiler (like dmd).

``` sh
git clone [email protected]:naelstrof/omnichem.git
Expand All @@ -18,4 +18,4 @@ Browsing to localhost:8080 should open up the application. Have fun!

### Windows

Just download the pre-compiled package on the releases page above.
Just download the pre-compiled package on the releases page above.
16 changes: 8 additions & 8 deletions database.json
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@
},
"capulettium": {
"class": "capulettium",
"description": "A rare drug that causes the user to appear dead for some time.\"",
"description": "A rare drug that causes the user to appear dead for some time.",
"fluid_b": 110,
"fluid_g": 145,
"fluid_r": 100,
Expand All @@ -1163,7 +1163,7 @@
},
"capulettium_plus": {
"class": "capulettium_plus",
"description": "A rare and expensive drug that causes the user to appear dead for some time while they retain consciousness and vision.\"",
"description": "A rare and expensive drug that causes the user to appear dead for some time while they retain consciousness and vision.",
"fluid_b": 110,
"fluid_g": 145,
"fluid_r": 100,
Expand Down Expand Up @@ -1502,7 +1502,7 @@
},
"cleaner": {
"class": "space_cleaner",
"description": "A compound used to clean things. It has a sharp, unpleasant odor.\"",
"description": "A compound used to clean things. It has a sharp, unpleasant odor.",
"fluid_b": 220,
"fluid_g": 220,
"fluid_r": 110,
Expand Down Expand Up @@ -1685,7 +1685,7 @@
"fluid_g": 195,
"fluid_r": 125,
"id": "coniine",
"name": "coniine\"",
"name": "coniine",
"reagent_state": "LIQUID",
"transparency": 80
},
Expand Down Expand Up @@ -1806,7 +1806,7 @@
"instant": 1,
"mix_phrase": "The mixture violently reacts, leaving behind a few crystalline shards.",
"mix_sound": "sound\/effects\/crystalshatter.ogg",
"name": "crank\"",
"name": "crank",
"overdose": 20,
"parents": [
"initropidril"
Expand Down Expand Up @@ -2626,7 +2626,7 @@
"fluid_r": 100,
"id": "flaptonium",
"instant": 1,
"mix_phrase": "The substance turns an airy sky-blue and foams up into a new shape.\"",
"mix_phrase": "The substance turns an airy sky-blue and foams up into a new shape.",
"mix_sound": "sound\/misc\/burp.ogg",
"name": "flaptonium",
"required_reagents": {
Expand Down Expand Up @@ -3449,7 +3449,7 @@
"fluid_g": 100,
"fluid_r": 250,
"id": "histamine",
"name": "histamine\"",
"name": "histamine",
"overdose": 40,
"parents": [
"initropidril"
Expand Down Expand Up @@ -7438,7 +7438,7 @@
"water_holy": 1,
"werewolf_serum": 1
},
"result": "\"vampire_serum",
"result": "vampire_serum",
"result_amount": 3,
"transparency": 255
},
Expand Down
Binary file added public/images/beaker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions public/scripts/get.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var redraw, g, renderer;

function getRandomColor() {
var letters = '0123456789ABC'.split('');
var letters = '3456789ABC'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 13)];
color += letters[Math.floor(Math.random() * 9)];
}
return color;
}
Expand All @@ -24,8 +24,16 @@ $(document).ready(function() {
}
$('edge').each( function( index ) {
var strings = $(this).text().split(",");
g.addNode( strings[1], { color : getRandomColor(), render : render } );
g.addNode( strings[0], { color : getRandomColor(), render : render } );
if ( $(this).attr("color_d") == "#333" ) {
g.addNode( strings[1], { color : getRandomColor(), render : render } );
} else {
g.addNode( strings[1], { color : $(this).attr("color_d"), render : render } );
}
if ( $(this).attr("color_s") == "#333" ) {
g.addNode( strings[0], { color : getRandomColor(), render : render } );
} else {
g.addNode( strings[0], { color : $(this).attr("color_s"), render : render } );
}
if ( $(this).attr("weight") != "1" ) {
g.addEdge( strings[1], strings[0], { directed: true, label: $(this).attr("weight") } );
} else {
Expand All @@ -37,11 +45,11 @@ $(document).ready(function() {
g.edges[e].style.fill = g.edges[e].source.color;
}
var layouter = new Graph.Layout.Spring(g);
renderer = new Graph.Renderer.Raphael('canvas', g, $("#content").width(), $("#content").height() );
renderer = new Graph.Renderer.Raphael('canvas', g, $("#content").width(), 600 );
redraw = function() {
layouter.layout();
renderer.width = $("#content").width()
renderer.height = $("#content").height()
renderer.height = 600
renderer.draw();
};
$(window).resize( redraw );
Expand Down
6 changes: 3 additions & 3 deletions public/styles/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ html, body {
svg {
margin: 0;
width: 100%;
height: 100%;
height: 600px;
}

.container {
Expand All @@ -21,16 +21,16 @@ svg {
}

.canvas {
background-color: #777;
margin: 0;
width: 100%;
height: 100%;
height: 600px;
}

.content {
margin: 0;
padding: 0;
width: 100%;
height: calc( 100% - 140px );
}

.search {
Expand Down
52 changes: 50 additions & 2 deletions source/chemAPI.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,62 @@ class ChemAPI : IChemAPI {
return "";
}
foreach( str ; j["required_reagents"].object.keys ) {
html ~= `<edge result="` ~ j["result_amount"].toString() ~ `" weight="` ~ j["required_reagents"][str].toString() ~ `" hidden>"`~ j["name"].str ~ `","` ~ reagents[str]["name"].str ~ `"</edge>`;
string color_s = "#333";
if ( j.object.keys.canFind( "fluid_r" ) ) {
color_s = format("#%02x%02x%02x", min(j["fluid_r"].integer,255), min(j["fluid_g"].integer,255), min(j["fluid_b"].integer,255) );
}
string color_d = "#333";
if ( reagents[str].object.keys.canFind( "fluid_r" ) ) {
color_d = format("#%02x%02x%02x", min(reagents[str]["fluid_r"].integer,255), min(reagents[str]["fluid_g"].integer,255), min(reagents[str]["fluid_b"].integer,255) );
}
html ~= `<edge color_s="` ~ color_s ~ `" color_d="` ~ color_d ~ `" result="` ~ j["result_amount"].toString() ~ `" weight="` ~ j["required_reagents"][str].toString() ~ `" hidden>"`~ j["name"].str ~ `","` ~ reagents[str]["name"].str ~ `"</edge>`;
html ~= generateEdges( str );
}
return html;
}
void getReagent( string id ) {
string html = generateEdges( id );
render!("get.dt", html );
string name, description;
string[] parents;
string[] children;
string color;
if ( reagents.object.keys.canFind( id ) ) {
if ( reagents[id].object.keys.canFind( "name" ) ) {
name = reagents[id]["name"].str ~ " (" ~ id ~ ")";
}
if ( reagents[id].object.keys.canFind( "description" ) ) {
description = reagents[id]["description"].str;
}
if ( reagents[id].object.keys.canFind( "parents" ) ) {
foreach( j ; reagents[id]["parents"].array ) {
parents ~= `<a href="/reagent?id=` ~ reagents[j.str]["id"].str ~ `">` ~ reagents[j.str]["name"].str ~ `</a>`;
}
}
if ( parents.length <= 0 ) {
parents ~= "None!";
}
if ( reagents[id].object.keys.canFind( "required_reagents" ) ) {
foreach( j ; reagents[id]["required_reagents"].object.keys ) {
children ~= `<a href="/reagent?id=` ~ reagents[j]["id"].str ~ `">` ~ reagents[j]["name"].str ~ `</a>`;
}
}
if ( children.length <= 0 ) {
children ~= "None!";
}
if ( reagents[id].object.keys.canFind( "fluid_r" ) ) {
color = format("#%02x%02x%02x", min(reagents[id]["fluid_r"].integer,255), min(reagents[id]["fluid_g"].integer,255), min(reagents[id]["fluid_b"].integer,255) );
}
if ( html == "" ) {
html = `<edge color_s="` ~ color ~ `" color_d="` ~ color ~ `" result="1" weight="1" hidden>"`~ reagents[id]["name"].str ~ `","` ~ reagents[id]["name"].str ~ `"</edge>`;
}
} else {
name = "Unknown";
description = "Unknown";
parents = ["Unknown"];
children = ["Unknown"];
color = "#FFF";
}
render!("get.dt", html, name, description, parents, children );
}
void index() {
render!("index.dt", sorted_reagents);
Expand Down
18 changes: 17 additions & 1 deletion views/get.dt
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
extends layout

block body
|!= html
h1!= name
p!= description
hr
#canvas.canvas
hr
h2 Children
table.table.table-hover.table-bordered.table-striped
tbody
- foreach( str ; children )
tr
td!= str
h2 Parents
table.table.table-hover.table-bordered.table-striped
tbody
- foreach( str ; parents )
tr
td!= str
|!= html

block after
- js( "raphael-min" );
Expand Down
2 changes: 1 addition & 1 deletion views/index.dt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ block body
table.table.table-hover.table-bordered
- foreach( r ; sorted_reagents )
tr
td!= `<a href="/reagent?id=` ~ r.id ~ `">` ~ r.name ~ `</a>`
td!= `<a href="/reagent?id=` ~ r.id ~ `">` ~ r.name ~ ` (` ~ r.id ~ `)</a>`
block after
- js( "filter" );

0 comments on commit ce703ab

Please sign in to comment.