"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CircularView = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _VeWarning = require("../helperComponents/VeWarning");

var _VeWarning2 = _interopRequireDefault(_VeWarning);

var _Labels = require("./Labels");

var _Labels2 = _interopRequireDefault(_Labels);

var _SelectionLayer = require("./SelectionLayer");

var _SelectionLayer2 = _interopRequireDefault(_SelectionLayer);

var _Caret = require("./Caret");

var _Caret2 = _interopRequireDefault(_Caret);

var _Axis = require("./Axis");

var _Axis2 = _interopRequireDefault(_Axis);

var _LineageLines = require("./LineageLines");

var _LineageLines2 = _interopRequireDefault(_LineageLines);

var _Orf = require("./Orf");

var _Orf2 = _interopRequireDefault(_Orf);

var _Feature = require("./Feature");

var _Feature2 = _interopRequireDefault(_Feature);

var _Primer = require("./Primer");

var _Primer2 = _interopRequireDefault(_Primer);

var _Cutsite = require("./Cutsite");

var _Cutsite2 = _interopRequireDefault(_Cutsite);

var _sortBy = require("lodash/sortBy");

var _sortBy2 = _interopRequireDefault(_sortBy);

var _PositionAnnotationOnCircle = require("./PositionAnnotationOnCircle");

var _PositionAnnotationOnCircle2 = _interopRequireDefault(_PositionAnnotationOnCircle);

var _getAngleForPositionMidpoint = require("./getAngleForPositionMidpoint");

var _getAngleForPositionMidpoint2 = _interopRequireDefault(_getAngleForPositionMidpoint);

var _veRangeUtils = require("ve-range-utils");

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _reactDraggable = require("react-draggable");

var _reactDraggable2 = _interopRequireDefault(_reactDraggable);

var _withEditorInteractions = require("../withEditorInteractions");

var _withEditorInteractions2 = _interopRequireDefault(_withEditorInteractions);

var _Part = require("./Part");

var _Part2 = _interopRequireDefault(_Part);

var _drawAnnotations = require("./drawAnnotations");

var _drawAnnotations2 = _interopRequireDefault(_drawAnnotations);

require("./style.css");

var _draggableClassnames = require("../constants/draggableClassnames");

var _draggableClassnames2 = _interopRequireDefault(_draggableClassnames);

var _orfFrameToColorMap = require("../constants/orfFrameToColorMap");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// import PassThrough from "../utils/PassThrough";

// import DeletionLayer from "./DeletionLayer";
// import ReplacementLayer from "./ReplacementLayer";


function noop() {}

// function toDegrees(radians) {
//     return radians / 2 / Math.PI * 360
// }

