The gridsvg package. Paul Murrell. October 30, 2017

Similar documents
Animation with the gridsvg package

Working with grid Viewports

Writing grid Code. Paul Murrell. December 14, 2009

Working with grid Viewports

Modifying grid grobs

A GUI-Builder Approach to grid Graphics

Package gridgraphics

Package grimport2. March 20, 2018

Display Lists in grid

Display Lists in grid

Talk Overview. grid Graphics and Programming. The Structure of R Graphics. Introduction to grid

Microscopic Measurement

Shadows for Many Lights sounds like it might mean something, but In fact it can mean very different things, that require very different solutions.

Scalable Vector Graphics (SVG) vector image World Wide Web Consortium (W3C) defined with XML searched indexed scripted compressed Mozilla Firefox

The LDheatmap Package

Hashing. Hashing Procedures

QUADRATIC AND CUBIC GRAPHS

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip.

Big Mathematical Ideas and Understandings

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Package gridgraphviz

Reading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field

R Graphics. Paul Murrell. The University of Auckland. R Graphics p.1/47

Animations involving numbers

3.2 A Three-Bar Linkage 51

Web-Friendly Sites. Planning & Design 1

CS 100 Spring Lecture Notes 3/8/05 Review for Exam 2

Solutions to In Class Problems Week 5, Wed.

CEng 477 Introduction to Computer Graphics Fall 2007

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

CS474 MULTIMEDIA TECHNOLOGY

Creating True Scale Map Books with AutoCAD Map 3D 2009

CSS Data Types. One of Those Things You Have To Know

Epidemic spreading on networks

ICH M8 Expert Working Group. Specification for Submission Formats for ectd v1.1

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2012 Lecture 5 September 13, 2012

Direct Variations DIRECT AND INVERSE VARIATIONS 19. Name

Working with the BCC 2D Particles Filter

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

(Refer Slide Time 6:48)

Animation is the illusion of motion created by the consecutive display of images of static elements. In film and video

1Anchors - Access. Part 23-1 Copyright 2004 ARCHIdigm. Architectural Desktop Development Guide PART 23 ANCHORS 1-23 ANCHORS

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

1

Triangle Rasterization

Image creation with PHP

Fraction Addition & Subtraction

Structural & Thermal Analysis using the ANSYS Workbench Release 11.0 Environment. Kent L. Lawrence

COMPUTER GRAPHICS COURSE. Rendering Pipelines

Ogonkify. Juliusz Chroboczek

Scalable Vector Graphics commonly known as SVG is a XML based format to draw vector images. It is used to draw twodimentional vector images.

Classroom Tips and Techniques: Branch Cuts for a Product of Two Square-Roots

File Size Distribution on UNIX Systems Then and Now

Let s Make a Front Panel using FrontCAD

Lab 1 Introduction to MATLAB and Scripts

lecture notes September 2, How to sort?

4 Visualization and. Approximation

Proceedings of the Third International DERIVE/TI-92 Conference

Exercise Guide. Published: August MecSoft Corpotation

COMPUTER AIDED ARCHITECTURAL GRAPHICS FFD 201/Fall 2013 HAND OUT 1 : INTRODUCTION TO 3D

MA 1128: Lecture 02 1/22/2018

S206E Lecture 3, 5/15/2017, Rhino 2D drawing an overview

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

This is the vector graphics "drawing" technology with its technical and creative beauty. SVG Inkscape vectors

Introduction to Domain Testing

Previously... contour or image rendering in 2D

Grade 6 Math Circles. Shapeshifting

A Sample L A TEX Document

PDF and Accessibility

Viewports. Peter-Paul Koch DevReach, 13 November 2017

CS 11 Haskell track: lecture 1

4. Write sets of directions for how to check for direct variation. How to check for direct variation by analyzing the graph :

The Limits of Sorting Divide-and-Conquer Comparison Sorts II

BCC Rays Ripply Filter

What's New in Rev. 3.0.

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Algebra of Sets (Mathematics & Logic A)

Topic C. Communicating the Precision of Measured Numbers

Activity Guide APIs and Using Functions with Parameters

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Computer Graphics. - Rasterization - Philipp Slusallek

