{% extends "admin/base_site_gridpivot.html" %} {% load i18n %} {% block extrahead %}{{block.super}} {% if mode == "graph" %}{% endif %} {% endblock %} {% block tools %}{% if args.0 %}{% tabs "input.item" %}{% endif %}{{block.super}}{% endblock %} {% block before_table %}{% if args.0 %}
{% endif %}{% endblock %} {% block crosses %} {% if args.0 %}$(function(){ // Resize top graph var h = $(window).height(); $("#graph").width($(window).width()-60).height(h>800 || h<480 ? 400 : h-420); });{% endif %} {% if args.0 or mode == "graph" %} function drawGraphs(jsondata) { {% if args.0 %}$("#grid").setGridHeight('100%');{% endif %} {% if args.0 %}var margin = {top: 0, right: 100, bottom: 30, left: 50}; {% else %}var margin = {top: 0, right: 0, bottom: 0, left: 50}; {% endif %}var width = $({% if args.0 %}"#graph"{% else %}"#grid_graph"{% endif %}).width() - margin.left - margin.right; var height = {% if args.0 %}$("#graph").height(){% else %}80{% endif %} - margin.top - margin.bottom; // Define X-axis var domain_x = []; var bucketnamelength = 0; for (var i in timebuckets) { domain_x.push(timebuckets[i]['name']); bucketnamelength = Math.max(timebuckets[i]['name'].length, bucketnamelength); } var x = d3.scale.ordinal() .domain(domain_x) .rangeRoundBands([0, width], .1); var x_width = x.rangeBand(); // Define Y-axis var y = d3.scale.linear().rangeRound([height, 0]); // Draw all graphs $("#grid"){% if not args.0 %}.find(".graph"){% endif %}.each(function(index) { // Create a new SVG element $({% if args.0 %}$("#graph").get(0){% else %}this{% endif %}).html(""); var svg = d3.select({% if args.0 %}$("#graph").get(0){% else %}this{% endif %}) .append("svg") .attr("class","graphcell") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // Build the data for d3 var max_y = 0; var min_y = 0; var data = []; for (var bckt in timebuckets) { var tmp = jsondata['rows'][index][timebuckets[bckt]['name']]; data.push({ 'item': jsondata['rows'][index]['item'], 'bucket': bckt, 'demand': tmp[0], 'supply': tmp[1], 'backlog': tmp[2] }); if (tmp[2] < min_y) min_y = tmp[2]; if (tmp[0] > max_y) max_y = tmp[0]; if (tmp[1] > max_y) max_y = tmp[1]; if (tmp[2] > max_y) max_y = tmp[2]; } // Update the scale of the Y-axis by looking for the max value y.domain([min_y,max_y]); var y_zero = y(0); // Create D3 bars var my_y; svg.selectAll("g") .data(data) .enter() .append("g") .attr("transform", function(d) { return "translate(" + x(timebuckets[d['bucket']]['name']) + ",0)"; }) .on("click", function(d) { if (d3.event.defaultPrevented || (d['produced'] == 0 && d['consumed'] == 0)) return; d3.select("#tooltip").style('display', 'none'); contextMenu = $("#detail1context"); contextMenu.find('a').each( function() { $(this).attr( 'href', $(this).attr('id') .replace(/{value}/g, admin_escape(d['item'])) .replace(/{enddate}/g, timebuckets[d['bucket']]['enddate']) .replace(/{startdate}/g, timebuckets[d['bucket']]['startdate']) ); }); var coord = d3.mouse(document.body); contextMenu.css({ left: coord[0], top: coord[1], display: 'block' }); d3.event.stopPropagation(); }) .on("mouseenter", function(d) { graph.showTooltip( '{{_('demand')|capfirst}} | ' + (Math.round(d['demand']*10)/10) + ' |
{{_('supply')|capfirst}} | ' + (Math.round(d['supply']*10)/10) + ' |
{{_('backlog')|capfirst}} | ' + (Math.round((d['backlog'])*10)/10) + ' |