-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
ka2 edited this page Jun 27, 2024
·
2 revisions
To use Sunorhc.Timeline on a web page, please follow the steps below.
- Include the CSS file in the head tag of your HTML and load the JS file before the end of the body tag.
<link rel="stylesheet" src="/path/to/dists/css/sunorhc.timeline.css"> <script src="/path/to/dists/js/sunorhc.timeline.js"></script>
- Then, prepare a container element within the body tag to display the timeline.
<div id="myTimeline"></div>
- Finally, instantiate the timeline component within the
script
tag to complete the process.Sunorhc.Timeline.create('myTimeline', { sidebar: { items: [ { type: 'text', label: 'Row 1'} ] } })
Note: Currently instantiation will fail unless at least one sidebar item is defined.
Note: The instantiated timeline component is automatically registered to the global Window object. To access the instance after it is created, refer to the window.SunorhcTimelineInstances
property.
- To control the component after it is instantiated, we recommend using asynchronous instantiation, as see below.
or
(async () => { await Sunorhc.Timeline.create('myTimeline', { options... }) .then(thisInstance => { console.log(window.SunorhcTimelineInstances, thisInstance.getOptions()) }) })()
(async () => { const ST = await Sunorhc.Timeline.create('myTimeline', { options... }) console.log('Timeline instancenated:', ST.getOptions()) })()
- It is also possible to define instantiation options for a timeline as a dataset attribute within its container element.
In this case, instantiate the instance factory method without including any optional arguments.
<div id="myTimeline" data-options="{ start: '2024-06-01', end : '2024-06-30', scale: 'day', header: { display: true, label: 'My Timeline Name' }, footer: { display: true, label: '© copyright' }, sidebar: { placement: 'left', itemHeight: 200, items: [ { type: 'text', label: 'Pointer Events' }, { type: 'text', label: 'Bar Events'} ] }, ruler: { placement: 'bottom', top: { rows: ['month', 'day', 'weekday'] }, bottom: { rows: ['weekday', 'day', 'month'] } }, layout: { outlined: 'both', width: 'auto', height: 'auto' }, zoomable: true, }" ></div>
Sunorhc.Timeline.create('myTimeline')
- You can also separate the timeline options from the HTML by specifying an external JSON file in the dataset attribute.
Again, the instance factory methods are simpler in this case as well.
<div id="myTimeline" data-options="timeline-options.json"></div>
This instantiation is useful when you want to separate the generation of timeline instances from the front-end and manage them in a separate system such as the back-end.Sunorhc.Timeline.create('myTimeline')