Skip to content
Snippets Groups Projects
Select Git revision
  • 55350dc3fc3e01e1c37a70d49e599319dc794ded
  • annotation-on-video default protected
  • demo_ci
  • 3-upstream-01022023
  • master
  • gh3538-captions
  • 16-adapt-for-images-annot
  • 15-api-for-annotations-on-video
  • 15-annotations-on-videos
  • video_for_annotations
  • wip-1-annotations-on-videos
  • 9-videoviewer-tests
  • 9_wip_videotests
  • 6-fix-tests-and-ci
  • _fix_ci
  • wip-webpack-from-git
16 results

AnnotationsOverlayVideo.js

Blame
  • AnnotationsOverlayVideo.js 22.12 KiB
    import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import isEqual from 'lodash/isEqual';
    import debounce from 'lodash/debounce';
    import flatten from 'lodash/flatten';
    import sortBy from 'lodash/sortBy';
    import xor from 'lodash/xor';
    import ResizeObserver from 'react-resize-observer';
    import CircularProgress from '@material-ui/core/CircularProgress';
    import CanvasOverlayVideo from '../lib/CanvasOverlayVideo';
    import CanvasWorld from '../lib/CanvasWorld';
    import CanvasAnnotationDisplay from '../lib/CanvasAnnotationDisplay';
    import { VideosReferences } from '../plugins/VideosReferences';
    
    /** AnnotationsOverlayVideo - based on AnnotationsOverlay */
    export class AnnotationsOverlayVideo extends Component {
      /**
       * annotationsMatch - compares previous annotations to current to determine
       * whether to add a new updateCanvas method to draw annotations
       * @param  {Array} currentAnnotations
       * @param  {Array} prevAnnotations
       * @return {Boolean}
       */
      static annotationsMatch(currentAnnotations, prevAnnotations) {
        if (!currentAnnotations && !prevAnnotations) return true;
        if (
          (currentAnnotations && !prevAnnotations)
          || (!currentAnnotations && prevAnnotations)
        ) return false;
    
        if (currentAnnotations.length === 0 && prevAnnotations.length === 0) return true;
        if (currentAnnotations.length !== prevAnnotations.length) return false;
        return currentAnnotations.every((annotation, index) => {
          const newIds = annotation.resources.map(r => r.id);
          const prevIds = prevAnnotations[index].resources.map(r => r.id);
          if (newIds.length === 0 && prevIds.length === 0) return true;
          if (newIds.length !== prevIds.length) return false;
    
          if ((annotation.id === prevAnnotations[index].id) && (isEqual(newIds, prevIds))) {
            return true;
          }
          return false;
        });
      }
    
      /** @private */
      static isAnnotaionInTemporalSegment(resource, time) {
        const temporalfragment = resource.temporalfragmentSelector;
        if (temporalfragment && temporalfragment.length > 0) {
          const start = temporalfragment[0] || 0;
          const end = (temporalfragment.length > 1) ? temporalfragment[1] : Number.MAX_VALUE;
          if (start <= time && time < end) {
            //
          } else {
            return false;
          }
        }
        return true;
      }
    
      /**
       * @param {Object} props
       */
      constructor(props) {
        super(props);
    
        this.ref = React.createRef();
        VideosReferences.set(props.windowId, this);
        this.canvasOverlay = null;
        // An initial value for the updateCanvas method