Assignment 5

Goals

Interaction and Linked Views

Instructions

There are three parts to the assignment. You may complete the assignment in a single HTML file or use multiple files (e.g. one for CSS, one for HTML, and one for JavaScript). You should use D3 v7 and/or Observable Plot for this assignment. You may use other libraries, but you must credit them in the HTML file you turn in. Extensive documentation for D3 is available, and Vadim Ogievetsky’s example-based introduction that we went through in class is also a useful reference. This Linked Highlighting Example may also help.

Due Date

The assignment is due at 11:59pm on Wednesday, December 6.

Submission

You should submit any files required for this assignment on Blackboard. For Observable, do not publish your notebook; instead, (1) share it with me (@dakoop) and (2) use the “Export -> Download Code” option and turn in that file renamed to a5.tar.gz (or a5.tgz) file to Blackboard. Please do both of these steps as (1) is easier for me to grade, but (2) makes it possible to persist the state of the submission. If you complete the assignment outside of Observable, you may complete the assignment in a single HTML file or use multiple files (e.g. one for HTML and one for CSS). Note that the files should be linked to the main HTML document accordingly in a relative manner (styles.css not C:\My Documents\Jane\NIU\CSCI627\assignment5\styles.css). If you submit multiple files, you may need to zip them in order for Blackboard to accept the submission.

Details

In this assignment, we will again examine Illinois farming data. This data comes from the USDA’s Census of Agriculture through the QuickStats service. Specifically, we are interested in how much of each crop different counties and agricultural districts produce in Illinois. The goal of the assignment is to extend our work in Assignment 4 to examine crop production and farming area with filtering and aggregation.

0. Info

Like Assignment 1, make sure your assignment contains the following text:

  • Your name
  • Your student id
  • The course title (“Data Visualization (CSCI 627/490)”), and
  • The assignment title (“Assignment 5

If you used any additional JavaScript libraries, please append a note to this section indicating their usage to the text above (e.g. “I used the @mootari/range-slider functionality to create a range input with lower and upper bounds.”) Include links to the projects used. You do not need to adhere to any particular style for this text, but I would suggest using headings to separate the sections of the assignment.

A starter notebook (sign in with your Teams account) for the assignment is provided. If you choose to use Observable, I recommend that you fork this notebook and complete your work. Otherwise, you may copy the pieces and use it in a standard HTML/JavaScript environment.

1. Filtering (30 pts)

We continue to be curious about the difference between corn and soybean production in different counties for 2022, and we wish to be able to show corn production in counties with given ranges of soybean production. In the provided notebook, you will find an Observable Plot choropleth map with corn production values. You need to create a range slider for soybean percentage that, when updated, will change the color of the counties that fall outside to gray (or whichever color you use for unspecified/unknown). The range slider should allow both lower and upper bounds. If using Observable, the interval function from @mootari/range-slider should work well. Another option is the noUiSlider library. Again, counties whose soybean percentage (soybeansPlanted) lies outside the specified ranges should be grayed out.

Hints

  • Investigate using the Observable viewof keyword to link the range slider with a variable.
  • Observable will automatically react to any change in the slider and redraw the map, assuming it depends on the range slider variables.
  • The color scale will change based on the data. You can fix the domain of the color scale so that it will not change depending on the data shown.
  • If you remove some of the counties when creating the map, those counties will not be shown. If you set their values to an unknown value, the counties will be shown according the unknown color.
  • To access the list of counties, use counties.features
  • The template provides a finished choropleth map.

2. Brushing (40 pts)

We are also interested in the relationship of the amount of farmland to the breakdown between corn and soybean production. We expect correlation between these two crops, but we are also interested in those counties that have proportionally higher amounts of one crop versus the other as seen in Assignment 4. To investigate this, we will use a multiple-view visualization with two views, a choropleth map and a scatterplot. The choropleth shows the percentage of land used for farming either crop in 2022, and the scatterplot shows the number of acres of farmland used for each individual crop. We will use two types of brushing (linked highlighting): (a) one-to-one highlighting between the scatterplot and the map, and (b) a way to highlight all points matching a specified region.

a. One-to-One Highlighting (20 pts)

Again, the template has multiple-view visualization without any linked highlighting. Use the #corn-soy-compare div for this part of the assignment. As the user moves the mouse over a county in the map, the corresponding point in the scatterplot should be highlighted. In addition, as the user moves the mouse over a point in the scatterplot, the corresponding county in the map should be highlighted.

D3’s .on(<callback>) functions will help handle pointerover and pointerout events over particular counties or points. Note that you can add these after the visualization has been created by selecting the corresponding elements. However, for Observable Plot elements, the data is an index into the corresponding data array. In this case, because both plots use the same data array (counties.features), just checking whether the data values match is good enough. If you need access to any of the county properties, you can access them by using the data value as an index into that array. Remember to reset the selection when a user moves off of the county or point.

Hints
  • Be careful about doing d3.selectAll. Remember that you can select subsets of svg elements by first selecting the view (e.g. d3.select(cropScatter)) and then using a sub-select to access the individual elements.
  • Remember to remove highlights from counties/points other than the selected one.
  • Use classes and CSS rules to simplify the highlighted and unhighlighted updates. In addition, D3’s classed method may be used.
  • In an on method, the current visual element is available via event.currentTarget
  • D3’s filter method may be useful.
  • D3’s raise may be useful to make the outlined regions appear other regions.

b. Region Highlighting (20 pts)

Use the Ag Districts from the crop data to redo the visualization so that the left side shows the region choropleth while the right side shows the individual counties. Now, when a viewer highlights a region in the map, the linked highlighting should highlight all points in the scatterplot from that region. In addition, highlight all the counties in that region on the map.

Hints
  • You cannot just compare index values in the event handlers because you need to check the agricultural district.
  • Remember that we can access the agricultural district from the ilCropMap given the CO_FIPS property from the map feature. You may wish to implement a new map that maps CO_FIPS to Ag District more directly.
  • Use classes and CSS rules to simplify the highlighted and unhighlighted updates. In addition, D3’s classed method may be used.

3. [CS 680 Only] Binned Scatterplot (30 pts)

Create a binned scatterplot (2D histogram) using the same data as the scatterplot in Part 2a. Review the documentation on binning. Encode the information by color; think about colormap choice here–should your colormap match the colormap used for the map?

Now, create a multiple view visualization like the one in Part 2a, but this time with the binned scatterplot. Our goal is to allow the user to select a bin in the binned scatterplot and highlight all of the counties that fall within that bin. Unforunately, Plot does not provide information about how to map the bin back to the county feature directly. However, you can obtain the information from the initialize function (see this post). The data that is returned details the features that are mapped to each bin. Now, you can use the CO_FIPS value from those features to highlight the correspond elements in the map.

Hints
  • The Array.includes method may be useful to filter those choropleth elements that match those in the selected bin.

Extra Credit

  • CS 490 students may do Part 3 for extra credit
  • Allow users to select multiple counties in Part 2a and highlight all of them in the scatterplot
  • Create a hexbin scatterplot for Part 3
  • Implement the reverse selection for Part 3 from counties to bins.