This post will cover how to create email interactive treemaps using the Nylas Email API. We will look at what is a treemap, how to consider categorizing emails and building a treemap visualization of your email inbox. You can find all the code in this blog on our Nylas Samples repository. We recently discussed creating email interactive treemaps on our LiveStreamCoding with Nylas:
Prerequisites
Sign up here if you need to create a Nylas account for free!
We will be using the Quickstart Application to connect an account to retrieve emails using Postman
We will need to have Node.js setup to run the code. Go ahead and setup Node.js on your machine.
What are Treemaps?
A treemap is a visual representation of data in the form of rectangles:
Example Treemap
Each rectangle represents specific pieces of data or collections of data that can represent treemaps themselves. In either case, the visualization is repetitive where each treemap can be a representation of more treemaps (treemaps on treemaps).
So by clicking on any specific rectangle will display more categories of data below. You can read more about Treemapping on Wikipedia. Similarly, if you think about Emails and their different purposes, we are going to group them to create email interactive treemaps.
Now we’ve gone over the basics of Treemaps.
Retrieving Emails using Nylas
Let’s retrieve emails using the Nylas Email API. So we are going to use Postman to retrieve emails using the Nylas Email API /messages endpoint and save the JSON response:
Saving Emails using Postman
Now we’ve retrieved emails using the Nylas Postman collection.
Exploring ways to Categorize Emails
Categorizing emails can be done in many ways. There can be different types of emails, let’s consider one approach to start. Here is is one approach for organizing emails:
Categorize Emails into Groups
So we will categorize emails as follows:
Internal
Status Updates (i.e. meeting updates, document shared)
Broadcasts (emails sent to a specific group)
Individuals
External Emails
Company or Tool
Individuals
In this section, we’ve explored how to categorize emails.
Create Email Interactive Treemaps
Let’s build out the functionality to create email interactive treemaps using the categorization we specified previously.
We are going to use FoamTree to create the interactive treemap. So here is a general code sample of what the JavaScript will look like to generate an treemap:
// example src/index.js
// add FoamTree via `npm i @carrotsearch/foamtree`
import { FoamTree } from "@carrotsearch/foamtree";
// data where each sub-category is represented by groups
const groups = {
label: "top-level label",
//total items in group
weight: 100,
groups: [
label: "sub-category label"
weight: 50
groups: [
//lower level category
]
],
}
new FoamTree({
// html tag to attach treemap to
id: "app",
// data to generate treemap
dataObject: groups,
parentFillOpacity: 0.9,
layout: "squarified"
});
Here is what the html file importing the JavaScript will look like:
Be sure to update the src/index.js to import the groups created in the src/categorization.js file.
Running the command npm start will load our email treemap in the browser at http://localhost:1234/:
Email Interactive Treemap
Now we’ve created a visualization of emails using an interactive treemap.
Build Time!
In this blog post, we explored how to create email interactive treemaps. Continue building with Nylas and learn more by visiting the documentation on the Nylas Email API. Sign up here if you need to create a Nylas account for free!