This commit is contained in:
James 2020-03-29 09:35:23 +01:00
parent c3d79d1e7b
commit 8a81683fbf

View File

@ -82,190 +82,192 @@ define(["jquery"], function ($) {
var scrollTop = $(window).scrollTop(); var scrollTop = $(window).scrollTop();
var tableTop = $("#table_container").offset().top; var tableTop = $("#table_container").offset().top;
var buttonTop = $('#button_container').offset().top; var buttonTop = $('#button_container').offset().top;
console.log("tt:"+tableTop+" st:"+scrollTop+" bt:"+buttonTop); console.log("tt:"+tableTop+" st:"+scrollTop+" bt:"+buttonTop);
if( scrollTop > tableTop ){ if( scrollTop > tableTop ){
$("#button_container").css('top', tableTop-(scrollTop-tableTop)); //$("#button_container").css('top', tableTop-(scrollTop-tableTop));
}else{ $("#button_container").css('position', 'fixed');
$("#button_container").css('top', tableTop);
}
/*
buttonOffset = $('#button_container').offset().top;
//buttonOffset = parseInt(buttonOffset, 10) || 0;
if(scrollPosition > buttonOffset){
$("#button_container").css('top', scrollPosition-buttonOffset);
$("#heatcalc thead th").css('top', scrollPosition-buttonOffset-1);
}else{ }else{
$("#button_container").css('top', 0); //$("#button_container").css('top', tableTop);
$("#heatcalc thead th").css('top', 0); $("#button_container").css('position', 'absolute');
} }
$('#heatcalc tbody th').css("left", $("#table_container").scrollLeft()); /*
$('#heatcalc thead th:nth-child(1)').css("left", $("#table_container").scrollLeft());
buttonOffset = $('#button_container').offset().top;
//buttonOffset = parseInt(buttonOffset, 10) || 0;
if(scrollPosition > buttonOffset){
$("#button_container").css('top', scrollPosition-buttonOffset);
$("#heatcalc thead th").css('top', scrollPosition-buttonOffset-1);
}else{
$("#button_container").css('top', 0);
$("#heatcalc thead th").css('top', 0);
}
$('#heatcalc tbody th').css("left", $("#table_container").scrollLeft());
$('#heatcalc thead th:nth-child(1)').css("left", $("#table_container").scrollLeft());
*/ */
} }
function draw_table(){ function draw_table(){
var prod_name = $("#hc_product option:selected").val(); var prod_name = $("#hc_product option:selected").val();
// creates the empty table // creates the empty table
// each cell has id=type-x-y for targeting during population // each cell has id=type-x-y for targeting during population
// get the data for just this product // get the data for just this product
var prod_data=data[prod_name]; var prod_data=data[prod_name];
//get a list of y values unique and complete for all type/depth and x combos //get a list of y values unique and complete for all type/depth and x combos
var y_vals={}; var y_vals={};
$.each(prod_data, function(idx1,val1) { // type/depth $.each(prod_data, function(idx1,val1) { // type/depth
$.each(val1, function(idx2,val2) { // x $.each(val1, function(idx2,val2) { // x
$.each(val2, function(idx3,val3) { // y $.each(val2, function(idx3,val3) { // y
y_vals[idx3]=true; y_vals[idx3]=true;
});
}); });
}); });
});
//delete any old table //delete any old table
$("#hc_table").remove(); $("#hc_table").remove();
// create the new table // create the new table
var table=$("<table id='hc_table'>"); var table=$("<table id='hc_table'>");
var thead=$("<thead>"); var thead=$("<thead>");
//header row 1: type/depths //header row 1: type/depths
var row=$("<tr>"); var row=$("<tr>");
var cell=$("<th>").text("Type/Depth"); var cell=$("<th>").text("Type/Depth");
row.append(cell);
$.each(prod_data, function(idx1,val1) {
// each "type/depth" will contain multiple x vales, so the cell needs to span them
// count into x_count
var x_count=0;
$.each(val1, function(idx2,val2) {
x_count++;
});
//create the cell
var cell=$("<th colspan='"+x_count+"'>").text(idx1);
row.append(cell); row.append(cell);
$.each(prod_data, function(idx1,val1) { });
// each "type/depth" will contain multiple x vales, so the cell needs to span them thead.append(row);
// count into x_count
var x_count=0; //header row 2: height x"s
$.each(val1, function(idx2,val2) { var row=$("<tr>");
x_count++; var cell=$("<th>").text("Length \\ Height");
}); row.append(cell);
//create the cell $.each(prod_data, function(idx1,val1) {
var cell=$("<th colspan='"+x_count+"'>").text(idx1); // each "type/depth" will contain multiple x vales
$.each(val1, function(idx2,val2) {
cell=$("<th>").text(idx2);
row.append(cell); row.append(cell);
}); });
thead.append(row); });
thead.append(row);
table.append(thead);
//header row 2: height x"s //data row, for all y_vals
$.each(y_vals, function(y) {
var row=$("<tr>"); var row=$("<tr>");
var cell=$("<th>").text("Length \\ Height"); var cell=$("<th>").text(y);
row.append(cell); row.append(cell);
//now all the x"s
$.each(prod_data, function(idx1,val1) { $.each(prod_data, function(idx1,val1) {
// each "type/depth" will contain multiple x vales // each "type/depth" will contain multiple x vales
$.each(val1, function(idx2,val2) { $.each(val1, function(idx2,val2) {
cell=$("<th>").text(idx2); cell=$("<td>").text("-").attr("id",idx1.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+idx2.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+y.replace(/\s/g,"").replace(/[\.\/]/g,"_"));
row.append(cell); row.append(cell);
}); });
}); });
thead.append(row);
table.append(thead);
//data row, for all y_vals table.append(row);
$.each(y_vals, function(y) {
var row=$("<tr>");
var cell=$("<th>").text(y);
row.append(cell);
//now all the x"s
$.each(prod_data, function(idx1,val1) {
// each "type/depth" will contain multiple x vales
$.each(val1, function(idx2,val2) {
cell=$("<td>").text("-").attr("id",idx1.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+idx2.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+y.replace(/\s/g,"").replace(/[\.\/]/g,"_"));
row.append(cell);
});
});
table.append(row); });
}); // display the table
$("#table_container").append(table);
// display the table //enable highlighting
$("#table_container").append(table); $("#hc_table td").on("mouseover", function() {
$(this).closest("tr").addClass("hover");
$(this).closest("table").find("td:nth-child(" + ($(this).index() + 1) + ")").addClass("hover");
});
$("#hc_table td").on("mouseout", function() {
$(this).closest("table").find("td,tr").removeClass("hover");
});
}
//enable highlighting function populate_table(){
$("#hc_table td").on("mouseover", function() { var prod_name = $("#hc_product option:selected").val();
$(this).closest("tr").addClass("hover");
$(this).closest("table").find("td:nth-child(" + ($(this).index() + 1) + ")").addClass("hover"); var dt=calc_dt();
}); var mode=$("[name='mode']").val();
$("#hc_table td").on("mouseout", function() { var dtr;
$(this).closest("table").find("td,tr").removeClass("hover"); if(mode=="a"){
}); dtr=dt/50;
}
if(mode=="l"){
dtr=dt/49.83;
} }
function populate_table(){ var w_min=parseFloat($("[name='w_min']").val());
var prod_name = $("#hc_product option:selected").val(); var w_max=parseFloat($("[name='w_max']").val());
var l_min=parseFloat($("[name='l_min']").val());
var l_max=parseFloat($("[name='l_max']").val());
var h_min=parseFloat($("[name='h_min']").val());
var h_max=parseFloat($("[name='h_max']").val());
var dt=calc_dt(); // get the data for just this product
var mode=$("[name='mode']").val(); var prod_data=data[prod_name];
var dtr;
if(mode=="a"){
dtr=dt/50;
}
if(mode=="l"){
dtr=dt/49.83;
}
var w_min=parseFloat($("[name='w_min']").val()); //lets do the calcs!
var w_max=parseFloat($("[name='w_max']").val()); $.each(prod_data, function(type,type_vals) {
var l_min=parseFloat($("[name='l_min']").val()); $.each(type_vals, function(x,x_vals) {
var l_max=parseFloat($("[name='l_max']").val()); $.each(x_vals, function(y,vals) {
var h_min=parseFloat($("[name='h_min']").val()); if(vals.w==0){
var h_max=parseFloat($("[name='h_max']").val()); return;
}
// get the data for just this product var target_cell=$("#"+type.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+x.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+y.replace(/\s/g,"").replace(/[\.\/]/g,"_"));
var prod_data=data[prod_name]; var n=parseFloat(vals.n);
var k=Math.pow(dtr,n);
//lets do the calcs! var w=(parseFloat(vals.w)*k).toFixed(0);
$.each(prod_data, function(type,type_vals) { target_cell.text( w + "W");
$.each(type_vals, function(x,x_vals) { if(
$.each(x_vals, function(y,vals) { (w_min>0 && w<w_min) ||
if(vals.w==0){ (w_max>0 && w>w_max) ||
return; (l_min>0 && y<l_min) ||
} (l_max>0 && y>l_max) ||
var target_cell=$("#"+type.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+x.replace(/\s/g,"").replace(/[\.\/]/g,"_")+"-"+y.replace(/\s/g,"").replace(/[\.\/]/g,"_")); (h_min>0 && x<h_min) ||
var n=parseFloat(vals.n); (h_max>0 && x>h_max)
var k=Math.pow(dtr,n); ){
var w=(parseFloat(vals.w)*k).toFixed(0); target_cell.addClass("filtered");
target_cell.text( w + "W"); }else{
if( target_cell.removeClass("filtered");
(w_min>0 && w<w_min) || }
(w_max>0 && w>w_max) ||
(l_min>0 && y<l_min) ||
(l_max>0 && y>l_max) ||
(h_min>0 && x<h_min) ||
(h_max>0 && x>h_max)
){
target_cell.addClass("filtered");
}else{
target_cell.removeClass("filtered");
}
});
}); });
}); });
});
}
function calc_dt(){
var mode=$("[name='mode']").val();
var t_flow=parseInt($("[name='t_flow']").val());
var t_return=parseInt($("[name='t_return']").val());
var t_room=parseInt($("[name='t_room']").val());
var dt;
if(mode=="a"){
dt=((t_flow+t_return)/2)-t_room;
}
if(mode=="l"){
dt=((t_flow-t_return)/Math.log((t_flow-t_room)/(t_return-t_room)));
} }
function calc_dt(){ $("[name='dt']").val(dt.toFixed(2));
var mode=$("[name='mode']").val(); return dt;
}
var t_flow=parseInt($("[name='t_flow']").val());
var t_return=parseInt($("[name='t_return']").val());
var t_room=parseInt($("[name='t_room']").val());
var dt;
if(mode=="a"){
dt=((t_flow+t_return)/2)-t_room;
}
if(mode=="l"){
dt=((t_flow-t_return)/Math.log((t_flow-t_room)/(t_return-t_room)));
}
$("[name='dt']").val(dt.toFixed(2));
return dt;
}
}); });