Skip to content

Commit

Permalink
scale and filter for capture_pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 18, 2024
1 parent b92a97b commit 0cc9915
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 53 deletions.
78 changes: 78 additions & 0 deletions examples/scales-pdf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
library(shiny)
library(capture)

ui <- fluidPage(
tags$h2("Capture PDF (scales) example"),
capture_pdf(
selector = "body",
filename = "pdf-default-scale",
icon("camera"), "Default scale",
loading = loading()
),
capture_pdf(
selector = "body",
filename = "pdf-larger-scale",
icon("camera"), "Larger scale",
scale = 2.5,
loading = loading()
),
capture_pdf(
selector = "body",
filename = "pdf-smaller-scale",
icon("camera"), "Smaller scale",
scale = 0.9,
loading = loading()
),
tags$br(),
fluidRow(
column(
width = 4,
wellPanel(
tags$b("Parameters :"),

selectInput(
inputId = "loi",
label = "Law:",
choices = c("normal", "uniform", "exponential")
)
)
),
column(
width = 8,
tags$div(
id = "result-block",
tags$b("Results :"),
plotOutput(outputId = "plot"),
uiOutput(outputId = "mean"),
verbatimTextOutput(outputId = "raw")
)
)
)
)

server <- function(input, output, session) {
distrib_r <- reactive({
switch(
input$loi,
"normal" = rnorm(1000),
"uniform" = runif(1000),
"exponential" = rexp(1000)
)
})

output$plot <- renderPlot({
hist(distrib_r())
})

output$mean <- renderUI({
tags$p(tags$b("The mean is :"), round(mean(distrib_r()), 2))
})

output$raw <- renderPrint({
summary(distrib_r())
})
}

if (interactive())
shinyApp(ui, server)

2 changes: 1 addition & 1 deletion inst/packer/capture-pdf.js

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions inst/packer/capture-pdf.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,56 +236,6 @@
WebPRiffParser [email protected]
*/

/** @license
*
* jsPDF - PDF Document creation from JavaScript
* Version 2.5.1 Built on 2022-01-28T15:37:57.791Z
* CommitID 00000000
*
* Copyright (c) 2010-2021 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
* 2015-2021 yWorks GmbH, http://www.yworks.com
* 2015-2021 Lukas Holländer <[email protected]>, https://github.com/HackbrettXXX
* 2016-2018 Aras Abbasi <[email protected]>
* 2010 Aaron Spike, https://github.com/acspike
* 2012 Willow Systems Corporation, https://github.com/willowsystems
* 2012 Pablo Hess, https://github.com/pablohess
* 2012 Florian Jenett, https://github.com/fjenett
* 2013 Warren Weckesser, https://github.com/warrenweckesser
* 2013 Youssef Beddad, https://github.com/lifof
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2013 Stefan Slonevskiy, https://github.com/stefslon
* 2013 Jeremy Morel, https://github.com/jmorel
* 2013 Christoph Hartmann, https://github.com/chris-rock
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Makes, https://github.com/dollaruw
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 Steven Spungin, https://github.com/Flamenco
* 2014 Kenneth Glassey, https://github.com/Gavvers
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Contributor(s):
* siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango,
* kim3er, mfo, alnorth, Flamenco
*/

/** @license
* Copyright (c) 2012 Willow Systems Corporation, https://github.com/willowsystems
*
Expand Down
2 changes: 1 addition & 1 deletion inst/packer/capture-pdf.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion srcjs/exts/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ import * as utils from "../modules/utils";
var ratio = width / height;
var orientation = ratio > 1 ? "landscape" : "portrait";

var scale = parseInt(el.getAttribute("data-scale"));
var scale = parseFloat(el.getAttribute("data-scale"));
var options = el.getAttribute("data-options");
options = JSON.parse(options);
if (options.hasOwnProperty("filter")) {
options.filter = eval("(" + options.filter + ")");
}
if (!isNaN(scale)) {
options.height = options.height ? options.height * scale : node.offsetHeight * scale;
options.width = options.width ? options.width * scale : node.offsetWidth * scale;
Expand Down

0 comments on commit 0cc9915

Please sign in to comment.