-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
61 lines (52 loc) · 1.71 KB
/
index.html
File metadata and controls
61 lines (52 loc) · 1.71 KB
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>
<html>
<head>
<title>D3 icon array</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
<meta name="description" content="A D3 plugin helping you to draw an array of icons.">"
<script type="text/javascript" src="build/d3-iconarray.js"></script>
<link rel="stylesheet" href="https://www.toffeemilkshake.co.uk/css/home.css">
</head>
<body>
<article>
<h1>D3 icon array</h1>
<p><a href="https://www.toffeemilkshake.co.uk/">Tom Pearson</a> Mar 2016</p>
<p>A D3 plugin helping you to draw an array of icons. Works fine with v4 or v5 (possibly later?)</p>
<p><a href="https://github.com/tomgp/d3-iconarray/blob/master/README.md">Check out the readme file</a> for usage examples, API docs, and more information on the rationale behind using icon arrays.</p>
<div id="simple-example">
</div>
</article>
</body>
<script type="text/javascript">
var layout = d3_iconarray.layout();
var data = d3.range(0, 2500, 1);
var grid = layout(data);
var width = 500,
height = 500,
margin = {top:40, bottom:10, left:40, right:10 };
var arrayScale = d3_iconarray.scale()
.domain([ 0, layout.maxDimension(data.length) ])
.range([0, width-(margin.left+margin.right)])
.gapSize(1);
var svg = d3.select('#simple-example')
.append('svg')
.attr('width',width)
.attr('height',height)
.append('g')
.attr('transform','translate('+margin.left+','+margin.top+')');
const threshold = Math.random()*(2500);
svg.selectAll('circle')
.data(grid)
.enter()
.append('circle')
.attr('cx', function(d){ return arrayScale(d.position.x) })
.attr('cy', function(d){ return arrayScale(d.position.y) })
.attr('r', 2)
.attr('fill',(d,i)=>{
if(i>threshold){
return '#000';
}
return '#ff2800';
});
</script>
</html>