@gravity-ui/graph
Version:
Modern graph editor component
93 lines (92 loc) • 4.03 kB
TypeScript
import { GraphComponent } from "../components/canvas/GraphComponent";
import { TBlock } from "../components/canvas/blocks/Block";
import { Graph } from "../graph";
import { TGraphColors, TGraphConstants } from "../graphConfig";
import { ESelectionStrategy } from "../services/selection/types";
import { TBlockId } from "../store/block/Block";
import { TConnection, TConnectionId } from "../store/connection/ConnectionState";
import { TGraphSettingsConfig } from "../store/settings";
import { TRect } from "../utils/types/shapes";
export type ZoomConfig = {
transition?: number;
padding?: number;
};
export declare class PublicGraphApi {
graph: Graph;
constructor(graph: Graph);
/**
* Zooms to blocks
* @param blockIds - block ids to zoom to
* @param zoomConfig - {@link ZoomConfig} zoom config
* @returns {boolean} true if zoom is successful, false otherwise
*
* @example
* ```typescript
* graph.zoomToBlocks([block1.id, block2.id]);
* graph.zoomToBlocks([block1.id, block2.id], { transition: 1000, padding: 50 });
* ```
*/
zoomToBlocks(blockIds: TBlockId[], zoomConfig?: ZoomConfig): boolean;
/**
* Zooms to GraphComponent instances
* @param instances - {@link GraphComponent} instances to zoom to
* @param zoomConfig - {@link ZoomConfig} zoom config
* @returns {boolean} true if zoom is successful, false otherwise
*
* @example
* ```typescript
* graph.zoomToElements([component1, component2]);
* graph.zoomToElements([component1, component2], { transition: 1000, padding: 50 });
* ```
*/
zoomToElements<T extends GraphComponent = GraphComponent>(elements: T[], zoomConfig?: ZoomConfig): boolean;
/**
* Zooms to fit all blocks in the viewport. This method is asynchronous and waits
* for the usableRect to be ready before performing the zoom operation.
*
* @param zoomConfig - Configuration for zoom transition and padding
* @returns Promise that resolves when zoom operation is complete
*/
zoomToViewPort(zoomConfig?: ZoomConfig): void;
/**
* Zooms to the specified rectangle in camera coordinates
*
* Zooms the camera to fit the specified rectangle in the viewport. The rectangle will be scaled
* to fill the visible area (respecting camera insets) and centered in the viewport.
*
* @param rect - {@link TRect} rectangle to zoom to in camera coordinates
* @param zoomConfig - {@link ZoomConfig} zoom config
* @returns {undefined}
*
* @example
* ```typescript
* graph.zoomToRect({ x: 0, y: 0, width: 100, height: 100 });
* graph.zoomToRect({ x: 0, y: 0, width: 100, height: 100 }, { transition: 1000, padding: 50 });
*/
zoomToRect(rect: TRect, zoomConfig?: ZoomConfig): void;
getGraphColors(): TGraphColors;
updateGraphColors(colors: TGraphColors): void;
getGraphConstants(): TGraphConstants;
updateGraphConstants(constants: TGraphConstants): void;
isGraphEmpty(): boolean;
setSetting(flagPath: keyof TGraphSettingsConfig, value: boolean | number): void;
setCurrentConfigurationName(newName: string): void;
deleteSelected(): void;
selectBlocks(blockIds: TBlockId[], selected: boolean, strategy?: ESelectionStrategy): void;
updateBlock(block: {
id: TBlockId;
} & Partial<Omit<TBlock, "id">>): void;
addBlock(block: Omit<TBlock, "id"> & {
id?: TBlockId;
}, selectionOptions?: {
selected?: boolean;
strategy?: ESelectionStrategy;
}): TBlockId;
setAnchorSelection(blockId: TBlockId, anchorId: string, selected: boolean): void;
selectConnections(connectionIds: TConnectionId[], selected: boolean, strategy?: ESelectionStrategy): void;
updateConnection(id: TConnectionId, connection: Partial<TConnection>): void;
addConnection(connection: TConnection): TConnectionId;
getBlockById(blockId: TBlockId): TBlock;
getUsableRect(): TRect;
unsetSelection(): void;
}