Link Search Menu Expand Document

A7—D3 brushing

Due M 2022-03-28⧗, 11:59pm EST 16pts

Follow the instructions below and submit a single PDF for the assignment.

Please post any questions about this assignment on Canvas in Discussion: A7—D3 brushing.

Warning: This is an individual assignment.

Table of contents

Change log

  • N/A.

Aim of the assignment

This assignment will help you get started with brushing, which is the approach for selecting data before doing brushing and linking or detail view interactions. Interactivity techniques like this are important for your final project. You will not have to create any new chart—you will just demonstrate your understanding of how brushing and linking works.

Instructions

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 assignment.

Setup

  1. Accept the GitHub Classroom assignment invitation by clicking this link to get your repository:

    https://classroom.github.com/a/AuWRq5WC

    For reference, this is the template repository your repository is being created from: https://github.com/NEU-DS-4200-S22/A7--D3_Brushing.

    Recall our general instructions and policies on GitHub Classroom assignments.

  2. Clone your GitHub-Classroom-generated 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 run: git clone <YOUR_REPO_URL>

    Warning: Under no circumstances should you be editing files via the GitHub website user interface. Do all your edits locally after cloning the repository.

  3. CD or open a terminal / command prompt window into the cloned folder.

  4. Start a simple python webserver. E.g., python -m http.server, python3 -m http.server, or py -m http.server. If you are using python 2 you will need to use python -m SimpleHTTPServer instead, but please switch to python 3 as Python 2 was sunset on 2020-01-01.

  5. Wait for the output: Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/).

  6. Now open your web browser (Firefox or Chrome) and navigate to the URL: http://localhost:8000.

Repo organization

Here is an overview of the files and folders we provide for you in your repo.

Root files

  • 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.

Folders

Each folder has an explanatory README.md file.

  • data holds the data file for the visualization, texas.json.

  • favicons contains the favicons for the web page. You don’t need to 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).

  • js will contain all JavaScript files you write. E.g.,

    • visualization.js is the main code that builds all your visualizations.

    • scatterplot.js is the code for creating a scatterplot using a Reusable Chart model.

    • linechart.js is the code for creating a line chart using a Reusable Chart model.

  • lib will contain any JavaScript library you use to ensure long-term survivability. It currently includes D3.

Implement brushing on two visualizations

In general, brushing means selecting a subset of the data marks with an input device, usually paired with adding a pop-out channel to the marks to highlight them. In linking, the same brush effect (pop-out, highlighting) is applied to marks in other visualizations that correspond to the same datums. If you drag a brush across the marks in one visualization, this causes marks in the other view to be highlighed too. Here, we will only do brushing. The next assignment will add linking.

  1. Create a brush interaction for each visualization when the user drags a rectangle across it. Each of the marks within the rectangle should be selected and highlighted. I.e., if you drag a rectangle across the line cart, the enclosed marks in it will be highlighted. This GIF illustrates what this interaction should look like:

    Example of brushing a line chart.

    Likewise, here is what the interaction on the scatterplot should look like: Example of brushing a scatter plot.

    You should use d3-brush (which is included as part of D3) to make this work. You can read the relevant D3 documentation as well as looking at modern examples like this one.

    To add a brush to a D3 selection (which should probably be the svg element), you will need to use selection.call(d3.brush().on(...));. The trick is to define what brush events to listen for using .on (see the relevant section on brush events at the end of the documentation) and what functions you need to write to use as callbacks for those events.

    Note that we’ve already given you CSS code to create the highlights for the points in both charts. See style.css, in particular circle.selected. In order to highlight the points you have in a D3 selection, you can use selection.classed('selected', d => ...);. Just insert a comparison that returns true or false (the boolean, not the strings) in place of the ellipses ....

    Note: It is ok if your brushing rectangle stays on the screen after use instead of disappearing.

  1. Commit and push your files to GitHub and test whether your website looks the same on GitHub pages. Note: the GitHub Pages site won’t show up until you make your first commit & push to the remote repository, and it may take up to a minute for it to finish deploying. You would normally need to turn on GitHub pages in the settings for your repository, but we have set that up for you so you’re using the gh-pages branch by default.

  2. Edit the last line of your README.md file to include a clickable hyperlink to the GitHub page website for your repo., replacing the <insert your clickable hyperlink here> code with your markdown.

  3. In index.html update the GitHub repo URL with the URL of your repository. It is in the span with id='forkongithub'.

  4. Make any edits necessary to ensure your code passes the W3 validator. You can see the results automatically from 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:

    GitHub Actions tab

Submission instructions

  1. 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.

  2. Submit the URL of your repository to the assignment A7—D3 brushing in GradeScope.

    Warning: Do not put a link to a personal repository. It must be within our class GitHub organization.

Academic integrity

You are welcome to use D3 tutorials or resources as a starting point for your code. However, keep our academic integrity policy in mind.

Warning: You must cite and reference the resources or sample code you use and explain how you use them and where (e.g. “js/main.js line 33”).

Warning: Cite everything, including code from the D3.js Graph Gallery, bl.ocks.org, Observable, or Stack Overflow!

Failure to properly cite and attribute code is a breach of academic honesty. Simply copying existing examples without performing thoughtful edits is a breach of academic honesty. Also, per our syllabus, homework is an individual assessment and should be completed by you alone. 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 academic integrity policy on the syllabus for more detail on our expectations.

Grading rubric

CriteriaPoints
Brushing correctly implemented10 pts
Coding Style6 pts
 16 pts

Tips, tricks, & troubleshooting

If you run into trouble, first look at our relevant tutorials which have links to various resources, tips, & tricks:


© 2022 Cody Dunne. Released under the CC BY-SA license