Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

theme_animint(rowspan, colspan, last_in_row) #153

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions inst/htmljs/animint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(" ")));
Expand Down
Loading