|
@@ -128,50 +128,75 @@ Vector2.prototype.add = function(v)
|
|
|
this.y += v.y;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Add a scalar value to booth vector components.
|
|
|
+ *
|
|
|
+ * @param {number} s
|
|
|
+ */
|
|
|
Vector2.prototype.addScalar = function(s)
|
|
|
{
|
|
|
this.x += s;
|
|
|
this.y += s;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Add two vectors and store the result in this vector.
|
|
|
+ *
|
|
|
+ * @param {Vector2} a
|
|
|
+ * @param {Vector2} b
|
|
|
+ */
|
|
|
Vector2.prototype.addVectors = function(a, b)
|
|
|
{
|
|
|
this.x = a.x + b.x;
|
|
|
this.y = a.y + b.y;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Scale a vector components and add the result to this vector.
|
|
|
+ *
|
|
|
+ * @param {Vector2} v
|
|
|
+ * @param {number} s
|
|
|
+ */
|
|
|
Vector2.prototype.addScaledVector = function(v, s)
|
|
|
{
|
|
|
this.x += v.x * s;
|
|
|
this.y += v.y * s;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Subtract the content of another vector to this one.
|
|
|
*
|
|
|
* @param {Vector2} v
|
|
|
*/
|
|
|
-
|
|
|
Vector2.prototype.sub = function(v)
|
|
|
{
|
|
|
this.x -= v.x;
|
|
|
this.y -= v.y;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Subtract a scalar value to booth vector components.
|
|
|
+ *
|
|
|
+ * @param {number} s
|
|
|
+ */
|
|
|
Vector2.prototype.subScalar = function(s)
|
|
|
{
|
|
|
this.x -= s;
|
|
|
this.y -= s;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Subtract two vectors and store the result in this vector.
|
|
|
+ *
|
|
|
+ * @param {Vector2} a
|
|
|
+ * @param {Vector2} b
|
|
|
+ */
|
|
|
Vector2.prototype.subVectors = function(a, b)
|
|
|
{
|
|
|
this.x = a.x - b.x;
|
|
|
this.y = a.y - b.y;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Multiply the content of another vector to this one.
|
|
|
*
|
|
@@ -183,6 +208,11 @@ Vector2.prototype.multiply = function(v)
|
|
|
this.y *= v.y;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Multiply a scalar value by booth vector components.
|
|
|
+ *
|
|
|
+ * @param {number} s
|
|
|
+ */
|
|
|
Vector2.prototype.multiplyScalar = function(scalar)
|
|
|
{
|
|
|
this.x *= scalar;
|
|
@@ -201,6 +231,11 @@ Vector2.prototype.divide = function(v)
|
|
|
this.y /= v.y;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Divide a scalar value by booth vector components.
|
|
|
+ *
|
|
|
+ * @param {number} s
|
|
|
+ */
|
|
|
Vector2.prototype.divideScalar = function(scalar)
|
|
|
{
|
|
|
return this.multiplyScalar(1 / scalar);
|
|
@@ -373,6 +408,12 @@ Vector2.prototype.equals = function(v)
|
|
|
return ((v.x === this.x) && (v.y === this.y));
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Set vector value from array with a offset.
|
|
|
+ *
|
|
|
+ * @param {array} array
|
|
|
+ * @param {number} [offset]
|
|
|
+ */
|
|
|
Vector2.prototype.fromArray = function(array, offset)
|
|
|
{
|
|
|
if(offset === undefined) offset = 0;
|
|
@@ -381,6 +422,12 @@ Vector2.prototype.fromArray = function(array, offset)
|
|
|
this.y = array[offset + 1];
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Convert this vector to an array.
|
|
|
+ *
|
|
|
+ * @param {array} array
|
|
|
+ * @param {number} [offset]
|
|
|
+ */
|
|
|
Vector2.prototype.toArray = function(array, offset)
|
|
|
{
|
|
|
if(array === undefined) array = [];
|
|
@@ -971,7 +1018,11 @@ Object2D.prototype.onPointerOver = null;
|
|
|
/**
|
|
|
* Callback method while the object is being dragged across the screen.
|
|
|
*
|
|
|
- * Receives (pointer, viewport, delta) as arguments. Delta is the movement of the pointer already translated into local object coordinates.
|
|
|
+ * By default is adds the delta value to the object position (making it follow the mouse movement).
|
|
|
+ *
|
|
|
+ * Delta is the movement of the pointer already translated into local object coordinates.
|
|
|
+ *
|
|
|
+ * Receives (pointer, viewport, delta) as arguments.
|
|
|
*/
|
|
|
Object2D.prototype.onPointerDrag = function(pointer, viewport, delta)
|
|
|
{
|
|
@@ -2208,6 +2259,11 @@ function Circle()
|
|
|
*/
|
|
|
this.strokeStyle = "#000000";
|
|
|
|
|
|
+ /**
|
|
|
+ * Line width.
|
|
|
+ */
|
|
|
+ this.lineWidth = 1;
|
|
|
+
|
|
|
/**
|
|
|
* Background color of the circle.
|
|
|
*/
|
|
@@ -2239,7 +2295,7 @@ Circle.prototype.draw = function(context, viewport, canvas)
|
|
|
context.fillStyle = this.fillStyle;
|
|
|
context.fill();
|
|
|
|
|
|
- context.lineWidth = 1;
|
|
|
+ context.lineWidth = this.lineWidth;
|
|
|
context.strokeStyle = this.strokeStyle;
|
|
|
context.stroke();
|
|
|
};
|
|
@@ -2371,6 +2427,11 @@ function Box()
|
|
|
*/
|
|
|
this.strokeStyle = "#000000";
|
|
|
|
|
|
+ /**
|
|
|
+ * Line width.
|
|
|
+ */
|
|
|
+ this.lineWidth = 1;
|
|
|
+
|
|
|
/**
|
|
|
* Background color of the box.
|
|
|
*/
|
|
@@ -2402,7 +2463,7 @@ Box.prototype.draw = function(context, viewport, canvas)
|
|
|
context.fillStyle = this.fillStyle;
|
|
|
context.fillRect(this.box.min.x, this.box.min.y, width, height);
|
|
|
|
|
|
- context.lineWidth = 1;
|
|
|
+ context.lineWidth = this.lineWidth;
|
|
|
context.strokeStyle = this.strokeStyle;
|
|
|
context.strokeRect(this.box.min.x, this.box.min.y, width, height);
|
|
|
};
|
|
@@ -2699,4 +2760,96 @@ Pattern.prototype.draw = function(context, viewport, canvas)
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-export { Box, Box2, BoxMask, Circle, DOM, EventManager, Helpers, Image, Key, Line, Mask, Matrix, Object2D, Pattern, Pointer, Renderer, Text, UUID, Vector2, Viewport };
|
|
|
+/**
|
|
|
+ * Graph object is used to draw simple graph data into the canvas.
|
|
|
+ *
|
|
|
+ * Graph data is composed of X, Y values.
|
|
|
+ *
|
|
|
+ * @class
|
|
|
+ */
|
|
|
+function Graph()
|
|
|
+{
|
|
|
+ Object2D.call(this);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Graph object containing the size of the object.
|
|
|
+ */
|
|
|
+ this.box = new Box2(new Vector2(-50, -35), new Vector2(50, 35));
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Color of the box border line.
|
|
|
+ */
|
|
|
+ this.strokeStyle = "rgb(0, 153, 255)";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Line width.
|
|
|
+ */
|
|
|
+ this.lineWidth = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Background color of the box.
|
|
|
+ */
|
|
|
+ this.fillStyle = "rgba(0, 153, 255, 0.3)";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Minimum value of the graph.
|
|
|
+ */
|
|
|
+ this.min = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Maximum value of the graph.
|
|
|
+ */
|
|
|
+ this.max = 10;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Data to be presented in the graph.
|
|
|
+ *
|
|
|
+ * The array should store numeric values.
|
|
|
+ */
|
|
|
+ this.data = [];
|
|
|
+}
|
|
|
+
|
|
|
+Graph.prototype = Object.create(Object2D.prototype);
|
|
|
+
|
|
|
+Graph.prototype.isInside = function(point)
|
|
|
+{
|
|
|
+ return this.box.containsPoint(point);
|
|
|
+};
|
|
|
+
|
|
|
+Graph.prototype.draw = function(context, viewport, canvas)
|
|
|
+{
|
|
|
+ if(this.data.length === 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var width = this.box.max.x - this.box.min.x;
|
|
|
+ var height = this.box.max.y - this.box.min.y;
|
|
|
+
|
|
|
+ context.lineWidth = this.lineWidth;
|
|
|
+ context.strokeStyle = this.strokeStyle;
|
|
|
+ context.beginPath();
|
|
|
+
|
|
|
+ var step = width / (this.data.length - 1);
|
|
|
+ var gamma = this.max - this.min;
|
|
|
+
|
|
|
+ context.moveTo(this.box.min.x, this.box.max.y - ((this.data[0] - this.min) / gamma) * height);
|
|
|
+
|
|
|
+ for(var i = 1, s = step; i < this.data.length; s += step, i++)
|
|
|
+ {
|
|
|
+ context.lineTo(this.box.min.x + s, this.box.max.y - ((this.data[i] - this.min) / gamma) * height);
|
|
|
+ }
|
|
|
+
|
|
|
+ context.stroke();
|
|
|
+
|
|
|
+ if(this.fillStyle !== null)
|
|
|
+ {
|
|
|
+ context.fillStyle = this.fillStyle;
|
|
|
+
|
|
|
+ context.lineTo(this.box.max.x, this.box.max.y);
|
|
|
+ context.lineTo(this.box.min.x, this.box.max.y);
|
|
|
+ context.fill();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export { Box, Box2, BoxMask, Circle, DOM, EventManager, Graph, Helpers, Image, Key, Line, Mask, Matrix, Object2D, Pattern, Pointer, Renderer, Text, UUID, Vector2, Viewport };
|