Skip to content

Commit

Permalink
Merge pull request nexus-js#124 from starfishmod/master
Browse files Browse the repository at this point in the history
Added restrictions to Envelope
  • Loading branch information
taylorbf authored Dec 14, 2018
2 parents f15872d + 367ee78 commit c9f3239
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/interfaces/envelope.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ let Point = function(point,envelope) {

this.x = point.x;
this.y = point.y;

this.xMin = point.xMin || 0;
this.xMax = point.xMax || 1;
this.yMin = point.yMin || 0;
this.yMax = point.yMax || 1;

this.envelope = envelope;

this.element = svg.create('circle');
Expand All @@ -35,10 +41,16 @@ let Point = function(point,envelope) {
let nextNode = this.envelope.nodes[nextIndex];

let lowX = prevIndex >= 0 ? prevNode.x : 0;
lowX = lowX<this.xMin?this.xMin:lowX;

let highX = nextIndex < this.envelope.nodes.length ? nextNode.x : 1;

if (this.x < lowX) { this.x = lowX; }
highX = highX>this.xMax?this.xMax:highX;

if (this.x < lowX) { this.x = lowX; }
if (this.x > highX) { this.x = highX; }

if (this.y < this.yMin) { this.x = this.yMin; }
if (this.y > this.yMax) { this.x = this.yMax; }

}

Expand Down Expand Up @@ -79,6 +91,7 @@ let Point = function(point,envelope) {
* @example
* var envelope = new Nexus.Envelope('#target',{
* 'size': [300,150],
* 'noNewPoints': false,
* 'points': [
* {
* x: 0.1,
Expand Down Expand Up @@ -119,6 +132,7 @@ export default class Envelope extends Interface {

let defaults = {
'size': [300,150],
'noNewPoints':false,
'points': [
{
x: 0.1,
Expand Down Expand Up @@ -306,7 +320,7 @@ export default class Envelope extends Interface {
}

// if not very close to any node, create a node
if (nearestDist>0.07) {
if (!this.settings.noNewPoints && nearestDist>0.07) {

nearestIndex = this.getIndexFromX(this.mouse.x/this.width);

Expand Down

0 comments on commit c9f3239

Please sign in to comment.