source: Dev/branches/jQueryUI/client/d3/examples/hull/hull.html @ 249

Last change on this file since 249 was 249, checked in by hendrikvanantwerpen, 13 years ago

This one's for Subversion, because it's so close...

First widget (stripped down sequencer).
Seperated client and server code in two direcotry trees.

File size: 1.4 KB
Line 
1<!DOCTYPE html>
2<html>
3  <head>
4    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5    <title>Convex Hull</title>
6    <script type="text/javascript" src="../../d3.js"></script>
7    <script type="text/javascript" src="../../d3.geom.js"></script>
8    <style type="text/css">
9
10svg {
11  border: solid 1px #aaa;
12  background: #eee;
13}
14
15path {
16  fill: lightsteelblue;
17  stroke: #000;
18}
19
20circle {
21  fill: #fff;
22  stroke: #000;
23}
24
25    </style>
26  </head>
27  <body>
28    <script type="text/javascript">
29
30var w = 960,
31    h = 500;
32
33var vertices = d3.range(15).map(function(d) {
34  return [
35    w / 4 + Math.random() * w / 2,
36    h / 4 + Math.random() * h / 2
37  ];
38});
39
40var svg = d3.select("body")
41  .append("svg:svg")
42    .attr("width", w)
43    .attr("height", h)
44    .attr("pointer-events", "all")
45    .on("mousemove", move)
46    .on("click", click);
47
48update();
49
50function update() {
51  svg.selectAll("path")
52      .data([d3.geom.hull(vertices)])
53      .attr("d", function(d) { return "M" + d.join("L") + "Z"; })
54          .enter().append("svg:path")
55            .attr("d", function(d) { return "M" + d.join("L") + "Z"; });
56
57  svg.selectAll("circle")
58      .data(vertices.slice(1))
59    .enter().append("svg:circle")
60      .attr("transform", function(d) { return "translate(" + d + ")"; })
61      .attr("r", 3);
62}
63
64function move() {
65  vertices[0] = d3.svg.mouse(this);
66  update();
67}
68
69function click() {
70  vertices.push(d3.svg.mouse(this));
71  update();
72}
73    </script>
74  </body>
75</html>
Note: See TracBrowser for help on using the repository browser.