Compare commits

...

1 Commits

Author SHA1 Message Date
cfd75bd5d7 Add notes for clipping text to fit activity rectangle widths 2023-02-27 10:40:19 -08:00

View File

@ -325,6 +325,7 @@ export default {
let textLines = this.getActivityDisplayText(this.canvasContext, activity.name, activityNameFitsRect); let textLines = this.getActivityDisplayText(this.canvasContext, activity.name, activityNameFitsRect);
const textWidth = textStart + this.getTextWidth(textLines[0]) + TEXT_LEFT_PADDING; const textWidth = textStart + this.getTextWidth(textLines[0]) + TEXT_LEFT_PADDING;
//We shouldn't need the else block here if we clip text to fit the rectangle
if (activityNameFitsRect) { if (activityNameFitsRect) {
currentRow = this.getRowForActivity(rectX, rectWidth, activitiesByRow); currentRow = this.getRowForActivity(rectX, rectWidth, activitiesByRow);
} else { } else {
@ -365,6 +366,8 @@ export default {
}; };
}); });
}, },
//REDO this to receive the rectangle width as the max width of text (minus padding)
// Cut off any text that exceeds this width.
getActivityDisplayText(context, text, activityNameFitsRect) { getActivityDisplayText(context, text, activityNameFitsRect) {
//TODO: If the activity start is less than viewBounds.start then the text should be cropped on the left/should be off-screen) //TODO: If the activity start is less than viewBounds.start then the text should be cropped on the left/should be off-screen)
let words = text.split(' '); let words = text.split(' ');
@ -376,6 +379,7 @@ export default {
let testLine = line + words[n] + ' '; let testLine = line + words[n] + ' ';
let metrics = context.measureText(testLine); let metrics = context.measureText(testLine);
let testWidth = metrics.width; let testWidth = metrics.width;
//We need to go to a new line if the width of our line is > MAX_TEXT_WIDTH
if (!activityNameFitsRect && (testWidth > MAX_TEXT_WIDTH && n > 0)) { if (!activityNameFitsRect && (testWidth > MAX_TEXT_WIDTH && n > 0)) {
activityText.push(line); activityText.push(line);
line = words[n] + ' '; line = words[n] + ' ';