Giter Club home page Giter Club logo

naver / egjs-axes Goto Github PK

View Code? Open in Web Editor NEW
177.0 17.0 32.0 45.43 MB

A module used to change the information of user action entered by various input devices such as touch screen or mouse into the logical virtual coordinates.

Home Page: https://naver.github.io/egjs-axes/

License: MIT License

JavaScript 37.85% HTML 3.58% TypeScript 44.21% Sass 1.10% CSS 6.49% Vue 1.49% Svelte 0.29% MDX 4.99%
egjs virtual-scroll javascript cartesian coordinate axis typescript

egjs-axes's Introduction

version npm weekly downloads npm bundle size (scoped) Build Status Coveralls github

You can easily create a UI that responds to user actions.


✨ Features

⚙️ Installation

npm

$ npm install @egjs/axes

CDN

🏃 Quick Start

1. Set up your HTML

<div id="area"></div>

2. Load files or import library

ES5
<script src="https://naver.github.io/egjs-axes/release/latest/axes.pkgd.js"></script>
var Axes = eg.Axes;
var PanInput = Axes.PanInput;
var PinchInput = Axes.PinchInput;
var WheelInput = Axes.WheelInput;
var MoveKeyInput = Axes.MoveKeyInput;
ES6+
import Axes, {PanInput, PinchInput, WheelInput, MoveKeyInput} from "@egjs/axes";

3. Initialize Axes

// create eg.Axes with option
const axes = new Axes({
  something1: { range: [0, 100] },
  something2: { range: [0, 100] },
  somethingN: { range: [-200, 200] }
});

4. Attach event handlers

axes.on({
 "change": evt => /* ... */
});

5. Initialize InputTypes to use

const panInput = new PanInput("#area");
const wheelInput = new WheelInput("#wArea");
const pinchInput = new PinchInput("#pArea");
const movekeyInput = new MoveKeyInput("#mArea");

6. Connect eg.Axes and InputTypes

axes.connect(["something2", "somethingN"], panInput);
axes.connect(["something1"], wheelInput);
axes.connect(["something2"], pinchInput);
axes.connect(["something1", "something2"], movekeyInput);

7. Enjoy!

You can change the value of the axis through touch screen, mouse or anything else.

🌐 Supported Browsers

IE Chrome Firefox Safari iOS Android
10+ Latest Latest Latest 7+ 2.3+(except 3.x)

🔧 Dependency

egjs-axes has the dependencies for the following libraries:

eg.Component eg.Agent
3.0.1+ 2.2.1+

📼 Demos

Check our Demos.

📖 Documentation

See Documentation page.

🙌 Contributing

See CONTRIBUTING.md.

📝 Feedback & Bug Report

Please file an Issue.

📜 License

@egjs/axes is released under the MIT license.

Copyright (c) 2015 NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

      

egjs-axes's People

Contributors

arkist avatar daybrush avatar happyhj avatar jaeyeophan avatar malangfox avatar okchangwon avatar sculove avatar sphilee avatar woodneck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egjs-axes's Issues

_animateParam must be null when `animationEnd` is fired.

Description

In the context, animationEnd means that it ends animation.

But sometimes it _animateParam is alive(=not null) on animationEnd.

I think animationEnd must be fired after _animateParam is initialized.( _animateParam = null).

image

Steps to check or reproduce

Grab(hold) movable area while it is animating.
It triggers _animationHandlers::_grab and this makes above issues.

Support PointerEvent

Description

There's report that only one input type(TouchInput) is working although the device is supporting both Touch and Mouse at the same time. So MouseInput is not working.

Test Environment

  • PC: Dell XPS 15 (which has Touch Display)
  • OS: Windows 10
  • Browser : Chrome, Firefox

I think It should support PointerEvent on devices like above.

Currently Axes uses Touch or Mouse as a default Input Type.

Need to prevent the latent error

Description

The below code block, it's trying to destroy hammer instance, but when seeing the condition, it's within else clause which means there's possibility being null value of this.hammer.

