Skip to content
Snippets Groups Projects
Select Git revision
  • d57054a0d0895fea48ee8879ab150ed57611e19c
  • main default protected
  • export
  • 28-conversion-tests
  • extraction
  • exploration
  • exploration-old
  • 2-encoding-fix
  • main-old
9 results

common.py

Blame
  • AnnotationsOverlayVideo.js 20.42 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';
    
    /** 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();
        this.canvasOverlay = null;
        // An initial value for the updateCanvas method
        this.updateCanvas = () => {};
        this.onCanvasClick = this.onCanvasClick.bind(this);