1 | <html> |
---|
2 | <head> |
---|
3 | <title>GFX on SVGWeb sample</title> |
---|
4 | |
---|
5 | <!-- tell svgweb to use flash rather than native svg --> |
---|
6 | <meta name="svg.render.forceflash" content="true"/> |
---|
7 | <!-- include svgweb, must before dojo, notice the extra 'data-path' attribute --> |
---|
8 | <script src="svgweb/src/svg.js" data-path="svgweb/src"></script> |
---|
9 | <!-- include dojo, notice the config: forceGfxRenderer:'svg' --> |
---|
10 | <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="async: true, isDebug: true, forceGfxRenderer: 'svg'"></script> |
---|
11 | |
---|
12 | <script type="text/javascript"> |
---|
13 | require(["dojo/dom", "dojox/gfx", "dojox/gfx/move"], function(dom){ |
---|
14 | |
---|
15 | function testSurface() { |
---|
16 | var node = dom.byId("surface"); |
---|
17 | var surface = dojox.gfx.createSurface(node, 600, 550); |
---|
18 | |
---|
19 | surface.whenLoaded( |
---|
20 | function() { |
---|
21 | surface.openBatch(); |
---|
22 | |
---|
23 | basicShapes(surface); |
---|
24 | basicTransform(surface); |
---|
25 | basicGroup(surface); |
---|
26 | basicMove(surface); |
---|
27 | basicText(surface); |
---|
28 | |
---|
29 | surface.closeBatch(); |
---|
30 | } |
---|
31 | ); |
---|
32 | |
---|
33 | window.s = surface; |
---|
34 | } |
---|
35 | |
---|
36 | function basicText(surface) { |
---|
37 | var text = surface.createText({x: 200, y: 200, text: "I'm wrong!"}); |
---|
38 | text.setShape({text: "The red circle is draggable"}); |
---|
39 | } |
---|
40 | |
---|
41 | function basicMove(surface) { |
---|
42 | var d = surface.createCircle({ |
---|
43 | r : 50, |
---|
44 | cx : 200, |
---|
45 | cy: 200 |
---|
46 | }).setFill({ |
---|
47 | type: "radial", |
---|
48 | cx : 200, |
---|
49 | cy: 200, |
---|
50 | r:50, |
---|
51 | colors: [ |
---|
52 | {color:"white",offset:0}, |
---|
53 | {color:"red",offset:1} |
---|
54 | ] |
---|
55 | }); |
---|
56 | new dojox.gfx.Moveable(d); |
---|
57 | } |
---|
58 | |
---|
59 | function basicGroup(surface) { |
---|
60 | var _defaultStroke = { |
---|
61 | color : "black", |
---|
62 | style : "solid", |
---|
63 | width : 1 |
---|
64 | }; |
---|
65 | |
---|
66 | var _arrowHeight = 5; |
---|
67 | var _arrowWidth = 3; |
---|
68 | |
---|
69 | drawArrow(300,300, 435,435); |
---|
70 | drawArrow(300,300, 165,165); |
---|
71 | drawArrow(300,300, 435,165); |
---|
72 | drawArrow(300,300, 165,435); |
---|
73 | |
---|
74 | drawArrow(300,300, 300,450); |
---|
75 | drawArrow(300,300, 300,150); |
---|
76 | drawArrow(300,300, 150,300); |
---|
77 | drawArrow(300,300, 450,300); |
---|
78 | |
---|
79 | function drawArrow(x1, y1, x2, y2) { |
---|
80 | var len = Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)); |
---|
81 | var group = surface.createGroup(); |
---|
82 | |
---|
83 | group.createLine({ |
---|
84 | x1 : 0, |
---|
85 | y1 : 0, |
---|
86 | x2 : 0+len, |
---|
87 | y2 : 0 |
---|
88 | }).setStroke(_defaultStroke); |
---|
89 | |
---|
90 | group.createPath() |
---|
91 | .moveTo(len-_arrowHeight,0) |
---|
92 | .lineTo(len-_arrowHeight,-_arrowWidth) |
---|
93 | .lineTo(len,0) |
---|
94 | .lineTo(len-_arrowHeight,_arrowWidth) |
---|
95 | .lineTo(len-_arrowHeight,0) |
---|
96 | .setStroke(_defaultStroke) |
---|
97 | .setFill("black"); |
---|
98 | |
---|
99 | var _rot = Math.asin((y2-y1)/len)*180/Math.PI; |
---|
100 | if (x2 <= x1) {_rot = 180-_rot;} |
---|
101 | |
---|
102 | group.setTransform([ |
---|
103 | dojox.gfx.matrix.translate(x1,y1), |
---|
104 | dojox.gfx.matrix.rotategAt(_rot,0,0) |
---|
105 | ]); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | function basicTransform(surface) { |
---|
110 | var rect1 = surface.createRect({ |
---|
111 | width : 200, |
---|
112 | height: 200 |
---|
113 | }) |
---|
114 | .setFill("red") |
---|
115 | .setTransform([ |
---|
116 | dojox.gfx.matrix.rotategAt(45,50,350), |
---|
117 | dojox.gfx.matrix.translate(50,350) |
---|
118 | ]); |
---|
119 | } |
---|
120 | |
---|
121 | function basicShapes(surface) { |
---|
122 | surface.createEllipse({ |
---|
123 | cx : 300, |
---|
124 | cy : 300, |
---|
125 | rx : 50, |
---|
126 | ry : 100 |
---|
127 | }).setFill("yellow"); |
---|
128 | |
---|
129 | surface.createRect({ |
---|
130 | x : 90, |
---|
131 | y : 90, |
---|
132 | width : 50, |
---|
133 | height : 170 |
---|
134 | }).setFill([255,0,0,0.5]); |
---|
135 | |
---|
136 | surface.createCircle({ |
---|
137 | cx : 400, |
---|
138 | cy : 200, |
---|
139 | r : 50 |
---|
140 | }).setFill([255,0,0,0.5]); |
---|
141 | |
---|
142 | surface.createCircle({ |
---|
143 | cx : 425, |
---|
144 | cy : 225, |
---|
145 | r : 50 |
---|
146 | }).setFill([0,255,0,0.5]); |
---|
147 | |
---|
148 | surface.createCircle({ |
---|
149 | cx : 425, |
---|
150 | cy : 175, |
---|
151 | r : 50 |
---|
152 | }).setFill([0,0,255,0.5]); |
---|
153 | |
---|
154 | } |
---|
155 | testSurface(); |
---|
156 | }); |
---|
157 | </script> |
---|
158 | </head> |
---|
159 | |
---|
160 | <body> |
---|
161 | <div id="surface" style="width:600;height:550;border:solid 1px"> |
---|
162 | </div> |
---|
163 | </body> |
---|
164 | </html> |
---|