找回密码
 注册
查看: 2186|回复: 0

R语言 SVGAnnotation包 addECMAScripts()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-22 21:05:05 | 显示全部楼层 |阅读模式
addECMAScripts(SVGAnnotation)
addECMAScripts()所属R语言包:SVGAnnotation

                                        Add Java/ECMAScript code and data to an SVG document
                                         新增的Java / ECMAScript代码和数据到SVG文档

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This function and its methods allow the caller to easily and programmatically add JavaScript/ECMAScript code to an SVG document or an HTML document. The functions take care of the details, allowing the code to be inserted directly or a reference to the file via an href link.  The code can also be given as verbatim (AsIs) text rather than being in a file which allows the content to be dynamically generated within R functions.
此功能和它的方法,让来电者轻松编程的JavaScript / ECMAScript代码添加到SVG文档或HTML文档。功能细节的照顾,使代码直接插入或通过href参考链接文件。代码也可以作为逐字(ASIS),而不是在一个文件中允许的内容进行动态生成的R函数内的文本。

The benefit of inserting the contents of a JavaScript file into the document is that the resulting document does not have external dependencies on this file. We can move the XML document and not have to remember to also move the JavaScript file or update the link.
一个JavaScript文件的内容插入到文档的好处是产生的文件,这个文件没有外部的依赖。我们可以将XML文档并没有记住也将JavaScript文件或更新的链接。

The downside is that it is often convenient to create the SVG and then modify the JavaScript code.  This is very common when developing the JavaScript code. If we keep the JavaScript file separate from the SVG, we can update it and then merely reload the SVG file in our viewer/browser to work with the updated JavaScript code.
缺点是,它常常是方便创建SVG和修改JavaScript代码。开发JavaScript代码时,这是很常见的。如果我们保持独立的JavaScript文件,从SVG,我们可以更新它,然后只重新在我们的浏览器/浏览器的SVG文件,以更新的JavaScript代码。

An additional drawback to inserting the code is that if we use it many different SVG files, we have many copies of the code and if it is large, we are wasting space and bandwidth.
插入代码的另外一个缺点是,如果我们使用了许多不同的SVG文件,我们有许多代码副本,如果是大的,我们是在浪费空间和带宽。

I tend to include the code after I have finished working out the bugs and features, i.e. when I am generating the SVG file knowing it is woring as desired.
我倾向于后,我已完成工作的缺陷和功能,即当我知道它是woring根据需要生成SVG文件包括代码。

In addition to adding JavaScript code, one can also add JavaScript variables which are created by serializing R objects. This allows us to use data computed in R within our JavaScript code with little effort. The serialization is done primarily via the rjson package, with some generalizations provided by this package.
除了添加JavaScript代码,也可以添加JavaScript变量序列R对象创建。这使我们能够使用毫不费力地在R的数据计算在我们的JavaScript代码。序列化完成,主要是通过rjson包,这个包提供了一些概括。


用法----------Usage----------


addECMAScripts(doc, scripts,
               insertJS = inherits(scripts, "AsIs"),
               at = NA, ..., .jsvars = list(...),
               escapeFun = newXMLCDataNode)



参数----------Arguments----------

参数:doc
the XML document to which the JavaScript code is to be added. This is expected to have been parsed previously rather than be the name of a file.
JavaScript代码是要添加XML文档。预计这已被解析,而不是以前的文件名。


参数:scripts
a character vector giving the names of the JavaScript code files or the code itself. Use I("text for code") to ensure the value is treated as verbatim code.
给一个字符向量的JavaScript代码文件或代码本身的名字。使用I("text for code")以确保值逐字代码的处理。


参数:insertJS
a logical value which controls whether the JavaScript code is actually inserted into the  XML document so that it is a stand-alone document with no references to this JavaScript code, or if href references are inserted into the XML document.
一个逻辑值,它控制的JavaScript代码是否实际插入到XML文档,所以,它是一个独立的文件没有提及这段JavaScript代码,或如果href引用插入到XML文档。


参数:at
an integer that specifies where to add the new XML nodes within the children of the SVG root. By default, the new nodes are added at the end. The order is typically not important.
一个整数,指定其中添加新的XML节点内的SVG根儿童。默认情况下,在末尾增加新的节点。通常的顺序是并不重要。


参数:...
name = value pairs of JavaScript variable names and R objects which are to be serialized and assigned to those JavaScript variables.
name = value对JavaScript变量名和R的对象进行序列化和分配的JavaScript变量。


参数:.jsvars
an alternative to ... in order to specify JavaScript variables to be defined and initialized. This is convenient when we have the variables already in a list.
替代...以指定JavaScript变量定义和初始化。当我们已经在列表中的变量,这是非常方便。


参数:escapeFun
either NULL or a function that is used to create the node to hold the text of the code. This is typically a CDATA node, but for HTML documents, it is a comment node
要么NULL或一个用于创建节点举行的代码文本的功能。这通常是一个CDATA节点,但对于HTML文件,它是一个注释节点


值----------Value----------

The updated XML document, invisibly.
更新后的XML文件,无形之中。


作者(S)----------Author(s)----------


Duncan Temple Lang



参考文献----------References----------



举例----------Examples----------


   # See linkPlots() for how to do this.[如何做到这一点linkPlots()。]
data(mtcars)
doc = svgPlot({
                 par(mfrow = c(1, 2))
                 plot(mpg ~ wt, mtcars)
                 plot(mpg ~ vs, mtcars)
               })

f = system.file("JavaScript", "link.js", package = "SVGAnnotation")
addECMAScripts(doc, f)
addECMAScripts(doc, f, insert = TRUE)


x = rnorm(20)
y = rnorm(20)

doc = svgPlot(plot(x, y))
d = as.matrix(dist(cbind(x, y)))
D = apply(d, 1, order)
addECMAScripts(doc,
                "http://www.omegahat.org/SVGAnnotation/tests/knn.js",
                neighbors = D)

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-22 16:08 , Processed in 0.026317 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表