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

layout ggplots in a table #139

Draft
wants to merge 73 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e5a6803
Test to check for title of 3 plots
siddhesh195 Jul 10, 2024
d11bd6f
added test to verify number of tables , their dimensions and number o…
siddhesh195 Jul 12, 2024
ae7bd35
ramping up on animint.js
siddhesh195 Jul 16, 2024
e516b9a
add all plots in single row
siddhesh195 Jul 16, 2024
6ba7e6a
used element variable
siddhesh195 Jul 16, 2024
89c1e2f
Update .gitignore
siddhesh195 Jul 18, 2024
e53e7d9
put all plots in one column
siddhesh195 Jul 22, 2024
0ae75de
add 2 plots per row and then make a new row
siddhesh195 Jul 22, 2024
adf012b
table with 3 plots per row or user defined layout
siddhesh195 Jul 26, 2024
a2b8c0a
test for putting plots in specific location of outer table
siddhesh195 Jul 26, 2024
45bbcf7
check if svg element exists in a particular location of outer table
siddhesh195 Jul 28, 2024
4951b0b
error message if user forgets to add either row or column
siddhesh195 Jul 28, 2024
96c5a45
made function to check svg
siddhesh195 Jul 29, 2024
0a78f92
put plots with fixed locations first, then put all other plots
siddhesh195 Jul 29, 2024
a692b3d
changed scope of implicitly global variables
siddhesh195 Jul 30, 2024
95cd30f
Give error message if only row or col is added in theme
siddhesh195 Jul 30, 2024
6999ac7
theme_animint now accepts dimensions and not theme
siddhesh195 Jul 31, 2024
91d0abb
removed debugging line
siddhesh195 Aug 6, 2024
5b05e8a
removed comments
siddhesh195 Aug 6, 2024
2e1a5f5
reverted to original style and indentation
siddhesh195 Aug 7, 2024
9af1fe8
made border transparent
siddhesh195 Aug 10, 2024
a1735d2
added var as prefix to make it local
siddhesh195 Aug 10, 2024
8698e18
plots save span
siddhesh195 Sep 2, 2024
fbd9541
Merge branch 'master' into html-plot
siddhesh195 Sep 4, 2024
d4c90aa
rowspan is applied
siddhesh195 Sep 4, 2024
80943e6
colspan can now be applied
siddhesh195 Sep 5, 2024
4ac2937
refactoring
siddhesh195 Sep 7, 2024
4a4d8ea
corrected response.plots[p_name].row toresponse.plots[p_name].positio…
siddhesh195 Sep 24, 2024
7fa9efe
throw error if user is incosistent is passing row and col
siddhesh195 Sep 24, 2024
3499fea
removed check_svg function
siddhesh195 Sep 24, 2024
905feb3
refactoring
siddhesh195 Sep 25, 2024
0287024
corrected code to properly traverse the outer table
siddhesh195 Sep 25, 2024
00040cc
Merge branch 'master' into html-plot
siddhesh195 Sep 26, 2024
e46f73c
Test to check for title of 3 plots
siddhesh195 Jul 10, 2024
3cefb99
added test to verify number of tables , their dimensions and number o…
siddhesh195 Jul 12, 2024
efcd2c5
ramping up on animint.js
siddhesh195 Jul 16, 2024
071eeb5
add all plots in single row
siddhesh195 Jul 16, 2024
744a638
used element variable
siddhesh195 Jul 16, 2024
0fe67a8
Update .gitignore
siddhesh195 Jul 18, 2024
57d530b
put all plots in one column
siddhesh195 Jul 22, 2024
c1fbe30
add 2 plots per row and then make a new row
siddhesh195 Jul 22, 2024
8da6e6c
table with 3 plots per row or user defined layout
siddhesh195 Jul 26, 2024
dbbfcc7
test for putting plots in specific location of outer table
siddhesh195 Jul 26, 2024
e671218
check if svg element exists in a particular location of outer table
siddhesh195 Jul 28, 2024
42eaf91
error message if user forgets to add either row or column
siddhesh195 Jul 28, 2024
3a3141b
made function to check svg
siddhesh195 Jul 29, 2024
cb45b68
put plots with fixed locations first, then put all other plots
siddhesh195 Jul 29, 2024
06d5c10
changed scope of implicitly global variables
siddhesh195 Jul 30, 2024
0368b85
Give error message if only row or col is added in theme
siddhesh195 Jul 30, 2024
28f5cac
theme_animint now accepts dimensions and not theme
siddhesh195 Jul 31, 2024
c5e4c8c
removed debugging line
siddhesh195 Aug 6, 2024
aa07dd9
removed comments
siddhesh195 Aug 6, 2024
7b31296
reverted to original style and indentation
siddhesh195 Aug 7, 2024
70d550d
made border transparent
siddhesh195 Aug 10, 2024
d3e15b3
added var as prefix to make it local
siddhesh195 Aug 10, 2024
731041f
plots save span
siddhesh195 Sep 2, 2024
06d02c8
rowspan is applied
siddhesh195 Sep 4, 2024
1eff5de
colspan can now be applied
siddhesh195 Sep 5, 2024
0ecc99f
refactoring
siddhesh195 Sep 7, 2024
54fcb77
corrected response.plots[p_name].row toresponse.plots[p_name].positio…
siddhesh195 Sep 24, 2024
3a11c39
throw error if user is incosistent is passing row and col
siddhesh195 Sep 24, 2024
a21e13b
removed check_svg function
siddhesh195 Sep 24, 2024
841c4ff
refactoring
siddhesh195 Sep 25, 2024
87ecfda
corrected code to properly traverse the outer table
siddhesh195 Sep 25, 2024
47544aa
Merge branch 'html-plot' of https://github.com/animint/animint2 into …
siddhesh195 Sep 26, 2024
c66cdb0
removed blank lines
siddhesh195 Sep 27, 2024
d9e0310
combined getRowAndColumn and getRowspanAndColumnspan functions
siddhesh195 Sep 30, 2024
446e549
reverting changes for debugging
siddhesh195 Oct 1, 2024
ff96811
merged functions into attribute function
siddhesh195 Oct 1, 2024
9624583
code for handling rowspan
siddhesh195 Oct 2, 2024
3996202
removed unnecessary lines and added test
siddhesh195 Oct 3, 2024
700f1d9
refactored code, added test
siddhesh195 Oct 5, 2024
4580713
Merge branch 'master' into html-plot
siddhesh195 Oct 12, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*ANIMINT_TEST_FOO
*pids.txt
*~
test-renderer1-knit-print.R
7 changes: 6 additions & 1 deletion R/theme-elements.r
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) {
plot.caption = el_def("element_text", "title"),
plot.margin = el_def("margin"),

aspect.ratio = el_def("character")
aspect.ratio = el_def("character"),

row = el_def("character"),
col = el_def("character")
)


