This repository is your starting point for the assignment and includes the instructions below.
Link to your GitHub pages website: [insert your *clickable* hyperlink here]
Using events is critical for implementing interactive visualizations using D3.
In this assignment you will learn how to handle and create new events with d3-dispatch
.
(This is particularly important for the upcoming brushing & linking assignment.)
You will not have to create any new chart, you will just demonstrate your understanding of how events work.
Please look through all the materials below so you understand the setup instructions; how to run, organize, and submit your code; and our requirements for the visualization.
Under no circumstances should you be editing files via the GitHub website user interface. Do all your edits locally after cloning the repository. Commit major versions to your git repository.
-
Clone this repository to your local machine. E.g., in your terminal / command prompt
CD
to where you want this the folder for this activity to be. Then rungit clone <YOUR_REPO_URL>
-
CD
or open a terminal / command prompt window into the cloned folder. -
Start a simple python webserver. E.g.,
python -m http.server
,python3 -m http.server
, orpy -m http.server
. If you are using python 2 you will need to usepython -m SimpleHTTPServer
instead, but please switch to python 3 as Python 2 was sunset on 2020-01-01. -
Wait for the output:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)
. -
Now open your web browser (Firefox or Chrome) and navigate to the URL: http://localhost:8000
-
Edit near the top of this
README.md
file to include a clickable hyperlink to the GitHub pages website for your repo., replacing the`[insert your *clickable* hyperlink here]`
code with your markdown. (Detailed instructions for GitHub pages here.) -
In
index.html
update the GitHub repo URL with the URL of your repository. It is in the span withid='forkongithub'
.
Here is an overview of the files and folders we provide for you in your repo.
-
README.md
is this explanatory file for the repo. -
index.html
contains the main website content. -
style.css
contains the CSS. -
LICENCE
is the source code license for the template. You can add your name or leave it as is.
Each folder has an explanatory README.md
file.
-
favicons
contains the favicons for the web page. You shouldn't change anything here. -
.github
contains GitHub Actions (docs) which will automatically validate your HTML, CSS, and hyperlinks when you push (see the validation last step below). Do not edit files here except to create new.yml
files for any additional actions you choose to add (you are not required to make any). -
img
contains a descriptive image for theREADME.md
. -
js
will contain all JavaScript files you write. E.g.,main.js
is the js code that you will have to fill in.
-
lib
will contain any JavaScript library you use. It currently includes D3. To ensure long-term survivability, use the included D3 here rather than linking to d3js.org or some other CDN. Likewise, put your other libraries here rather than loading them from elsewhere.
js/main.js
creates an svg inside the div
with id #vis1
and draws a square and a circle for you.
You will be creating a new custom event type to handle clicking on a pre-existing square in an svg.
When the square is clicked, the circle should change color to red.
Implement the following functionality as part of js/main.js
.
As you work, make your edits and commit major versions to your git repository.
-
Define a custom event
changeColor
using d3-dispatch. -
Create an event listener that dispatches a
changeColor
event when the square is clicked.There are pre-existing DOM events for
click
andmousedown
which are part of the standard DOM events. You may listen for aclick
ormousedown
event and use it to then dispatch thechangeColor
event usingd3-dispatch
. -
Create an event listener using
d3-dispatch
that is triggered on achangeColor
event and changes the circle's color to red.Do not simply have a listener on the square that changes the color directly, e.g.,
selection
.on('click', function(d, i){ // code that changes the color });
You must used3-dispatch
to send and listen for a customchangeColor
event.We are aware that the same objective can be obtained by using standard predefined DOM events. However, learning how to use
d3-dispatch
correctly will be especially useful to you in the upcoming brushing and linking assignment. In that assignment you will create multiple modular yet linked visualizations and you will want your code to be more loosely coupled and easier to manage. The brushing and linking assignment will be impossible to do without first understandingd3-dispatch
. -
Ensure your code passes the 'Validate HTML, CSS, and Links' checks we run when you push to GitHub. I.e., you want to see a green check next to your commit () and not a red X (). You can also see the results in the Actions tab of your repo:
To get a 1-point bonus on your grade, additionally implement the following functionality as part of js/main.js
.
-
Similar to before, and continuing to use
d3-dispatch
, implement a customchangeColor2
event. -
Create an event listener that dispatches a
changeColor2
event when the circle is double-clicked.A double-click is two clicks in a very short period of time. In order to implement a double-click, you will need to use a timer, like this:
setTimeout(function, milliseconds);
Reference: Javascript timing events.
Using the pre-existing
dblclick
DOM event is not allowed in this submission. -
Create an event listener using
d3-dispatch
that is triggered on achangeColor2
event and changes the square's color to green.
Points will not be deducted for failing this bonus step, but make sure that the code in your GitHub repository works properly for the first step from the time of the deadline onwards.
You are welcome to use D3 tutorials or resources as a starting point for your code. However, you must cite and reference the resources or sample code you use and explain how you use them. This includes anything from bl.ocks.org, Observable, or Stack Overflow! Failure to properly cite and attribute code is a breach of academic honesty. Also, per our syllabus, homework is an individual assessment and should be completed by you alone. Simply copying existing examples without performing thoughtful edits is a breach of academic honesty. You are welcome to ask fellow classmates and students for help and discuss the assignment, but the submission should be your own work. See the syllabus for much more detail on our academic integrity policy and expectations.
-
Ensure you updated (1) the GitHub Pages URL at the top of this
README.md
file and (2) the GitHub repository URL inindex.html
in the span withid='forkongithub'
. -
Commit all your local files and push them to the remote repository on GitHub which was generated by GitHub Classroom. We will grade based on what is visible on the GitHub Page.
-
Submit the URL of your GitHub Classroom-generated repository (not your GitHub Page) to the associated assignment on Canvas. Do not submit a link to a personal repository. It must be within our class GitHub organization.
See https://github.com/NEU-DS-4200-F20-Staff/General_Course_Information/blob/master/d3.md
There are a ton of built-in browser DOM events that you can leverage in general!
See https://github.com/NEU-DS-4200-F20-Staff/General_Course_Information/blob/master/assignment-setup.md