2018-06-15 23:03:24 +08:00
|
|
|
import { observes } from "ember-addons/ember-computed-decorators";
|
|
|
|
import {
|
|
|
|
createPreviewComponent,
|
|
|
|
LOREM,
|
|
|
|
darkLightDiff
|
|
|
|
} from "wizard/lib/preview";
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
export default createPreviewComponent(659, 320, {
|
|
|
|
logo: null,
|
|
|
|
avatar: null,
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@observes("step.fieldsById.homepage_style.value")
|
2016-09-22 04:09:18 +08:00
|
|
|
styleChanged() {
|
|
|
|
this.triggerRepaint();
|
|
|
|
},
|
|
|
|
|
|
|
|
images() {
|
2018-06-15 23:03:24 +08:00
|
|
|
return {
|
|
|
|
logo: this.get("wizard").getLogoUrl(),
|
|
|
|
avatar: "/images/wizard/trout.png"
|
|
|
|
};
|
2016-09-22 04:09:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
paint(ctx, colors, width, height) {
|
|
|
|
this.drawFullHeader(colors);
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (this.get("step.fieldsById.homepage_style.value") === "latest") {
|
2016-09-22 05:34:15 +08:00
|
|
|
this.drawPills(colors, height * 0.15);
|
2016-09-22 04:09:18 +08:00
|
|
|
this.renderLatest(ctx, colors, width, height);
|
2018-06-15 23:03:24 +08:00
|
|
|
} else if (
|
|
|
|
["categories_only", "categories_with_featured_topics"].includes(
|
|
|
|
this.get("step.fieldsById.homepage_style.value")
|
|
|
|
)
|
|
|
|
) {
|
2016-09-22 05:34:15 +08:00
|
|
|
this.drawPills(colors, height * 0.15, { categories: true });
|
2016-09-22 04:09:18 +08:00
|
|
|
this.renderCategories(ctx, colors, width, height);
|
2018-11-06 22:52:13 +08:00
|
|
|
} else if (
|
|
|
|
["categories_boxes", "categories_boxes_with_topics"].includes(
|
|
|
|
this.get("step.fieldsById.homepage_style.value")
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
this.drawPills(colors, height * 0.15, { categories: true });
|
|
|
|
const topics =
|
|
|
|
this.get("step.fieldsById.homepage_style.value") ===
|
|
|
|
"categories_boxes_with_topics";
|
|
|
|
this.renderCategoriesBoxes(ctx, colors, width, height, { topics });
|
2018-06-14 14:31:56 +08:00
|
|
|
} else {
|
|
|
|
this.drawPills(colors, height * 0.15, { categories: true });
|
|
|
|
this.renderCategoriesWithTopics(ctx, colors, width, height);
|
2016-09-22 04:09:18 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-11-06 22:52:13 +08:00
|
|
|
renderCategoriesBoxes(ctx, colors, width, height, opts) {
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
|
|
const borderColor = darkLightDiff(
|
|
|
|
colors.primary,
|
|
|
|
colors.secondary,
|
|
|
|
90,
|
|
|
|
-75
|
|
|
|
);
|
|
|
|
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
|
|
|
const margin = height * 0.03;
|
|
|
|
const bodyFontSize = height / 440.0;
|
|
|
|
const boxHeight = height * 0.7 - margin * 2;
|
|
|
|
const descriptions = this.getDescriptions();
|
|
|
|
const boxesSpacing = 15;
|
|
|
|
const boxWidth = (width - margin * 2 - boxesSpacing * 2) / 3;
|
|
|
|
|
|
|
|
this.categories().forEach((category, index) => {
|
|
|
|
const boxStartX = margin + index * boxWidth + index * boxesSpacing;
|
|
|
|
const boxStartY = height * 0.33;
|
|
|
|
|
|
|
|
this.drawSquare(
|
|
|
|
ctx,
|
|
|
|
{ x: boxStartX, y: boxStartY },
|
|
|
|
{ x: boxStartX + boxWidth, y: boxStartY + boxHeight },
|
|
|
|
[
|
|
|
|
{ color: borderColor },
|
|
|
|
{ color: borderColor },
|
|
|
|
{ color: borderColor },
|
|
|
|
{ color: category.color, width: 5 }
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
ctx.font = `Bold ${bodyFontSize * 1.3}em 'Arial'`;
|
|
|
|
ctx.fillStyle = colors.primary;
|
|
|
|
ctx.textAlign = "center";
|
|
|
|
ctx.fillText(category.name, boxStartX + boxWidth / 2, boxStartY + 25);
|
|
|
|
ctx.textAlign = "left";
|
|
|
|
|
|
|
|
if (opts.topics) {
|
|
|
|
let startY = boxStartY + 60;
|
|
|
|
this.getTitles().forEach(title => {
|
|
|
|
ctx.font = `${bodyFontSize * 1}em 'Arial'`;
|
|
|
|
ctx.fillStyle = colors.tertiary;
|
|
|
|
startY +=
|
|
|
|
this.fillTextMultiLine(
|
|
|
|
ctx,
|
|
|
|
title.split("\n").join(" "),
|
|
|
|
boxStartX + 10,
|
|
|
|
startY,
|
|
|
|
13,
|
|
|
|
boxWidth * 0.95
|
|
|
|
) + 8;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ctx.font = `${bodyFontSize * 1}em 'Arial'`;
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.textAlign = "center";
|
|
|
|
this.fillTextMultiLine(
|
|
|
|
ctx,
|
|
|
|
descriptions[index],
|
|
|
|
boxStartX + boxWidth / 2,
|
|
|
|
boxStartY + 60,
|
|
|
|
13,
|
|
|
|
boxWidth * 0.8
|
|
|
|
);
|
|
|
|
ctx.textAlign = "left";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
renderCategories(ctx, colors, width, height) {
|
|
|
|
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
|
|
|
const margin = height * 0.03;
|
|
|
|
const bodyFontSize = height / 440.0;
|
2018-06-14 14:31:56 +08:00
|
|
|
const titles = this.getTitles();
|
|
|
|
let categoryHeight = height / 6;
|
|
|
|
|
|
|
|
const drawLine = (x, y) => {
|
|
|
|
ctx.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.strokeStyle = darkLightDiff(
|
|
|
|
colors.primary,
|
|
|
|
colors.secondary,
|
|
|
|
90,
|
|
|
|
-75
|
|
|
|
);
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.moveTo(margin + x, y);
|
|
|
|
ctx.lineTo(width - margin, y);
|
|
|
|
ctx.stroke();
|
|
|
|
};
|
|
|
|
|
|
|
|
const cols = [0.025, 0.45, 0.53, 0.58, 0.94, 0.96].map(c => c * width);
|
|
|
|
|
|
|
|
const headingY = height * 0.33;
|
|
|
|
ctx.font = `${bodyFontSize * 0.9}em 'Arial'`;
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.fillText("Category", cols[0], headingY);
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("step.fieldsById.homepage_style.value") === "categories_only"
|
|
|
|
) {
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.fillText("Topics", cols[4], headingY);
|
|
|
|
} else {
|
|
|
|
ctx.fillText("Topics", cols[1], headingY);
|
|
|
|
ctx.fillText("Latest", cols[2], headingY);
|
|
|
|
categoryHeight = height / 5;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
let y = headingY + bodyFontSize * 12;
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.lineWidth = 2;
|
|
|
|
drawLine(0, y);
|
|
|
|
drawLine(width / 2, y);
|
|
|
|
|
|
|
|
// Categories
|
|
|
|
this.categories().forEach(category => {
|
2018-06-15 23:03:24 +08:00
|
|
|
const textPos = y + categoryHeight * 0.35;
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.font = `Bold ${bodyFontSize * 1.1}em 'Arial'`;
|
|
|
|
ctx.fillStyle = colors.primary;
|
|
|
|
ctx.fillText(category.name, cols[0], textPos);
|
|
|
|
|
|
|
|
ctx.font = `${bodyFontSize * 0.8}em 'Arial'`;
|
|
|
|
ctx.fillStyle = textColor;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(
|
|
|
|
titles[0],
|
|
|
|
cols[0] - margin * 0.25,
|
|
|
|
textPos + categoryHeight * 0.36
|
|
|
|
);
|
2018-06-14 14:31:56 +08:00
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(margin, y);
|
|
|
|
ctx.strokeStyle = category.color;
|
|
|
|
ctx.lineWidth = 3.5;
|
|
|
|
ctx.lineTo(margin, y + categoryHeight);
|
|
|
|
ctx.stroke();
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("step.fieldsById.homepage_style.value") ===
|
|
|
|
"categories_with_featured_topics"
|
|
|
|
) {
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(
|
|
|
|
Math.floor(Math.random() * 90) + 10,
|
|
|
|
cols[1] + 15,
|
|
|
|
textPos
|
|
|
|
);
|
2018-06-14 14:31:56 +08:00
|
|
|
} else {
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
|
|
|
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[5], textPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
y += categoryHeight;
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
drawLine(0, y);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Featured Topics
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("step.fieldsById.homepage_style.value") ===
|
|
|
|
"categories_with_featured_topics"
|
|
|
|
) {
|
2018-06-14 14:31:56 +08:00
|
|
|
const topicHeight = height / 15;
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
y = headingY + bodyFontSize * 22;
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.lineWidth = 1;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillStyle = colors.tertiary;
|
2018-06-14 14:31:56 +08:00
|
|
|
|
|
|
|
titles.forEach(title => {
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
const textPos = y + topicHeight * 0.35;
|
|
|
|
ctx.fillStyle = colors.tertiary;
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.fillText(`${title}`, cols[2], textPos);
|
|
|
|
y += topicHeight;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
renderCategoriesWithTopics(ctx, colors, width, height) {
|
|
|
|
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
|
|
|
const margin = height * 0.03;
|
|
|
|
const bodyFontSize = height / 440.0;
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
const drawLine = (x, y) => {
|
|
|
|
ctx.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.strokeStyle = darkLightDiff(
|
|
|
|
colors.primary,
|
|
|
|
colors.secondary,
|
|
|
|
90,
|
|
|
|
-75
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.moveTo(margin + x, y);
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.lineTo(margin + x + (width * 0.9) / 2, y);
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.stroke();
|
|
|
|
};
|
|
|
|
|
2018-06-14 14:31:56 +08:00
|
|
|
const cols = [0.025, 0.42, 0.53, 0.58, 0.94].map(c => c * width);
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
const headingY = height * 0.33;
|
|
|
|
ctx.font = `${bodyFontSize * 0.9}em 'Arial'`;
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.fillText("Category", cols[0], headingY);
|
|
|
|
ctx.fillText("Topics", cols[1], headingY);
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("step.fieldsById.homepage_style.value") ===
|
|
|
|
"categories_and_latest_topics"
|
|
|
|
) {
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.fillText("Latest", cols[2], headingY);
|
2018-06-15 23:03:24 +08:00
|
|
|
} else {
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.fillText("Top", cols[2], headingY);
|
|
|
|
}
|
2016-09-22 04:09:18 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
let y = headingY + bodyFontSize * 12;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.lineWidth = 2;
|
|
|
|
drawLine(0, y);
|
|
|
|
drawLine(width / 2, y);
|
|
|
|
|
|
|
|
const categoryHeight = height / 6;
|
|
|
|
const titles = this.getTitles();
|
|
|
|
|
|
|
|
// Categories
|
|
|
|
this.categories().forEach(category => {
|
2018-06-15 23:03:24 +08:00
|
|
|
const textPos = y + categoryHeight * 0.35;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.font = `Bold ${bodyFontSize * 1.1}em 'Arial'`;
|
|
|
|
ctx.fillStyle = colors.primary;
|
|
|
|
ctx.fillText(category.name, cols[0], textPos);
|
|
|
|
|
|
|
|
ctx.font = `${bodyFontSize * 0.8}em 'Arial'`;
|
|
|
|
ctx.fillStyle = textColor;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(
|
|
|
|
titles[0],
|
|
|
|
cols[0] - margin * 0.25,
|
|
|
|
textPos + categoryHeight * 0.36
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(margin, y);
|
|
|
|
ctx.strokeStyle = category.color;
|
|
|
|
ctx.lineWidth = 3.5;
|
|
|
|
ctx.lineTo(margin, y + categoryHeight);
|
|
|
|
ctx.stroke();
|
|
|
|
|
2018-06-14 14:31:56 +08:00
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
|
|
|
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[1] + 15, textPos);
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
y += categoryHeight;
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
drawLine(0, y);
|
|
|
|
});
|
|
|
|
|
2018-06-14 14:31:56 +08:00
|
|
|
// Latest/Top Topics
|
2016-09-22 04:09:18 +08:00
|
|
|
const topicHeight = height / 8;
|
|
|
|
const avatarSize = topicHeight * 0.7;
|
2018-06-15 23:03:24 +08:00
|
|
|
y = headingY + bodyFontSize * 12;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.lineWidth = 1;
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
|
|
|
|
titles.forEach(title => {
|
|
|
|
const category = this.categories()[0];
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
const textPos = y + topicHeight * 0.45;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fillStyle = textColor;
|
2018-06-15 23:03:24 +08:00
|
|
|
this.scaleImage(
|
|
|
|
this.avatar,
|
|
|
|
cols[2],
|
|
|
|
y + margin * 0.6,
|
|
|
|
avatarSize,
|
|
|
|
avatarSize
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fillText(title, cols[3], textPos);
|
|
|
|
|
|
|
|
ctx.font = `Bold ${bodyFontSize}em 'Arial'`;
|
|
|
|
ctx.fillText(Math.floor(Math.random() * 90) + 10, cols[4], textPos);
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(`1h`, cols[4], textPos + topicHeight * 0.4);
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = category.color;
|
|
|
|
const badgeSize = topicHeight * 0.1;
|
|
|
|
ctx.font = `Bold ${bodyFontSize * 0.5}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.rect(
|
|
|
|
cols[3] + margin * 0.5,
|
|
|
|
y + topicHeight * 0.65,
|
|
|
|
badgeSize,
|
|
|
|
badgeSize
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fill();
|
|
|
|
|
|
|
|
ctx.fillStyle = colors.primary;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(
|
|
|
|
category.name,
|
|
|
|
cols[3] + badgeSize * 3,
|
|
|
|
y + topicHeight * 0.76
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
y += topicHeight;
|
|
|
|
|
|
|
|
drawLine(width / 2, y);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getTitles() {
|
2018-06-15 23:03:24 +08:00
|
|
|
return LOREM.split(".")
|
|
|
|
.slice(0, 8)
|
|
|
|
.map(t => t.substring(0, 40));
|
2016-09-22 04:09:18 +08:00
|
|
|
},
|
|
|
|
|
2018-11-06 22:52:13 +08:00
|
|
|
getDescriptions() {
|
|
|
|
return LOREM.split(".");
|
|
|
|
},
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
renderLatest(ctx, colors, width, height) {
|
|
|
|
const rowHeight = height / 10.0;
|
|
|
|
const textColor = darkLightDiff(colors.primary, colors.secondary, 50, 50);
|
|
|
|
const bodyFontSize = height / 440.0;
|
|
|
|
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
|
|
|
|
|
|
|
const margin = height * 0.03;
|
|
|
|
|
|
|
|
const drawLine = y => {
|
|
|
|
ctx.beginPath();
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.strokeStyle = darkLightDiff(
|
|
|
|
colors.primary,
|
|
|
|
colors.secondary,
|
|
|
|
90,
|
|
|
|
-75
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.moveTo(margin, y);
|
|
|
|
ctx.lineTo(width - margin, y);
|
|
|
|
ctx.stroke();
|
|
|
|
};
|
|
|
|
|
|
|
|
const cols = [0.02, 0.5, 0.65, 0.8, 0.87, 0.93].map(c => c * width);
|
|
|
|
|
|
|
|
// Headings
|
|
|
|
const headingY = height * 0.33;
|
|
|
|
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.font = `${bodyFontSize * 0.9}em 'Arial'`;
|
|
|
|
ctx.fillText("Topic", cols[0], headingY);
|
|
|
|
ctx.fillText("Category", cols[1], headingY);
|
|
|
|
ctx.fillText("Users", cols[2], headingY);
|
|
|
|
ctx.fillText("Replies", cols[3], headingY);
|
|
|
|
ctx.fillText("Views", cols[4], headingY);
|
|
|
|
ctx.fillText("Activity", cols[5], headingY);
|
|
|
|
|
|
|
|
// Topics
|
|
|
|
let y = headingY + rowHeight / 2.6;
|
|
|
|
ctx.lineWidth = 2;
|
|
|
|
drawLine(y);
|
|
|
|
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
this.getTitles().forEach(title => {
|
2018-06-15 23:03:24 +08:00
|
|
|
const textPos = y + rowHeight * 0.7;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.fillText(title, cols[0], textPos);
|
|
|
|
|
|
|
|
const category = this.categories()[0];
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = category.color;
|
|
|
|
const badgeSize = rowHeight * 0.2;
|
|
|
|
ctx.font = `Bold ${bodyFontSize * 0.5}em 'Arial'`;
|
|
|
|
ctx.rect(cols[1], y + rowHeight * 0.5, badgeSize, badgeSize);
|
|
|
|
ctx.fill();
|
|
|
|
|
|
|
|
ctx.fillStyle = colors.primary;
|
2018-06-15 23:03:24 +08:00
|
|
|
ctx.fillText(
|
|
|
|
category.name,
|
|
|
|
cols[1] + badgeSize * 1.5,
|
|
|
|
y + rowHeight * 0.65
|
|
|
|
);
|
|
|
|
this.scaleImage(
|
|
|
|
this.avatar,
|
|
|
|
cols[2],
|
|
|
|
y + rowHeight * 0.3,
|
|
|
|
rowHeight * 0.5,
|
|
|
|
rowHeight * 0.5
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
|
|
|
|
ctx.fillStyle = textColor;
|
|
|
|
ctx.font = `${bodyFontSize}em 'Arial'`;
|
2018-06-15 23:03:24 +08:00
|
|
|
for (let j = 3; j <= 5; j++) {
|
|
|
|
ctx.fillText(
|
2018-06-16 09:41:34 +08:00
|
|
|
j === 5 ? "1h" : Math.floor(Math.random() * 90) + 10,
|
2018-06-15 23:03:24 +08:00
|
|
|
cols[j] + margin,
|
|
|
|
y + rowHeight * 0.7
|
|
|
|
);
|
2016-09-22 04:09:18 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
drawLine(y + rowHeight * 1);
|
2016-09-22 04:09:18 +08:00
|
|
|
y += rowHeight;
|
|
|
|
});
|
2018-11-06 22:52:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
fillTextMultiLine(ctx, text, x, y, lineHeight, maxWidth) {
|
|
|
|
const words = text.split(" ").filter(f => f);
|
|
|
|
let line = "";
|
|
|
|
let totalHeight = 0;
|
|
|
|
|
|
|
|
words.forEach(word => {
|
|
|
|
if (ctx.measureText(`${line} ${word} `).width >= maxWidth) {
|
|
|
|
ctx.fillText(line, x, y + totalHeight);
|
|
|
|
totalHeight += lineHeight;
|
|
|
|
line = word.trim();
|
|
|
|
} else {
|
|
|
|
line = `${line} ${word}`.trim();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx.fillText(line, x, y + totalHeight);
|
|
|
|
totalHeight += lineHeight;
|
|
|
|
|
|
|
|
return totalHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Edges expected in this order: NW to NE -> NE to SE -> SE to SW -> SW to NW
|
|
|
|
drawSquare(ctx, from, to, edges = []) {
|
|
|
|
const edgeConfiguration = index => {
|
|
|
|
const edge = edges[index] || {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
width: edge.width || 1,
|
|
|
|
color: edge.color || "#333"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
[
|
|
|
|
{ from: { x: from.x, y: from.y }, to: { x: to.x, y: from.y } },
|
|
|
|
{ from: { x: to.x, y: from.y }, to: { x: to.x, y: to.y } },
|
|
|
|
{ from: { x: to.x, y: to.y }, to: { x: from.x, y: to.y } },
|
|
|
|
{ from: { x: from.x, y: to.y }, to: { x: from.x, y: from.y } }
|
|
|
|
].forEach((path, index) => {
|
|
|
|
const configuration = edgeConfiguration(index);
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(path.from.x, path.from.y);
|
|
|
|
ctx.strokeStyle = configuration.color;
|
|
|
|
ctx.lineWidth = configuration.width;
|
|
|
|
ctx.lineTo(path.to.x, path.to.y);
|
|
|
|
ctx.stroke();
|
|
|
|
});
|
2016-09-22 04:09:18 +08:00
|
|
|
}
|
|
|
|
});
|