Skip to content

Commit 717a2c4

Browse files
committed
show label with Bbox in annotator page
1 parent 24731c6 commit 717a2c4

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

annotator/static/views/rect.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ class Rect {
7272
// Raphel rect element
7373
this.$el = null;
7474

75+
// lock unlock feature
7576
this.locked = false;
7677
this.$lock_el = null;
7778
this.lock_el = null;
7879
this.lock_offset = 0;
7980

81+
//display label over rect
82+
this.$label_el = null;
83+
this.label_el = null;
84+
this.label_offset = 0;
85+
86+
this.$label_background_el = null;
87+
this.label_background_el = null;
88+
8089
// jQuer rect element
8190
this.el = null;
8291

@@ -116,9 +125,9 @@ class Rect {
116125
this.$el = this.$paper.rect(0, 0, this.$paper.width, this.$paper.height);
117126
this.el = this.$el.node;
118127
$(this.el).attr("id", this.$el.id);
119-
128+
120129
var {scale} = this.getPlayerMetrics();
121-
130+
122131
this.$lock_el = this.$paper.text(this.$paper.width/2, this.$paper.height/2, '\uf023')
123132
this.lock_el = this.$lock_el.node;
124133
$(this.lock_el).removeAttr('style');
@@ -130,6 +139,21 @@ class Rect {
130139
$(this.lock_el).addClass('fas');
131140
$(this.lock_el).css({visibility: "hidden"});
132141

142+
this.$label_el = this.$paper.text(this.$paper.width/2, this.$paper.height/2,"");
143+
this.label_el = this.$label_el.node;
144+
$(this.label_el).removeAttr('style');
145+
this.$label_el.attr({
146+
fill: "white",
147+
"font-size": 15/scale,
148+
});
149+
this.label_offset = 8/scale;
150+
$(this.label_el).css({visibility: "hidden"});
151+
152+
this.$label_background_el = this.$paper.rect(0, 0, 0, 0);
153+
this.label_background_el = this.$label_background_el.node;
154+
$(this.label_background_el).removeAttr('style');
155+
$(this.label_background_el).css({visibility: "hidden"});
156+
133157
//container
134158
this.applyPreAttachedAppearance();
135159
this.setHandlers();
@@ -161,13 +185,19 @@ class Rect {
161185

162186
appear({real, selected, singlekeyframe}) {
163187
this.setClassNameExts({real, selected, singlekeyframe});
164-
188+
165189
if (real) {
190+
this.$label_el.attr('text', this._title);
191+
$(this.label_el).css({visibility: "visible"});
192+
$(this.label_background_el).css({visibility: "visible"});
193+
this.$label_el.toFront();
166194
if (this.locked) {
167195
$(this.lock_el).css({visibility: "visible"});
168196
}
169197
} else {
170198
$(this.lock_el).css({visibility: "hidden"});
199+
$(this.label_el).css({visibility: "hidden"});
200+
$(this.label_background_el).css({visibility: "hidden"});
171201
}
172202

173203
if (selected === true) {
@@ -288,10 +318,21 @@ class Rect {
288318
}
289319
else {
290320
this.$el.attr(Bounds.toAttrs(bounds));
291-
this.$lock_el.attr({x: bounds.xMin + this.lock_offset,
321+
this.$lock_el.attr({x: bounds.xMin + this.lock_offset,
292322
y: bounds.yMin + this.lock_offset});
293-
}
323+
this.$label_el.attr({x: (bounds.xMax - (bounds.xMax - bounds.xMin)/2) ,
324+
y: bounds.yMax + this.label_offset});
325+
var box = this.$label_el.getBBox();
326+
this.$label_background_el.attr({
327+
x: box.x,
328+
y: box.y,
329+
width: box.width,
330+
height: box.height,
331+
fill: '#337ab7',
332+
stroke: '#337ab7'
294333

334+
});
335+
}
295336
this._bounds = bounds;
296337

297338
// Trigger event

0 commit comments

Comments
 (0)