<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>{{ontology.uri}}</title>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />




<style type="text/css" media="screen">



		svg {
		  font-size: 14px;
		}

		rect.background {
		  fill: none;
		  pointer-events: all;
		}

		.axis {
		  shape-rendering: crispEdges;
		}

		.axis path, .axis line {
		  fill: none;
		  stroke: #000;
		  stroke-width: .5px;
		}

		.hint {
		  position: absolute;
		  right: 0;
		  width: 1280px;
		  font-size: 12px;
		  color: #999;
		}


		.bde {
			background: yellow; 
			font-size: 21px; 
			font-family: monospace;
			display: inline;
		}

		.divider {
			background: white;
		}

</style>


</head>


<body>

	{# VISIBLE PAGE HTML #}

	{# note: showpanel arg is the ID of the div that is showing.. #}

	<h1 class="title">Ontology:&nbsp;<a href="javascript:showpanel('ontoinfo');">{{main_uri}}</a></h1>
	<h3>{{ontology.bestDescription}}</h3>

	<p><small>Ontology documentation automatically generated by <a class="greylink" href="http://ontospy.readthedocs.org/">OntoSpy</a> on {% now "jS F Y H:i" %}</small></p>

	<hr>


	{% if TOTAL_CLASSES %}
		<div class="row">
			<h3>Classes ({{TOTAL_CLASSES}})</h3>


			<div id="breadcrumbs">You are here: 
				<li class="bde">Owl:Thing</li>
			</div>



			<div class="col-md-12" id="graph_classes" style="margin-top: 10px;">

			</div>


		</div>
	{% endif %}



	<hr>
	<small>Documentation automatically generated by <a href="https://github.com/lambdamusic/OntoSpy">OntoSpy</a> on {% now "jS F Y H:i" %}</small>







{# JAVASCRIPT #}

<script type="text/javascript" src="{{STATIC_URL}}libs/d3-v3/d3.min.js"></script>

<script type="text/javascript" src="{{STATIC_URL}}libs/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="{{STATIC_URL}}libs/jquery/jquery.slidereveal.min.js"></script>

<script type="text/javascript">

    var root = {{JSON_DATA_CLASSES|safe}} ;

	var m = [80, 160, 0, 260], // top right bottom left
	    w = 1280 - m[1] - m[3], // width
	    h = 1800 - m[0] - m[2], // height
	    x = d3.scale.linear().range([0, w]),
	    y = 25, // bar height
	    z = d3.scale.ordinal().range(["steelblue", "#aaa"]); // bar color

	var hierarchy = d3.layout.partition()
	    .value(function(d) { return d.size; });

	var xAxis = d3.svg.axis()
	    .scale(x)
        .ticks(5)
        .tickFormat(d3.format("d"))
	    .orient("top");

	var svg = d3.select("#graph_classes").append("svg:svg")
	    .attr("width", w + m[1] + m[3])
	    .attr("height", h + m[0] + m[2])
	  .append("svg:g")
	    .attr("transform", "translate(" + m[3] + "," + m[0] + ")");

	svg.append("svg:rect")
	    .attr("class", "background")
	    .attr("width", w)
	    .attr("height", h)
	    .on("click", up);

	svg.append("svg:g")
	    .attr("class", "x axis");

	svg.append("svg:g")
	    .attr("class", "y axis")
	    .append("svg:line")
	    .attr("y1", "10%");

	// d3.json(JSON_STUFF, function(root) {
	  hierarchy.nodes(root);
	  x.domain([0, root.value]).nice();
	  down(root, 0);
	// });



	function say_position(d, direction) {
		// 2017-11-17 

		console.log(direction);

		if (direction == "up") {

			$("#breadcrumbs li:last").remove();

		} else if (direction == "down")  {

			if (d.parent) {
				var t = "<li class='bde'><span class='divider'> &gt; </span>" + d.qname||d.name + "</li>"
				$("#breadcrumbs").append(t)
			}
		}
		
	}



	function down(d, i) {
	  if (!d.children || this.__transition__) return;
	  
	  say_position(d, "down");

	  var duration = d3.event && d3.event.altKey ? 7500 : 750,
	      delay = duration / d.children.length;

	  // Mark any currently-displayed bars as exiting.
	  var exit = svg.selectAll(".enter").attr("class", "exit");

	  // Entering nodes immediately obscure the clicked-on bar, so hide it.
	  exit.selectAll("rect").filter(function(p) { return p === d; })
	      .style("fill-opacity", 1e-6);

	  // Enter the new bars for the clicked-on data.
	  // Per above, entering bars are immediately visible.
	  var enter = bar(d)
	      .attr("transform", stack(i))
	      .style("opacity", 1);

	  // Have the text fade-in, even though the bars are visible.
	  // Color the bars as parents; they will fade to children if appropriate.
	  enter.select("text").style("fill-opacity", 1e-6);
	  enter.select("rect").style("fill", z(true));

	  // Update the x-scale domain.
	  x.domain([0, d3.max(d.children, function(d) { return d.value; })]).nice();

	  // Update the x-axis.
	  svg.selectAll(".x.axis").transition()
	      .duration(duration)
	      .call(xAxis);

	  // Transition entering bars to their new position.
	  var enterTransition = enter.transition()
	      .duration(duration)
	      .delay(function(d, i) { return i * delay; })
	      .attr("transform", function(d, i) { return "translate(0," + y * i * 1.2 + ")"; });

	  // Transition entering text.
	  enterTransition.select("text").style("fill-opacity", 1);

	  // Transition entering rects to the new x-scale.
	  enterTransition.select("rect")
	      .attr("width", function(d) { return x(d.value); })
	      .style("fill", function(d) { return z(!!d.children); });

	  // Transition exiting bars to fade out.
	  var exitTransition = exit.transition()
	      .duration(duration)
	      .style("opacity", 1e-6)
	      .remove();

	  // Transition exiting bars to the new x-scale.
	  exitTransition.selectAll("rect").attr("width", function(d) { return x(d.value); });

	  // Rebind the current node to the background.
	  svg.select(".background").data([d]).transition().duration(duration * 2); d.index = i;
	}

	function up(d) {
	  if (!d.parent || this.__transition__) return;

	  say_position(d, "up");

	  var duration = d3.event && d3.event.altKey ? 7500 : 750,
	      delay = duration / d.children.length;

	  // Mark any currently-displayed bars as exiting.
	  var exit = svg.selectAll(".enter").attr("class", "exit");

	  // Enter the new bars for the clicked-on data's parent.
	  var enter = bar(d.parent)
	      .attr("transform", function(d, i) { return "translate(0," + y * i * 1.2 + ")"; })
	      .style("opacity", 1e-6);

	  // Color the bars as appropriate.
	  // Exiting nodes will obscure the parent bar, so hide it.
	  enter.select("rect")
	      .style("fill", function(d) { return z(!!d.children); })
	    .filter(function(p) { return p === d; })
	      .style("fill-opacity", 1e-6);

	  // Update the x-scale domain.
	  x.domain([0, d3.max(d.parent.children, function(d) { return d.value; })]).nice();

	  // Update the x-axis.
	  svg.selectAll(".x.axis").transition()
	      .duration(duration * 2)
	      .call(xAxis);

	  // Transition entering bars to fade in over the full duration.
	  var enterTransition = enter.transition()
	      .duration(duration * 2)
	      .style("opacity", 1);

	  // Transition entering rects to the new x-scale.
	  // When the entering parent rect is done, make it visible!
	  enterTransition.select("rect")
	      .attr("width", function(d) { return x(d.value); })
	      .each("end", function(p) { if (p === d) d3.select(this).style("fill-opacity", null); });

	  // Transition exiting bars to the parent's position.
	  var exitTransition = exit.selectAll("g").transition()
	      .duration(duration)
	      .delay(function(d, i) { return i * delay; })
	      .attr("transform", stack(d.index));

	  // Transition exiting text to fade out.
	  exitTransition.select("text")
	      .style("fill-opacity", 1e-6);

	  // Transition exiting rects to the new scale and fade to parent color.
	  exitTransition.select("rect")
	      .attr("width", function(d) { return x(d.value); })
	      .style("fill", z(true));

	  // Remove exiting nodes when the last child has finished transitioning.
	  exit.transition().duration(duration * 2).remove();

	  // Rebind the current parent to the background.
	  svg.select(".background").data([d.parent]).transition().duration(duration * 2);
	}

	// Creates a set of bars for the given data node, at the specified index.
	function bar(d) {
	  var bar = svg.insert("svg:g", ".y.axis")
	      .attr("class", "enter")
	      .attr("transform", "translate(0,5)")
	    .selectAll("g")
	      .data(d.children)
	    .enter().append("svg:g")
	      .style("cursor", function(d) { return !d.children ? null : "pointer"; })
	      .on("click", down);

	  bar.append("svg:text")
	      .attr("x", -6)
	      .attr("y", y / 2)
	      .attr("dy", ".35em")
	      .attr("text-anchor", "end")
	      .text(function(d) { return d.qname; });

	  bar.append("svg:rect")
      // was x(d.value) but the rect sizes didnt make much sense [mikele]
	      .attr("width", function(d) { return x(d.size); })
	      .attr("height", y);

	  return bar;
	}

	// A stateful closure for stacking bars horizontally.
	function stack(i) {
	  var x0 = 0;
	  return function(d) {
	    var tx = "translate(" + x0 + "," + y * i * 1.2 + ")";
	    x0 += x(d.value);
	    return tx;
	  };
	}

    </script>



</body>
</html>
