annotation-box.vue 5.0 KB

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