Skip to content

Commit

Permalink
feat(timeline): add markers to custom time bars (#86)
Browse files Browse the repository at this point in the history
* feat(timeline): add markers to custom time bars (#84)

* chore(docs): update the document (#84)

* fix(docs): move the description to the timeline document (#84)
  • Loading branch information
ryamaguchi0220 authored and mojoaxel committed Sep 12, 2019
1 parent 90f727b commit 808c5a0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
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;
}

0 comments on commit 808c5a0

Please sign in to comment.