if (this.hammer) { // for sharing hammer instance.
this.dettachEvent();
// hammer remove previous PinchRecognizer.
this.hammer.add(new Hammer.Pinch(hammerOption));
} else {
let keyValue: string = this.element[UNIQUEKEY];
if (keyValue) {
this.hammer.destroy();

It should be preventing by checking the instance as this.hammer && this.hammer.destroy();

support startPos when eg.Axes is initialized.

AS-IS

        var axes = new eg.Axes({
		axis: {
			panX: {
				range: [0, gridWidth - 100],
				bounce: 50
			},
			panY: {
				range: [0, gridWidth/2 - 100],
				bounce: 50
			}
		}
	}).setTo({panX: 0, panY: 0});

TO-BE

        var axes = new eg.Axes({
		axis: {
			panX: {
				range: [0, gridWidth - 100],
				bounce: 50
			},
			panY: {
				range: [0, gridWidth/2 - 100],
				bounce: 50
			}
		}
	}, {panX: 0, panY: 0});

Need support circular on setBy method

Description

As I see,`setBy' is method for relative movement from current position. But It's not working when target position is out of range on circular mode.

Steps to check or reproduce

For example,

Current status is as follow

  • range[0, 359]
  • current position: 359

If setBy({angle:10}) is called,

RESULT
It doesn't move.

EXPECTED
position is changed to 9.

fix main page for 4 inputTypes.

Description

Add MoveKeyInput in Getting Started.

Introduce 4 inputType in animation.
Introduce the demo to each inputType.
Introduce projects with Axes.

Steps to check or reproduce

module property in package.json makes error on build

Description

When making build(eg. npm run build) project which depends on movablecoord 2.0.0-rc.1,
There's error.

Unexpected token punc «(», expected punc «:» [yawpitch.min.js:1880,20]

npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/jongmoon/.nvm/versions/node/v6.6.0/bin/node" "/Users/jongmoon/.nvm/versions/node/v6.6.0/bin/npm" "run" "build"
npm ERR! node v6.6.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! @egjs/[email protected] build: `webpack --env.mode production --config webpack.config.js && webpack --env.mode pkgd --config webpack.
config.js`
npm ERR! Exit status 2

If you change module property, It works!

NOT WORK!

"main": "dist/movablecoord.js",
"module": "src/MovableCoord.js",
"name": "@egjs/movablecoord",

WORK

"main": "dist/movablecoord.js",
"module": "dist/movablecoord.js",//changed!
"name": "@egjs/movablecoord",

information inconsistency on release event

Description

I think animationEnd event will be fired when depsPos is not equal destPos on release time.
It is reasonable because if there are some change in position, it have to be moved with animation.

but when I slightly move position, animationEnd event wasn't fired.

I found the reason is duration.

when duration is under 100, then value is zero

It's okay if animation was not performed, but It's not okay that information was hided.

Steps to check or reproduce

here are codepen link

  • check console
  • second information (Object) is delta
  • move slightly until delta is not zero
  • animationEnd will not be fired

setTo / setBy method called within the "change" event have no effect

Description

The setTo / setBy method that is called synchronously within the "change" event handler caused by user interaction is not reflected in the axes coordinates. (for example, checking with axes.get ())

Steps to check or reproduce

https://codepen.io/happyhj/pen/VrQJBg

Set method for changing value

Description

Currently user action is only way to change value. But There's 2 required situation to change value manually.

  1. Test
  2. In the structure in which target(?) is moved by axes. But If you want to provide API to move target manually.

Consider it~

Apply bind options dynamicaly

Description

The movableCoord can't apply bind options in runtime.
we need to support new interface about bind options.

Move key input needed

Description

I want to add user interaction via keystrokes. Especially, move keys (awsd, arrow keys)

Refactor plugin structure

Description

MovableCoord supports pointer, mouse, touch using Hammer.js
I proposes the structure supported a number of types
we add some types like orientationChange, keyboard, wheel,...etc.

import by CommonJS dosen't working in typescript environment

Description

following code throw runtime error Uncaught TypeError: axes_1.default is not a constructor

import Axes from "@egjs/Axes"

const axes = new Axes(...)

transpiled version references default property, but Axes constructor is axes_1 itself. that means default property is not constructor.

// transpiled version
var axes_1 = __webpack_require__(4);

var axes = new axes_1["default"](...)

Steps to check or reproduce

I changed Axes.d.ts by my self. but not sure it's right.
I can use import * as Axes from "@egjs/axes" with changed definition file;

export = Axes;

export as namespace Axes;

declare class Axes extends Component {
    axis: {
        [key: string]: AxisOption;
    };
    static VERSION: string;
    static PanInput: any;
    static PinchInput: any;
    static WheelInput: any;
    static MoveKeyInput: any;
    static TRANSFORM: string;
    static DIRECTION_NONE: DIRECTION;
    static DIRECTION_LEFT: DIRECTION;
    static DIRECTION_RIGHT: DIRECTION;
    static DIRECTION_UP: DIRECTION;
    static DIRECTION_DOWN: DIRECTION;
    static DIRECTION_HORIZONTAL: DIRECTION;
    static DIRECTION_VERTICAL: DIRECTION;
    static DIRECTION_ALL: DIRECTION;
    options: AxesOption;
    em: EventManager;
    axm: AxisManager;
    itm: InterruptManager;
    am: AnimationManager;
    io: InputObserver;
    private _inputs;
    constructor(axis: {
        [key: string]: AxisOption;
    }, options: AxesOption, startPos?: Axis);
    connect(axes: string[] | string, inputType: IInputType): this;
    disconnect(inputType?: IInputType): this;
    get(axes?: string[]): Axis;
    setTo(pos: Axis, duration?: number): this;
    setBy(pos: Axis, duration?: number): this;
    isBounceArea(axes?: string[]): boolean;
    destroy(): void;
}

declare interface AxesOption {
	easing?: (x: number) => number;
	maximumDuration?: number;
	minimumDuration?: number;
	deceleration?: number;
	interruptable?: boolean;
}

declare namespace Axes {
	export interface AxesOption {
		easing?: (x: number) => number;
		maximumDuration?: number;
		minimumDuration?: number;
		deceleration?: number;
		interruptable?: boolean;
	}
}

MovableCoord - increase default threashold value options for Hammer

@jongmoon commented on Wed Jul 13 2016

Description

It's not a bug. but It is need to be discussed.

current threashold = 0,
But in recent device browsers, browser sends touch offset more correctly(?) . So when moved vertically or horizontally, sometimes Hammer does not recognize it as vertical or horizontal perfectly.

For example when you touches screen vertically on HORIZONTAL mode, Hammer sometimes thinks it as horizontal movement by 1~ 2px.


@sculove commented on Thu Jul 14 2016

@jongmoon Could you give us some information like browser test?

Access undefined value in grab

Description

event is not defined in grab it makes firefox error.

AnimationManager.prototype.grab = function (axes, option) {
        if (this._animateParam && axes.length) {
            var orgPos_1 = this.axm.get(axes);
            var pos = this.axm.map(orgPos_1, function (v, k, opt) { return Coordinate_1["default"].getCirculatedPos(v, opt.range, opt.circular); });
            if (!this.axm.every(pos, function (v, k) { return orgPos_1[k] === v; })) {
                this.em.triggerChange(pos, option, !!option);
            }
            this._animateParam = null;
            this._raf && utils_1.cancelAnimationFrame(this._raf);
            this._raf = null;
            this.em.triggerAnimationEnd(!!event); // THIS event is not defiend!!
        }
    };

add basic demos

Description

create basic demos

  • one coordinate, and one bind
  • one coordinate, and multi binds

add scroll demos

Description

make demo using eg.movablecoord like iScroll.

  • simple scroll (vertical/horizontal)
  • scroll pull-to-refresh

Supports extend plugins

Description

MovableCoord is a raw(?) component.
Threrefore, movablecoord is so extensible. but, movablecoord is so hard to use it.

the Extend plugin is so simple class.
if you want to use scroll UI, you can use like this.

new eg.MovableCoord.Scroll('#wrapper', {
    scrollX : true,
    scrollY : false,
    mouseWheel: true,
    scrollbars: true
});

Goals: supports so simple component.

There are teleportation in restore

Description

restore animation
You can see teleportation when user release touch.

This occurs when deceleration value is high
And high deceleration leads Coordinate.getDuration make duration zero.

Steps to check or reproduce

Here are codepen link. I changed only deceleration value to 0.01 on axes demo.

  • check link on mobile size
  • move a little bit

Should cancel animation when "hold" event is triggered.

I think axes should cancel animation when "hold" event is triggered.

For example, in the case of Pan input type,
if the touch is started again during the animation,
the reaction starts after all the animation ends.
So, the reactivity is not good.

After touch start, I think the animation should be stopped and the reaction should begin immediately.

Is there any method to stop animation when "hold" event is triggered?

PinchInputType need to return offset value which calculated with base value

Problem

The zoomming UI using pinch gesture can not be implemented correctly using the offset value returned by PinchInputType at present.

Problem Description

The PinchInputType returns the offset value of the difference in scale value provided by the hammer's pinch recognizer.

If the offset given by PinchInputType is cumulatively added, the size and scale of the change will be the same. This scale value is relative value to the value at the pinchstart point.

The coordinate value handled by axes is an absolute value. The problem is to add the relative offset value to the absolute coordinate value.

How to resolve

To solve this problem, the offset value should return the difference of the absolute coordinate value to be changed due to the scale value.

To do this, you can add an item called base to the option property and allocate the absolute coordinate value at the point of pinchstart so that it can be used for offset calculation.

new event suggestion

Description

A triggered event is required after all actions have been completed.

Take the snap function of iScroll as an example. Currently, I have to check both animationEnd event handler and release event handler.

// animationEnd
const onAnimationEnd = (event) => {
    snap()
}

// release
const onRelease = (event) => {
    if (event.depaPos === event.pestPos) {
        // animationEnd is not fired. so snap function performed here.
        snap()
    } else {
        // animation will be performed. so animationEnd event will be triggered.
    }
}

I think some event will be helpful in this situation.

const onFinish = (event) => {
    snap()
}

support isTrusted property

Description

provide isTrusted property on events.

When the event is fired using API method, isTrusted is false
When the event is fired using User action, isTrusted is true

Coordinate.ts - getInsidePosition

According to the unit test(https://goo.gl/G2kNn6), range param is given as [start, end] and
always start <end. therefore No need to iterate the algorithm in the return statement.

current code

  toDestPos = Math.max(targetRange[0], toDestPos);
  toDestPos = Math.min(targetRange[1], toDestPos);
return +Math.min(targetRange[1], Math.max(targetRange[0], toDestPos)).toFixed(5);

recommand

  toDestPos = Math.max(targetRange[0], toDestPos);
  toDestPos = Math.min(targetRange[1], toDestPos);
return +toDestPos.toFixed(5);

Script Error on Firefox

Description

In EventManager, triggerChange access the variable(event) that is undefined.

It(event) was remove by 3afd0c5#diff-8ae8f9b823941c19b97e465a152fa1d2R159 commit.

And related code is not modified.

But error is not occurs on chrome, because it access window.event variable that is not intended.

Steps to check or reproduce

  • FireFox trigger script error which

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.