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. if (!this.box || !this.box.label)
  39. return false;
  40. for (let label of this.labels) {
  41. if (label.identifier === this.box.label) {
  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}, ${this.shine ? 0.6 : 0.3})`,
  61. borderColor: `rgba(${color}, ${this.shine ? 0.8 : 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.identifier}/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.identifier}/label`, {
  84. label: this.taggable.identifier
  85. });
  86. event.stopPropagation();
  87. }
  88. if (this.confirmable) {
  89. // TODO then / error
  90. this.$root.socket.post(`/results/${this.box.identifier}/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.box);
  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.identifier}/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. .label {
  121. position: absolute;
  122. bottom: 0.25rem;
  123. left: 50%;
  124. transform: translateX(-50%);
  125. font-size: 80%;
  126. color: whitesmoke;
  127. text-shadow: 0 0 1px #000000;
  128. }
  129. .nw {
  130. position: absolute;
  131. top: -0.3rem;
  132. left: -0.3rem;
  133. width: 0.6rem;
  134. height: 0.6rem;
  135. cursor: nwse-resize;
  136. /* background-color: blue; */
  137. }
  138. .nn {
  139. position: absolute;
  140. top: -0.3rem;
  141. left: 0.3rem;
  142. right: 0;
  143. height: 0.6rem;
  144. cursor: ns-resize;
  145. /* background-color: orangered; */
  146. }
  147. .ne {
  148. position: absolute;
  149. top: -0.3rem;
  150. right: -0.3rem;
  151. width: 0.6rem;
  152. height: 0.6rem;
  153. cursor: nesw-resize;
  154. /* background-color: cadetblue; */
  155. }
  156. .ww {
  157. position: absolute;
  158. top: 0.3rem;
  159. left: -0.3rem;
  160. width: 0.6rem;
  161. bottom: 0.3rem;
  162. cursor: ew-resize;
  163. /* background-color: fuchsia; */
  164. }
  165. .ee {
  166. position: absolute;
  167. top: 0.3rem;
  168. right: -0.3rem;
  169. width: 0.6rem;
  170. bottom: 0.3rem;
  171. cursor: ew-resize;
  172. /* background-color: midnightblue; */
  173. }
  174. .sw {
  175. position: absolute;
  176. bottom: -0.3rem;
  177. left: -0.3rem;
  178. width: 0.6rem;
  179. height: 0.6rem;
  180. cursor: nesw-resize;
  181. /* background-color: aqua; */
  182. }
  183. .ss {
  184. position: absolute;
  185. bottom: -0.3rem;
  186. left: 0.3rem;
  187. right: 0.3rem;
  188. height: 0.6rem;
  189. cursor: ns-resize;
  190. /* background-color: gold; */
  191. }
  192. .se {
  193. position: absolute;
  194. bottom: -0.3rem;
  195. right: -0.3rem;
  196. width: 0.6rem;
  197. height: 0.6rem;
  198. cursor: nwse-resize;
  199. /* background-color: brown; */
  200. }
  201. </style>