sigma
Version:
A JavaScript library dedicated to graph drawing.
155 lines (154 loc) • 4.65 kB
TypeScript
/// <reference types="node" />
/**
* Sigma.js Camera Class
* ======================
*
* Class designed to store camera information & used to update it.
* @module
*/
import { EventEmitter } from "events";
import { AnimateOptions } from "../utils/animate";
import { CameraState, Coordinates, Dimensions } from "../types";
/**
* Camera class
*
* @constructor
*/
export default class Camera extends EventEmitter implements CameraState {
x: number;
y: number;
angle: number;
ratio: number;
nextFrame: number | null;
previousState: CameraState;
enabled: boolean;
animationCallback?: () => void;
constructor();
/**
* Static method used to create a Camera object with a given state.
*
* @param state
* @return {Camera}
*/
static from(state: CameraState): Camera;
/**
* Method used to enable the camera.
*
* @return {Camera}
*/
enable(): this;
/**
* Method used to disable the camera.
*
* @return {Camera}
*/
disable(): this;
/**
* Method used to retrieve the camera's current state.
*
* @return {object}
*/
getState(): CameraState;
/**
* Method used to retrieve the camera's previous state.
*
* @return {object}
*/
getPreviousState(): CameraState;
/**
* Method used to check whether the camera is currently being animated.
*
* @return {boolean}
*/
isAnimated(): boolean;
/**
* Method returning the coordinates of a point from the framed graph system to the
* viewport system.
*
* @param {object} dimensions - Dimensions of the viewport.
* @param {object} coordinates - Coordinates of the point.
* @return {object} - The point coordinates in the viewport.
*/
framedGraphToViewport(dimensions: Dimensions, coordinates: Coordinates): Coordinates;
/**
* Method returning the coordinates of a point from the viewport system to the
* framed graph system.
*
* @param {object} dimensions - Dimensions of the viewport.
* @param {object} coordinates - Coordinates of the point.
* @return {object} - The point coordinates in the graph frame.
*/
viewportToFramedGraph(dimensions: Dimensions, coordinates: Coordinates): Coordinates;
/**
* Method returning the abstract rectangle containing the graph according
* to the camera's state.
*
* @return {object} - The view's rectangle.
*/
viewRectangle(dimensions: {
width: number;
height: number;
}): {
x1: number;
y1: number;
x2: number;
y2: number;
height: number;
};
/**
* Method used to set the camera's state.
*
* @param {object} state - New state.
* @return {Camera}
*/
setState(state: Partial<CameraState>): this;
/**
* Method used to (un)zoom, while preserving the position of a viewport point.
* Used for instance to
*
* @param viewportTarget
* @param dimensions
* @param ratio
* @return {CameraState}
*/
getViewportZoomedState(viewportTarget: Coordinates, dimensions: Dimensions, ratio: number): CameraState;
/**
* Method used to animate the camera.
*
* @param {object} state - State to reach eventually.
* @param {object} opts - Options:
* @param {number} duration - Duration of the animation.
* @param {string | number => number} easing - Easing function or name of an existing one
* @param {function} callback - Callback
*/
animate(state: Partial<CameraState>, opts?: Partial<AnimateOptions>, callback?: () => void): void;
/**
* Method used to zoom the camera.
*
* @param {number|object} factorOrOptions - Factor or options.
* @return {function}
*/
animatedZoom(factorOrOptions: number | (Partial<AnimateOptions> & {
factor: number;
})): void;
/**
* Method used to unzoom the camera.
*
* @param {number|object} factorOrOptions - Factor or options.
*/
animatedUnzoom(factorOrOptions: number | (Partial<AnimateOptions> & {
factor: number;
})): void;
/**
* Method used to reset the camera.
*
* @param {object} options - Options.
*/
animatedReset(options: Partial<AnimateOptions>): void;
/**
* Returns a new Camera instance, with the same state as the current camera.
*
* @return {Camera}
*/
copy(): Camera;
}