{% extends "admin/base_site_gridpivot.html" %} {% load i18n %} {% block tools %} {% if active_tab == "inventory" %} {% include "common/snippet_follow.html" %}{% tabs "input.item" %} {% elif args.0 %} {% include "common/snippet_follow.html" %}{% tabs "input.buffer" %} {% 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: 70}; {% else %}var margin = {top: 0, right: 0, bottom: 0, left: 70}; {% 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 = new Set(); // dict that gives from an id the name of the cross var field_by_id = {}; // dict that gives from the name of a cross the id var id_by_field = {}; for (var i in cross_idx) { fields.add(cross[cross_idx[i]]["key"]); field_by_id[cross_idx[i]] = cross[cross_idx[i]]["key"]; id_by_field[cross[cross_idx[i]]["key"]] = cross_idx[i]; } // 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 min_y = 0; var data = []; for (var bckt in timebuckets) { var tmp = jsondata['rows'][index][timebuckets[bckt]['name']]; data.push({ 'buffer': jsondata['rows'][index]['buffer'], 'bucket': bckt, 'startinv': tmp[id_by_field['startoh']], 'startohdoc': tmp[id_by_field['startohdoc']], 'safetystock': tmp[id_by_field['safetystock']], 'consumed': tmp[id_by_field['consumed']], 'consumedMO': tmp[id_by_field['consumedMO']], 'consumedDO': tmp[id_by_field['consumedDO']], 'consumedSO': tmp[id_by_field['consumedSO']], 'consumedFcst': tmp[id_by_field['consumedFcst']], 'produced': tmp[id_by_field['produced']], 'producedMO': tmp[id_by_field['producedMO']], 'producedDO': tmp[id_by_field['producedDO']], 'producedPO': tmp[id_by_field['producedPO']], 'endinv': tmp[id_by_field['endoh']], 'total_in_progress': tmp[id_by_field['total_in_progress']], 'work_in_progress_mo': tmp[id_by_field['work_in_progress_mo']], 'on_order_po': tmp[id_by_field['on_order_po']], 'in_transit_do': tmp[id_by_field['in_transit_do']] }); for (var i in cross_idx) { var t = field_by_id[cross_idx[i]]; if (t == 'startoh' || t == 'safetystock' || t == 'consumed' || t == 'produced' || t == 'endoh') { if (tmp[cross_idx[i]] < min_y) min_y = tmp[cross_idx[i]]; if (tmp[cross_idx[i]] > max_y) max_y = tmp[cross_idx[i]]; } } } // 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)"; }) .each(function(d) { var bucket = d3.select(this); if (d['produced'] > 0 && fields.has('produced')) { my_y = y(d['produced']); bucket.append("rect") .attr("width", x_width/2) .attr("height", y_zero - my_y) .attr("x", x_width/2) .attr("y", my_y) .style("fill","#2B95EC"); } if (d['consumed'] > 0 && fields.has('consumed')) { my_y = y(d['consumed']); bucket.append("rect") .attr("width", x_width/2) .attr("height", y_zero - my_y) .attr("y", my_y) .style("fill","#F6BD0F"); } // 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['produced'] == 0 && d['consumed'] == 0)) return; d3.select("#tooltip").style('display', 'none'); window.location = url_prefix + "/data/input/operationplanmaterial/buffer/" + admin_escape(d['buffer']) + "/?noautofilter&flowdate__gte=" + timebuckets[d['bucket']]['startdate'] + "&flowdate__lt=" + timebuckets[d['bucket']]['enddate']; d3.event.stopPropagation(); }) .on("mouseenter", function(d) { if (timebuckets[d['bucket']]['history']) { var tiptext = '