chore: remove accidental challenges (#43948)
This commit is contained in:
committed by
GitHub
parent
2dc68c9be2
commit
f08b6a9eb4
@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9de
|
|
||||||
title: Part 1
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-1
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Welcome to the dashboard project! You will be using the JavaScript data visualization library, D3, to build a visualization of your social media followers. It will consist of a line graph, a pie chart, and a legend.
|
|
||||||
|
|
||||||
First, you need to create the HTML file. Start by adding the `<!DOCTYPE html>` declaration at the top of the file to tell the browser what type of document it's reading.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/<!DOCTYPE\s+html\s*>/gi.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
```
|
|
@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9df
|
|
||||||
title: Part 2
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-2
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Next, add opening and closing `html`, `head` and `body` tags below the doctype. Be sure to nest them properly.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/<!DOCTYPE\s+html\s*>\s*<html\s*>\s*<head\s*>\s*<\/head\s*>\s*<body\s*>\s*<\/body\s*>\s*<\/html\s*>/gi.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,51 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e0
|
|
||||||
title: Part 3
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-3
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
In the head, add a `title` of `D3 Dashboard`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/<head\s*>\s*<title\s*>D3 Dashboard<\/title\s*>\s*<\/head\s*>/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,55 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e1
|
|
||||||
title: Part 4
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-4
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Below the title, link to your external stylesheet by adding a `link` element with a `rel` attribute of `stylesheet` and an `href` attribute of `./dashboard.css`. Remember that link elements do not need a closing tag. You will be adding some styles to this file shortly.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const link = code.match(/<link\s+[\s\S]+?[^>]>/gi)[0];
|
|
||||||
assert(
|
|
||||||
/rel\s*=\s*('|")\s*stylesheet\s*\1/gi.test(link) &&
|
|
||||||
/href\s*=\s*('|")\s*(.\/)?dashboard\.css\s*\1/gi.test(link)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,55 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e2
|
|
||||||
title: Part 5
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-5
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Next, add a container for the dashboard. Put an empty `div` element in the body with class of `dashboard`. You will be appending all the dashboard elements to this div.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('div.dashboard').length === 1);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,55 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e3
|
|
||||||
title: Part 6
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-6
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
You are now looking at the stylesheet that you linked to earlier. At the top of this file, target the `body` of the HTML document and give it a `background-color` of `#ccc`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const body = code.match(/body\s*{[\s\S]+?[^}]}/g)[0];
|
|
||||||
assert(/background-color\s*:\s*#ccc\s*(;|})/gi.test(body));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,66 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e4
|
|
||||||
title: Part 7
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-7
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Next, target the `dashboard` class you created and give it a `width` of `980px` and a `height` of `500px`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const dashboard = $('.dashboard');
|
|
||||||
assert(
|
|
||||||
dashboard.css('width') === '980px' && dashboard.css('height') === '500px'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,73 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e5
|
|
||||||
title: Part 8
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-8
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Give the dashboard a `background-color` of `white` and a `box-shadow` of `5px 5px 5px 5px #888` to give it a little depth.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const dashboard = $('.dashboard');
|
|
||||||
assert(
|
|
||||||
dashboard.css('background-color') === 'rgb(255, 255, 255)' &&
|
|
||||||
dashboard.css('box-shadow') === 'rgb(136, 136, 136) 5px 5px 5px 5px'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,73 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e6
|
|
||||||
title: Part 9
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-9
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Now you can see your dashboard element. Center it by adding a `margin` of `auto` to it.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const dashboard = code.match(/.dashboard\s*{[\s\S]+?[^}]}/g)[0];
|
|
||||||
assert(/margin\s*:\s*auto\s*(;|})/g.test(dashboard));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,75 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e7
|
|
||||||
title: Part 10
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-10
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Give the container some space by adding a `padding` of `100px 10px` to the `body` element.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const body = code.match(/body\s*{[\s\S]+?[^}]}/g)[0];
|
|
||||||
assert(/padding\s*:\s*100px\s*10px\s*(;|})/g.test(body));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,81 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e8
|
|
||||||
title: Part 11
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-11
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Later on, you will be adding more elements to the dashboard container. Set the `display` to `flex` and the `align-items` to `center` so those items will be vertically centered.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const dashboard = $('.dashboard');
|
|
||||||
assert(
|
|
||||||
dashboard.css('display') === 'flex' &&
|
|
||||||
dashboard.css('align-items') === 'center'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
@ -1,79 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9e9
|
|
||||||
title: Part 12
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-12
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Back in the HTML file, add a `script` tag at the bottom of the head element and give it a `src` attribute of `./d3-5.9.2.min.js`. Don't forget the closing tag. This will add the D3 library to your project from a downloaded copy.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const script = code.match(/<script\s+[\s\S]+?[^>]>\s*<\/script\s*>/gi)[0];
|
|
||||||
assert(/src\s*=\s*('|")\s*(\.\/)?d3-5.9.2.min.js\s*\1/gi.test(script));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
<script src="./d3-5.9.2.min.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,96 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ea
|
|
||||||
title: Part 13
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-13
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add another `script` below the one you just added. Give it a `src` attribute of `./data.js`.
|
|
||||||
|
|
||||||
This adds a `data` variable to your project that contains your number of social media followers, it is an array of objects. Each object has the year and your followers for three different platforms. You will see what it looks like shortly.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const script = code.match(/<script\s+[\s\S]+?[^>]>\s*<\/script\s*>/gi)[1];
|
|
||||||
assert(/src\s*=\s*('|")\s*(\.\/)?data.js\s*\1/gi.test(script));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
<script src="./d3-5.9.2.min.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
<script src="./d3-5.9.2.min.js"></script>
|
|
||||||
<script src="./data.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,95 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9eb
|
|
||||||
title: Part 14
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-14
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add a third script just before the closing body tag. It will be the JavaScript file you will use to create the rest of the dashboard. Give the script a `src` of `./dashboard.js`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const script = code.match(/<script\s+[\s\S]+?[^>]>\s*<\/script\s*>/gi)[2];
|
|
||||||
assert(/src\s*=\s*('|")\s*(\.\/)?dashboard.js\s*\1/gi.test(script));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
<script src="./d3-5.9.2.min.js"></script>
|
|
||||||
<script src="./data.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="./dashboard.css">
|
|
||||||
<script src="./d3-5.9.2.min.js"></script>
|
|
||||||
<script src="./data.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
|
|
||||||
<script src="dashboard.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
@ -1,103 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ec
|
|
||||||
title: Part 15
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-15
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The script at the top is the `data.js` file you added. I have placed it here so you can see the data and recommend taking a look at it. The second script is the one you just added and where you will build the rest of the project.
|
|
||||||
|
|
||||||
In the second script, create three `const` variables; `svgMargin` with a value of `70`, `svgWidth` with a value of `700`, and `svgHeight` equal to `500`. The first part of the dashboard will be a line graph. It will use these variables as its dimensions.
|
|
||||||
|
|
||||||
The line graph will have the years from your data variable across the bottom, and a scale on the left to show the numbers of followers. Each platform will have a line going across the graph that shows how many followers you had for each year.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(svgMargin === 70 && svgWidth === 700 && svgHeight === 500);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500;
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,108 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ed
|
|
||||||
title: Part 16
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-16
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add three more variables; `twitterColor` with a value of `#7cd9d1`, `tumblrColor` equal to `#f6dd71`, and `instagramColor` at `#fd9b98`. Make sure those Hex values are strings. These will be colors used to represent the different platforms throughout the project.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
twitterColor === '#7cd9d1' &&
|
|
||||||
tumblrColor === '#f6dd71' &&
|
|
||||||
instagramColor === '#fd9b98'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500;
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,113 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ee
|
|
||||||
title: Part 17
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-17
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
When you added the D3 library earlier, it put an object named `d3` in your project with a bunch of functions. One of them is `select`; you can use dot notation to access this and the other functions from the object. Create a new variable named `lineGraph` and use `d3.select` to select the `.dashboard` element. Here's an example of something similar:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const variableName = d3.select('.className')
|
|
||||||
```
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(lineGraph._groups[0][0] === $('.dashboard')[0]);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,117 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ef
|
|
||||||
title: Part 18
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-18
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Your dashboard element is now "selected". D3 has a number of functions for working with a selection; one of them is `append`. It is used to add an element. Chain the `append` function to your selection and use it to add an `svg` element. Here's an example of how that might be done:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const variableName = d3.select('selectedElement')
|
|
||||||
.append('elementToAdd')
|
|
||||||
```
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(lineGraph._groups[0][0] === $('svg')[0]);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,124 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f0
|
|
||||||
title: Part 19
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-19
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
You can't see it, but there is now an `svg` element nested in your dashboard container. When you appended it, it became the "selection" for this area of code. Any functions you chain after it will be used on this selection.
|
|
||||||
|
|
||||||
`attr` is a function to set attributes. You need to pass it the attribute you want to set, and the value you want to give it. Here's an example of how to chain `attr` to a selection:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const variableName = d3.select('element')
|
|
||||||
.append('element')
|
|
||||||
.attr('attribute', 'value')
|
|
||||||
```
|
|
||||||
|
|
||||||
Chain an `attr` function to the selection that sets the `width` as the `svgWidth` variable you created earlier. When using a variable as a value, you do not need to put it in any kind of quotations.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg')[0].attributes.width.value === '700');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,116 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f1
|
|
||||||
title: Part 20
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-20
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Chain another `attr` function that sets the `height` as the `svgHeight` variable you created.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg')[0].attributes.height.value === '500');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,123 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f2
|
|
||||||
title: Part 21
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-21
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Your line graph needs some scales so it knows how to translate the data into visual distances. The first one is the scale for the y-axis. It will be to show the number of followers. D3 has many utilities for creating scales. You want to use it's `scaleLinear` method for this scale.
|
|
||||||
|
|
||||||
Create a new `const` named `yScale`, and set it equal to `d3.scaleLinear()`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
typeof yScale === 'function' && /yScale\s*=\s*d3\.scaleLinear/.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,123 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f3
|
|
||||||
title: Part 22
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-22
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
D3 has a bunch of functions for working with scales as well. One of them is `domain`. It takes an array that is used to describe the highest and lowest values of the data for this scale. After a quick look at the data, the values of the "followers" go from about 0 to 5000. Chain the `domain` function to the `yScale` and pass it the array `[0, 5000]`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const domain = yScale.domain();
|
|
||||||
assert(domain.length === 2 && domain[0] === 0 && domain[1] === 5000);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,129 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f4
|
|
||||||
title: Part 23
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-23
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The `range` function describes how to map the domain values for display on the graph. For example, a value of 5000 followers can't use 5000 as it y-coordinate on the SVG or it would be off the graph. You need to tell the range where the top and bottom of the graph is so the scale can give appropriate values for the y-coordinate.
|
|
||||||
|
|
||||||
Chain the `range` function below the `domain` and pass it an array with `svgHeight - svgMargin` and `svgMargin` as the values. That will translate to `[430, 70]`. This is where the top and bottom of the graph are. So a data point of 5000 followers will map to a value of 430 to use as its y-coordinate and 0 followers will use 70 as its y-coordinate. Any value in between will scale linearly.
|
|
||||||
|
|
||||||
Your graph will have a margin around it for things like axes and labels. The actual line data will display on the inside of this margin area, which is why you use those values. This will become more clear as you progress through the project.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const range = yScale.range();
|
|
||||||
assert(range.length === 2 && range[0] === 430 && range[1] === 70);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,129 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f5
|
|
||||||
title: Part 24
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-24
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `xScale`. Use it to create another linear scale like you did for the y-scale. This will be the horizontal or "x" axis.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
typeof xScale === 'function' && /xScale\s*=\s*d3\.scaleLinear/.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,131 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f6
|
|
||||||
title: Part 25
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-25
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The `year` values of your data will be used for the x-scale. Chain the `domain` function to `xScale` and pass it an array with the first and last years of your data.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const domain = xScale.domain();
|
|
||||||
assert(domain.length === 2 && domain[0] === 2012 && domain[1] === 2020);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,133 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f7
|
|
||||||
title: Part 26
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-26
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The range for this scale will go from the left of your graph to the right, with 2012 on the left and 2020 on the right. Add the `range` function to the `xScale` and pass it an array with the values: `svgMargin` and `svgWidth - svgMargin`. This will translate to `[70, 630]`. So 2012 will use 70 as is x-coordinate and 2020 will use 630 as its x-coordinate.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const range = xScale.range();
|
|
||||||
assert(range.length === 2 && range[0] === 70 && range[1] === 630);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,138 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f8
|
|
||||||
title: Part 27
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-27
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The two scales you defined will be used to create the axes and lines. First is the y-axis, it will be a line with some labels on the left of the graph. Create a new `const` named `yAxis` and set it equal to `d3.axisLeft(yScale)`. This will use the information from the `yScale` variable to build the axis.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
typeof yAxis === 'function' &&
|
|
||||||
/yAxis\s*=\s*d3\.axisLeft\(\s*yScale\)/.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,142 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9f9
|
|
||||||
title: Part 28
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-28
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `xAxis` and set the value equal to `d3.axisBottom(xScale)`. This will create another axis for the bottom of the graph using the information from `xScale`. Although the axes do not display yet, they have the information they need to display correctly.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
typeof xAxis === 'function' &&
|
|
||||||
/xAxis\s*=\s*d3\.axisBottom\(\s*xScale\)/.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,143 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9fa
|
|
||||||
title: Part 29
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-29
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, append a new `g` element to your `lineGraph` variable. `lineGraph.append('g')` will do that for you. This will add a `g` to your SVG and be for displaying the y-axis. `g` is an SVG element that stands for "group".
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg')[0].children[0] === $('g')[0] && $('g').length === 1);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,147 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9fb
|
|
||||||
title: Part 30
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-30
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
`call` is another function to use with selections. Chain a `call` function to the selection and pass your `yAxis` variable to it. This will draw your y-axis on the SVG.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('.tick').length === 11 && /\.call\(\s*yAxis\s*\)/.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,151 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9fc
|
|
||||||
title: Part 31
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-31
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
After all that work, something is finally displayed on the graph. It's the y-axis and all the numbers are hidden on the left.
|
|
||||||
|
|
||||||
Move the axis your `svgMargin` to the right by chaining an `attr` function to the selection. Use it to set the `transform` to `translate(${svgMargin}, 0)`. Use a template literal (backticks) to set the value so you can put your variable in there.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('g')[0].attributes.transform.nodeValue === 'translate(70, 0)');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,150 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9fd
|
|
||||||
title: Part 32
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-32
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
`style` is a function similar to `attr`, but is more for manipulating CSS styles rather than element attributes. Add a `style` function to the selection that sets the `font` to `10px verdana`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('g')[0].attributes.style.nodeValue === 'font: 10px verdana;');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,153 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9fe
|
|
||||||
title: Part 33
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-33
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, append another `g` element to your `lineGraph` variable like you did before. This one will be for the x-axis.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('g').length === 13);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,156 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1c9ff
|
|
||||||
title: Part 34
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-34
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use the `call` function to draw the x-axis onto the SVG like you did for the y-axis.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('g').length === 22);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,158 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca00
|
|
||||||
title: Part 35
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-35
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The axis has the right size and labels, but needs to be moved down. Use the `attr` function to set the `transform` like you did before. This time move it down your `svgHeight` minus the `svgMargin`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg > g')[1].attributes.transform.nodeValue === 'translate(0, 430)');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,168 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca01
|
|
||||||
title: Part 36
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-36
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The axis labels are `text` elements within the `g`, you can use the `selectAll` function to select them. Chain the `selectAll` function to select the `text` elements in this group. You can do that like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
.selectAll('element')
|
|
||||||
```
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.attr\('transform', `translate\(0, \$\{svgHeight - svgMargin\}\)`\)\s*\.selectAll\s*\(\s*('|"|`)text\1\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,168 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca02
|
|
||||||
title: Part 37
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-37
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
I want the text elements to be rotated slightly. Chain the `style` function to set the `transform` to `translate(-12px, 0) rotate(-50deg)`. This will put them at an angle.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('.tick > text').filter(
|
|
||||||
(node, index) =>
|
|
||||||
index.style.transform === 'translate(-12px) rotate(-50deg)' ||
|
|
||||||
index.style.transform === 'translate(-12px, 0px) rotate(-50deg)'
|
|
||||||
).length === 9
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,168 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca03
|
|
||||||
title: Part 38
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-38
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add another `style` function to set the `text-anchor` to `end`. This will change the spot that each text element rotates around to the `end` of the element so they will align better.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('.tick > text').filter(
|
|
||||||
(node, index) => index.style['text-anchor'] === 'end'
|
|
||||||
).length === 9
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,173 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca04
|
|
||||||
title: Part 39
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-39
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add two more `style` functions; one to set the `cursor` to `pointer`, and another to set the `font` to `10px verdana`.
|
|
||||||
|
|
||||||
You will add some hover effects later, so the pointer will make for a better experience.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('.tick > text').filter(
|
|
||||||
(node, index) =>
|
|
||||||
index.style.cursor === 'pointer' && index.style.font === '10px verdana'
|
|
||||||
).length === 9
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,178 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca05
|
|
||||||
title: Part 40
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-40
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
There are a number of D3 functions to work with how the "ticks" or your axis labels are displayed; one of them is `ticks`. Go back to where you defined the `yAxis` variable and chain a `ticks` function to it and pass it these two arguments: `6, '~s'`.
|
|
||||||
|
|
||||||
The `6` will set the number of ticks used to 6, and the `~s` will make the labels display the number of thousands followed by a `k`. For example, `4000` will become `4k`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const ticks = $('.tick > text');
|
|
||||||
assert(
|
|
||||||
ticks[0].innerHTML === '0k' &&
|
|
||||||
ticks[1].innerHTML === '1k' &&
|
|
||||||
ticks[2].innerHTML === '2k' &&
|
|
||||||
ticks[3].innerHTML === '3k' &&
|
|
||||||
ticks[4].innerHTML === '4k' &&
|
|
||||||
ticks[5].innerHTML === '5k'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,171 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca06
|
|
||||||
title: Part 41
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-41
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Go back to where you defined your `xAis` variable and chain the `tickFormat` function to it. Pass it `d3.format('')`. This will remove the commas in the year labels of the x-axis.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const ticks = $('.tick > text');
|
|
||||||
assert(ticks[6].innerHTML === '2012' && ticks[14].innerHTML === '2020');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,178 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca07
|
|
||||||
title: Part 42
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-42
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
In the same spot, chain the `tickPadding` function to the `xAxis` and pass it `10`. This will add a little padding to the ticks so the labels are better aligned.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.tickFormat\(d3\.format\((''\)\)\s*\.tickPadding\s*\(\s*10\s*\))/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,178 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca08
|
|
||||||
title: Part 43
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-43
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The axes and labels are looking good. Next, you will start to add some of the lines for the data. First is the line for the Twitter data. On a new line, create a new `const` named `twitterLine` and set it equal to `d3.line()`. `line` is a D3 function for creating a line.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*twitterLine\s*=\s*d3\s*\.\s*line\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,192 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca09
|
|
||||||
title: Part 44
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-44
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The line needs x and y values for each point of data. Chain `x` to the line and pass it a "d function". Here's how that will look:
|
|
||||||
|
|
||||||
```js
|
|
||||||
.x(d => d.year)
|
|
||||||
```
|
|
||||||
|
|
||||||
You will be passing your `data` array to this line function, where it will go through each item in the array(`d`) and create an x value based on the year(`d.year`).
|
|
||||||
|
|
||||||
This is the first place you have seen a "d function". These are common in D3 and that is how I will refer to them throughout this project.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const twitterLine = d3\.line\(\)\s*\.x\s*\(\s*d\s*=>\s*d\.year\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => d.year)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,183 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0a
|
|
||||||
title: Part 45
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-45
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Instead of simply using the year(`d.year`) for the x-coordinate, you need to pass each year to the `xScale` so it can set the appropriate coordinate based on your scale.
|
|
||||||
|
|
||||||
In the "d function" you created, return `xScale(d.year)` instead of `d.year`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/\.x\s*\(d\s*=>\s*xScale\s*\(\s*d\.year\s*\)\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => d.year)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,189 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0b
|
|
||||||
title: Part 46
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-46
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Chain the `y` function to the line and pass it a "d function" that returns your `yScale` with `d.followers.twitter` as its argument.
|
|
||||||
|
|
||||||
This is similar to how you set the x values. It will use the values of your Twitter followers and your `yScale` to set the y coordinate for each item.
|
|
||||||
|
|
||||||
These "d functions" use implicit returns. But if you add curly brackets and a return statement, you can put any JavaScript in there that you want. Including `console.log` statements that can be useful for debugging.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.y\s*\(\s*d\s*=>\s*yScale\s*\(\s*d\.followers.twitter\s*\)\s*\)/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,189 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0c
|
|
||||||
title: Part 47
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-47
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The first line is created and ready to be displayed, which will take a couple steps. On a new line, `append` a `path` element to your `lineGraph` variable. This is similar to how you appended the `g` before.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg path').length === 3 &&
|
|
||||||
/lineGraph\.append\((`|'|")path\1\)/gi.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,193 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0d
|
|
||||||
title: Part 48
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-48
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Tell the path what data to use. Add an `attr` function and set the `d` to `twitterLine(data)`. This will the build the path using the `twitterLine` function you created and your data variable.
|
|
||||||
|
|
||||||
Note that the `d` in this case is a path attribute for drawing a line and is different from a "d function".
|
|
||||||
|
|
||||||
After you have added your code, take a look at the data flow to help understand what is happening. You pass the data array to your `twitterLine` function where it sets the x and y values using your "d functions". The "d functions" go through each item in the array, passing part of the item to each scale to find the appropriate coordinates. When it's done, the value you are setting here is created and sent back. The result ends up being a confusing string of numbers and coordinates to tell the path how to be drawn.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg path')[2].getAttribute('d').length === 151);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,199 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0e
|
|
||||||
title: Part 49
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-49
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add three more `attr` functions to the path; one to set the `stroke` to your `twitterColor` variable, another to set the `stroke-width` to `3`, and a third to set the `fill` to `transparent`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const twitterPath = $('svg path')[2];
|
|
||||||
assert(
|
|
||||||
twitterPath.getAttribute('stroke') === '#7cd9d1' &&
|
|
||||||
twitterPath.getAttribute('stroke-width') == '3' &&
|
|
||||||
twitterPath.getAttribute('fill') === 'transparent'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,198 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca0f
|
|
||||||
title: Part 50
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-50
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, create a new `const` named `tumblrLine` and set it equal to `d3.line()`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*tumblrLine\s*=\s*d3\s*\.\s*line\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,204 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca10
|
|
||||||
title: Part 51
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-51
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `x` values for `tumblrLine` using another "d function". Use your `xScale` and the `d.year` to calculcate their values just like you did for the Twitter line.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const tumblrLine = d3\.line\(\)\s*\.x\s*\(\s*d\s*=>\s*xScale\s*\(\s*d\.year\s*\)\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,207 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca11
|
|
||||||
title: Part 52
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-52
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `y` values for `tumblrLine` using a "d function" again. Use your `yScale` and `d.followers.tumblr` to calculcate their values just like you did for the Twitter line.
|
|
||||||
|
|
||||||
The x values for each line will be the same, but the y values will use the data from the different platforms.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.y\s*\(\s*d\s*=>\s*yScale\s*\(\s*d\.followers.tumblr\s*\)\s*\)/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,209 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca12
|
|
||||||
title: Part 53
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-53
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, `append` a `path` element to the `lineGraph` variable. This one will be for displaying the `tumblrLine`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg path').length === 4 &&
|
|
||||||
code.match(/lineGraph\.append\((`|'|")path\1\)/gi).length === 2
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,209 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca13
|
|
||||||
title: Part 54
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-54
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Tell the new path how to be drawn by setting the `d` attribute to `tumblrLine(data)` using the `attr` function.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg path')[3].getAttribute('d').length === 115);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,218 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca14
|
|
||||||
title: Part 55
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-55
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add three `attr` functions to the selection; one to set the `stroke` to your `tumblrColor` variable, another to set the `stroke-width` to `3`, and a third to set the `fill` to `transparent`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const tumblrPath = $('svg path')[3];
|
|
||||||
assert(
|
|
||||||
tumblrPath.getAttribute('stroke') === '#f6dd71' &&
|
|
||||||
tumblrPath.getAttribute('stroke-width') == '3' &&
|
|
||||||
tumblrPath.getAttribute('fill') === 'transparent'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,218 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca15
|
|
||||||
title: Part 56
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-56
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Two lines down, only one more to add for the Instagram followers. On a new line, create a new `const` named `instagramLine` and use the D3 `line` function to create another line like you did for the other two.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*instagramLine\s*=\s*d3\s*\.\s*line\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,226 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca16
|
|
||||||
title: Part 57
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-57
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Appropriately set the `x` values for `instagramLine` like you did for the other two lines.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const instagramLine = d3\.line\(\)\s*\.x\s*\(\s*d\s*=>\s*xScale\s*\(\s*d\.year\s*\)\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,229 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca17
|
|
||||||
title: Part 58
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-58
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Appropriately set the `y` values for `instagramLine` like you did for the other two lines. Use the Instagram followers data this time.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.y\s*\(\s*d\s*=>\s*yScale\s*\(\s*d\.followers.instagram\s*\)\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,231 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca18
|
|
||||||
title: Part 59
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-59
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, `append` a new `path` for the Instagram line like you did for the other two lines.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg path').length === 5 &&
|
|
||||||
code.match(/lineGraph\.append\((`|'|")path\1\)/gi).length === 3
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,230 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca19
|
|
||||||
title: Part 60
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-60
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use your `instagramLine` variable and your data to set the `d` attribute for this path like you did for the other two.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg path')[4].getAttribute('d').length === 171);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,239 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1a
|
|
||||||
title: Part 61
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-61
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `stroke`, `stroke-width`, and `fill` attributes to their appropriate values for this line. The `stroke-width` and `fill` are the same as the other two.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const instagramPath = $('svg path')[4];
|
|
||||||
assert(
|
|
||||||
instagramPath.getAttribute('stroke') === '#fd9b98' &&
|
|
||||||
instagramPath.getAttribute('stroke-width') == '3' &&
|
|
||||||
instagramPath.getAttribute('fill') === 'transparent'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,247 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1b
|
|
||||||
title: Part 62
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-62
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Okay, your graph is coming along. All the lines are drawn, but they look a little plain. The next series of code additions will add circles to each point on each line. First is the Twitter line. On a new line, use the `selectAll` function on your `lineGraph` variable and pass it the string `twitter-circles`. It will look like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
```
|
|
||||||
|
|
||||||
`twitter-circles` don't exist and this selection will be an empty array, but it's needed. For now, you can just think of this string as a reference, similar to a variable name, so you know what elements you are working with.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/lineGraph\s*\.\s*selectAll\s*\((`|'|")\s*twitter-circles\1\s*\)/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,246 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1c
|
|
||||||
title: Part 63
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-63
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the D3 `data` function to your selection and pass it the data array like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
.data(data)
|
|
||||||
```
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/\.data\s*\(\s*data\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', '3')
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,248 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1d
|
|
||||||
title: Part 64
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-64
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Next, chain the `enter()` function to the selection.
|
|
||||||
|
|
||||||
The enter function identifies elements that need to be added when the data array is longer than the selection array. This is why you wanted the `selectAll` to be an empty array before.
|
|
||||||
|
|
||||||
In this case, the `twitter-circles` selection has a length of 0, and the data array has a length of 9. So nine elements will be added when you use `append` in the next step.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/\.data\(data\)\s*\.enter\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,246 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1e
|
|
||||||
title: Part 65
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-65
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the `append` function to the selection, and use it to add `circle` elements. This will add the nine `circle` elements for your Twitter circles. They will be invisible to start, but the elements are there.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle').length === 9);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,250 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca1f
|
|
||||||
title: Part 66
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-66
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Each circle needs a `cx` and `cy` attribute so it knows where to display on the SVG. These are similar to the x and y coordinates for the lines and will be calculated in the same way. The difference is that, for circles, the `cx` and `cy` are attributes, so you need to use the `attr` function.
|
|
||||||
|
|
||||||
Use the `attr` function to set the `cx` to `d => xScale(d.year)`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[0].getAttribute('cx') == '70');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,252 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca20
|
|
||||||
title: Part 67
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-67
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Next, set the `cy` attribute to `d => xScale(d.followers.twitter)`.
|
|
||||||
|
|
||||||
As a reminder, this will pass each value of your Twitter followers to the `xScale` function where it will determine the y coordinate to use.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[0].getAttribute('cy') == '243.232');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,252 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca21
|
|
||||||
title: Part 68
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-68
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Circles also need an `r` (radius) attribute so they know how big to be. Use the `attr` function to set the `r` to `6`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[0].getAttribute('r') == '6');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,258 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca22
|
|
||||||
title: Part 69
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-69
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The circles are now visible, but I don't like the color. Use the appropriate function to set the `fill` to `white` and the `stroke` to your `twitterColor` variable.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg circle')[0].getAttribute('fill') === 'white' &&
|
|
||||||
$('svg circle')[0].getAttribute('stroke') === '#7cd9d1'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,258 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca23
|
|
||||||
title: Part 70
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-70
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use the `style` function to set the `cursor` to `pointer`. Like your year labels, this will be an indicator for a hover effect you will add later.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[0].style.cursor === 'pointer');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,263 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca24
|
|
||||||
title: Part 71
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-71
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, use the `selectAll` function on your `lineGraph` variable again and pass it the string `tumblr-circles` this time. The next few steps will be for adding circles to the Tumblr line.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/lineGraph\s*\.\s*selectAll\s*\((`|'|")\s*tumblr-circles\1\s*\)/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,268 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca25
|
|
||||||
title: Part 72
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-72
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the same `data`, `enter`, and `append` functions here that you added for the `twitter-circles`, passing in the same arguments. Make sure they are in the same order.
|
|
||||||
|
|
||||||
Remember that this will take the difference in length between the `tumblr-circles` selection(0) and the data array(9) and append that many circle elements.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle').length === 18);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,274 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca26
|
|
||||||
title: Part 73
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-73
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `cx` and `cy` attributes for the Tumblr circles to their appropriate values.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg circle')[9].getAttribute('cx') == '70' &&
|
|
||||||
$('svg circle')[9].getAttribute('cy') == '401.128'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,280 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca27
|
|
||||||
title: Part 74
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-74
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use the `attr` function to set the `r` to `6`, the `fill` to `white`, and the `stroke` to your `tumblrColor` variable.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg circle')[9].getAttribute('r') == '6' &&
|
|
||||||
$('svg circle')[9].getAttribute('fill') === 'white' &&
|
|
||||||
$('svg circle')[9].getAttribute('stroke') === '#f6dd71'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,280 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca28
|
|
||||||
title: Part 75
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-75
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `cursor` to `pointer` using the `style` function.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[9].style.cursor === 'pointer');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,287 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca29
|
|
||||||
title: Part 76
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-76
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The circles have been added to two of the lines and look good, on to the last one. On a new line, create another empty selection like you did before. Use the string: `instagram-circles` this time.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/lineGraph\s*\.\s*selectAll\s*\((`|'|")\s*instagram-circles\1\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,288 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2a
|
|
||||||
title: Part 77
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-77
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the three functions necessary to append the new circle elements. Remember that they won't actually be visible yet.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle').length === 27);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,296 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2b
|
|
||||||
title: Part 78
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-78
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Appropriately set the `cx` and `cy` attributes for the Instagram circles.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg circle')[18].getAttribute('cx') == '70' &&
|
|
||||||
$('svg circle')[18].getAttribute('cy') == '424.024'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,302 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2c
|
|
||||||
title: Part 79
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-79
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Appropriately set the radius (`r`), `fill`, and `stroke` for these circles.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg circle')[18].getAttribute('r') == '6' &&
|
|
||||||
$('svg circle')[18].getAttribute('fill') === 'white' &&
|
|
||||||
$('svg circle')[18].getAttribute('stroke') === '#fd9b98'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,302 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2d
|
|
||||||
title: Part 80
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-80
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Apply the appropriate `cursor` style for these circles.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg circle')[18].style.cursor === 'pointer');
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,309 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2e
|
|
||||||
title: Part 81
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-81
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The line graph is looking good. All the empty space to the right will be for the pie graph and legend. Create a new `const` named `rightDashboard` and set equal to `d3.select('.dashboard')`. This will select your dashboard container again which currently only has the SVG element as a child.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const\s*rightDashboard\s*=\s*d3\.select\s*\((`|'|")\.dashboard\1\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,312 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca2f
|
|
||||||
title: Part 82
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-82
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use `append` to add a `div` element to the selection. This will put a div as another child of the dashboard container to hold the pie graph and legend.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const rightDashboard = d3\.select\((`|'|")\.dashboard\1\)\s*\.append\s*\(\s*(`|'|")div\2\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,315 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca30
|
|
||||||
title: Part 83
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-83
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `pieGraph` and set it equal to `rightDashboard.append('svg')`. This will add an SVG element for the pie graph as a child of the div you just added. The pie graph will have three slices, one for each platform. It will display a percentage of how many followers each platform has for the displayed year.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const\s*pieGraph\s*=\s*rightDashboard\s*\.\s*append\s*\((`|'|")svg\1\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,318 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca31
|
|
||||||
title: Part 84
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-84
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add two `attr` functions that set the `width` and `height` of the new SVG to `200`.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
$('svg')[1].getAttribute('width') == '200' &&
|
|
||||||
$('svg')[1].getAttribute('height') == '200'
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,319 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca32
|
|
||||||
title: Part 85
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-85
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `pieArc` and set it equal to `d3.arc()`. This will be used to create the angles for the lines of the pie chart using the D3 arc generator.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*pieArc\s*=\s*d3\s*\.\s*arc\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,324 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca33
|
|
||||||
title: Part 86
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-86
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Chain the function `outerRadius(100)` to the arc. This will set the outer radius of the pie chart to 100.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pieArc = d3\.arc\(\)\s*\.\s*outerRadius\s*\(\s*100\s*\)/g.test(code)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,328 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca34
|
|
||||||
title: Part 87
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-87
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Chain `innerRadius` to the arc and pass it `0` (zero). This is set to zero to make a traditional pie chart, you would use a larger inner radius to create a doughnut chart.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pieArc = d3\.arc\(\)\s*\.outerRadius\(100\)\s*\.\s*innerRadius\s*\(\s*0\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,329 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca35
|
|
||||||
title: Part 88
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-88
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The pie chart needs a new scale to set the colors. Create a new `const` named `pieColors` and set it equal to `d3.scaleOrdinal()`. An ordinal scale is for a set of data that will have exactly one item in the range specifically for it.
|
|
||||||
|
|
||||||
In this case, each platform of followers you have will map directly to a single color with nothing in between.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*pieColors\s*=\s*d3\s*\.\s*scaleOrdinal\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,334 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca36
|
|
||||||
title: Part 89
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-89
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `domain` of the scale to `data[8].followers`. This will be three items, one for each platform.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pieColors = d3\.scaleOrdinal\(\)\s*\.\s*domain\s*\(\s*data\s*\[\s*8\s*\]\s*\.\s*followers\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,336 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca37
|
|
||||||
title: Part 90
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-90
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Since the domain has three items, the range also needs to have three items. If it had less, the values would repeat, putting the same color on the pie chart multiple times. Add the `range` function to the scale and pass it an array with your three color variables. Put them in the same order in which they are defined.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.domain\(data\[8\]\.followers\)\s*\.\s*range\s*\(\s*\[\s*twitterColor\s*,\s*tumblrColor\s*,\s*instagramColor\s*\]\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,335 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca38
|
|
||||||
title: Part 91
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-91
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `pie` and set it equal to `d3.pie()`. This is the D3 pie chart generator.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/const\s*pie\s*=\s*d3\s*\.\s*pie\s*\(\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,344 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca39
|
|
||||||
title: Part 92
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-92
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Chain a `value` function to `pie` and pass it `d => d.value`. Each piece of data(`d`) will have a `key`(platform) and a `value`(number of followers), you want to return the number of followers here. The pie function will create an array of objects from these values that describe the angles and sizes the pie chart needs.
|
|
||||||
|
|
||||||
In a few steps, you will make an array out of your data variable that will be passed to this function.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pie = d3\.pie\(\)\s*\.\s*value\s*\(\s*d\s*=>\s*d\.value\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,345 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3a
|
|
||||||
title: Part 93
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-93
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Create a new `const` named `pieGraphData` and set the value equal to `pieGraph.selectAll('pieSlices')`. This is an empty selection similar circles you created earlier.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const\s*pieGraphData\s*=\s*pieGraph\s*\.\s*selectAll\s*\(\s*(`|'|")pieSlices\1\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,348 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3b
|
|
||||||
title: Part 94
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-94
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the `data` function to the selection. Pass it your `pie` function with an empty array as its argument for now. The next step will get the correct array to put there.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pieGraphData = pieGraph\.selectAll\((`|'|")pieSlices\1\)\s*\.\s*data\s*\(pie\s*\(\s*\[\s*\]\s*\)\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie([]))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,367 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3c
|
|
||||||
title: Part 95
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-95
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
You want the array passed to `pie` to be an array of key/value objects for the 2020 followers. `d3.entries` will build that array for you. Here's how that looks:
|
|
||||||
|
|
||||||
```js
|
|
||||||
d3.entries(data[8].followers))
|
|
||||||
```
|
|
||||||
|
|
||||||
The array it builds looks like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
[
|
|
||||||
{ key: 'twitter', value: 2845 },
|
|
||||||
{ key: 'tumblr', value: 2040 },
|
|
||||||
{ key: 'instagram', value: 4801 }
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
This is where the `value` comes from in your `pie` variable.
|
|
||||||
|
|
||||||
Add the `d3.entries` function as your `pie` argument. Use it to create the above array.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/const pieGraphData = pieGraph\.selectAll\((`|'|")pieSlices\1\)\s*\.\s*data\s*\(pie\s*\(\s*d3\s*\.\s*entries\s*\(\s*data\s*\[\s*8\s*\]\s*\.\s*followers\s*\)\s*\)\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie([]))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,350 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3d
|
|
||||||
title: Part 96
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-96
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Add the `enter` function to the current selection. Just like before, the initial selection here has a length of zero and the data has a length of three. So when you append elements in the next step, three will be created; one for each slice of the pie.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(
|
|
||||||
/\.data\(pie\(d3\.entries\(data\[8\]\.followers\)\)\)\s*\.\s*enter\s*\(\s*\)/g.test(
|
|
||||||
code
|
|
||||||
)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,348 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3e
|
|
||||||
title: Part 97
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-97
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Use `append` to add three `g` elements for the pie.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('svg g').length === 20);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,351 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca3f
|
|
||||||
title: Part 98
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-98
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
On a new line, `append` a `path` element to your `pieGraphData` variable. This is where you will start to draw the pie chart.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert(/pieGraphData\s*\.\s*append\s*\((`|'|")path\1\s*\)/g.test(code));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
pieGraphData.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,352 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca40
|
|
||||||
title: Part 99
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-99
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
Set the `d` attribute to your `pieArc` variable. Just like the `d` in your lines, this is an SVG attribute for path elements that describes how to draw things. Your `pieArc` variable will determine what this value is for you.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
assert($('.dashboard div svg path')[0].getAttribute('d').length === 94);
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
pieGraphData.append('path')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
pieGraphData.append('path')
|
|
||||||
.attr('d', pieArc)
|
|
||||||
</script>
|
|
||||||
```
|
|
@ -1,372 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5d8a4cfbe6b6180ed9a1ca41
|
|
||||||
title: Part 100
|
|
||||||
challengeType: 0
|
|
||||||
dashedName: part-100
|
|
||||||
---
|
|
||||||
|
|
||||||
# --description--
|
|
||||||
|
|
||||||
The pie graph is being drawn at the `0, 0` coordinates of the SVG. Back on your `pieGraphData` variable, add an attribute that changes the `transform` to `translate(100, 100)`.
|
|
||||||
|
|
||||||
Since the pie chart has a radius of 100, and the SVG is 200 by 200, this will move it so it is centered.
|
|
||||||
|
|
||||||
# --hints--
|
|
||||||
|
|
||||||
test-text
|
|
||||||
|
|
||||||
```js
|
|
||||||
const transform = $('.dashboard div svg g')[0].getAttribute('transform');
|
|
||||||
assert(/translate\s*\(\s*100\s*,\s*100\s*\)/g.test(transform));
|
|
||||||
```
|
|
||||||
|
|
||||||
# --seed--
|
|
||||||
|
|
||||||
## --before-user-code--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>D3 Dashboard</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #ccc;
|
|
||||||
padding: 100px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard {
|
|
||||||
width: 980px;
|
|
||||||
height: 500px;
|
|
||||||
background-color: white;
|
|
||||||
box-shadow: 5px 5px 5px 5px #888;
|
|
||||||
margin: auto;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="dashboard"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
## --seed-contents--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale)
|
|
||||||
.ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana')
|
|
||||||
|
|
||||||
const twitterLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
lineGraph.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard')
|
|
||||||
.append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200)
|
|
||||||
|
|
||||||
const pieArc = d3.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie()
|
|
||||||
.value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
|
|
||||||
|
|
||||||
pieGraphData.append('path')
|
|
||||||
.attr('d', pieArc)
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
# --solutions--
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
const data = [
|
|
||||||
{ year: 2012, followers: { twitter: 2594, tumblr: 401, instagram: 83 }},
|
|
||||||
{ year: 2013, followers: { twitter: 3049, tumblr: 440, instagram: 192 }},
|
|
||||||
{ year: 2014, followers: { twitter: 3511, tumblr: 415, instagram: 511 }},
|
|
||||||
{ year: 2015, followers: { twitter: 3619, tumblr: 492, instagram: 1014 }},
|
|
||||||
{ year: 2016, followers: { twitter: 4046, tumblr: 543, instagram: 2066 }},
|
|
||||||
{ year: 2017, followers: { twitter: 3991, tumblr: 701, instagram: 3032 }},
|
|
||||||
{ year: 2018, followers: { twitter: 3512, tumblr: 1522, instagram: 4512 }},
|
|
||||||
{ year: 2019, followers: { twitter: 3274, tumblr: 1989, instagram: 4715 }},
|
|
||||||
{ year: 2020, followers: { twitter: 2845, tumblr: 2040, instagram: 4801 }}
|
|
||||||
];
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
const svgMargin = 70,
|
|
||||||
svgWidth = 700,
|
|
||||||
svgHeight = 500,
|
|
||||||
twitterColor = '#7cd9d1',
|
|
||||||
tumblrColor = '#f6dd71',
|
|
||||||
instagramColor = '#fd9b98';
|
|
||||||
|
|
||||||
const lineGraph = d3
|
|
||||||
.select('.dashboard')
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', svgWidth)
|
|
||||||
.attr('height', svgHeight);
|
|
||||||
|
|
||||||
const yScale = d3
|
|
||||||
.scaleLinear()
|
|
||||||
.domain([0, 5000])
|
|
||||||
.range([svgHeight - svgMargin, svgMargin]);
|
|
||||||
|
|
||||||
const xScale = d3
|
|
||||||
.scaleLinear()
|
|
||||||
.domain([2012, 2020])
|
|
||||||
.range([svgMargin, svgWidth - svgMargin]);
|
|
||||||
|
|
||||||
const yAxis = d3.axisLeft(yScale).ticks(6, '~s');
|
|
||||||
|
|
||||||
const xAxis = d3
|
|
||||||
.axisBottom(xScale)
|
|
||||||
.tickFormat(d3.format(''))
|
|
||||||
.tickPadding(10);
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.append('g')
|
|
||||||
.call(yAxis)
|
|
||||||
.attr('transform', `translate(${svgMargin}, 0)`)
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.append('g')
|
|
||||||
.call(xAxis)
|
|
||||||
.attr('transform', `translate(0, ${svgHeight - svgMargin})`)
|
|
||||||
.selectAll('text')
|
|
||||||
.style('transform', 'translate(-12px, 0) rotate(-50deg)')
|
|
||||||
.style('text-anchor', 'end')
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.style('font', '10px verdana');
|
|
||||||
|
|
||||||
const twitterLine = d3
|
|
||||||
.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.twitter));
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.append('path')
|
|
||||||
.attr('d', twitterLine(data))
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const tumblrLine = d3
|
|
||||||
.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.tumblr));
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.append('path')
|
|
||||||
.attr('d', tumblrLine(data))
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
const instagramLine = d3
|
|
||||||
.line()
|
|
||||||
.x(d => xScale(d.year))
|
|
||||||
.y(d => yScale(d.followers.instagram));
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.append('path')
|
|
||||||
.attr('d', instagramLine(data))
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.attr('stroke-width', 3)
|
|
||||||
.attr('fill', 'transparent');
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.selectAll('twitter-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.twitter))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', twitterColor)
|
|
||||||
.style('cursor', 'pointer');
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.selectAll('tumblr-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.tumblr))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', tumblrColor)
|
|
||||||
.style('cursor', 'pointer');
|
|
||||||
|
|
||||||
lineGraph
|
|
||||||
.selectAll('instagram-circles')
|
|
||||||
.data(data)
|
|
||||||
.enter()
|
|
||||||
.append('circle')
|
|
||||||
.attr('cx', d => xScale(d.year))
|
|
||||||
.attr('cy', d => yScale(d.followers.instagram))
|
|
||||||
.attr('r', 6)
|
|
||||||
.attr('fill', 'white')
|
|
||||||
.attr('stroke', instagramColor)
|
|
||||||
.style('cursor', 'pointer');
|
|
||||||
|
|
||||||
const rightDashboard = d3.select('.dashboard').append('div');
|
|
||||||
|
|
||||||
const pieGraph = rightDashboard
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', 200)
|
|
||||||
.attr('height', 200);
|
|
||||||
|
|
||||||
const pieArc = d3
|
|
||||||
.arc()
|
|
||||||
.outerRadius(100)
|
|
||||||
.innerRadius(0);
|
|
||||||
|
|
||||||
const pieColors = d3
|
|
||||||
.scaleOrdinal()
|
|
||||||
.domain(data[8].followers)
|
|
||||||
.range([twitterColor, tumblrColor, instagramColor]);
|
|
||||||
|
|
||||||
const pie = d3.pie().value(d => d.value);
|
|
||||||
|
|
||||||
const pieGraphData = pieGraph
|
|
||||||
.selectAll('pieSlices')
|
|
||||||
.data(pie(d3.entries(data[8].followers)))
|
|
||||||
.enter()
|
|
||||||
.append('g')
|
|
||||||
.attr('transform', 'translate(100, 100)');
|
|
||||||
|
|
||||||
pieGraphData.append('path')
|
|
||||||
.attr('d', pieArc)
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
```
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user