diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index 3097224d..f80b26a1 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -218,11 +218,26 @@ var animint = function (to_select, json_file) { // Save this geom and load it! update_geom(g_name, null); }; - var add_plot = function (p_name, p_info) { + var span_array = ["rowspan","colspan"]; + var add_plot = function (p_name, p_info,making_outer_table) { // Each plot may have one or more legends. To make space for the // legends, we put each plot in a table with one row and two // columns: tdLeft and tdRight. - var plot_table = plot_td.append("table").style("display", "inline-block"); + var parent_of_plot; + if(making_outer_table){ + parent_of_plot = current_outer_tr.append("td"); + for(var span_attr in span_array){ + if(p_info.hasOwnProperty(span_attr)){ + parent_of_plot.attr(span_attr, p_info[span_attr]); + } + } + }else{ + parent_of_plot = element; + } + if(p_info.last_in_row){ + current_outer_tr = outer_table.append("tr"); + } + var plot_table = parent_of_plot.append("table").style("display", "inline-block"); var plot_tr = plot_table.append("tr"); var tdLeft = plot_tr.append("td"); var tdRight = plot_tr.append("td").attr("class", p_name+"_legend"); @@ -2022,9 +2037,26 @@ var animint = function (to_select, json_file) { // global d3.select here. d3.select("title").text(response.title); } + // Determine if we should create an outer table to arrange plots in a grid. + var outer_table, current_outer_tr; + outer_table_plot_attrs = span_array.slice(); + outer_table_plot_attrs.push("last_in_row"); + var making_outer_table = false; + for (var p_name in response.plots) { + var p_info = response.plots[p_name]; + for(var outer_tab_attr in outer_table_plot_attrs){ + if(p_info.hasOwnProperty(outer_tab_attr)){ + making_outer_table = true; + } + } + } + if (making_outer_table){ + outer_table = element.append("table"); + current_outer_tr = outer_table.append("tr"); + } // Add plots. for (var p_name in response.plots) { - add_plot(p_name, response.plots[p_name]); + add_plot(p_name, response.plots[p_name],making_outer_table); add_legend(p_name, response.plots[p_name]); // Append style sheet to document head. css.appendChild(document.createTextNode(styles.join(" ")));