Expand All @@ -297,6 +300,8 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) {
# @param el an element
# @param elname the name of the element
validate_element <- function(el, elname) {
#print(el)
#print(elname)
Faye-yufan marked this conversation as resolved.
Show resolved Hide resolved
eldef <- .element_tree[[elname]]

if (is.null(eldef)) {
Expand Down
11 changes: 8 additions & 3 deletions R/z_animint.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ parsePlot <- function(meta, plot, plot.name){
## Now ggplot specifies panel.margin in 'pt' instead of 'lines'
plot.info$panel_margin_lines <- pt.to.lines(theme.pars$panel.margin)

## No legend if theme(legend.postion="none").
## No legend if theme(legend.position="none").
plot.info$legend <- if(theme.pars$legend.position != "none"){
getLegendList(built)
}
Expand Down Expand Up @@ -103,7 +103,9 @@ parsePlot <- function(meta, plot, plot.name){
# extract minor grid lines
plot.info$grid_minor <- get_grid(theme.pars$panel.grid.minor, theme.pars,
plot.info, meta, built, major = F)

theme <- plot_theme(built$plot)
plot.info$row <-theme$row
plot.info$col <-theme$col
## Flip labels if coords are flipped - transform does not take care
## of this. Do this BEFORE checking if it is blank or not, so that
## individual axes can be hidden appropriately, e.g. #1.
Expand Down Expand Up @@ -249,6 +251,7 @@ storeLayer <- function(meta, g, g.data.varied){
animint2dir <- function(plot.list, out.dir = NULL,
json.file = "plot.json", open.browser = interactive(),
css.file = "") {

if(is.null(out.dir)){
out.dir <- tempfile()
}
Expand Down Expand Up @@ -359,6 +362,7 @@ animint2dir <- function(plot.list, out.dir = NULL,
if(is.ggplot(p)){
## If plot is correct, save to meta for further processing
parsed_info <- parsePlot(meta, p, list.name) # calls ggplot_build.
#print(parsed_info$plot.info)
AllPlotsInfo[[list.name]] <- parsed_info$plot.info
ggplot.list[[list.name]]$ggplot <- parsed_info$ggplot
ggplot.list[[list.name]]$built <- parsed_info$built
Expand Down Expand Up @@ -638,7 +642,7 @@ animint2dir <- function(plot.list, out.dir = NULL,
stop("missing first selector variable")
}
}

meta$plots <- AllPlotsInfo
meta$time <- AnimationInfo$time
meta$timeValues <- AnimationInfo$timeValues
Expand Down Expand Up @@ -690,6 +694,7 @@ getLegendList <- function(plistextra){
position <- theme$legend.position
text <- theme$legend.text
title <- theme$legend.title
#print(theme$row)
# by default, guide boxes are vertically aligned
if(is.null(theme$legend.box)) theme$legend.box <- "vertical" else theme$legend.box

Expand Down
19 changes: 19 additions & 0 deletions helper-functions2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sendKey <- function(key, code, keyCode) {
remDr$Input$dispatchKeyEvent(type = "keyDown", key = key, code = code, windowsVirtualKeyCode = keyCode, nativeVirtualKeyCode = keyCode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these functions redundant with other functions? why do they need to be in a separate file? how are they different? please either delete, move, or add a comment here to explain why they need to stay here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these functions redundant with other functions? why do they need to be in a separate file? how are they different? please either delete, move, or add a comment here to explain why they need to stay here.

I will take a look into that. I don't remember the exact reason I thought of to make a new file, maybe I missed to notice that a separate file was not necessary.

remDr$Input$dispatchKeyEvent(type = "keyUp", key = key, code = code, windowsVirtualKeyCode = keyCode, nativeVirtualKeyCode = keyCode)
}

clickID <- function(...){
v <- c(...)
stopifnot(length(v) == 1)
runtime_evaluate(script=sprintf("document.getElementById('%s').dispatchEvent(new CustomEvent('click'))", as.character(v)))
}

runtime_evaluate <- function(script=NULL,return.value=FALSE){
eval.result<- remDr$Runtime$evaluate(script,returnByValue = TRUE)
if (return.value){
eval.result$result$value
}else{
eval.result
}
}
113 changes: 109 additions & 4 deletions inst/htmljs/animint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {

var animint = function (to_select, json_file) {
//console.log(json_file)
fetch(json_file)
.then(response => response.json())
.then(data => {
console.log(data); // Prints the entire JSON data
})
.catch(error => console.error('Error fetching the JSON file:', error));
Faye-yufan marked this conversation as resolved.
Show resolved Hide resolved
var default_axis_px = 16;

function wait_until_then(timeout, condFun, readyFun) {
Expand Down Expand Up @@ -214,11 +221,14 @@ 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 add_plot = function (p_name, p_info,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 = element.append("table").style("display", "inline-block");

var plot_table = outer_table.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 @@ -1066,6 +1076,7 @@ var animint = function (to_select, json_file) {
}else{
get_stroke_width = function(d){
return stroke_width;

};
}

Expand Down Expand Up @@ -2019,13 +2030,107 @@ var animint = function (to_select, json_file) {
d3.select("title").text(response.title);
}
// Add plots.


var check_svg = function (row_number,col_number) {
var id="#row"+row_number+"col"+col_number
var parentElement= d3.select(id)
if (!parentElement.select('svg').empty()) {
return true
}else{
return false
}
}


for (var p_name in response.plots) {
if ('row' in response.plots[p_name] && 'col' in response.plots[p_name]) {
user_defined_layout= true
}
if ('row' in response.plots[p_name] && !('col' in response.plots[p_name])){
throw new Error("You forgot to add column in "+response.plots[p_name].title+" plot.");
}
if ('col' in response.plots[p_name] && !('row'in response.plots[p_name])){
throw new Error("You forgot to add row in "+response.plots[p_name].title+" plot.");
}
}

var maximum_row= 0
var maximum_column= 0
var construct_outer_table = function () {
var count=0

var find_maximum_dimensions = function () {


for (var p_name in response.plots) {
add_plot(p_name, response.plots[p_name]);
count=count+1
if (response.plots[p_name].row>maximum_row){
maximum_row=response.plots[p_name].row
}
if (response.plots[p_name].col>maximum_column){
maximum_column=response.plots[p_name].col
}
}
}
find_maximum_dimensions()
var count_dimensions = Math.ceil(Math.sqrt(count))-1;
tdhock marked this conversation as resolved.
Show resolved Hide resolved
var outer_table = element.append("table").attr("id", "outerTable").style("width", "1500px").style("border", "1px solid white");
tdhock marked this conversation as resolved.
Show resolved Hide resolved
maximum_row=Math.max(maximum_row,count_dimensions)
tdhock marked this conversation as resolved.
Show resolved Hide resolved
maximum_column=Math.max(maximum_column,count_dimensions)
tdhock marked this conversation as resolved.
Show resolved Hide resolved
//console.log(maximum_row)
//console.log(maximum_column)
for (var i = 0; i <=maximum_row; i++) {
var current_row = outer_table.append("tr").style("border", "1px solid white").style("height", "500px");
for (var j = 0; j <=maximum_column; j++){
current_row.append("td").attr("id", "row"+i+"col"+j).style("border", "1px solid white").style("width", "500px");
}
tdhock marked this conversation as resolved.
Show resolved Hide resolved
}

return outer_table;
}
var outer_table=construct_outer_table();

for (var p_name in response.plots) {
if ('row' in response.plots[p_name] && 'col' in response.plots[p_name]) {
var id= "#row"+response.plots[p_name].row+"col"+response.plots[p_name].col
var cell= d3.select(id);

add_plot(p_name, response.plots[p_name],cell);
add_legend(p_name, response.plots[p_name]);
// Append style sheet to document head.
css.appendChild(document.createTextNode(styles.join(" ")));
document.head.appendChild(css);
}
}
var pointer_row=0
var pointer_column=0
for (var p_name in response.plots) {
if (!('row' in response.plots[p_name])){
while (check_svg(pointer_row,pointer_column)) {
pointer_column=pointer_column+1
if (pointer_column>maximum_column){
pointer_column=0
pointer_row=pointer_row+1
}
}
var id= "#row"+pointer_row+"col"+pointer_column
//console.log(id)
var cell= d3.select(id);

add_plot(p_name, response.plots[p_name],cell);
add_legend(p_name, response.plots[p_name]);
// Append style sheet to document head.
css.appendChild(document.createTextNode(styles.join(" ")));
document.head.appendChild(css);

}
}





// Then add selectors and start downloading the first data subset.
for (var s_name in response.selectors) {
add_selector(s_name, response.selectors[s_name]);
Expand Down
Loading
Loading