Repository navigation
Test coord equal #253
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
base: master
Are you sure you want to change the base?
Test coord equal #253
Changes from all commits
07f3835
ab19433
7b53778
208161c
f1b8aac
b29d411
680957f
5fcd6a1
9ac872b
b88d304
7b02aa4
c104a55
6277a93
929e42e
56a52eb
109e061
608ae1c
bdcbf3f
707738a
6120537
39369a8
ff3b03d
2f50368
a601fb0
31f7dae
cae57f6
08a7939
c99e59f
6818162
81ca7ec
c6aed56
99547e8
8cf2681
abd7bcd
fa7f131
99ad2e6
d4dfaca
d6353ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -401,9 +401,7 @@ var setMultilineText = function(textElement, text) { | |
| var svg = tdLeft.append("svg") | ||
| .attr("id", p_info.plot_id) | ||
| .attr("height", p_info.options.height) | ||
| .attr("width", p_info.options.width) | ||
| // block avoids inline SVG baseline/descender gap below the plot (issue #279) | ||
| .style("display", "block"); | ||
| .attr("width", p_info.options.width); | ||
|
|
||
| // divvy up width/height based on the panel layout | ||
| var nrows = Math.max.apply(null, p_info.layout.ROW); | ||
|
|
@@ -540,6 +538,14 @@ var setMultilineText = function(textElement, text) { | |
| } | ||
| return cumsum; | ||
| } | ||
| function max_group_sum(group, values){ | ||
| var sums = []; | ||
| for(var i=0; i<values.length; i++){ | ||
| var g = group[i] - 1; | ||
| sums[g] = (sums[g] || 0) + values[i]; | ||
| } | ||
| return d3.max(sums) || 0; | ||
| } | ||
| var cum_height_per_row = cumsum_array(row_strip_heights); | ||
| var cum_width_per_col = cumsum_array(col_strip_widths); | ||
| var strip_width = d3.max(cum_width_per_col); | ||
|
|
@@ -559,17 +565,28 @@ var setMultilineText = function(textElement, text) { | |
| // proportions calculated by the compiler. This has to be done on the | ||
| // rendering side since the precomputed proportions apply to the *graph* | ||
| // and the graph size depends upon results of measureText() | ||
| // | ||
| // R fixed_spaces() gives proportions for a square panel cell. Available | ||
| // cells may be non-square; aspect is cell_height/cell_width in pixels. | ||
| // Dividing heights by aspect makes panel pixel aspect match the data | ||
| // aspect (issue #234). Then scale so the largest row/column still fits. | ||
| if (p_info.layout.coord_fixed[0]) { | ||
| var aspect = (graph_height / nrows) / (graph_width / ncols); | ||
| } else { | ||
| var aspect = 1; | ||
| } | ||
| var wp = p_info.layout.width_proportion.map(function(x){ | ||
| return x * Math.min(1, aspect); | ||
| }) | ||
| var hp = p_info.layout.height_proportion.map(function(x){ | ||
| return x * Math.min(1, 1/aspect); | ||
| }) | ||
| var wp = p_info.layout.width_proportion.slice(); | ||
| var hp = p_info.layout.height_proportion.map(function(y){ | ||
| return y / aspect; | ||
| }); | ||
| var fit_prop = Math.max( | ||
| max_group_sum(p_info.layout.ROW, wp), | ||
| max_group_sum(p_info.layout.COL, hp) | ||
| ); | ||
| if (fit_prop > 0) { | ||
| wp = wp.map(function(x) { return x / fit_prop; }); | ||
|
Comment on lines
+578
to
+587
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is repetitive, please simplify
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for loop over ROW and COL? |
||
| hp = hp.map(function(y) { return y / fit_prop; }); | ||
| } | ||
|
|
||
| // track the proportion of the graph that should be 'blank' | ||
| // this is mainly used to implement coord_fixed() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| acontext("coord_equal fix for issue #234") | ||
|
|
||
| test_that("fixed_spaces keeps at least one dimension filling space", { | ||
| # Test with iris petal data ranges (issue #234 example) | ||
| ranges <- list(list(x.range = c(1, 7), y.range = c(0, 2.5))) | ||
| spaces <- animint2:::fixed_spaces(ranges, ratio = 1) | ||
|
|
||
| # At least one dimension should be 1 (fills available space on a square cell) | ||
| max_prop <- max(spaces$x, spaces$y) | ||
| expect_equal(max_prop, 1) | ||
|
|
||
| # Both proportions should be positive and <= 1 | ||
| expect_gt(spaces$x, 0) | ||
| expect_lte(spaces$x, 1) | ||
| expect_gt(spaces$y, 0) | ||
| expect_lte(spaces$y, 1) | ||
| # Data aspect y/x preserved for the JS scale-to-fit step | ||
| expect_equal(spaces$y / spaces$x, 2.5 / 6) | ||
| }) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| acontext("coord_equal renderer tests") | ||
|
|
||
| test_that("coord_equal fills available space (issue #234)", { | ||
| # Create the iris petal plot from issue #234 | ||
| # This test ensures coord_equal() doesn't shrink the plot unnecessarily | ||
| library(data.table) | ||
| data.mat <- as.matrix(iris[,c("Petal.Width","Petal.Length")]) | ||
|
|
||
| # Create the visualization with a specific size | ||
| viz <- animint( | ||
| plot1=ggplot(data=data.table(data.mat), aes(Petal.Length, Petal.Width))+ | ||
| geom_point()+ | ||
| coord_equal()+ | ||
| theme_animint(width=500, height=500) | ||
| ) | ||
|
|
||
| # Render the plot using animint2HTML (not animint2dir) | ||
| info <- animint2HTML(viz) | ||
|
|
||
| # Extract SVG plotting area dimensions | ||
| # Get the SVG element to check overall plot dimensions | ||
| svg.nodes <- getNodeSet(info$html, '//svg[@id="plot_plot1"]') | ||
| expect_equal(length(svg.nodes), 1) | ||
| svg.attrs <- xmlAttrs(svg.nodes[[1]]) | ||
|
|
||
| # Extract width and height attributes | ||
| svg.width <- as.numeric(svg.attrs[["width"]]) | ||
| svg.height <- as.numeric(svg.attrs[["height"]]) | ||
|
|
||
| # The key test: with coord_equal(), at least one dimension should | ||
| # fill the available space (close to 500px as specified in theme_animint) | ||
| # On the old buggy code (before the fix in commit e4b9634b), BOTH dimensions | ||
| # would be unnecessarily shrunk below the available space. | ||
| # With the fix, at least one dimension uses nearly all available space. | ||
|
|
||
| # The iris petal data has aspect ratio of ~0.417 (y_range=2.5, x_range=6) | ||
| # So with coord_equal (ratio=1), the x-axis fills space (width≈500) | ||
| # and y-axis is constrained by aspect ratio (height≈200) | ||
|
|
||
| # Test that at least ONE dimension is close to requested size (500) | ||
| max_dimension <- max(svg.width, svg.height) | ||
| expect_gt(max_dimension, 450) | ||
|
|
||
| # Both dimensions should be positive | ||
| expect_gt(svg.width, 0) | ||
| expect_gt(svg.height, 0) | ||
| # Issue #234 acceptance: fill available space. Aspect-ratio math is covered by | ||
| # test-compiler-coord-equal-fix.R and test-renderer1-coord.R (normDiffs). | ||
| }) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please look at Files changed tab before asking me to review again?
this section, and another below, delete error messages about facets, unrelated to coord_equal.
please undo or explain?