Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easey

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easey - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

test/spec/easey_handlers.js

2

package.json
{
"name": "easey",
"version": "1.0.3",
"version": "2.0.0",
"description": "Easing for Modest Maps",

@@ -5,0 +5,0 @@ "author": {

;(function(context, MM) {
easey.TouchHandler = function() {
var easey_handlers = {};
easey_handlers.TouchHandler = function() {
var handler = {},

@@ -261,3 +263,3 @@ map,

easey.DoubleClickHandler = function() {
easey_handlers.DoubleClickHandler = function() {
var handler = {},

@@ -293,3 +295,3 @@ map;

easey.MouseWheelHandler = function() {
easey_handlers.MouseWheelHandler = function() {
var handler = {},

@@ -362,3 +364,3 @@ map,

easey.DragHandler = function() {
easey_handlers.DragHandler = function() {
var handler = {},

@@ -473,2 +475,4 @@ map,

this.easey_handlers = easey_handlers;
})(this, MM);

@@ -5,3 +5,4 @@ ;(function(context, MM) {

running = false,
abort = false; // killswitch for transitions
abort = false, // killswitch for transitions
abortCallback; // callback called when aborted

@@ -24,4 +25,6 @@ var easings = {

easey.stop = function() {
easey.stop = function(callback) {
abort = true;
from = undefined;
abortCallback = callback;
};

@@ -49,3 +52,3 @@

easey.from = function(x) {
if (!arguments.length) return from.copy();
if (!arguments.length) return from ? from.copy() : from;
from = x.copy();

@@ -74,3 +77,2 @@ return easey;

map = x;
from = map.coordinate.copy();
to = map.coordinate.copy();

@@ -151,2 +153,8 @@ return easey;

if (running) return easey.stop(function() {
easey.run(time, callback);
});
if (!from) from = map.coordinate.copy();
time = time || 1000;

@@ -161,6 +169,9 @@

if (abort) {
return void (abort = running = false);
abort = running = false;
abortCallback();
return abortCallback = undefined;
} else if (delta > time) {
running = false;
map.coordinate = path(from, to, 1);
from = undefined;
map.draw();

@@ -196,3 +207,4 @@ if (callback) return callback(map);

map.coordinate = from; // For when `from` not current coordinate
if (from) map.coordinate = from; // For when `from` not current coordinate
else from = map.coordinate.copy();

@@ -250,3 +262,3 @@ // Width is measured in coordinate units at zoom 0

path = function (a, b, t) {
var path = function (a, b, t) {
if (t == 1) return to;

@@ -256,8 +268,7 @@ var s = t * S,

z = a.zoom + (Math.log(w0/w(s)) / Math.LN2),
x = interp(c0.x, c1.x, us/u1),
y = interp(c0.y, c1.y, us/u1);
x = interp(c0.x, c1.x, us/u1 || 1),
y = interp(c0.y, c1.y, us/u1 || 1);
return new MM.Coordinate(y, x, 0).zoomTo(z);
};
easey.easing('linear');
easey.run(S / V * 1000, callback);

@@ -264,0 +275,0 @@ };

describe("Easey", function() {
function Receiver() { }
Receiver.prototype.receive = function() { };
function Receiver() { }
Receiver.prototype.receive = function() { };
var map, sink;
var map, sink;
beforeEach(function() {
sink = new Receiver();
var map_div = document.createElement('div');
map = new MM.Map(map_div, new MM.TemplatedLayer('http://b.tile.openstreetmap.org/{Z}/{X}/{Y}.png'));
});
beforeEach(function() {
sink = new Receiver();
var map_div = document.createElement('div');
map = new MM.Map(map_div, new MM.TemplatedLayer('http://b.tile.openstreetmap.org/{Z}/{X}/{Y}.png'));
});
it('assigns the map var correctly', function() {
var ease = easey();
ease.map(map);
expect(ease.map()).toEqual(map);
});
it('assigns the map var correctly', function() {
var ease = easey();
ease.map(map);
expect(ease.map()).toEqual(map);
});
it('automatically sets to and from', function() {
var ease = easey();
ease.map(map);
expect(ease.from()).toEqual(map.coordinate);
expect(ease.to()).toEqual(map.coordinate);
});
it('automatically sets to', function() {
var ease = easey();
ease.map(map);
expect(ease.to()).toEqual(map.coordinate);
});
it('zooms the to coordinate with zoom()', function() {
var ease = easey();
ease.map(map);
ease.zoom(10);
expect(ease.to().zoom).toEqual(10);
});
it('zooms the to coordinate with zoom()', function() {
var ease = easey();
ease.map(map);
ease.zoom(10);
expect(ease.to().zoom).toEqual(10);
});
it('correctly interpolates between two coordinates', function() {
easey().map(map)
.from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0))
.easing('linear')
.t(0.5);
it('correctly interpolates between two coordinates', function() {
easey().map(map)
.from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0))
.easing('linear')
.t(0.5);
expect(map.coordinate.column).toEqual(5);
expect(map.coordinate.row).toEqual(0);
expect(map.coordinate.zoom).toEqual(0);
});
expect(map.coordinate.column).toEqual(5);
expect(map.coordinate.row).toEqual(0);
expect(map.coordinate.zoom).toEqual(0);
});
it('predicts the future correctly', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
var future = ease.future(10);
expect(future.length).toEqual(10);
expect(future[0].column).toEqual(10);
expect(future[9].column).toEqual(0);
});
it('predicts the future correctly', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
var future = ease.future(10);
expect(future.length).toEqual(10);
expect(future[0].column).toEqual(10);
expect(future[9].column).toEqual(0);
});
it('moves the map quickly', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
runs(function() {
ease.run(10);
it('moves the map quickly', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
runs(function() {
ease.run(10);
});
waits(200);
runs(function() {
expect(map.coordinate.column).toEqual(0);
expect(map.coordinate.row).toEqual(0);
expect(map.coordinate.zoom).toEqual(0);
});
});
waits(200);
runs(function() {
expect(map.coordinate.column).toEqual(0);
expect(map.coordinate.row).toEqual(0);
expect(map.coordinate.zoom).toEqual(0);
it('calls a callback after finishing an ease', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
spyOn(sink, 'receive');
runs(function() {
ease.run(10, sink.receive);
});
waits(200);
runs(function() {
expect(sink.receive).toHaveBeenCalledWith(map);
});
});
});
it('calls a callback after finishing an ease', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0));
spyOn(sink, 'receive');
runs(function() {
ease.run(10, sink.receive);
it('ends up at the correct coord after an optimal zoom/pan', function() {
map.setSize(new MM.Point(10, 10));
var ease = easey();
ease.map(map).from(new MM.Coordinate(2, 2, 2))
.to(new MM.Coordinate(1, 1, 1));
runs(function() {
ease.optimal(20);
});
waits(200);
runs(function() {
expect(map.coordinate.column).toEqual(1);
expect(map.coordinate.row).toEqual(1);
expect(map.coordinate.zoom).toEqual(1);
});
});
waits(200);
runs(function() {
expect(sink.receive).toHaveBeenCalledWith(map);
});
});
it('ends up at the correct coord after an optimal zoom/pan', function() {
map.setSize(new MM.Point(10, 10));
var ease = easey();
ease.map(map).from(new MM.Coordinate(2, 2, 2))
.to(new MM.Coordinate(1, 1, 1));
runs(function() {
ease.optimal(20);
it('resets from after a run', function() {
var ease = easey();
ease.map(map).from(new MM.Coordinate(0, 10, 0))
.to(new MM.Coordinate(0, 0, 0)).run(1);
waits(50);
runs(function() {
expect(ease.from()).toEqual(undefined);
});
});
waits(200);
runs(function() {
expect(map.coordinate.column).toEqual(1);
expect(map.coordinate.row).toEqual(1);
expect(map.coordinate.zoom).toEqual(1);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc