Skip to content

Commit 273f179

Browse files
author
raywu6
committed
add K15
1 parent f6febb4 commit 273f179

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

15_svg/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>K15</title>
6+
<link rel="stylesheet" type="text/css" href="style.css">
7+
</head>
8+
9+
<body>
10+
<svg class="scatterplot" xmlns="http://www.w3.org/2000/svg">
11+
</svg>
12+
13+
<script src="http://d3js.org/d3.v5.min.js" charset="utf-8"></script>
14+
<script src="index.js"></script>
15+
</body>
16+
17+
</html>
18+

15_svg/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Raymond Wu
2+
// SoftDev pd7
3+
// HW15 -- Scattered
4+
// 2019-03-21
5+
6+
var data = [
7+
[45, 10],
8+
[36, 537],
9+
[263, 419],
10+
[879, 357],
11+
[121, 658],
12+
[764, 932],
13+
[891, 375],
14+
[91, 324],
15+
[465, 61],
16+
[178, 354],
17+
[907, 69],
18+
[434, 76],
19+
[0, 0],
20+
[907,932],
21+
];
22+
23+
var scaleX = d3.scaleLinear()
24+
.domain( [0, 1000] )
25+
.range( [0, 500] );
26+
var scaleY = d3.scaleLinear()
27+
.domain( [0, 1000] )
28+
.range( [0, 500] );
29+
30+
var scatterplot = d3.select(".scatterplot");
31+
var dot = scatterplot.selectAll("circle");
32+
var dotUpdate = dot.data(data);
33+
var dotEnter = dotUpdate.enter().append("circle");
34+
35+
dotEnter.attr("cx", function(d) {return scaleX(d[0]);} )
36+
.attr("cy", function(d) {return 500-scaleY(d[1]);} ) // to make 0,0 at bottom left
37+
.attr("r", "5");

15_svg/style.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
svg {
2+
border-left: 1px solid black;
3+
border-bottom: 1px solid black;
4+
width: 500px;
5+
height: 500px;
6+
}
7+
8+
svg circle {
9+
fill: red;
10+
fill-opacity: .25;
11+
}

0 commit comments

Comments
 (0)