OMINO PYTHON for After Effects

Topic: Topic 1-Numeration

grid Graphics Paul Murrell December 7, 2017

Hello, world! 206 TUGboat, Volume 31 (2010), No. 2. resulting in: Drawing structured diagrams with SDDL Mathieu Bourgeois and Roger Villemaire

Digitizer Leapfrogging

III-6Exporting Graphics (Windows)

SESSION FIVE CIRCUMFERENCE AND AREA OF A CIRCLE

521493S Computer Graphics Exercise 1 (Chapters 1-3)

Section 1.1 The Distance and Midpoint Formulas

Types of Plotting Functions. Managing graphics devices. Further High-level Plotting Functions. The plot() Function

Interpretations and Models. Chapter Axiomatic Systems and Incidence Geometry

The Java Type System (continued)

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

function at the given point. Thus, for our previous example we would find that lim f(x) = 0

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Transcription:

The gridsvg package Paul Murrell October 30, 2017 Introduction This package is an experiment in writing a graphics device, purely in R code, for the grid graphics system. The specific device implemented is for the W3C SVG (Scalable Vector Graphics) format, but there is also some effort at a general device interface that would support other specific devices. User Interface There are five functions of interest to the user: grid.hyperlink takes a grid grob and turns it into an object of class linked.grob, with an associated href. This allows the association of hyperlinks with elements of a grid graphic. See gridsvg/tests/testlink.r for examples. grid.animate allows the user to associate a duration (plus some other things) with certain aspects of a grid grob. This allows a grid graphic element to be animated. See gridsvg/tests/testanimate.r testpendulum.r and testball.r for examples. grid.garnish allows the user to associate arbitrary SVG attributes with a grid grob. This provides a way to associate with a grob things that have no corresponding grid concept, like an onclick attribute. See gridsvg/tests/testattrib.r for a simple example. grid.script allows the user to create a grid grob that contains an SVG script (e.g., some ECMAscript code). This provides a way to produce a complete SVG document (complete with scripts) entirely using R grid code (i.e., without having to hand edit the SVG file that gridsvg creates. Again, see gridsvg/tests/testattrib.r for a simple example. gridtosvg() saves the current grid graphic to an SVG file. See the gridsvg/tests directory for examples of what can be done. See the section Known Problems below for things that are not yet supported. 1

In addition to these functions, gridsvg supports alpha-transparency by respecting the alpha graphical parameter which can be specified in a grid gpar object. For example, the following code produces overlapping transparent circles 1 : > pushviewport(viewport(gp=gpar(col="black", fill=na))) > grid.circle(x=0.33, r=unit(2, "inches"), gp=gpar(alpha=0.3, fill="red")) > grid.circle(x=0.67, r=unit(2, "inches"), gp=gpar(alpha=0.3, fill="green")) > popviewport() > gridtosvg() > Internal Structure There are nine.r files in the gridsvg/r directory, corresponding to the nine different things that gridsvg aims to provide: dev.r This contain (S4 methods) code defining a generic R-level graphics device interface. In other words, generic functions that may be called by a graphics system (such as grid), and that a graphics device (such as an SVG device) should provide methods for. griddev.r Code for running through the grid display list and calling generic device functions. devsvg.r Code implementing SVG methods for the generic device interface. svg.r A set of R-level functions for producing SVG output. Callable directly (see, e.g., gridsvg/tests/testsvg.r), but mostly just called by code in devsvg.r. gridsvg.r The function gridtosvg(). hyper.r Code implementing the linked.grob class i.e., an extension of the standard grid grob that supports hyperlinks. Includes the function grid.hyperlink(). animate.r Code implementing the animated.grob class i.e., an extension of the standard grid grob that supports animation. Includes the function grid.animate(). script.r Code implementing the script class i.e., an extension of the standard grid grob that supports SVG scripts. Includes the function grid.script(). attrib.r Code implementing the svg.grob class i.e., an extension of the standard grid grob that supports arbitrary SVG attributes. Includes the function grid.garnish(). 1 The pushviewport() call is currently necessary to set some default values. It may be possible to remove this in future versions. 2

Known Problems This package is a partial implementation of several ideas. This section describes some of the known holes in and issues with the implementation. Overall Design The package is ass-backwards in its design. Normal devices receive calls from grid to perform operations; gridsvg works off grid s display list so only has the information stored there to figure out what to do. This means that it has to replicate some of the work that grid does when grid draws (e.g., in order to enforce vp slots in grobs). If/when normal devices are implemented as R-level objects, so that grid includes a dev argument in all its calls to devices, it may be possible to make gridsvg behave more like a normal device and this may lead to some simplifications. Sizing of and units in the SVG image Software that tries to render SVG on a device has the same problem that R graphics devices have when trying to render grid output: Locations and sizes can be in a variety of units (cm, inches, percentages,...) some of which are physical units with real-world meaning. The renderer has to figure out how big something like 1" is in the native device units. This problem is worst on computer screens where it is not necessarily easy (or possible) to find out how many pixels there are in a physical inch on the screen. What R does is try its best and it seems that SVG renderers must do the same 2. gridsvg works off the grid display list. This means that the image must first be drawn on some other device (e.g., X11 or PostScript) then copied (via the gridsvg() function) to an SVG format. It is not possible to use the SVG notion of transformations to mirror grid s viewport transformations because the SVG transformations work on ALL graphical elements, including text. In particular, any scaling transformations scale the size of text. Furthermore, grid actions such as upviewport() and downviewport() are difficult to replicate as SVG transformations. So the copying of grid output to SVG involves converting all locations and sizes to a single SVG coordinate system. There are two (serious) possibilities for this coordinate system: 1. specify everything (including the size of the SVG image) in pixels. In this case, what we do is work off the original device s concept of a pixel. The SVG image may be rendered quite a different size compared to the original if the size of pixels on the rendering device is different from the 2 According to Section 7.1 Introduction of the W3C Scalable Vector Graphics (SVG) 1.0 Specification, a real number value that indicates the size in real world units, such as millimeters, of a pixel is highly desirable but not required. 3

size of pixels on the original device. Things should be pretty consistent something that is supposed to be half the size of the image should be rendered half the size of the image though this will not be the case if the change in pixel size is different for x- and y-axes. An image drawn first in a screen window then copied to SVG and viewed on the same screen should hopefully be the same size. If the original device is a screen device, there is no guarantee that physical sizes will be respected; this will depend on how accurately the screen device can determine the physical size of its pixels. If the original device is a file device (e.g. PostScript) then physical sizes will be accurate on the original device, BUT the correspondence between pixels on the file device and pixels when the SVG is rendered on screen is very unlikely to be good (e.g., pixels on PostScript are 1 72 ", which is highly unlikely to correspond to pixel size on a modern screen). 2. specify everything (including the size of the SVG image) in inches. In this case, there is no guarantee that the SVG image will end up the right physical size (it will depend on whether the rendering software can find out enough about pixels-to-inches, BUT everything should be in proportion (if the image is overall a little smaller than it should be, at least something that should be half the size of the image will be half the size of the image. The final rendered size of the image will totally depend on where it gets rendered 3. This appears to have fewer problems; unfortunately it is totally killed by the fact that the locations for drawing polylines MUST be in pixels! (technically, that should be user coordinates, but since I have a single, flat coordinate system structure, it equates to pixels.) Plotting Symbols Only pch=1 and pch=3 are currently supported. This is just a matter of filling in the other options. Mathematical Annotation The use of things like grid.text(expression(x[i])) is supported in the main R graphics engine. gridsvg bypasses that and so does not support mathematical annotation (and probably never will!). Time unit arithmetic Animation is no longer achieved via time units so old problems with arithmetic on time units in previous versions of gridsvg disappear (i.e., the user does not need to be as careful when doing animation; just specify some unit values and/or expressions and it should go.) Having said that, there is still only support for 3 This is not to say that it should be riciculously off; it should be pretty close to the right physical size if it s not exactly the right size. 4

animating a small set of aspects of grid grobs (basically the locations and sizes of grobs. Acknowledgements Many thanks to Nathan Whitehouse and colleagues who contributed ideas and code for including arbitrary SVG attributes and SVG scripts. 5