{% extends "admin/base_site_gridpivot.html" %} {% load i18n %} {% block tools %} {% if args.0 %} {% include "common/snippet_follow.html" %} {% tabs model %} {% 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<550 ? 360 : h-450); });{% endif %} {% if args.0 or mode == "graph" %} function drawGraphs(jsondata) { $('#curerror').html(""); {% 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; // Lookup table of displayed columns var fields = {}; for (var i in cross_idx) fields[cross_idx[i]] = 0; // 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(); {% if mode == "graph" and not args.0 %}graph.header(margin.left, x);{% endif %} // 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 data = []; for (var bckt in timebuckets) { var tmp = jsondata['rows'][index][timebuckets[bckt]['name']]; data.push({ 'operation': jsondata['rows'][index]['operation'], 'bucket': bckt, 'proposed_start': tmp[0], 'total_start': tmp[1], 'proposed_end': tmp[2], 'total_end': tmp[3], 'proposed_production': tmp[4], 'total_production': tmp[5] }); if (tmp[1] > max_y && 1 in fields) max_y = tmp[1]; else if (tmp[0] > max_y && 0 in fields) max_y = tmp[0]; if (tmp[3] > max_y && 3 in fields) max_y = tmp[3]; else if (tmp[2] > max_y && 2 in fields) max_y = tmp[2]; if (tmp[5] > max_y && 5 in fields) max_y = tmp[5]; else if (tmp[4] > max_y && 4 in fields) max_y = tmp[4]; } // Update the scale of the Y-axis by looking for the max value y.domain([0,max_y]); // Number of bars to display var numbars = 0; var barnum = [0, 1, 2]; if (0 in fields || 1 in fields) numbars++; else { barnum[1]--; barnum[2]--; } if (2 in fields || 3 in fields) numbars++; else barnum[2]--; if (4 in fields || 5 in fields) numbars++; // D3 visualization svg.selectAll("g") .data(data) .enter() .append("g") .attr("transform", function(d) { return "translate(" + x(timebuckets[d['bucket']]['name']) + ",0)"; }) .each(function(d) { var bucket = d3.select(this); var top = y(0); if (d['total_start'] > d['proposed_start'] && 1 in fields) { top = y(d['total_start'] - d['proposed_start']); bucket.append("rect") .attr("width", x_width/numbars) .attr("x", barnum[0] * x_width / numbars) .attr("y", top) .attr("height", y(0) - top) .style("fill","#113C5E") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_start'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location ="{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&startdate__lt="+timebuckets[d['bucket']]['enddate'] +"&startdate__gte="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } if (d['proposed_start'] > 0 && (0 in fields || 1 in fields)) { var newtop = y(d['total_start']); bucket.append("rect") .attr("width", x_width/numbars) .attr("x", barnum[0] * x_width / numbars) .attr("y", newtop) .attr("height", top - newtop) .style("fill","#2B95EC") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_start'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&startdate__lt="+timebuckets[d['bucket']]['enddate'] +"&startdate__gte="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } top = y(0); if (d['total_production'] > d['proposed_production'] && 5 in fields) { top = y(d['total_production'] - d['proposed_production']); bucket.append("rect") .attr("width", x_width / numbars) .attr("x", barnum[1] * x_width / numbars) .attr("y", top) .attr("height", y(0) - top) .style("fill","#0C3B00") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_production'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&startdate__lte="+timebuckets[d['bucket']]['enddate'] +"&enddate__gt="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } if (d['proposed_production'] > 0 && (4 in fields || 5 in fields)) { var newtop = y(d['total_production']); bucket.append("rect") .attr("width", x_width / numbars) .attr("x", barnum[1] * x_width / numbars) .attr("y", newtop) .attr("height", top - newtop) .style("fill","#8BBA00") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_production'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&startdate__lt="+timebuckets[d['bucket']]['enddate'] +"&enddate__gt="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } top = y(0); if (d['total_end'] > d['proposed_end'] && 3 in fields) { top = y(d['total_end'] - d['proposed_end']); bucket.append("rect") .attr("width", x_width / numbars) .attr("x", barnum[2] * x_width / numbars) .attr("y", top) .attr("height", y(0) - top) .style("fill","#7B5E08") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_end'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&enddate__lte="+timebuckets[d['bucket']]['enddate'] +"&enddate__gt="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } if (d['proposed_end'] > 0 && (2 in fields || 3 in fields)) { var newtop = y(d['total_end']); bucket.append("rect") .attr("width", x_width/numbars) .attr("x", barnum[2] * x_width / numbars) .attr("y", newtop) .attr("height", top - newtop) .style("fill","#F6BD0F") .on("click", function(d) { if (d3.event.defaultPrevented || d['total_end'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&enddate__lte="+timebuckets[d['bucket']]['enddate'] +"&enddate__gt="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }); } // Invisible rectangle for the tooltip bucket.append("rect") .attr("height", height) .attr("width", x_width) .attr("fill-opacity", 0) .on("click", function(d) { if (d3.event.defaultPrevented || d['total_start'] == 0) return; d3.select("#tooltip").style('display', 'none'); window.location = "{{ request.prefix }}" +"/data/input/manufacturingorder/" +"?noautofilter&operation__name="+admin_escape(d['operation']) +"&startdate__lt="+timebuckets[d['bucket']]['enddate'] +"&enddate__gte="+timebuckets[d['bucket']]['startdate']; var coord = d3.mouse(document.body); d3.event.stopPropagation(); }) .on("mouseenter", function(d) { graph.showTooltip( '{{_('proposed starts')|capfirst}} | ' + grid.formatNumber(d['proposed_start']) + ' |
{{_('total starts')|capfirst}} | ' + grid.formatNumber(d['total_start']) + ' |
{{_('proposed ends')|capfirst}} | ' + grid.formatNumber(d['proposed_end']) + ' |
{{_('total ends')|capfirst}} | ' + grid.formatNumber(d['total_end']) + ' |
{{_('proposed production')|capfirst}} | ' + grid.formatNumber(d['proposed_production']) + ' |
{{_('total production')|capfirst}} | ' + grid.formatNumber(d['total_production']) + ' |