google calendar graphs | test google calendar search heatmap | test google calendar search pie chart | Search

This code creates an interactive swimlane chart visualizing Google Calendar events grouped by search query, allowing you to see the schedule of events for each keyword over time.

Run example

npm run import -- "test google calendar search swimlane"

test google calendar search swimlane

var importer = require('../Core');

var options = {};
var {
    listEvents, sumEvents, d3Swimlane
} = importer.import("list events",
"import google calendar api",
"sum a list of events",
"d3 swimlane");

var now = new Date();
function calendarSearchToSwimlane(searches) {
    return importer.runAllPromises(searches
        .map((s, i) => (resolve) => listEvents({
            auth: options.auth,
            q: s
        })
            .then(r => {
                //console.log(s);
                //console.log(r.map(e => e.event.summary));
                resolve(r.map(e => ({
                    id: e.event.id,
                    lane: i,
                    start: new Date(e.event.start.dateTime),
                    end: new Date(e.event.end.dateTime),
                    class: e.event.end.dateTime > now ? 'future' : 'past',
                    desc: e.event.summary
                })));
            })
            .catch(e => console.log(e))))
        .then(r => d3Swimlane({
            lanes: searches.map((s, i) => ({
                id: i,
                label: s
            })),
            items: [].concat(...r)
        }))
        .catch(e => console.log(e))
}

$.async();
calendarSearchToSwimlane([
    'study sauce',
    'portal',
    'renewal',
    'work on sos',
    'jupyter',
    'jupytangular',
    'unit tests',
    'selenium',
    'angular',
    'mind spree',
    '"c#"',
    'docker'
])
    .then(r => $.html(r))
    .catch(e => $.sendError(e))

What the code could have been:

import { importModules, runAllPromises, html, sendError } from '../Core';

const modules = [
    'list events',
    'import google calendar api',
   'sum a list of events',
    'd3 swimlane'
];

const { listEvents, sumEvents, d3Swimlane } = importModules(modules);

// Extract search query options
const searchOptions = {
  async getSearchQueries() {
    return ['study sauce', 'portal','renewal', 'work on sos', 'jupyter', 'jupytangular', 'unit tests','selenium', 'angular','mind spree', '"c#"', 'docker'];
  },
  async getSearchLabels() {
    return this.getSearchQueries().map((query, index) => ({ id: index, label: query }));
  },
  async getPromises(searchQueries) {
    return searchQueries.map((searchQuery, index) => () => listEvents({ auth: options.auth, q: searchQuery }));
  },
  async processPromises(promises) {
    return Promise.all(promises.map(promise => promise()
     .then(result => result.map(event => ({
        id: event.event.id,
        lane: 0,
        start: new Date(event.event.start.dateTime),
        end: new Date(event.event.end.dateTime),
        class: event.event.end.dateTime > now? 'future' : 'past',
        desc: event.event.summary
      }))));
  },
  async createSwimlane(items) {
    return d3Swimlane({
      lanes: await this.getSearchLabels(),
      items
    });
  }
};

// Get current date
const now = new Date();

// Create calendar search to swimlane function
async function calendarSearchToSwimlane() {
  try {
    const searches = await searchOptions.getSearchQueries();
    const promises = await searchOptions.getPromises(searches);
    const items = await searchOptions.processPromises(promises);
    const swimlane = await searchOptions.createSwimlane(items);
    return html(swimlane);
  } catch (error) {
    return sendError(error);
  }
}

// Run the calendar search to swimlane function
calendarSearchToSwimlane()
 .catch(error => console.log(error));

This code visualizes Google Calendar events using a swimlane chart, grouping events by search query and showing their schedule over time.

Here's a breakdown:

  1. Imports:

  2. Initialization:

  3. calendarSearchToSwimlane Function:

  4. Execution:

In essence, this code provides a way to visualize Google Calendar events based on keywords, creating a swimlane chart that shows the schedule of events for each keyword over time.