Updated demo page

This commit is contained in:
Ray 2023-10-03 00:04:03 +01:00
parent f935d337d6
commit ecce768399
2 changed files with 46 additions and 5 deletions

View File

@ -48,6 +48,7 @@ class BBTimeline {
a.Events = []; a.Events = [];
a.StartDate = a.DateToString(new Date(), "yyyy-MM-dd"); a.StartDate = a.DateToString(new Date(), "yyyy-MM-dd");
a.ShowDate = a.StartDate; a.ShowDate = a.StartDate;
a.LastDate = null;
a.GraphRectangle = a.calcGraphArea(); a.GraphRectangle = a.calcGraphArea();
a.Enabled = false; a.Enabled = false;
a.Debug = false; a.Debug = false;
@ -62,11 +63,11 @@ class BBTimeline {
AddEvent(date, label, options) { AddEvent(date, label, options) {
const a = this; const a = this;
const _options = Object.assign(a.GetEventItem(), options); const _options = Object.assign(a.GenerateEventItem(), options);
let event = a.FindEvent(date); let event = a.FindEvent(date);
if (event == null) { if (event == null) {
a.Events.push(a.GetEvent(date)); a.Events.push(a.GenerateEvent(date));
event = a.FindEvent(date); event = a.FindEvent(date);
} }
@ -87,6 +88,7 @@ class BBTimeline {
a.ShowDate = a.StartDate; a.ShowDate = a.StartDate;
a.Enabled = false; a.Enabled = false;
a.Events = []; a.Events = [];
a.LastDate = null;
} }
DeleteMarker(date) DeleteMarker(date)
@ -295,7 +297,7 @@ class BBTimeline {
} }
GetEvent(date) { GenerateEvent(date) {
const a = this; const a = this;
return { return {
@ -309,7 +311,7 @@ class BBTimeline {
}; };
} }
GetEventItem() { GenerateEventItem() {
return { return {
Title: "", Title: "",
Description: "", Description: "",
@ -509,6 +511,8 @@ class BBTimeline {
const labelSize = a.drawText(e.X, (y + a.Axis.X.DayLineHeight), a.DateToString(date, "dd"), a.Axis.Font, a.Axis.LabelColour, "center"); const labelSize = a.drawText(e.X, (y + a.Axis.X.DayLineHeight), a.DateToString(date, "dd"), a.Axis.Font, a.Axis.LabelColour, "center");
const label2Spacing = 6; const label2Spacing = 6;
a.LastDate = a.DateToString(date, "yyyy-MM-dd");
// Write month on first of the month // Write month on first of the month
if (writeLabel) { if (writeLabel) {
a.drawText(e.X, (y + a.Axis.X.DayLineHeight + labelSize.Height + label2Spacing), a.DateToString(date, "MMMM yyyy"), a.Axis.Font, a.Axis.LabelColour, "left"); a.drawText(e.X, (y + a.Axis.X.DayLineHeight + labelSize.Height + label2Spacing), a.DateToString(date, "MMMM yyyy"), a.Axis.Font, a.Axis.LabelColour, "left");

View File

@ -34,7 +34,12 @@
<button onclick="UpdateMarker()">Update Marker</button> <button onclick="UpdateMarker()">Update Marker</button>
<button onclick="DeleteMarker()">Delete Marker</button> <button onclick="DeleteMarker()">Delete Marker</button>
</p> </p>
<p>
<button onclick="GetDisplayedDateRange()">Get Displayed Date Range</button>
<button onclick="FindEvent()">Find Event</button>
<button onclick="FindDatePosition()">Find Date Position</button>
<button onclick="FindVisibleEvents()">Find Visible Events</button>
</p>
<style> <style>
body { body {
@ -129,6 +134,38 @@ function DeleteMarker()
timeline1.Invalidate(false, true); timeline1.Invalidate(false, true);
} }
function GetDisplayedDateRange()
{
alert(timeline1.ShowDate + " - " + timeline1.LastDate);
}
function FindEvent()
{
const result = timeline1.FindEvent("2023-10-26");
console.log(result);
alert(JSON.stringify(result));
}
function FindDatePosition()
{
const result = timeline1.FindDatePosition("2023-10-26");
console.log(result);
alert(JSON.stringify(result));
}
function FindVisibleEvents()
{
const result = timeline1.FindVisibleEvents()
console.log(result);
alert(JSON.stringify(result));
}
</script> </script>