File: touch-test.html

package info (click to toggle)
d3 3.5.17-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,464 kB
  • sloc: javascript: 43,334; makefile: 8; xml: 4
file content (61 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1"/>
<style>

html, body {
  height: 100%;
}

body {
  margin: 0;
}

svg {
  display: block;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

</style>
<body>
<script src="../../d3.js"></script>
<script>

var color = d3.scale.category10();

var svg = d3.select("body").append("svg");

d3.select("body")
    .on("touchstart", touch)
    .on("touchmove", touch)
    .on("touchend", touch);

function touch() {
  d3.event.preventDefault();

  var circle = svg.selectAll("circle.touch")
      .data(d3.touches(svg.node()), function(d) { return d.identifier; })
      .attr("cx", function(d) { return d[0]; })
      .attr("cy", function(d) { return d[1]; });

  circle.enter().append("circle")
      .attr("class", "touch")
      .attr("cx", function(d) { return d[0]; })
      .attr("cy", function(d) { return d[1]; })
      .style("fill", function(d) { return color(d.identifier); })
      .attr("r", 1e-6)
    .transition()
      .duration(500)
      .ease("elastic")
      .attr("r", 48);

  circle.exit()
      .attr("class", null)
    .transition()
      .attr("r", 1e-6)
      .remove();
}

</script>