2023-10-18 13:44:49 +00:00
|
|
|
class BBTimelineBackgroundCanvas extends BBTimelineCanvas {
|
|
|
|
constructor(parentEl, el) {
|
|
|
|
super(parentEl, el);
|
2023-11-12 01:13:17 +00:00
|
|
|
}
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
initialiseOptions() {
|
|
|
|
super.initialiseOptions();
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
const a = this;
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
a.Options = {
|
|
|
|
Axis: {
|
|
|
|
LineColour1: "#000000",
|
|
|
|
LineWidth: 1,
|
|
|
|
Font: "8pt Arial",
|
|
|
|
LabelColour: "#000000",
|
|
|
|
LabelSpacing: 6
|
|
|
|
},
|
|
|
|
XAxis: {
|
|
|
|
NoPartPerDay: 4,
|
|
|
|
HourLineSpace: 6,
|
|
|
|
HourLineHeight: 10,
|
|
|
|
HourLineColour: "#EAEAEA",
|
|
|
|
DayLineHeight: 20,
|
|
|
|
DayLineColour: "#9E9E9E",
|
|
|
|
Position: 'bottom'
|
|
|
|
}
|
|
|
|
};
|
2023-10-18 13:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initialiseComponents() {
|
|
|
|
super.initialiseComponents();
|
|
|
|
|
|
|
|
const a = this;
|
|
|
|
|
|
|
|
a.Invalidate();
|
|
|
|
}
|
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
|
2023-10-22 21:14:12 +00:00
|
|
|
get GraphRectangle() {
|
|
|
|
const a = this;
|
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
if (a.Options.XAxis.Position == 'top') {
|
2023-10-22 21:14:12 +00:00
|
|
|
return {
|
|
|
|
X: a.ClientRectangle.X,
|
|
|
|
Y: (a.ClientRectangle.Y + a.XAxisHeight),
|
|
|
|
W: a.ClientRectangle.W,
|
|
|
|
H: (a.ClientRectangle.H - a.XAxisHeight)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
X: a.ClientRectangle.X,
|
|
|
|
Y: a.ClientRectangle.Y,
|
|
|
|
W: a.ClientRectangle.W,
|
|
|
|
H: (a.ClientRectangle.H - a.XAxisHeight)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
get XAxisHeight() {
|
|
|
|
const a = this;
|
2023-11-12 01:13:17 +00:00
|
|
|
const labelSize = a.measureText(a.Options.Axis.Font, "0");
|
2023-10-19 23:22:29 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
return labelSize.H + a.Options.Axis.LabelSpacing + (a.Options.XAxis.DayLineHeight * 2);
|
2023-10-19 23:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get XAxisPositions() {
|
|
|
|
const a = this;
|
|
|
|
const endPosX = (a.GraphRectangle.X + a.GraphRectangle.W);
|
|
|
|
|
|
|
|
let result = [];
|
|
|
|
let x = a.GraphRectangle.X;
|
|
|
|
let date = a.Parent.ConvertToDate(a.Parent.ShowDate);
|
|
|
|
|
|
|
|
// Rollback one day
|
|
|
|
date.setDate(date.getDate() - 1);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (x >= endPosX) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.push({
|
|
|
|
Date: a.Parent.DateToInternalString(date),
|
|
|
|
X: x
|
|
|
|
});
|
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
x += (a.Options.XAxis.HourLineSpace * a.Options.XAxis.NoPartPerDay);
|
2023-10-19 23:22:29 +00:00
|
|
|
date.setDate(date.getDate() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:44:49 +00:00
|
|
|
Invalidate() {
|
|
|
|
const a = this;
|
|
|
|
|
|
|
|
a.Clear();
|
|
|
|
|
|
|
|
a.drawAxis();
|
|
|
|
a.drawXAxisTicks();
|
|
|
|
a.drawXAxisLabels();
|
|
|
|
|
|
|
|
if (a.Parent.Debug) a.drawRectangle(a.ClientRectangle, "red");
|
|
|
|
if (a.Parent.Debug) a.drawRectangle(a.GraphRectangle, "red");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drawAxis() {
|
|
|
|
const a = this;
|
|
|
|
|
|
|
|
a.CTX.beginPath();
|
2023-10-22 21:14:12 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
if (a.Options.XAxis.Position == 'top') {
|
2023-10-22 21:14:12 +00:00
|
|
|
a.CTX.moveTo(a.GraphRectangle.X, (a.GraphRectangle.Y + a.GraphRectangle.H));
|
|
|
|
a.CTX.lineTo(a.GraphRectangle.X, a.GraphRectangle.Y);
|
|
|
|
a.CTX.lineTo((a.GraphRectangle.X + a.GraphRectangle.W), a.GraphRectangle.Y);
|
|
|
|
} else {
|
|
|
|
a.CTX.moveTo(a.GraphRectangle.X, a.GraphRectangle.Y);
|
|
|
|
a.CTX.lineTo(a.GraphRectangle.X, (a.GraphRectangle.Y +a.GraphRectangle.H));
|
|
|
|
a.CTX.lineTo((a.GraphRectangle.X + a.GraphRectangle.W), (a.GraphRectangle.Y + a.GraphRectangle.H));
|
|
|
|
}
|
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
a.CTX.lineWidth = a.Options.Axis.LineWidth;
|
|
|
|
a.CTX.strokeStyle = a.Options.Axis.LineColour1;
|
2023-10-18 13:44:49 +00:00
|
|
|
a.CTX.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
drawXAxisLabels() {
|
|
|
|
const a = this;
|
2023-11-12 01:13:17 +00:00
|
|
|
const labelSize = a.measureText(a.Options.Axis.Font, "0");
|
2023-10-22 21:14:12 +00:00
|
|
|
|
|
|
|
let posY = 0;
|
|
|
|
let posDayY = 0;
|
|
|
|
let posMonthY = 0;
|
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
if (a.Options.XAxis.Position == 'top') {
|
|
|
|
posY = (a.GraphRectangle.Y - a.Options.Axis.LineWidth) - 2;
|
|
|
|
posDayY = (posY - (labelSize.H + a.Options.XAxis.DayLineHeight));
|
|
|
|
posMonthY = (posDayY - (labelSize.H + a.Options.Axis.LabelSpacing));
|
2023-10-22 21:14:12 +00:00
|
|
|
} else {
|
2023-11-12 01:13:17 +00:00
|
|
|
posY = (a.GraphRectangle.Y + a.GraphRectangle.H) + a.Options.Axis.LineWidth;
|
|
|
|
posDayY = (posY + a.Options.XAxis.DayLineHeight);
|
|
|
|
posMonthY = (posDayY + labelSize.H + a.Options.Axis.LabelSpacing);
|
2023-10-22 21:14:12 +00:00
|
|
|
}
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
a.XAxisPositions.forEach(function(e, i) {
|
2023-10-18 13:44:49 +00:00
|
|
|
const date = a.Parent.ConvertToDate(e.Date);
|
|
|
|
|
|
|
|
let writeLabel = false;
|
|
|
|
if ((i == 0)) {
|
|
|
|
// Don't label first entry if too close to the next month
|
|
|
|
if (date.getDate() < 25) {
|
|
|
|
writeLabel = true;
|
|
|
|
}
|
|
|
|
} else if (date.getDate() == 1) {
|
|
|
|
writeLabel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (i == 0) {
|
2023-10-22 21:14:12 +00:00
|
|
|
// // Don't write first date
|
|
|
|
// } else {
|
|
|
|
// Write date (dd)
|
2023-11-12 01:13:17 +00:00
|
|
|
a.drawText(e.X, posDayY, a.Parent.DateToString(date, "dd"), a.Options.Axis.Font, a.Options.Axis.LabelColour, "center");
|
2023-10-18 13:44:49 +00:00
|
|
|
// }
|
|
|
|
|
2023-10-22 21:14:12 +00:00
|
|
|
// Write month (MMMM) on first of the month
|
2023-10-18 13:44:49 +00:00
|
|
|
if (writeLabel) {
|
2023-11-12 01:13:17 +00:00
|
|
|
a.drawText(e.X, posMonthY, a.Parent.DateToString(date, "MMMM yyyy"), a.Options.Axis.Font, a.Options.Axis.LabelColour, "left");
|
2023-10-18 13:44:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
drawXAxisTicks() {
|
2023-10-18 13:44:49 +00:00
|
|
|
const a = this;
|
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
let startPosX = a.GraphRectangle.X;
|
|
|
|
const endPosX = (a.GraphRectangle.X + a.GraphRectangle.W);
|
2023-10-22 21:14:12 +00:00
|
|
|
let posY = 0;
|
|
|
|
let posDayY = 0;
|
|
|
|
let posHourY = 0;
|
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
if (a.Options.XAxis.Position == 'top') {
|
|
|
|
posY = (a.GraphRectangle.Y - a.Options.Axis.LineWidth);
|
|
|
|
posDayY = (posY - a.Options.XAxis.DayLineHeight);
|
|
|
|
posHourY = (posY - a.Options.XAxis.HourLineHeight);
|
2023-10-22 21:14:12 +00:00
|
|
|
} else {
|
2023-11-12 01:13:17 +00:00
|
|
|
posY = (a.GraphRectangle.Y + a.GraphRectangle.H) + a.Options.Axis.LineWidth;
|
|
|
|
posDayY = (posY + a.Options.XAxis.DayLineHeight);
|
|
|
|
posHourY = (posY + a.Options.XAxis.HourLineHeight);
|
2023-10-22 21:14:12 +00:00
|
|
|
}
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
let i = 0;
|
2023-10-18 13:44:49 +00:00
|
|
|
|
|
|
|
while (true) {
|
2023-10-19 23:22:29 +00:00
|
|
|
if (startPosX >= endPosX) {
|
2023-10-18 13:44:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
a.CTX.beginPath();
|
|
|
|
a.CTX.moveTo(startPosX, posY);
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
if ((i % a.Options.XAxis.NoPartPerDay) == 0) {
|
2023-10-22 21:14:12 +00:00
|
|
|
a.CTX.lineTo(startPosX, posDayY);
|
2023-11-12 01:13:17 +00:00
|
|
|
a.CTX.strokeStyle = a.Options.XAxis.DayLineColour;
|
2023-10-19 23:22:29 +00:00
|
|
|
} else {
|
2023-10-22 21:14:12 +00:00
|
|
|
a.CTX.lineTo(startPosX, posHourY);
|
2023-11-12 01:13:17 +00:00
|
|
|
a.CTX.strokeStyle = a.Options.XAxis.HourLineColour;
|
2023-10-19 23:22:29 +00:00
|
|
|
}
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
a.CTX.lineWidth = a.Options.Axis.LineWidth;
|
2023-10-19 23:22:29 +00:00
|
|
|
a.CTX.stroke();
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-11-12 01:13:17 +00:00
|
|
|
startPosX += a.Options.XAxis.HourLineSpace;
|
2023-10-18 13:44:49 +00:00
|
|
|
|
2023-10-19 23:22:29 +00:00
|
|
|
i++;
|
|
|
|
}
|
2023-10-18 13:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|