We launched a new IT training category! Check out the 140+ courses now.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using rollovers

From: Interactive Data Visualization with Processing

Video: Using rollovers

Another common form of interacting with data visualizations and sketches in general is by rollovers and clicking. Now so far, we've done zooming and rotating and sliding and we have done slicing. Rollovers are familiar. We've done them before were you go over the top of something and it changes. In this example, I am going to be using a sketch that we did a couple of chapters ago which was on bar charts where I am using the Olympic data from the early 1900s on the tug of war as an Olympic event. Except this time what I'm doing is I want to show you a little more detail and also in the last one, I mentioned that you could use flags to pop up on the bars as a way of highlighting things and that's what we have actually done in this particular case.

Using rollovers

Another common form of interacting with data visualizations and sketches in general is by rollovers and clicking. Now so far, we've done zooming and rotating and sliding and we have done slicing. Rollovers are familiar. We've done them before were you go over the top of something and it changes. In this example, I am going to be using a sketch that we did a couple of chapters ago which was on bar charts where I am using the Olympic data from the early 1900s on the tug of war as an Olympic event. Except this time what I'm doing is I want to show you a little more detail and also in the last one, I mentioned that you could use flags to pop up on the bars as a way of highlighting things and that's what we have actually done in this particular case.

So let me just explain the few things that are different. The font stuff at the top is the same. The string of the country abbreviations is the same. The array of the medal counts is the same. The string array of the full names of the countries is the same. The next two are new, PImage is the processing image format and I've made an array to hold the flags. Now unfortunately, you have to do this in a multi step process, really Processing only wants me to declare how long the array is, and so what I did is I simply grabbed the country's list and said if the same length is that.

And then what I did is I created a separate array with the names of the image files. Now in this particular example, I use the three character abbreviations of the countries and I did all PNG ping files. Ping files are nice because they support transparency, and we got all of these files and put them into the sketches data folder. In fact, let me show that to you real fast. So here's the sketch. It's in it's own folder right here and here's the data folder and now you see that I have flags for several different countries. You also notice that the images are slightly different sizes and it turns out that that's completely irrelevant because we're going to have Processing automatically resize and just squish them to fit the bars that they go in, and I'll show you the code for that in a minute.

So the two new arrays here are for the image arrays where I simply say how long it is, and then I have an array with the actual names of the image files. Then I am going to scroll down a little bit. The setup is the same, come down little further and the 4 loop is the same except at the bottom of it, I've added flags as it's going through the arrays item by item and it's loading and how tall each item should be based on their medals wins and it's loaded in the "x" and the "y" coordinates.

I also am having it load in the names of the flag files, so that SWE.PNG for Sweden's into the flags array. Previously I can only see have how long it is now. I can actually put the names of those files into the array. Then we go down a little further and this is the hovering code. This is the key part for what we're doing right now. Because the bars are rectangles I need to use the four-part conditional. I need to check that the mouse has gone inside the bar, that it's gone past the left side but it has not gone past the to right side. That it's below the top and that it's above the bottom.

And because I've centered the bars that way I could use the same x-coordinates for the labels. I have this little thing where first identify the center of the bar and then I add or subtract half of the width or the height to specify the boundaries of the bar. We come down a few lines here, I specify the fill, then I bring in the font, and then I say that I am going to be centering the text. Then I bring in the text. So if we're hovering over a bar it will bring in the full name of that country along with it's medal count and it'll put it right above the bar. That's what the one that says text tugNames is.

Also I am going to put the image into the bar so I'll use imagemode (CENTER) so I can use the same coordinates that produce the bar where we used Ridgemont Center. And so what I do is I specify the image. What I need to input is the name of the file and I say go to the array flags and go to the indexItemI and that will be for instance BL.PNG for Belgium's flag. And then I want you to get the same x-coordinates and y-coordinates that are used for pushing the rectangle in, and then I want you to adjust the size of the Ping files so that it's the same width of the bar, that's "w" and that's the same for all of them, and it is the same height as that particular bar and that's "t" for the I index number.

Also the next one is important. It's to turn off the fill and the reason for that is because the rectangles are drawn outside of the hovering loop and if I don't shut off the fill, the rectangles will just draw right over the top of the flags, and I'll lose the effect, and it's little hard to juggle, because they're in different loops. But if I simply turn off the fill that will carry over and the rectangle will draw it's just because it has no fill and it has no stroke. You can't see it. And so what remains is the flag and that's the important part of this.

