-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7a3f397
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Timeline</title> | ||
<script src="https://docs.getgrist.com/grist-plugin-api.js"></script> | ||
<script type="text/javascript" src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script> | ||
<link href="https://unpkg.com/vis-timeline@latest/styles/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" /> | ||
<style type="text/css"> | ||
body, html { | ||
font-family: arial, sans-serif; | ||
font-size: 10pt; | ||
} | ||
#visualization { | ||
border: 1px solid lightgray; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="visualization"></div> | ||
|
||
<script type="text/javascript"> | ||
|
||
var container = document.getElementById('visualization'); | ||
var options = { | ||
stack: false | ||
}; | ||
var timeline = new vis.Timeline(container, null, options); | ||
|
||
grist.ready({columns: [ | ||
{ name: "content", title: "Content", optional: false, description: "Some text", allowMultiple: false }, | ||
{ name: "start", title: "Start", optional: false, type: "Date", description: "Some text", allowMultiple: false }, | ||
{ name: "end", title: "End", optional: true, type: "Date", description: "Some text", allowMultiple: false }, | ||
{ name: "group", title: "Group", optional: true, description: "Some text", allowMultiple: false }, | ||
], requiredAccess: 'read table'}); | ||
|
||
grist.onRecords(function (records, mappings) { | ||
const items = grist.mapColumnNames(records); | ||
const groups = Array.from(new Set(items.map(item => item.group))).map((group, index) => ({id: index, content: group})); | ||
|
||
items.forEach(item => { | ||
const helper = groups.find(g => g.content === item.group); | ||
if (helper) { | ||
item.group = helper.id; // replace the group name with the ID from helperList | ||
} | ||
}); | ||
|
||
const items_dataset = new vis.DataSet(items); | ||
const groups_dataset = new vis.DataSet(groups); | ||
timeline.setItems(items_dataset); | ||
timeline.setGroups(groups_dataset); | ||
timeline.fit(); | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |