-
Notifications
You must be signed in to change notification settings - Fork 332
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 an option to make the custom marker editable #117
Changes from all commits
ba9d752
cf5a44b
2f8c9e4
01e5c06
4a52f8b
9cf487a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Timeline | Markers example</title> | ||
|
||
<style type="text/css"> | ||
body, html { | ||
font-family: sans-serif; | ||
font-size: 11pt; | ||
} | ||
</style> | ||
|
||
<script src="../../../dist/vis-timeline-graph2d.min.js"></script> | ||
<link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" /> | ||
|
||
</head> | ||
<body> | ||
|
||
<p>The Timeline has a function to add multiple custom time markers which can be dragged by the user.</p> | ||
<p>In this example, you can add new markers by double-clicking the timeline below and delete the markers by double-clicking it.</p> | ||
<p> | ||
<input type="text" id="markerText" placeholder="marker text"> | ||
</p> | ||
|
||
<div id="visualization"></div> | ||
|
||
<script type="text/javascript"> | ||
var container = document.getElementById('visualization'); | ||
var items = new vis.DataSet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if some dummy-data would be displayed. var items = [
{x: '2014-06-11', y: 10},
{x: '2014-06-12', y: 25},
{x: '2014-06-13', y: 30},
{x: '2014-06-14', y: 10},
{x: '2014-06-15', y: 15},
{x: '2014-06-16', y: 30}
];
var dataset = new vis.DataSet(items); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are write, I copied the wrong example code. Feel free to add some data-points or leave it as it is. |
||
var customDate = new Date(); | ||
var options = { | ||
start: new Date(Date.now() - 1000 * 60 * 60 * 24), | ||
end: new Date(Date.now() + 1000 * 60 * 60 * 24 * 6) | ||
}; | ||
var timeline = new vis.Timeline(container, items, options); | ||
|
||
timeline.on('doubleClick', function (properties) { | ||
var eventProps = timeline.getEventProperties(properties.event); | ||
if (eventProps.what === 'custom-time') { | ||
timeline.removeCustomTime(eventProps.customTime); | ||
} else { | ||
var id = new Date().getTime(); | ||
var markerText = document.getElementById('markerText').value || undefined; | ||
timeline.addCustomTime(eventProps.time, id); | ||
timeline.setCustomTimeMarker(markerText, id); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE HTML> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example file needs to be added to the example overview. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 4a52f8b |
||
<html> | ||
<head> | ||
<title>Timeline | Editable markers</title> | ||
|
||
<style type="text/css"> | ||
body, html { | ||
font-family: sans-serif; | ||
font-size: 11pt; | ||
} | ||
</style> | ||
|
||
<script src="../../../dist/vis-timeline-graph2d.min.js"></script> | ||
<link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" /> | ||
|
||
</head> | ||
<body> | ||
|
||
<p>Custom time markers have an option to make the title editable.</p> | ||
|
||
<div id="visualization"></div> | ||
|
||
<script type="text/javascript"> | ||
var container = document.getElementById('visualization'); | ||
var items = new vis.DataSet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add some dummy-data (see above). |
||
var customDate = new Date(); | ||
var options = { | ||
start: new Date(Date.now() - 1000 * 60 * 60 * 24), | ||
end: new Date(Date.now() + 1000 * 60 * 60 * 24 * 6) | ||
}; | ||
var timeline = new vis.Timeline(container, items, options); | ||
|
||
var id1 = new Date().getTime(); | ||
var id2 = new Date().getTime(); | ||
timeline.addCustomTime(new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 2), id1); | ||
timeline.setCustomTimeMarker("This is editable", id1, true); | ||
timeline.addCustomTime(new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 3), id2); | ||
timeline.setCustomTimeMarker("This is not editable", id2, false); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,13 +187,20 @@ class CustomTime extends Component { | |
|
||
/** | ||
* Set custom marker. | ||
* @param {string} title | ||
* @param {string} [title] Title of the custom marker | ||
* @param {boolean} [editable] Make the custom marker editable. | ||
*/ | ||
setCustomMarker(title) { | ||
setCustomMarker(title, editable) { | ||
const marker = document.createElement('div'); | ||
marker.className = `vis-custom-time-marker`; | ||
marker.innerHTML = title; | ||
marker.style.position = 'absolute'; | ||
if (editable) { | ||
marker.setAttribute('contenteditable', 'true'); | ||
marker.addEventListener('pointerdown', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing |
||
marker.focus(); | ||
}); | ||
} | ||
this.bar.appendChild(marker); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example file needs to be added to the example overview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4a52f8b