Skip to content

Commit

Permalink
release 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
per committed Dec 8, 2021
1 parent 1c22335 commit 8d058cb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ Here is an example:

html.new("<html><body>")
html.add("<h2>A Sample report with a table and an image</h2>")
html.addPlot({
plot(mtcars$mpg ~ mtcars$hp, pch=23, col="orange", bg="orange", cex=1.5, lwd=2)
abline(h = mean(mtcars$mpg), col="green")
})
html.addPlot(
{
plot(mtcars$mpg ~ mtcars$hp, pch=23, col="orange", bg="orange", cex=1.5, lwd=2)
abline(h = mean(mtcars$mpg), col="green")
},
width=300,
height=400,
htmlattr=list(alt="mtcars mpg ~ hp", id="plot1")
)
html.add(mtcars)
html.add("</html></body>")
# save the html to a file
Expand All @@ -24,7 +29,7 @@ To be able to do this, add the dependency to your pom.xml as follows:
<dependency>
<groupId>se.alipsa</groupId>
<artifactId>htmlcreator</artifactId>
<version>1.4</version>
<version>1.4.1</version>
</dependency>
```
As you can see, the main method is the overloaded `html.add`. It can take
Expand All @@ -35,12 +40,12 @@ or
with `{ }`, this to allow the plot function to be executed by the html.addPlot method (which converts the result of the plot to an image and
base64 encodes it into a string which is then made part of the img tag) rather than executed before the function is called.

In addition to `html.add(x,...)`, there is the `html.clear()` function which resets the
In addition to `html.add(x,...)` and `html.addPlot(x, ...)`, there is the `html.clear()` function which resets the
underlying html object (clears the content). The `html.new(x, ...)` is an alias for `html.clear()`
followed by `html.add(x,...)` and is a good way to start the script
(especially if you run multiple scripts in the same session).

html attributes can be set by passing setting the parameter `htmlattr` to a list of attribute, e.g:
html attributes can be set by setting the parameter `htmlattr` to a list of attribute, e.g:
```r
# add id and class to a table:
html.add(mtcars, htmlattr=list(id="cardetails", class="table table-striped"))
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>se.alipsa</groupId>
<artifactId>htmlcreator</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<name>Renjin html content creator</name>
Expand Down Expand Up @@ -63,9 +63,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>se.alipsa</groupId>
<artifactId>xmlr</artifactId>
<version>0.2.1</version>
<groupId>se.alipsa</groupId>
<artifactId>xmlr</artifactId>
<version>0.2.1</version>
</dependency>

<!-- the hamcrest package is only required if you use it for unit tests -->
Expand Down
4 changes: 3 additions & 1 deletion src/main/R/Html.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ html.clear <- function() {

html.new <- function(x, ...) {
html.clear()
html.add(x, ...)
if(! missing(x)) {
html.add(x, ...)
}
}

setMethod('as.vector', signature("Html"),
Expand Down
2 changes: 0 additions & 2 deletions src/main/R/HtmlImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ html.imgPlot <- function(plotFunction, ..., htmlattr=NA) {
html.imgPlotComplex <- function(plotFunction, ..., htmlattr=NA) {
outFile <- tempfile("plot", fileext = ".png")
png(outFile, ...)
# alt
# height: exists both in img and barplot
eval(plotFunction)
dev.off()
imgContent <- FileEncoder$contentAsBase64(outFile)
Expand Down
13 changes: 6 additions & 7 deletions src/test/R/HtmlcontentTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ test.dataFrameToTable <- function() {
}

test.plotToImage <- function() {
html.new(
barplot,
table(mtcars$vs, mtcars$gear),
main="Car Distribution by Gears and VS",
col=c("darkblue","red")
)
html.new()
html.addPlot({
plot(mtcars$mpg ~ mtcars$hp, pch=23, col="orange", bg="orange", cex=1.5, lwd=2)
abline(h = mean(mtcars$mpg), col="green")
}, width=300, height=400, htmlattr=list(alt="mtcars mpg ~ hp", width=450, height=250))
outFile <- paste0(getwd(), "/test.plotToImage.html")
write(html.content(), outFile)
print(paste("Wrote", outFile))
assertThat(html.content(), str.beginsWith("<html><img src='data:image/png;base64,"))
assertThat(html.content(), str.beginsWith("<html><img alt='mtcars mpg ~ hp' width='450' height='250' src='data:image/png;base64,i"))
assertThat(html.content(), str.endsWith("</img></html>"))

}
Expand Down

0 comments on commit 8d058cb

Please sign in to comment.