How to use the ve-range-utils.getRangeLength function in ve-range-utils

To help you get started, we’ve selected a few ve-range-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TeselaGen / openVectorEditor / src / withEditorInteractions / clickAndDragUtils.js View on Github external
start: caretPosition,
    end: normalizePositionByRangeLength(
      nearestCaretPos - 1,
      sequenceLength,
      true
    )
  };
  let dragStart = {
    start: nearestCaretPos,
    end: normalizePositionByRangeLength(caretPosition - 1, sequenceLength, true)
  };
  if (caretPosition === nearestCaretPos) {
    return; // do nothing because nearestCaretPos === caretPosition
  } else if (
    getRangeLength(dragEnd, sequenceLength) <
    getRangeLength(dragStart, sequenceLength)
  ) {
    draggingEnd = true; //the caret becomes the "selection end"
    selectionLayerUpdate(dragEnd);
    caretPositionOnDragStart = null;
  } else {
    draggingEnd = false; //the caret becomes the "selection end"
    selectionLayerUpdate(dragStart);
    caretPositionOnDragStart = null;
  }
}
export function handleCaretDrag({
github TeselaGen / openVectorEditor / src / utils / editorUtils.js View on Github external
export function getSelectionMessage({
  caretPosition = -1,
  selectionLayer = { start: -1, end: -1 },
  customTitle,
  sequenceLength,
  sequenceData,
  showGCContent,
  GCDecimalDigits,
  isProtein
}) {
  let isSelecting = selectionLayer.start > -1;
  if (isSelecting) {
    let length = getRangeLength(selectionLayer, sequenceLength);
    const GCContent = (numDecimalDigits = 0) =>
      calculatePercentGC(
        getSequenceDataBetweenRange(sequenceData, selectionLayer).sequence
      ).toFixed(numDecimalDigits);
    const seqLen = divideBy3(length, isProtein);
    return `${customTitle || "Selecting"} ${seqLen} ${(isProtein
      ? "AA"
      : "bp") + (seqLen === 1 ? "" : "s")} from ${divideBy3(
      selectionLayer.start,
      isProtein
    ) + 1} to ${divideBy3(selectionLayer.end + 1, isProtein)}${
      showGCContent && !isProtein ? ` (${GCContent(GCDecimalDigits)}% GC)` : ""
    }`;
  } else if (caretPosition > -1) {
    let insertBetween = getInsertBetweenVals(
      caretPosition,
github TeselaGen / openVectorEditor / src / helperComponents / PropertiesDialog / FeatureProperties.js View on Github external
const featuresToUse = map(features, feature => {
      return {
        ...feature,
        ...(feature.strand === undefined && {
          strand: feature.forward ? 1 : -1
        }),
        size: getRangeLength(feature, sequenceLength)
      };
    });
    return (
github TeselaGen / openVectorEditor / src / helperComponents / PropertiesDialog / OrfProperties.js View on Github external
const orfsToUse = map(orfs, orf => {
      return {
        ...orf,
        color: getOrfColor(orf),
        frame: orf.frame + 1,
        ...(orf.strand === undefined && {
          strand: orf.forward ? 1 : -1
        }),
        size: getRangeLength(orf, sequenceLength),
        sizeAa: Math.floor(getRangeLength(orf, sequenceLength) / 3)
      };
    });
    return (
github TeselaGen / openVectorEditor / src / withEditorProps / index.js View on Github external
export const handleInverse = props => () => {
  const {
    sequenceLength,
    selectionLayer,
    caretPosition,
    selectionLayerUpdate,
    caretPositionUpdate
  } = props;

  if (sequenceLength <= 0) {
    return false;
  }
  if (selectionLayer.start > -1) {
    if (getRangeLength(selectionLayer, sequenceLength) === sequenceLength) {
      caretPositionUpdate(selectionLayer.start);
    } else {
      selectionLayerUpdate(invertRange(selectionLayer, sequenceLength));
    }
  } else {
    if (caretPosition > -1) {
      selectionLayerUpdate(
        normalizeRange(
          {
            start: caretPosition,
            end: caretPosition - 1
          },
          sequenceLength
        )
      );
    } else {
github TeselaGen / openVectorEditor / src / withEditorInteractions / clickAndDragUtils.js View on Github external
function getMinRangeLength(start, end, sequenceLength) {
  let range1 = getRangeLength({ start, end }, sequenceLength);
  let range2 = getRangeLength({ start: end, end: start }, sequenceLength);
  return range1 < range2 ? range1 : range2;
}
github TeselaGen / openVectorEditor / src / utils / selectionAndCaretUtils / updateSelectionOrCaret.js View on Github external
function getMinRangeLength(start, end, sequenceLength) {
  let range1 = getRangeLength({ start, end }, sequenceLength);
  let range2 = getRangeLength({ start: end, end: start }, sequenceLength);
  return range1 < range2 ? range1 : range2;
}
github TeselaGen / openVectorEditor / src / withEditorInteractions / clickAndDragUtils.js View on Github external
selectionLayer
        );

        let { newRange: range1 } = expandOrContractRangeToPosition(
          selectionLayer,
          newRange.start,
          sequenceLength
        );
        let { newRange: range2 } = expandOrContractRangeToPosition(
          selectionLayer,
          newRange.end + 1,
          sequenceLength
        ); //+1 to go from range end to position
        let range1Shorter =
          getRangeLength(range1, sequenceLength) <
          getRangeLength(range2, sequenceLength);

        if (newRangeFullyContained) {
          range1Shorter
            ? selectionLayerUpdate(range1)
            : selectionLayerUpdate(range2);
        } else {
          selectionLayerUpdate({
            start: selectionLayer.start,
            end: newRange.end
          });
        }
      }
    } else {
      //no caret, no selection, so just do a simple update
      simpleUpdate();
    }