|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Basic Path</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Basic Path</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
#custom-doc { width: 95%; min-width: 950px; } |
|
|
30 |
#pagetitle {background-image: url(../../assets/bg_hd.gif);} |
|
|
31 |
#mygraphiccontainer { |
|
|
32 |
position: relative; |
|
|
33 |
width: 700px; |
|
|
34 |
height:300px; |
|
|
35 |
} |
|
|
36 |
</style> |
|
|
37 |
<div class="intro"> |
|
|
38 |
<p>This example shows how to draw shapes and line segments with the <code>Path</code> shape.</p> |
|
|
39 |
</div> |
|
|
40 |
<div class="example"> |
|
|
41 |
<div id="mygraphiccontainer"></div> |
|
|
42 |
<script> |
|
|
43 |
YUI().use('graphics', function (Y) |
|
|
44 |
{ |
|
|
45 |
var mygraphic = new Y.Graphic({render: "#mygraphiccontainer"}), |
|
|
46 |
connector = mygraphic.addShape({ |
|
|
47 |
type: "path", |
|
|
48 |
stroke: { |
|
|
49 |
weight: 1, |
|
|
50 |
color: "#000", |
|
|
51 |
opacity: 1, |
|
|
52 |
dashstyle: [3, 4] |
|
|
53 |
}, |
|
|
54 |
id: "connector" |
|
|
55 |
}), |
|
|
56 |
diamond1 = mygraphic.addShape({ |
|
|
57 |
type: "path", |
|
|
58 |
stroke: { |
|
|
59 |
weight: 1, |
|
|
60 |
color: "#000" |
|
|
61 |
}, |
|
|
62 |
fill: { |
|
|
63 |
color: "#f00" |
|
|
64 |
}, |
|
|
65 |
id: "diamond1" |
|
|
66 |
}), |
|
|
67 |
diamond2 = mygraphic.addShape({ |
|
|
68 |
type: "path", |
|
|
69 |
stroke: { |
|
|
70 |
weight: 1, |
|
|
71 |
color: "#000" |
|
|
72 |
}, |
|
|
73 |
fill: { |
|
|
74 |
color: "#f00" |
|
|
75 |
}, |
|
|
76 |
id: "diamond2" |
|
|
77 |
}); |
|
|
78 |
|
|
|
79 |
diamond1.moveTo(60, 60); |
|
|
80 |
diamond1.lineTo(80, 40); |
|
|
81 |
diamond1.lineTo(100, 60); |
|
|
82 |
diamond1.lineTo(80, 80); |
|
|
83 |
diamond1.lineTo(60, 60); |
|
|
84 |
diamond1.end(); |
|
|
85 |
|
|
|
86 |
connector.moveTo(100, 60); |
|
|
87 |
connector.lineTo(450, 220); |
|
|
88 |
connector.end(); |
|
|
89 |
|
|
|
90 |
diamond2.moveTo(450, 220); |
|
|
91 |
diamond2.lineTo(470, 200); |
|
|
92 |
diamond2.lineTo(490, 220); |
|
|
93 |
diamond2.lineTo(470, 240); |
|
|
94 |
diamond2.lineTo(450, 220); |
|
|
95 |
diamond2.end(); |
|
|
96 |
}); |
|
|
97 |
</script> |
|
|
98 |
|
|
|
99 |
</div> |
|
|
100 |
|
|
|
101 |
<h2>HTML</h2> |
|
|
102 |
<pre class="code prettyprint"><div id="mygraphiccontainer"></div></pre> |
|
|
103 |
|
|
|
104 |
|
|
|
105 |
<h2>CSS</h2> |
|
|
106 |
<pre class="code prettyprint">#mygraphiccontainer { |
|
|
107 |
position: relative; |
|
|
108 |
width: 700px; |
|
|
109 |
height:300px; |
|
|
110 |
}</pre> |
|
|
111 |
|
|
|
112 |
|
|
|
113 |
<h2>Javascript</h2> |
|
|
114 |
<p>Create a <code>Graphic</code> instance.</p> |
|
|
115 |
<pre class="code prettyprint">var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"});</pre> |
|
|
116 |
|
|
|
117 |
|
|
|
118 |
<p>Create two path elements for end shapes. Give each a red fill and a black stroke.</p> |
|
|
119 |
|
|
|
120 |
<pre class="code prettyprint">var diamond1 = mygraphic.addShape({ |
|
|
121 |
type: "path", |
|
|
122 |
stroke: { |
|
|
123 |
weight: 1, |
|
|
124 |
color: "#000" |
|
|
125 |
}, |
|
|
126 |
fill: { |
|
|
127 |
color: "#f00" |
|
|
128 |
} |
|
|
129 |
}); |
|
|
130 |
|
|
|
131 |
var diamond2 = mygraphic.addShape({ |
|
|
132 |
type: "path", |
|
|
133 |
stroke: { |
|
|
134 |
weight: 1, |
|
|
135 |
color: "#000" |
|
|
136 |
}, |
|
|
137 |
fill: { |
|
|
138 |
color: "#f00" |
|
|
139 |
} |
|
|
140 |
});</pre> |
|
|
141 |
|
|
|
142 |
<p>Create a path for the connecting segment. Give it a black dashed stroke and no fill. The <code>dashstyle</code> property of the stroke attribute allows for the creation of a dashed stroke. The first value is |
|
|
143 |
the length of the dash and the second value is the gap space between dashes.</p> |
|
|
144 |
<pre class="code prettyprint">var connector = mygraphic.addShape({ |
|
|
145 |
type: "path", |
|
|
146 |
stroke: { |
|
|
147 |
weight: 1, |
|
|
148 |
color: "#000", |
|
|
149 |
opacity: 1, |
|
|
150 |
dashstyle: [3, 4] |
|
|
151 |
} |
|
|
152 |
});</pre> |
|
|
153 |
|
|
|
154 |
<p>Draw the first diamond.</p> |
|
|
155 |
|
|
|
156 |
<pre class="code prettyprint">diamond1.moveTo(60, 60); |
|
|
157 |
diamond1.lineTo(80, 40); |
|
|
158 |
diamond1.lineTo(100, 60); |
|
|
159 |
diamond1.lineTo(80, 80); |
|
|
160 |
diamond1.lineTo(60, 60); |
|
|
161 |
diamond1.end();</pre> |
|
|
162 |
|
|
|
163 |
<p>Draw the connector segment.</p> |
|
|
164 |
<pre class="code prettyprint">connector.moveTo(100, 60); |
|
|
165 |
connector.lineTo(450, 220); |
|
|
166 |
connector.end();</pre> |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
<p>Draw the second diamond.</p> |
|
|
170 |
<pre class="code prettyprint">diamond2.moveTo(450, 220); |
|
|
171 |
diamond2.lineTo(470, 200); |
|
|
172 |
diamond2.lineTo(490, 220); |
|
|
173 |
diamond2.lineTo(470, 240); |
|
|
174 |
diamond2.lineTo(450, 220); |
|
|
175 |
diamond2.end();</pre> |
|
|
176 |
|
|
|
177 |
<h2>Complete Example Source</h2> |
|
|
178 |
<pre class="code prettyprint"><div id="mygraphiccontainer"></div> |
|
|
179 |
<script> |
|
|
180 |
YUI().use('graphics', function (Y) |
|
|
181 |
{ |
|
|
182 |
var mygraphic = new Y.Graphic({render: "#mygraphiccontainer"}), |
|
|
183 |
connector = mygraphic.addShape({ |
|
|
184 |
type: "path", |
|
|
185 |
stroke: { |
|
|
186 |
weight: 1, |
|
|
187 |
color: "#000", |
|
|
188 |
opacity: 1, |
|
|
189 |
dashstyle: [3, 4] |
|
|
190 |
}, |
|
|
191 |
id: "connector" |
|
|
192 |
}), |
|
|
193 |
diamond1 = mygraphic.addShape({ |
|
|
194 |
type: "path", |
|
|
195 |
stroke: { |
|
|
196 |
weight: 1, |
|
|
197 |
color: "#000" |
|
|
198 |
}, |
|
|
199 |
fill: { |
|
|
200 |
color: "#f00" |
|
|
201 |
}, |
|
|
202 |
id: "diamond1" |
|
|
203 |
}), |
|
|
204 |
diamond2 = mygraphic.addShape({ |
|
|
205 |
type: "path", |
|
|
206 |
stroke: { |
|
|
207 |
weight: 1, |
|
|
208 |
color: "#000" |
|
|
209 |
}, |
|
|
210 |
fill: { |
|
|
211 |
color: "#f00" |
|
|
212 |
}, |
|
|
213 |
id: "diamond2" |
|
|
214 |
}); |
|
|
215 |
|
|
|
216 |
diamond1.moveTo(60, 60); |
|
|
217 |
diamond1.lineTo(80, 40); |
|
|
218 |
diamond1.lineTo(100, 60); |
|
|
219 |
diamond1.lineTo(80, 80); |
|
|
220 |
diamond1.lineTo(60, 60); |
|
|
221 |
diamond1.end(); |
|
|
222 |
|
|
|
223 |
connector.moveTo(100, 60); |
|
|
224 |
connector.lineTo(450, 220); |
|
|
225 |
connector.end(); |
|
|
226 |
|
|
|
227 |
diamond2.moveTo(450, 220); |
|
|
228 |
diamond2.lineTo(470, 200); |
|
|
229 |
diamond2.lineTo(490, 220); |
|
|
230 |
diamond2.lineTo(470, 240); |
|
|
231 |
diamond2.lineTo(450, 220); |
|
|
232 |
diamond2.end(); |
|
|
233 |
}); |
|
|
234 |
</script></pre> |
|
|
235 |
|
|
|
236 |
</div> |
|
|
237 |
</div> |
|
|
238 |
</div> |
|
|
239 |
|
|
|
240 |
<div class="yui3-u-1-4"> |
|
|
241 |
<div class="sidebar"> |
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
<div class="sidebox"> |
|
|
246 |
<div class="hd"> |
|
|
247 |
<h2 class="no-toc">Examples</h2> |
|
|
248 |
</div> |
|
|
249 |
|
|
|
250 |
<div class="bd"> |
|
|
251 |
<ul class="examples"> |
|
|
252 |
|
|
|
253 |
|
|
|
254 |
<li data-description="Shows how to create a Graphic instance and add shapes."> |
|
|
255 |
<a href="graphics-simple.html">Basic Graphics Implementation</a> |
|
|
256 |
</li> |
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
<li data-description="Shows how to draw lines and polygons."> |
|
|
261 |
<a href="graphics-path.html">Basic Path</a> |
|
|
262 |
</li> |
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
<li data-description="Shows how to create linear and radial gradient fills."> |
|
|
267 |
<a href="graphics-gradients.html">Create Gradient Fills</a> |
|
|
268 |
</li> |
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
<li data-description="Shows how to add drag to a shape."> |
|
|
273 |
<a href="graphics-drag.html">Basic drag with graphic object</a> |
|
|
274 |
</li> |
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
<li data-description="Shows how to apply transforms to shape."> |
|
|
279 |
<a href="graphics-transforms.html">Using Transforms</a> |
|
|
280 |
</li> |
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
<li data-description="Shows how to use a custom shape with the Graphics module."> |
|
|
285 |
<a href="graphics-customshape.html">Custom Shape</a> |
|
|
286 |
</li> |
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
<li data-description="Shows to use the graphics api to draw a realistic glass."> |
|
|
291 |
<a href="graphics-muddyglass.html">Transparent Glass with Shadow</a> |
|
|
292 |
</li> |
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
<li data-description="Shows to use the graphics api to draw a violin."> |
|
|
297 |
<a href="graphics-violin.html">Complex Drawing: Violin</a> |
|
|
298 |
</li> |
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
</ul> |
|
|
304 |
</div> |
|
|
305 |
</div> |
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
<div class="sidebox"> |
|
|
310 |
<div class="hd"> |
|
|
311 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
312 |
</div> |
|
|
313 |
|
|
|
314 |
<div class="bd"> |
|
|
315 |
<ul class="examples"> |
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
<li data-description="This example demonstrates animating an element along a curved path using bezier control points."> |
|
|
335 |
<a href="../anim/curve.html">Animating Along a Curved Path</a> |
|
|
336 |
</li> |
|
|
337 |
|
|
|
338 |
|
|
|
339 |
</ul> |
|
|
340 |
</div> |
|
|
341 |
</div> |
|
|
342 |
|
|
|
343 |
</div> |
|
|
344 |
</div> |
|
|
345 |
</div> |
|
|
346 |
</div> |
|
|
347 |
|
|
|
348 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
349 |
<script>prettyPrint();</script> |
|
|
350 |
|
|
|
351 |
<script> |
|
|
352 |
YUI.Env.Tests = { |
|
|
353 |
examples: [], |
|
|
354 |
project: '../assets', |
|
|
355 |
assets: '../assets/graphics', |
|
|
356 |
name: 'graphics-path', |
|
|
357 |
title: 'Basic Path', |
|
|
358 |
newWindow: '', |
|
|
359 |
auto: false |
|
|
360 |
}; |
|
|
361 |
YUI.Env.Tests.examples.push('graphics-simple'); |
|
|
362 |
YUI.Env.Tests.examples.push('graphics-path'); |
|
|
363 |
YUI.Env.Tests.examples.push('graphics-gradients'); |
|
|
364 |
YUI.Env.Tests.examples.push('graphics-drag'); |
|
|
365 |
YUI.Env.Tests.examples.push('graphics-transforms'); |
|
|
366 |
YUI.Env.Tests.examples.push('graphics-customshape'); |
|
|
367 |
YUI.Env.Tests.examples.push('graphics-muddyglass'); |
|
|
368 |
YUI.Env.Tests.examples.push('graphics-violin'); |
|
|
369 |
YUI.Env.Tests.examples.push('curve'); |
|
|
370 |
|
|
|
371 |
</script> |
|
|
372 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
</body> |
|
|
377 |
</html> |