var CircularView = exports.CircularView = function (_React$Component) {
  _inherits(CircularView, _React$Component);

  function CircularView() {
    _classCallCheck(this, CircularView);

    return _possibleConstructorReturn(this, (CircularView.__proto__ || Object.getPrototypeOf(CircularView)).apply(this, arguments));
  }

  _createClass(CircularView, [{
    key: "getNearestCursorPositionToMouseEvent",
    value: function getNearestCursorPositionToMouseEvent(event, sequenceLength, callback) {
      if (!event.clientX) {
        return;
      }
      var boundingRect = this.refs.circularView.getBoundingClientRect();
      //get relative click positions
      var clickX = event.clientX - boundingRect.left - boundingRect.width / 2;
      var clickY = event.clientY - boundingRect.top - boundingRect.height / 2;

      //get angle
      var angle = Math.atan2(clickY, clickX) + Math.PI / 2;
      if (angle < 0) angle += Math.PI * 2; //normalize the angle if necessary
      var nearestCaretPos = (0, _veRangeUtils.normalizePositionByRangeLength)((0, _veRangeUtils.getPositionFromAngle)(angle, sequenceLength, true), sequenceLength); //true because we're in between positions
      if (this.props.sequenceData && this.props.sequenceData.isProtein) {
        nearestCaretPos = Math.round(nearestCaretPos / 3) * 3;
      }
      callback({
        event: event,
        className: event.target.className.animVal,
        shiftHeld: event.shiftKey,
        nearestCaretPos: nearestCaretPos,
        selectionStartGrabbed: event.target.classList.contains(_draggableClassnames2.default.selectionStart),
        selectionEndGrabbed: event.target.classList.contains(_draggableClassnames2.default.selectionEnd)
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _props = this.props,
          _props$width = _props.width,
          width = _props$width === undefined ? 400 : _props$width,
          _props$height = _props.height,
          height = _props$height === undefined ? 400 : _props$height,
          _props$scale = _props.scale,
          scale = _props$scale === undefined ? 1 : _props$scale,
          _props$sequenceData = _props.sequenceData,
          sequenceData = _props$sequenceData === undefined ? {} : _props$sequenceData,
          _props$hideName = _props.hideName,
          hideName = _props$hideName === undefined ? false : _props$hideName,
          editorName = _props.editorName,
          _props$selectionLayer = _props.selectionLayer,
          selectionLayer = _props$selectionLayer === undefined ? { start: -1, end: -1 } : _props$selectionLayer,
          _props$annotationHeig = _props.annotationHeight,
          annotationHeight = _props$annotationHeig === undefined ? 15 : _props$annotationHeig,
          _props$spaceBetweenAn = _props.spaceBetweenAnnotations,
          spaceBetweenAnnotations = _props$spaceBetweenAn === undefined ? 2 : _props$spaceBetweenAn,
          _props$annotationVisi = _props.annotationVisibility,
          annotationVisibility = _props$annotationVisi === undefined ? {} : _props$annotationVisi,
          _props$annotationLabe = _props.annotationLabelVisibility,
          annotationLabelVisibility = _props$annotationLabe === undefined ? {} : _props$annotationLabe,
          _props$caretPosition = _props.caretPosition,
          caretPosition = _props$caretPosition === undefined ? -1 : _props$caretPosition,
          circularAndLinearTickSpacing = _props.circularAndLinearTickSpacing,
          _props$editorDragged = _props.editorDragged,
          editorDragged = _props$editorDragged === undefined ? noop : _props$editorDragged,
          _props$editorDragStar = _props.editorDragStarted,
          editorDragStarted = _props$editorDragStar === undefined ? noop : _props$editorDragStar,
          _props$editorClicked = _props.editorClicked,
          editorClicked = _props$editorClicked === undefined ? noop : _props$editorClicked,
          _props$searchLayers = _props.searchLayers,
          searchLayers = _props$searchLayers === undefined ? [] : _props$searchLayers,
          _props$editorDragStop = _props.editorDragStopped,
          editorDragStopped = _props$editorDragStop === undefined ? noop : _props$editorDragStop,
          _props$featureClicked = _props.featureClicked,
          featureClicked = _props$featureClicked === undefined ? noop : _props$featureClicked,
          _props$featureRightCl = _props.featureRightClicked,
          featureRightClicked = _props$featureRightCl === undefined ? noop : _props$featureRightCl,
          _props$partClicked = _props.partClicked,
          partClicked = _props$partClicked === undefined ? noop : _props$partClicked,
          _props$partRightClick = _props.partRightClicked,
          partRightClicked = _props$partRightClick === undefined ? noop : _props$partRightClick,
          _props$orfClicked = _props.orfClicked,
          orfClicked = _props$orfClicked === undefined ? noop : _props$orfClicked,
          _props$orfRightClicke = _props.orfRightClicked,
          orfRightClicked = _props$orfRightClicke === undefined ? noop : _props$orfRightClicke,
          _props$primerClicked = _props.primerClicked,
          primerClicked = _props$primerClicked === undefined ? noop : _props$primerClicked,
          _props$primerRightCli = _props.primerRightClicked,
          primerRightClicked = _props$primerRightCli === undefined ? noop : _props$primerRightCli,
          _props$selectionLayer2 = _props.selectionLayerRightClicked,
          selectionLayerRightClicked = _props$selectionLayer2 === undefined ? noop : _props$selectionLayer2,
          _props$backgroundRigh = _props.backgroundRightClicked,
          backgroundRightClicked = _props$backgroundRigh === undefined ? noop : _props$backgroundRigh,
          _props$deletionLayerC = _props.deletionLayerClicked,
          deletionLayerClicked = _props$deletionLayerC === undefined ? noop : _props$deletionLayerC,
          _props$replacementLay = _props.replacementLayerClicked,
          replacementLayerClicked = _props$replacementLay === undefined ? noop : _props$replacementLay,
          _props$cutsiteClicked = _props.cutsiteClicked,
          cutsiteClicked = _props$cutsiteClicked === undefined ? noop : _props$cutsiteClicked,
          _props$cutsiteRightCl = _props.cutsiteRightClicked,
          cutsiteRightClicked = _props$cutsiteRightCl === undefined ? noop : _props$cutsiteRightCl,
          _props$featureOptions = _props.featureOptions,
          featureOptions = _props$featureOptions === undefined ? {} : _props$featureOptions,
          _props$additionalSele = _props.additionalSelectionLayers,
          additionalSelectionLayers = _props$additionalSele === undefined ? [] : _props$additionalSele,
          _props$maxAnnotations = _props.maxAnnotationsToDisplay,
          maxAnnotationsToDisplay = _props$maxAnnotations === undefined ? {} : _props$maxAnnotations,
          _props$lineageLines = _props.lineageLines,
          lineageLines = _props$lineageLines === undefined ? [] : _props$lineageLines,
          _props$deletionLayers = _props.deletionLayers,
          deletionLayers = _props$deletionLayers === undefined ? {} : _props$deletionLayers,
          _props$replacementLay2 = _props.replacementLayers,
          replacementLayers = _props$replacementLay2 === undefined ? {} : _props$replacementLay2,
          instantiated = _props.instantiated;
      var _sequenceData$sequenc = sequenceData.sequence,
          sequence = _sequenceData$sequenc === undefined ? "atgc" : _sequenceData$sequenc,
          circular = sequenceData.circular;

      var sequenceLength = sequence.length;
      var sequenceName = hideName ? "" : sequenceData.name || "";
      circularAndLinearTickSpacing = circularAndLinearTickSpacing || (sequenceLength < 10 ? 1 : sequenceLength < 50 ? Math.ceil(sequenceLength / 5) : Math.ceil(sequenceLength / 100) * 10);
      var _annotationVisibility = annotationVisibility.features,
          showFeatures = _annotationVisibility === undefined ? true : _annotationVisibility,
          _annotationVisibility2 = annotationVisibility.primers,
          showPrimers = _annotationVisibility2 === undefined ? true : _annotationVisibility2,
          _annotationVisibility3 = annotationVisibility.parts,
          showParts = _annotationVisibility3 === undefined ? true : _annotationVisibility3,
          _annotationVisibility4 = annotationVisibility.orfs,
          showOrfs = _annotationVisibility4 === undefined ? true : _annotationVisibility4,
          _annotationVisibility5 = annotationVisibility.cutsites,
          showCutsites = _annotationVisibility5 === undefined ? true : _annotationVisibility5,
          _annotationVisibility6 = annotationVisibility.axis,
          showAxis = _annotationVisibility6 === undefined ? true : _annotationVisibility6,
          _annotationVisibility7 = annotationVisibility.lineageLines,
          showLineageLines = _annotationVisibility7 === undefined ? true : _annotationVisibility7,
          _annotationVisibility8 = annotationVisibility.axisNumbers,
          showAxisNumbers = _annotationVisibility8 === undefined ? true : _annotationVisibility8;
      var _annotationLabelVisib = annotationLabelVisibility.features,
          showFeatureLabels = _annotationLabelVisib === undefined ? true : _annotationLabelVisib,
          _annotationLabelVisib2 = annotationLabelVisibility.parts,
          showPartLabels = _annotationLabelVisib2 === undefined ? true : _annotationLabelVisib2,
          _annotationLabelVisib3 = annotationLabelVisibility.cutsites,
          showCutsiteLabels = _annotationLabelVisib3 === undefined ? true : _annotationLabelVisib3,
          _annotationLabelVisib4 = annotationLabelVisibility.primers,
          showPrimerLabels = _annotationLabelVisib4 === undefined ? true : _annotationLabelVisib4;
      var _maxAnnotationsToDisp = maxAnnotationsToDisplay.features,
          maxFeaturesToDisplay = _maxAnnotationsToDisp === undefined ? 50 : _maxAnnotationsToDisp,
          _maxAnnotationsToDisp2 = maxAnnotationsToDisplay.primers,
          maxPrimersToDisplay = _maxAnnotationsToDisp2 === undefined ? 50 : _maxAnnotationsToDisp2,
          _maxAnnotationsToDisp3 = maxAnnotationsToDisplay.parts,
          maxPartsToDisplay = _maxAnnotationsToDisp3 === undefined ? 50 : _maxAnnotationsToDisp3,
          _maxAnnotationsToDisp4 = maxAnnotationsToDisplay.orfs,
          maxOrfsToDisplay = _maxAnnotationsToDisp4 === undefined ? 50 : _maxAnnotationsToDisp4,
          _maxAnnotationsToDisp5 = maxAnnotationsToDisplay.cutsites,
          maxCutsitesToDisplay = _maxAnnotationsToDisp5 === undefined ? 100 : _maxAnnotationsToDisp5;

      var paredDownOrfs = void 0;
      var paredDownCutsites = void 0;
      var paredDownFeatures = void 0;
      var paredDownPrimers = void 0;
      var paredDownParts = void 0;

      var baseRadius = 80;
      var innerRadius = baseRadius - annotationHeight / 2; //tnr: -annotationHeight/2 because features are drawn from the center
      var radius = baseRadius;
      var annotationsSvgs = [];
      var labels = {};

      var isProtein = sequenceData.isProtein;
      //RENDERING CONCEPTS:
      //-"Circular" annotations get a radius, and a curvature based on their radius:
      //<CircularFeature>
      //-Then we rotate the annotations as necessary (and optionally flip them):
      //<PositionAnnotationOnCircle>

      var layersToDraw = [{ layer: drawSequenceChars, zIndex: 10, layerName: "SequenceChars" }, {
        layer: drawFeatures,
        zIndex: 20,
        layerName: "Features",
        // spaceBefore: 10,
        spaceAfter: 5
      }, { layer: drawPrimers, zIndex: 20, layerName: "Primers" }, {
        layer: drawAxis,
        zIndex: 0,
        layerName: "Axis",
        spaceBefore: 0,
        spaceAfter: 0
      }, { layer: drawCaret, zIndex: 15, layerName: "Caret" }, { layer: drawSelectionLayer, zIndex: 10, layerName: "SelectionLayer" }, {
        layer: drawReplacementLayers,
        zIndex: 20,
        layerName: "ReplacementLayers",
        spaceAfter: 20
      }, {
        layer: drawDeletionLayers,
        zIndex: 20,
        layerName: "DeletionLayers",
        spaceAfter: 20
      }, { layer: drawLineageLines, zIndex: 0, layerName: "LineageLines" }, { layer: drawCutsites, zIndex: 10, layerName: "Cutsites" }, { layer: drawOrfs, zIndex: 20, layerName: "Orfs", spaceBefore: 10 }, {
        layer: drawParts,
        zIndex: 20,
        layerName: "Parts",
        spaceBefore: 20
      }, { layer: drawLabels, zIndex: 30, layerName: "Labels" }];

      var output = layersToDraw.map(function (_ref) {
        var layer = _ref.layer,
            _ref$spaceBefore = _ref.spaceBefore,
            spaceBefore = _ref$spaceBefore === undefined ? 0 : _ref$spaceBefore,
            _ref$spaceAfter = _ref.spaceAfter,
            spaceAfter = _ref$spaceAfter === undefined ? 0 : _ref$spaceAfter,
            zIndex = _ref.zIndex;

        //   console.warn('-------------------------------------')
        //   console.warn('layerName:',JSON.stringify(layerName,null,4))
        //   console.warn('radius before draw:',JSON.stringify(radius,null,4))
        radius += spaceBefore;
        var result = layer();
        if (!result) {
          radius -= spaceBefore;
          return null;
        }
        radius += spaceAfter;
        // console.warn('radius after draw:',JSON.stringify(radius,null,4))
        return {
          result: result,
          // layer({
          //   radius,
          //   baseRadius,
          //   innerRadius,
          //   labels,
          //   annotationsSvgs,
          // }),
          zIndex: zIndex
        };
      }).filter(function (i) {
        return !!i;
      });

      annotationsSvgs = (0, _sortBy2.default)(output, "zIndex").reduce(function (arr, _ref2) {
        var result = _ref2.result;

        return arr.concat(result);
      }, []);

      //debug hash marks
      // annotationsSvgs = annotationsSvgs.concat([0,50,100,150,190].map(function (pos) {
      //     return <text key={pos} transform={`translate(0,${-pos})`}>{pos}</text>
      // }))

      function drawFeatures() {
        //DRAW FEATURES
        if (showFeatures && sequenceData.features) {
          var _pareDownAnnotations = pareDownAnnotations(sequenceData.filteredFeatures || sequenceData.features, maxFeaturesToDisplay),
              _pareDownAnnotations2 = _slicedToArray(_pareDownAnnotations, 2),
              annotations = _pareDownAnnotations2[0],
              paredDown = _pareDownAnnotations2[1];

          paredDownFeatures = paredDown;
          var results = (0, _drawAnnotations2.default)(_extends({
            Annotation: _Feature2.default,
            annotationType: "feature",
            radius: radius,
            reverseAnnotations: true,
            showLabels: showFeatureLabels,
            onClick: featureClicked,
            onRightClicked: featureRightClicked,
            annotations: annotations,
            annotationHeight: annotationHeight,
            spaceBetweenAnnotations: spaceBetweenAnnotations,
            sequenceLength: sequenceLength,
            editorName: editorName
          }, featureOptions));
          if (!results) return null;
          //update the radius, labels, and svg
          radius += results.height;
          labels = _extends({}, labels, results.labels);
          return results.component;
        }
      }

      function drawParts() {
        if (showParts && sequenceData.parts) {
          var _pareDownAnnotations3 = pareDownAnnotations(sequenceData.parts, maxPartsToDisplay),
              _pareDownAnnotations4 = _slicedToArray(_pareDownAnnotations3, 2),
              annotations = _pareDownAnnotations4[0],
              paredDown = _pareDownAnnotations4[1];

          paredDownParts = paredDown;

          var results = (0, _drawAnnotations2.default)({
            Annotation: _Part2.default,
            annotationType: "part",
            radius: radius,
            reverseAnnotations: true,
            showLabels: showPartLabels,
            onClick: partClicked,
            onRightClicked: partRightClicked,
            annotations: annotations,
            annotationHeight: annotationHeight,
            spaceBetweenAnnotations: spaceBetweenAnnotations,
            sequenceLength: sequenceLength,
            editorName: editorName
          });
          if (!results) return null;
          //update the radius, labels, and svg
          radius += results.height;
          labels = _extends({}, labels, results.labels);
          return results.component;
        }
      }

      function drawPrimers() {
        //DRAW FEATURES
        if (showPrimers && sequenceData.primers) {
          var _pareDownAnnotations5 = pareDownAnnotations(sequenceData.primers, maxPrimersToDisplay),
              _pareDownAnnotations6 = _slicedToArray(_pareDownAnnotations5, 2),
              annotations = _pareDownAnnotations6[0],
              paredDown = _pareDownAnnotations6[1];

          paredDownPrimers = paredDown;
          var results = (0, _drawAnnotations2.default)({
            Annotation: _Primer2.default,
            annotationType: "primer",
            radius: radius,
            reverseAnnotations: true,
            showLabels: showPrimerLabels,
            onClick: primerClicked,
            onRightClicked: primerRightClicked,
            annotations: annotations,
            annotationHeight: annotationHeight,
            spaceBetweenAnnotations: spaceBetweenAnnotations,
            sequenceLength: sequenceLength,
            editorName: editorName
          });
          if (!results) return null;

          //update the radius, labels, and svg
          radius += results.height;
          labels = _extends({}, labels, results.labels);
          return results.component;
        }
      }

      function drawDeletionLayers() {
        if (!deletionLayers || !deletionLayers.length) return null;
        var results = (0, _drawAnnotations2.default)({
          // Annotation: DeletionLayer,
          annotationType: "deletionLayer",
          radius: radius,
          reverseAnnotations: true,
          onClick: deletionLayerClicked,
          // showLabels: showDeletionLayerLabels,
          // onRightClicked: deletionLayerRightClicked,
          annotations: deletionLayers,
          annotationHeight: annotationHeight,
          spaceBetweenAnnotations: spaceBetweenAnnotations,
          sequenceLength: sequenceLength,
          editorName: editorName
        });
        if (!results) return null;
        //update the radius, labels, and svg
        radius += results.height;
        labels = _extends({}, labels, results.labels);
        return results.component;
      }

      function drawReplacementLayers() {
        if (!replacementLayers || !replacementLayers.length) return null;
        var results = (0, _drawAnnotations2.default)({
          // Annotation: ReplacementLayer,
          annotationType: "replacementLayer",
          radius: radius,
          reverseAnnotations: true,
          // showLabels: showReplacementLayerLabels,
          onClick: replacementLayerClicked,
          // onRightClicked: replacementLayerRightClicked,
          annotations: replacementLayers,
          annotationHeight: annotationHeight,
          spaceBetweenAnnotations: spaceBetweenAnnotations,
          sequenceLength: sequenceLength,
          editorName: editorName
        });
        if (!results) return null;
        //update the radius, labels, and svg
        radius += results.height;
        labels = _extends({}, labels, results.labels);
        return results.component;
      }

      function drawOrfs() {
        //DRAW FEATURES
        if (showOrfs && sequenceData.orfs) {
          var _pareDownAnnotations7 = pareDownAnnotations(sequenceData.orfs, maxOrfsToDisplay),
              _pareDownAnnotations8 = _slicedToArray(_pareDownAnnotations7, 2),
              annotations = _pareDownAnnotations8[0],
              paredDown = _pareDownAnnotations8[1];

          paredDownOrfs = paredDown;
          var results = (0, _drawAnnotations2.default)({
            Annotation: _Orf2.default,
            annotationType: "orf",
            radius: radius,
            getColor: _orfFrameToColorMap.getOrfColor,
            reverseAnnotations: true,
            // showLabels: showOrfLabels,
            onClick: orfClicked,
            onRightClicked: orfRightClicked,
            annotations: annotations,
            annotationHeight: annotationHeight,
            spaceBetweenAnnotations: spaceBetweenAnnotations,
            sequenceLength: sequenceLength,
            editorName: editorName
          });
          if (!results) return null;

          //update the radius, labels, and svg
          radius += results.height;
          labels = _extends({}, labels, results.labels);
          return results.component;
        }
      }

      function drawSequenceChars() {
        //DRAW CHARS (only if there are fewer than 85 of them)
        if (sequenceLength < 85 && sequenceData.sequence && !sequenceData.noSequence) {
          radius += 25;
          sequenceData.sequence.split("").forEach(function (bp, index) {
            var tickAngle = (0, _getAngleForPositionMidpoint2.default)(index, sequenceLength);
            return _react2.default.createElement(
              "text",
              _extends({}, (0, _PositionAnnotationOnCircle2.default)({
                sAngle: tickAngle,
                eAngle: tickAngle,
                height: radius
              }), {
                key: index,
                transform: "rotate(180)",
                style: {
                  textAnchor: "middle",
                  dominantBaseline: "central",
                  fontSize: "small"
                }
              }),
              bp
            );
          });
        }
      }

      function drawAxis() {
        if (showAxis) {
          var axisResult = (0, _Axis2.default)({
            isProtein: isProtein,
            showAxisNumbers: showAxisNumbers,
            radius: radius,
            sequenceLength: sequenceLength,
            circularAndLinearTickSpacing: circularAndLinearTickSpacing
          });
          //update the radius, and svg
          radius += axisResult.height;
          return axisResult.component;
        }
      }

      function drawLineageLines() {
        if (showLineageLines && lineageLines && lineageLines.length) {
          var results = (0, _LineageLines2.default)({
            radius: radius,
            sequenceLength: sequenceLength,
            annotationHeight: 6,
            editorName: editorName,
            lineageLines: lineageLines
            // lineageLines: [{start: 10, end:2000,},{start: 201, end:9,}],
          });
          if (!results) return null;
          //update the radius, and svg
          radius += results.height;
          return results.component;
        }
      }

      function drawCutsites() {
        //DRAW CUTSITES
        if (showCutsites && sequenceData.cutsites) {
          var _pareDownAnnotations9 = pareDownAnnotations(sequenceData.cutsites, maxCutsitesToDisplay),
              _pareDownAnnotations10 = _slicedToArray(_pareDownAnnotations9, 2),
              annotations = _pareDownAnnotations10[0],
              paredDown = _pareDownAnnotations10[1];

          paredDownCutsites = paredDown;
          var results = (0, _drawAnnotations2.default)({
            Annotation: _Cutsite2.default,
            useStartAngle: true,
            annotationType: "cutsite",
            radius: radius,
            allOnSameLevel: true,
            positionBy: positionCutsites,
            showLabels: showCutsiteLabels,
            onClick: cutsiteClicked,
            onRightClicked: cutsiteRightClicked,
            annotations: annotations,
            annotationHeight: annotationHeight,
            spaceBetweenAnnotations: spaceBetweenAnnotations,
            sequenceLength: sequenceLength,
            editorName: editorName
          });
          if (!results) return null;
          //update the radius, labels, and svg
          radius += results.height;
          labels = _extends({}, labels, results.labels);
          return results.component;
        }
      }

      function drawSelectionLayer() {
        //DRAW SELECTION LAYER
        var selectionLayers = [].concat(_toConsumableArray(additionalSelectionLayers), _toConsumableArray(searchLayers), _toConsumableArray(Array.isArray(selectionLayer) ? selectionLayer : [selectionLayer]));
        return selectionLayers.map(function (selectionLayer, index) {
          if (selectionLayer.start >= 0 && selectionLayer.end >= 0 && sequenceLength > 0) {
            return _react2.default.createElement(_SelectionLayer2.default, {
              index: index,
              isDraggable: true,
              isProtein: isProtein,
              key: "veCircularViewSelectionLayer" + index,
              selectionLayer: selectionLayer,
              selectionLayerRightClicked: selectionLayerRightClicked,
              sequenceLength: sequenceLength,
              baseRadius: baseRadius,
              radius: radius,
              innerRadius: innerRadius
            });
          } else {
            return null;
          }
        }).filter(function (el) {
          return !!el;
        });
      }

      function drawCaret() {
        //DRAW CARET
        if (caretPosition !== -1 && selectionLayer.start < 0 && sequenceLength > 0) {
          //only render if there is no selection layer
          return _react2.default.createElement(_Caret2.default, {
            caretPosition: caretPosition,
            sequenceLength: sequenceLength,
            isProtein: isProtein,
            innerRadius: innerRadius,
            outerRadius: radius,
            key: "veCircularViewCaret"
          });
        }
      }
      function drawLabels() {
        var results = (0, _Labels2.default)({
          editorName: editorName,
          circularViewWidthVsHeightRatio: width / height,
          labels: labels,
          outerRadius: radius
        });
        if (!results) return null;
        radius += results.height;
        return results.component;
      }
      //tnr: Make the radius have a minimum so the empty yellow axis circle doesn't take up the entire screen
      if (radius < 150) radius = 150;
      var widthToUse = Math.max(Number(width) || 300);
      var heightToUse = Math.max(Number(height) || 300);
      return _react2.default.createElement(
        "div",
        {
          style: {
            width: widthToUse,
            height: heightToUse
          },
          tabIndex: "0",
          className: "veCircularView"
        },
        _react2.default.createElement(
          _reactDraggable2.default
          // enableUserSelectHack={false} //needed to prevent the input bubble from losing focus post user drag
          ,
          { bounds: { top: 0, left: 0, right: 0, bottom: 0 },
            onDrag: function onDrag(event) {
              _this2.getNearestCursorPositionToMouseEvent(event, sequenceLength, editorDragged);
            },
            onStart: function onStart(event) {
              _this2.getNearestCursorPositionToMouseEvent(event, sequenceLength, editorDragStarted);
            },
            onStop: editorDragStopped
          },
          _react2.default.createElement(
            "div",
            null,
            !hideName && _react2.default.createElement(
              "div",
              {
                style: {
                  position: "absolute",
                  width: "100%",
                  height: "100%",
                  pointerEvents: "none"
                }
              },
              _react2.default.createElement(
                "div",
                {
                  key: "circViewSvgCenterText",
                  className: "veCircularViewMiddleOfVectorText",
                  style: { width: innerRadius, textAlign: "center" }
                },
                _react2.default.createElement(
                  "span",
                  null,
                  sequenceName,
                  " "
                ),
                _react2.default.createElement("br", null),
                _react2.default.createElement(
                  "span",
                  { style: { fontSize: 10 } },
                  isProtein ? Math.floor(sequenceLength / 3) + " AAs" : sequenceLength + " bps"
                )
              )
            ),
            _react2.default.createElement(
              "svg",
              {
                key: "circViewSvg",
                onClick: function onClick(event) {
                  instantiated && _this2.getNearestCursorPositionToMouseEvent(event, sequenceLength, editorClicked);
                },
                onContextMenu: function onContextMenu(e) {
                  _this2.getNearestCursorPositionToMouseEvent(e, sequenceLength, backgroundRightClicked);
                },
                style: { overflow: "visible", display: "block" },
                width: widthToUse,
                height: heightToUse,
                ref: "circularView",
                className: "circularViewSvg",
                viewBox: "-" + radius * scale + " -" + radius * scale + " " + radius * 2 * scale + " " + radius * 2 * scale
              },
              annotationsSvgs
            ),
            _react2.default.createElement(
              "div",
              { className: "veCircularViewWarningContainer" },
              !circular && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-circular-to-linear",
                intent: "warning",
                tooltip: "Warning! You're viewing a linear sequence in the Circular Map. Click on 'Linear Map' to view the linear sequence in a more intuitive way."
              }),
              paredDownOrfs && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-maxOrfsToDisplay",
                tooltip: "Warning: More than " + maxOrfsToDisplay + " Open Reading Frames. Displaying only the largest " + maxOrfsToDisplay
              }),
              paredDownCutsites && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-maxCutsitesToDisplay",
                tooltip: "Only the first " + maxCutsitesToDisplay + " cut sites will be displayed. Filter the display by cut site by selecting your desired Restriction Enzyme type "
              }),
              paredDownFeatures && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-maxFeaturesToDisplay",
                tooltip: "Warning: More than " + maxFeaturesToDisplay + " Features. Displaying only the largest " + maxFeaturesToDisplay
              }),
              paredDownParts && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-maxPartsToDisplay",
                tooltip: "Warning: More than " + maxPartsToDisplay + " Parts. Displaying only the largest " + maxPartsToDisplay
              }),
              paredDownPrimers && _react2.default.createElement(_VeWarning2.default, {
                "data-test": "ve-warning-maxPrimersToDisplay",
                tooltip: "Warning: More than " + maxPrimersToDisplay + " Primers. Displaying only the largest " + maxPrimersToDisplay
              })
            )
          )
        )
      );
    }
  }]);

  return CircularView;
}(_react2.default.Component);

function pareDownAnnotations(annotations, max) {
  var annotationsToPass = annotations;
  var paredDown = false;
  if (Object.keys(annotations).length > max) {
    paredDown = true;
    var sortedAnnotations = (0, _sortBy2.default)(annotations, function (annotation) {
      return -(0, _veRangeUtils.getRangeLength)(annotation);
    });
    annotationsToPass = sortedAnnotations.slice(0, max).reduce(function (obj, item) {
      obj[item.id] = item;
      return obj;
    }, {});
  }
  return [annotationsToPass, paredDown];
}

// function (messages) {
//   messages.forEach(function ([displayMessage, message]) {
//     displayMessage &&
//   })
// }

exports.default = (0, _withEditorInteractions2.default)(CircularView);


function positionCutsites(annotation) {
  return {
    start: annotation.topSnipPosition,
    end: annotation.topSnipPosition
  };
}