private updateLabel()

in tensorflow_similarity/visualization/projector_v2/views/projector.ts [228:262]


  private updateLabel() {
    const pointIndex = this.hoveredMesh
      ? this.objectToIndex.get(this.hoveredMesh) ?? -1
      : null;
    if (
      !this.containerRect ||
      !this.hoveredMesh ||
      pointIndex == null ||
      !this.camera
    ) {
      updateStyles(this.labelContainer, {display: 'none'});
      return;
    }

    const metadata = this.metadata[pointIndex] || {label: 'Unknown'};
    const target = this.hoveredMesh.position.clone();
    target.project(this.camera);
    const {width, height} = this.containerRect;
    const x = (target.x * width) / 2 + width / 2;
    const y = -((target.y * height) / 2) + height / 2;
    this.labelText.textContent = metadata.label;

    if (metadata.imageLabel) {
      updateStyles(this.labelImg, {
        backgroundImage: `url(${metadata.imageLabel})`,
      });
    }

    updateStyles(this.labelContainer, {
      display: 'block',
      fontSize: '1.5em',
      left: String(x + 5) + 'px',
      top: String(y + 5) + 'px',
    });
  }