@Yori
2015-04-20T04:52:54.000000Z
字数 1262
阅读 1156
创新实验班
译文标题:不一样的Go:图像绘制模式
原文标题:The Other Side of Go: Programming Pictures, the Read, Parse, Draw Pattern
来源:http://blog.gopheracademy.com/advent-2014/other-side/
译文:https://www.zybuluo.com/Yori/note/63094
SVGo is designed so that programmers can think in terms of high-level objects like circles, rectangles, lines, polygons, and curves, using the program’s logic to manage layout and relationships, while applying styles and other attributes to the objects as needed.
SVGo的设计思想使我们在对高层对象(即圆、矩形、线、 多边形、曲线等)进行操作时,可以想到利用程序的逻辑性来管理其布局和元素之间的关系,并且根据需要向该高层对象应用图形样式和其他属性。
Here is a simple example that takes data from XML (using JSON is very similar), and creates a simple visualization in SVG to standard output. Note that for your own data you are free to define the input structure as you see fit, but other sources like Internet service APIs will define their own structure.
下面通过一个简单的例子,解释如何通过从XML(使用JSON也非常相似)中获取数据并且生成一个简单的可视化的SVG。需要注意的是,如果采用自定义数据,你可以自由的定义数据的结构,但如果使用其他诸如Internet service APIs的数据来源时,需要遵循它们定义好的数据结构。
You can see the correspondence between the elements and attributes of the data with the Go struct: A “thing” has a top and left location that defines the drawing’s origin, along with an attribute that defines the separation between elements.
在例子中,我们可以看到在结构体中定义的元素和数据属性之间的对应关系:结构体'Thing'中定义了图形初始时的顶部和左侧的位置和元素的间距。
in terms of
visualization 形象化
correspondence 通信
destination 目的地
dimensions 规模
conventional 符合习俗的