Skip to content

Conversation

@caijun
Copy link
Collaborator

@caijun caijun commented Mar 12, 2015

Using test-hjust-text-anchor.R to test Animint, the testing results are as follows

  1. Failure(@test-hjust-text-anchor.R#96): geom_text(hjust=0) => ----------------
    style.value does not match 'start'. Actual value: "middle"
  2. Failure(@test-hjust-text-anchor.R#103): geom_text(hjust=1) => -----------------
    style.value does not match 'end'. Actual value: "middle"

Copy link
Owner

Choose a reason for hiding this comment

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

in tests it is best to be as explicit as possible, so I would recommend that grad.desc.viz returns an animint list of ggplots and options, and then you take animint2HTML outside of the grad.desc.viz function, e.g.

viz <- grad.desc.viz(hjust=0)
info <- animint2HTML(viz)

@caijun
Copy link
Collaborator Author

caijun commented Mar 21, 2015

I have implemented get_text_anchor function in animint.js.

https://github.com/caijun/animint/blob/master/inst/htmljs/animint.js#L717-L733

Tests of geom_text(hjust=0) => <text style="text-anchor: start">, geom_text(hjust=1) => <text style="text-anchor: end">, and geom_text(hjust=0.5) => <text style="text-anchor: middle"> tests in test_hjust_text_anchor.R have successfully been passed.

Yes, it's easier to understand the code if putting animint2HTML outside of the grad.desc.viz function. I have updated test-hjust-text-anchor.R.

As for the geom_text(hjust=0.5) => <text style="text-anchor: middle"> test, in my grad.desc.viz, hjust aesthetic is given by a variable name rather than a value.

geom_text(aes(hjust = hjust)

The invalid input of hjust should be checked in get_text_anchor function and give a warning. But I don't know how pass warning from Javascript to R.

@tdhock
Copy link
Owner

tdhock commented Mar 23, 2015

These changes look good. Although it is possible to check for invalid hjust values at rendering time (and maybe report it using console.log), I think it makes more sense to check at compile time and then assume we have valid values at rendering time.

Actually there is already R code that should stop the compiler with an error

https://github.com/tdhock/animint/blob/master/R/animint.R#L174-L188

so please change the test to check for an error (not a warning), as we do with hjust for axis labels

https://github.com/tdhock/animint/blob/master/tests/testthat/test-rotate.R#L90-L97

@caijun
Copy link
Collaborator Author

caijun commented Mar 23, 2015

I check for invalid hjust values inside the saveLayer function of animint compiler.

https://github.com/caijun/animint/blob/master/R/animint.R#L322-L330

The test for invalid hjust values has been changed to check for an error.

https://github.com/caijun/animint/blob/master/tests/testthat/test-hjust-text-anchor.R#L114

All tests of test-hjust-text-anchor.R have been successfully passed, and you can merge this branch.

@tdhock
Copy link
Owner

tdhock commented Mar 23, 2015

Looks good to me. Now just update the package version to 2015.03.23 in DESCRIPTION, and add some info about the bug that you fixed in NEWS. After that I will merge into master.

tdhock pushed a commit that referenced this pull request Mar 24, 2015
implement geom_text(aes(hjust))
@tdhock tdhock merged commit 839c2b6 into tdhock:master Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants