import Dispatcher from "./Dispatcher"; import { AbstractQuad as Quad } from "./quadtree/AbstractQuad"; import { Edge, Node } from "../../interfaces"; export interface CameraLocation { x: number; y: number; ratio?: number; angle?: number; } /** * The camera constructor. It just initializes its attributes and methods. * * @param {string} id The id. * @param {graph} graph The graph. * @param {configurable} settings The settings function. * @param {?object} options Eventually some overriding options. * @return {camera} Returns the fresh new camera instance. */ export default class Camera extends Dispatcher { id: string; graph: any; x: number; y: number; ratio: number; angle: number; isAnimated: boolean; isMoving: boolean; settings: any; prefix: string; readPrefix: string; kill?: Function; quadtree?: Quad; edgequadtree?: Quad; constructor(id: string, graph: any, settings: any, options?: any); /** * Updates the camera position. * * @param {object} coordinates The new coordinates object. * @return {camera} Returns the camera. */ goTo: (coordinates?: Partial) => this; /** * This method takes a graph and computes for each node and edges its * coordinates relatively to the center of the camera. Basically, it will * compute the coordinates that will be used by the graphic renderers. * * Since it should be possible to use different cameras and different * renderers, it is possible to specify a prefix to put before the new * coordinates (to get something like "node.camera1_x") * * @param {?string} read The prefix of the coordinates to read. * @param {?string} write The prefix of the coordinates to write. * @param {?object} options Eventually an object of options. Those can be: * - A restricted nodes array. * - A restricted edges array. * - A width. * - A height. * @return {camera} Returns the camera. */ applyView: (read?: string, write?: string, options?: any) => this; /** * This function converts the coordinates of a point from the frame of the * camera to the frame of the graph. * * @param {number} x The X coordinate of the point in the frame of the * camera. * @param {number} y The Y coordinate of the point in the frame of the * camera. * @return {object} The point coordinates in the frame of the graph. */ graphPosition: (x: number, y: number, vector?: boolean) => { x: number; y: number; }; /** * This function converts the coordinates of a point from the frame of the * graph to the frame of the camera. * * @param {number} x The X coordinate of the point in the frame of the * graph. * @param {number} y The Y coordinate of the point in the frame of the * graph. * @return {object} The point coordinates in the frame of the camera. */ cameraPosition: (x: number, y: number, vector?: boolean) => { x: number; y: number; }; /** * This method returns the transformation matrix of the camera. This is * especially useful to apply the camera view directly in shaders, in case of * WebGL rendering. * * @return {array} The transformation matrix. */ getMatrix: () => number[]; /** * Taking a width and a height as parameters, this method returns the * coordinates of the rectangle representing the camera on screen, in the * graph's referentiel. * * To keep displaying labels of nodes going out of the screen, the method * keeps a margin around the screen in the returned rectangle. * * @param {number} width The width of the screen. * @param {number} height The height of the screen. * @return {object} The rectangle as x1, y1, x2 and y2, representing * two opposite points. */ getRectangle: (width: number, height: number) => { x1: number; y1: number; x2: number; y2: number; height: number; }; }