beta
Eugene Lazutkin Kun Xi
Implementation of simple portable 2D graphics library.
Dojo Core
Currently it can be found here: http://docs.google.com/Doc?id=d764479_1hnb2tn
Just include this line in your code:
dojo.require("dojox.gfx");
dojox.gfx is a cross-platform declarative interactive graphics package. It follows SVG loosely as the underlying model. At present time SVG and VML back-ends are implemented.
The dojox.gfx package provides graphics rendering and manipulation. Under Firefox, Opera and Safari dojox.gfx renders the final product as SVG, under IE it renders as VML.
Potentially the gfx package can allow you to create live and interactive graphing, a web based vector drawing program, view svg files in IE.
On conceptual level dojo.gfx has a simple declarative model: All basic primitives required for 2D graphics are defined:
There is a surface, which serves as a visual rectangular container for shapes:
There is a notion of a shape description object, which represent a simple description of geometry, with corresponding shape objects. dojox.gfx supports following shapes:
Shapes support following set of properties:
Shapes are stacked from bottom to top in an order of their definition. This z-order can be changed dynamically.
There is a group, which is a pseudo-shape. It combines other shapes (and possibly groups), and can be used to apply transformation to a group. All group members share a single z-order, but can be re-arranged within a group.
In order to draw a picture a programmer constructs a pseudo-DOM from a surface object, shapes, and groups, sets appropriate attributes, and picture is drawn automatically by a browser. Modifications of shapes change picture automatically. It is possible to attach event handlers to shapes using dojo.event.connect(). Following conventions are used:
While a path is the most universal geometric shape, which can emulate almost all other shapes (exceptions: image, and text shapes), all frequently-used shapes are provided as a convenience: rectangle (with optionally rounded corners), circle, ellipse, line, polyline/polygon.
All shape description properties are defined using a duck-typing technique. Incomplete shape description definitions are supported. All missing members will be taken from corresponding default shape definitions listed in common.js or from the current shape description object. Example: rect.setShape({width: 200}) - all missing members will be taken from dojo.gfx.defaultRect object making it equivalent to rect.setShape({x: 0, y: 0, width: 200, height: 100, r: 0}).
All shape description objects and visual property objects have a member called "type", which uniquely identifies a property type. This is a provision for a possible serialization.
Certain shape properties can be defined using shortcuts:
All methods without an apparent return type return their object itself. It is used for chaining multiple operations: