UNPKG

lost-sia

Version:

Single Image Annotation Tool

2 lines (1 loc) 1.14 kB
import{jsx as s,jsxs as h}from"react/jsx-runtime";import{useState as D,useEffect as g}from"react";import{List as d,Label as c}from"semantic-ui-react";import C from"./InfoBox.js";import{getDefaultColor as x}from"../utils/colorlut.js";const w=t=>{const[r,a]=D([]);g(()=>{a([])},[t.imgLoadCount]);const f=()=>{t.onDismiss&&t.onDismiss()},u=e=>{let n=!1;r.includes(e.id)?(a(r.filter(i=>i!==e.id)),n=!1):(a([...r,e.id]),n=!0),t.onHideLbl&&t.onHideLbl(e,n)},m=e=>{const n=r.includes(e.id)?.5:1;return s(d.Item,{children:s(d.Content,{children:h(c,{as:"a",tag:!0,style:{background:e.color,opacity:n},onClick:()=>u(e),children:[e.label,s(c.Detail,{children:e.amount})]})})},e.id)},b=()=>{let e={};return t.annos.forEach(i=>{i.status!=="deleted"&&(i.labelIds.forEach(o=>{o in e?e[o]+=1:e[o]=1}),i.labelIds.length===0&&(-1 in e?e[-1]+=1:e[-1]=1))}),Object.entries(e).map(([i,o])=>{let l=t.possibleLabels.find(L=>L.id===parseInt(i));return l||(l={id:-1,label:"No Label",color:x()}),l.amount=o,m(l)})};return s(C,{header:"Annotations per Label",content:s(d,{children:b()}),visible:t.visible,defaultPos:t.defaultPos,onDismiss:e=>f()})};export{w as default};