annotation-box.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="annotation-box"
  3. :style="style"
  4. :class="{draggable: draggable, shine: shine}"
  5. @mousedown.prevent="click" @touchstart.prevent="click">
  6. <template v-if="draggable">
  7. <div class="nw" @mousedown.prevent.stop="resize('nw')" @touchstart.prevent.stop="resize('nw')"/>
  8. <div class="nn" @mousedown.prevent.stop="resize('nn')" @touchstart.prevent.stop="resize('nn')"/>
  9. <div class="ne" @mousedown.prevent.stop="resize('ne')" @touchstart.prevent.stop="resize('ne')"/>
  10. <div class="ww" @mousedown.prevent.stop="resize('ww')" @touchstart.prevent.stop="resize('ww')"/>
  11. <div class="ee" @mousedown.prevent.stop="resize('ee')" @touchstart.prevent.stop="resize('ee')"/>
  12. <div class="sw" @mousedown.prevent.stop="resize('sw')" @touchstart.prevent.stop="resize('sw')"/>
  13. <div class="ss" @mousedown.prevent.stop="resize('ss')" @touchstart.prevent.stop="resize('ss')"/>
  14. <div class="se" @mousedown.prevent.stop="resize('se')" @touchstart.prevent.stop="resize('se')"/>
  15. </template>
  16. <div v-if="labelName" class="label">
  17. {{ labelName }}
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: "annotation-box",
  24. props: [
  25. 'box',
  26. 'position',
  27. 'draggable',
  28. 'deletable',
  29. 'taggable',
  30. 'confirmable',
  31. 'zoomable',
  32. 'croppable',
  33. 'labels',
  34. 'shine'
  35. ],
  36. computed: {
  37. labelName: function () {
  38. if (!this.box || !this.box.label_id)
  39. return false;
  40. for (let label of this.labels) {
  41. if (label.id === this.box.label_id) {
  42. return label.name;
  43. }
  44. }
  45. return 'unknown';
  46. },
  47. style: function () {
  48. let color = '255, 255, 255';
  49. if (this.box) {
  50. switch (this.box.origin) {
  51. case 'user':
  52. color = '255, 0, 0';
  53. break;
  54. case 'pipeline':
  55. color = '0, 0, 255';
  56. break;
  57. }
  58. }
  59. return {
  60. backgroundColor: `rgba(${color}, 0.3)`,
  61. borderColor: `rgba(${color}, 0.4)`,
  62. top: this.position.y * 100 + '%',
  63. left: this.position.x * 100 + '%',
  64. width: this.position.w * 100 + '%',
  65. height: this.position.h * 100 + '%'
  66. }
  67. }
  68. },
  69. methods: {
  70. click: function (event) {
  71. if (this.deletable) {
  72. // TODO then / error
  73. this.$root.socket.post(`/results/${this.box.id}/remove`, {remove: true});
  74. event.stopPropagation();
  75. }
  76. if (this.draggable) {
  77. // TODO then / error
  78. this.$emit('move', event, this.position, this.update);
  79. event.stopPropagation();
  80. }
  81. if (this.taggable) {
  82. // TODO then / error
  83. this.$root.socket.post(`/results/${this.box.id}/label`, {
  84. label: this.taggable.id
  85. });
  86. event.stopPropagation();
  87. }
  88. if (this.confirmable) {
  89. // TODO then / error
  90. this.$root.socket.post(`/results/${this.box.id}/confirm`, {
  91. confirm: true
  92. });
  93. event.stopPropagation();
  94. }
  95. if (this.zoomable) {
  96. this.$emit('zoom', this.position);
  97. event.stopPropagation();
  98. }
  99. if (this.croppable) {
  100. this.$emit('crop', this);
  101. event.stopPropagation();
  102. }
  103. },
  104. resize: function (mode) {
  105. this.$emit('resize', mode, this.position, this.update);
  106. },
  107. update: function (value) {
  108. this.$root.socket.post(`/results/${this.box.id}/data`, {
  109. data: value
  110. });
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .annotation-box {
  117. position: absolute;
  118. border: 1px solid transparent;
  119. }
  120. .annotation-box.shine {
  121. background: none !important;
  122. border-width: 5px;
  123. }
  124. .label {
  125. position: absolute;
  126. bottom: 0.25rem;
  127. left: 50%;
  128. transform: translateX(-50%);
  129. font-size: 80%;
  130. color: whitesmoke;
  131. text-shadow: 0 0 1px #000000;
  132. }
  133. .nw {
  134. position: absolute;
  135. top: -0.3rem;
  136. left: -0.3rem;
  137. width: 0.6rem;
  138. height: 0.6rem;
  139. cursor: nwse-resize;
  140. /* background-color: blue; */
  141. }
  142. .nn {
  143. position: absolute;
  144. top: -0.3rem;
  145. left: 0.3rem;
  146. right: 0;
  147. height: 0.6rem;
  148. cursor: ns-resize;
  149. /* background-color: orangered; */
  150. }
  151. .ne {
  152. position: absolute;
  153. top: -0.3rem;
  154. right: -0.3rem;
  155. width: 0.6rem;
  156. height: 0.6rem;
  157. cursor: nesw-resize;
  158. /* background-color: cadetblue; */
  159. }
  160. .ww {
  161. position: absolute;
  162. top: 0.3rem;
  163. left: -0.3rem;
  164. width: 0.6rem;
  165. bottom: 0.3rem;
  166. cursor: ew-resize;
  167. /* background-color: fuchsia; */
  168. }
  169. .ee {
  170. position: absolute;
  171. top: 0.3rem;
  172. right: -0.3rem;
  173. width: 0.6rem;
  174. bottom: 0.3rem;
  175. cursor: ew-resize;
  176. /* background-color: midnightblue; */
  177. }
  178. .sw {
  179. position: absolute;
  180. bottom: -0.3rem;
  181. left: -0.3rem;
  182. width: 0.6rem;
  183. height: 0.6rem;
  184. cursor: nesw-resize;
  185. /* background-color: aqua; */
  186. }
  187. .ss {
  188. position: absolute;
  189. bottom: -0.3rem;
  190. left: 0.3rem;
  191. right: 0.3rem;
  192. height: 0.6rem;
  193. cursor: ns-resize;
  194. /* background-color: gold; */
  195. }
  196. .se {
  197. position: absolute;
  198. bottom: -0.3rem;
  199. right: -0.3rem;
  200. width: 0.6rem;
  201. height: 0.6rem;
  202. cursor: nwse-resize;
  203. /* background-color: brown; */
  204. }
  205. </style>