|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Dot Plot</title> |
|
5 <script type="text/javascript" src="../../d3.js"></script> |
|
6 <script type="text/javascript" src="superformula.js"></script> |
|
7 <style type="text/css"> |
|
8 |
|
9 body { |
|
10 font: 10px sans-serif; |
|
11 } |
|
12 |
|
13 path.dot { |
|
14 fill: white; |
|
15 stroke-width: 1.5px; |
|
16 } |
|
17 |
|
18 rect { |
|
19 fill: none; |
|
20 stroke: black; |
|
21 shape-rendering: crispEdges; |
|
22 } |
|
23 |
|
24 .x line, .y line { |
|
25 stroke: #ccc; |
|
26 shape-rendering: crispEdges; |
|
27 } |
|
28 |
|
29 </style> |
|
30 </head> |
|
31 <body> |
|
32 <script type="text/javascript"> |
|
33 |
|
34 var data = d3.range(100).map(function(i) { |
|
35 return {x: i / 99, y: Math.random()}; |
|
36 }); |
|
37 |
|
38 var w = 450, |
|
39 h = 450, |
|
40 p = 20, |
|
41 x = d3.scale.linear().range([0, w]), |
|
42 y = d3.scale.linear().range([h, 0]), |
|
43 type = d3.scale.ordinal().range(superformulaTypes), |
|
44 color = d3.scale.category10(); |
|
45 |
|
46 var vis = d3.select("body") |
|
47 .append("svg:svg") |
|
48 .attr("width", w + p * 2) |
|
49 .attr("height", h + p * 2) |
|
50 .append("svg:g") |
|
51 .attr("transform", "translate(" + p + "," + p + ")"); |
|
52 |
|
53 var xrule = vis.selectAll("g.x") |
|
54 .data(x.ticks(10)) |
|
55 .enter().append("svg:g") |
|
56 .attr("class", "x"); |
|
57 |
|
58 xrule.append("svg:line") |
|
59 .attr("x1", x) |
|
60 .attr("x2", x) |
|
61 .attr("y1", 0) |
|
62 .attr("y2", h); |
|
63 |
|
64 xrule.append("svg:text") |
|
65 .attr("x", x) |
|
66 .attr("y", h + 3) |
|
67 .attr("dy", ".71em") |
|
68 .attr("text-anchor", "middle") |
|
69 .text(x.tickFormat(10)); |
|
70 |
|
71 var yrule = vis.selectAll("g.y") |
|
72 .data(y.ticks(10)) |
|
73 .enter().append("svg:g") |
|
74 .attr("class", "y"); |
|
75 |
|
76 yrule.append("svg:line") |
|
77 .attr("x1", 0) |
|
78 .attr("x2", w) |
|
79 .attr("y1", y) |
|
80 .attr("y2", y); |
|
81 |
|
82 yrule.append("svg:text") |
|
83 .attr("x", -3) |
|
84 .attr("y", y) |
|
85 .attr("dy", ".35em") |
|
86 .attr("text-anchor", "end") |
|
87 .text(y.tickFormat(10)); |
|
88 |
|
89 vis.append("svg:rect") |
|
90 .attr("width", w) |
|
91 .attr("height", h); |
|
92 |
|
93 vis.selectAll("path.dot") |
|
94 .data(data) |
|
95 .enter().append("svg:path") |
|
96 .attr("class", "dot") |
|
97 .attr("stroke", function(d, i) { return color(i); }) |
|
98 .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; }) |
|
99 .attr("d", superformula() |
|
100 .type(function(d, i) { return type(i); })); |
|
101 |
|
102 </script> |
|
103 </body> |
|
104 </html> |