Skip to content

Commit

Permalink
commit initial
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneCharignon committed May 1, 2024
0 parents commit 7a3f397
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions vistimeline.html
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>

0 comments on commit 7a3f397

Please sign in to comment.