Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(timeline): add markers to custom time bars #86

Merged
merged 3 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,16 @@ <h2 id="Methods">Methods</h2>
</td>
</tr>

<tr>
<td>setCustomTimeMarker(title [, id])</td>
<td>none</td>
<td>Attach a marker to the custom time bar.
Parameter <code>title</code> is the string to be set as title of the marker.
Parameter <code>id</code> is the id of the custom time bar which the marker is attached to, and is <code>undefined</code> by default.
Any marker's style can be overridden by specifying css selectors such as <code>.vis-custom-time > .vis-custom-time-marker</code>, <code>.${The id of the custom time bar} > .vis-custom-time-marker</code>.
</td>
</tr>

<tr>
<td>setCustomTimeTitle(title [, id])</td>
<td>none</td>
Expand Down
16 changes: 16 additions & 0 deletions lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,22 @@ class Core {
return customTimes[0].getCustomTime();
}

/**
* Set a custom marker for the custom time bar.
* @param {string} [title] Title of the custom marker.
* @param {number} [id=undefined] Id of the custom time bar.
*/
setCustomTimeMarker(title, id) {
const customTimes = this.customTimes.filter(component => component.options.id === id);

if (customTimes.length === 0) {
throw new Error(`No custom time bar found with id ${JSON.stringify(id)}`)
}
if (customTimes.length > 0) {
customTimes[0].setCustomMarker(title);
}
}

/**
* Set a custom title for the custom time bar.
* @param {string} [title] Custom title
Expand Down
12 changes: 12 additions & 0 deletions lib/timeline/component/CustomTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ class CustomTime extends Component {
return new Date(this.customTime.valueOf());
}

/**
* Set custom marker.
* @param {string} title
*/
setCustomMarker(title) {
const marker = document.createElement('div');
marker.className = `vis-custom-time-marker`;
marker.innerHTML = title;
marker.style.position = 'absolute';
this.bar.appendChild(marker);
}

/**
* Set custom title.
* @param {Date | number | string} title
Expand Down
11 changes: 11 additions & 0 deletions lib/timeline/component/css/customtime.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@
width: 2px;
cursor: move;
z-index: 1;
}

.vis-custom-time > .vis-custom-time-marker {
background-color: inherit;
color: white;
font-size: 12px;
white-space: nowrap;
padding: 3px 5px;
top: 0px;
cursor: initial;
z-index: inherit;
}