So let me show you the final effect. I am just going to come up and press Run and so far this looks the same. Now in the previous version, if I came over and I hovered over something it would turn yellow and it would put the statistics above, now if I hover over I get the country flag along with the full name of the country and the number of medals they have won in this particular event. And the flags have been distorted to fit into the bar. By the way, for you history buffs, we're aware that these are not the historically accurate flags for these countries in the early 1900s, nevertheless, we thought it would be a more informative to use the flags that were familiar to people right now and also given the unusual shapes as some of the other flags, these ones just fit better.

But you get the idea. As you just roll over, you get a flag for the country and you get its name and the number of medals they won, and that's a very simple, but eye-catching form of interaction in this particular visualization.

Show transcript

This video is part of

Image for Interactive Data Visualization with Processing
Interactive Data Visualization with Processing

72 video lessons · 13094 viewers

Barton Poulson
Author

 
Expand all | Collapse all
  1. 3m 16s
    1. Welcome
      58s
    2. What you should know
      1m 22s
    3. Using the exercise files
      56s
  2. 11m 51s
    1. Overview of data visualization
      11m 51s
  3. 11m 53s
    1. Installing Processing
      3m 38s
    2. Overview of Processing
      4m 5s
    3. Exploring libraries
      4m 10s
  4. 1h 1m
    1. Basic setup
      7m 31s
    2. Drawing points
      4m 37s
    3. Drawing lines
      5m 6s
    4. Drawing ellipses and circles
      5m 24s
    5. Drawing arcs
      6m 54s
    6. Drawing rectangles and squares
      4m 58s
    7. Drawing quadrangles
      3m 25s
    8. Drawing triangles
      2m 55s
    9. Drawing polygons
      3m 37s
    10. Drawing simple curves
      4m 54s
    11. Drawing complex curves
      6m 46s
    12. Drawing Bézier curves
      5m 38s
  5. 54m 3s
    1. Introduction to variables
      10m 44s
    2. Understanding variable scope
      6m 53s
    3. Modifying variables
      9m 8s
    4. Creating arrays
      9m 53s
    5. Modifying arrays
      6m 37s
    6. Creating strings
      7m 3s
    7. Modifying strings
      3m 45s
  6. 1h 2m
    1. Incorporating randomness
      7m 59s
    2. Using Perlin noise
      4m 24s
    3. Shuffling with Java
      3m 30s
    4. Specifying line attributes
      8m 2s
    5. Changing placement modes
      5m 45s
    6. Understanding color attributes and functions
      4m 16s
    7. Exploring color spaces
      7m 44s
    8. Using color palettes
      7m 5s
    9. Transforming the grid
      8m 38s
    10. Exploring the attribute matrix
      5m 33s
  7. 52m 7s
    1. Building code blocks
      5m 57s
    2. Writing a while loop
      3m 52s
    3. Using for loops
      5m 35s
    4. Creating conditionals
      14m 50s
    5. Working with easing
      10m 51s
    6. Creating spirals
      11m 2s
  8. 18m 55s
    1. Mouse tracking
      3m 54s
    2. Hovering and clicking
      11m 16s
    3. Understanding keyboard interaction
      3m 45s
  9. 27m 32s
    1. Specifying fonts
      6m 43s
    2. Using images
      5m 51s
    3. Playing a video loop
      6m 20s
    4. Exporting video
      3m 47s
    5. Adding sound
      4m 51s
  10. 20m 49s
    1. Creating functions
      11m 48s
    2. Creating classes and objects
      9m 1s
  11. 31m 10s
    1. Using embedded data
      5m 26s
    2. Working with appended text data
      6m 4s
    3. Working with appended tabular data
      10m 26s
    4. Reading XML data
      9m 14s
  12. 48m 17s
    1. Generating dot plots
      11m 11s
    2. Building scatter plots
      10m 0s
    3. Making line plots
      9m 55s
    4. Creating bar charts
      9m 12s
    5. Checking out examples of maps, hierarchies, and networks
      7m 59s
  13. 20m 57s
    1. Introducing some principles of 2D design
      13m 44s
    2. Understanding color theory
      7m 13s
  14. 24m 46s
    1. Interacting with zooming, rotating, and sliding
      6m 26s
    2. Implementing slicing
      6m 47s
    3. Using rollovers
      5m 58s
    4. Introducing the GUI libraries
      5m 35s
  15. 10m 35s
    1. Sharing via OpenProcessing and other sites
      3m 19s
    2. Saving as a desktop application
      2m 42s
    3. Saving as JavaScript
      1m 47s
    4. Saving as an Android application
      2m 47s
  16. 2m 38s
    1. Where to go from here
      2m 38s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Interactive Data Visualization with Processing.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.