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.
npm run import -- "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))
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:
Imports:
importer
: A custom module for importing other modules.listEvents
: Function to fetch events from Google Calendar.sumEvents
: Function to sum events (not used in this code).d3Swimlane
: Function to create a swimlane chart using D3.js.Initialization:
options
: An empty object for configuration (likely authentication).now
: A Date
object representing the current time.calendarSearchToSwimlane
Function:
importer.runAllPromises
to concurrently fetch events for each query using listEvents
.d3Swimlane
, grouping events by lane (search query) and displaying them chronologically.Execution:
$
is defined (likely a custom environment variable or object).calendarSearchToSwimlane
with a list of search queries.$.html
.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.