Skip to content

Commit

Permalink
wrap object title if larger than box width
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliorivas committed Jul 26, 2024
1 parent 538060e commit 89a2012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 12 additions & 3 deletions js/draw/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import { getApp, getContainer } from "./app.js";

const MARGIN = 20;
const PADDING = 5;
const TITLE_MARGIN = 12;

function createText(text, { fontFamily, fontSize, fontWeight, align, fill }) {
function createText(
text,
{ fontFamily, fontSize, fontWeight, align, fill, wrap = false, maxWidth }
) {
return new Text({
text,
style: new TextStyle({
Expand All @@ -20,6 +24,8 @@ function createText(text, { fontFamily, fontSize, fontWeight, align, fill }) {
fontWeight,
align,
fill,
wordWrap: wrap,
wordWrapWidth: maxWidth,
}),
resolution: 2,
});
Expand Down Expand Up @@ -118,10 +124,12 @@ export function addTitleToBox(title, box) {
align: "center",
fill: "black",
fontWeight: "bold",
wrap: true,
maxWidth: box.width,
});
box.addChild(boxTitle);
boxTitle.position.set((box.width - boxTitle.width) / 2, MARGIN);
return boxTitle.position.y + boxTitle.height + 12;
return boxTitle.position.y + boxTitle.height + TITLE_MARGIN;
}

export function addLinesToBox(lines, box, y) {
Expand All @@ -131,7 +139,8 @@ export function addLinesToBox(lines, box, y) {
fontWeight: "normal",
align: "center",
fill: "black",
width: box.width,
wrap: true,
maxWidth: box.width,
});
box.addChild(text);
text.position.set((box.width - text.width) / 2, y);
Expand Down
10 changes: 8 additions & 2 deletions js/types/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EDMObject {
box.interactiveChildren = false;
addBox(box);
box.position.set(this.x, this.y);
const nextY = addTitleToBox(this.constructor.name, box);
const nextY = addTitleToBox(this.titleName, box);

box.cursor = "pointer";
box.eventMode = "static";
Expand Down Expand Up @@ -83,6 +83,7 @@ export class MCParticle extends EDMObject {
this.color = "#dff6ff";
this.radius = 15;
this.height = 270;
this.titleName = "MCParticle";
}

async draw() {
Expand Down Expand Up @@ -242,10 +243,11 @@ export class MCParticle extends EDMObject {
class ReconstructedParticle extends EDMObject {
constructor() {
super();
this.width = 140;
this.width = 145;
this.height = 190;
this.color = "#fbffdf";
this.radius = 30;
this.titleName = "Reconstructed\nParticle";
}

async draw() {
Expand Down Expand Up @@ -279,6 +281,7 @@ class Cluster extends EDMObject {
this.height = 170;
this.color = "#ffe8df";
this.radius = 20;
this.titleName = "Cluster";
}

async draw() {
Expand Down Expand Up @@ -309,6 +312,7 @@ class Track extends EDMObject {
this.height = 150;
this.color = "#fff6df";
this.radius = 25;
this.titleName = "Track";
}

async draw() {
Expand Down Expand Up @@ -338,6 +342,7 @@ class ParticleID extends EDMObject {
this.height = 140;
this.color = "#c9edf7";
this.radius = 25;
this.titleName = "Particle ID";
}

async draw() {
Expand All @@ -363,6 +368,7 @@ class Vertex extends EDMObject {
this.height = 150;
this.color = "#f5d3ef";
this.radius = 25;
this.titleName = "Vertex";
}

async draw() {
Expand Down

0 comments on commit 89a2012

Please sign in to comment.