import { Canvas } from '../../interfaces/canvas'; /** * The configuration for the visual behavior of a diagram in the user interface. * @public */ export interface CanvasConfig { /** * Configuration for the context menu in this diagram. * If left undefined, the default context menu is used. */ contextMenu?: ContextMenuConfig; /** * Configuration for the main grid in the canvas. * If left undefined, it is interpreted as disabling the grid, * same as if the attribute `enabled` in its configuration was set to `false`. * The grid repeats with a period of diagram units determined by the `spacing` attribute. */ grid?: EmptyGridConfig | DotsGridConfig | LinesGridConfig | ImageGridConfig; /** * Configuration for ancillary grids in the canvas. * They accompany the main grid without affecting the diagram. */ ancillaryGrids?: (DotsGridConfig | LinesGridConfig | ImageGridConfig)[]; /** * Configuration for the background of the canvas. * If left undefined, it is interpreted as a solid white (`'#FFFFFF'`) background. * The background of the canvas covers the entire canvas and does not move when changing the position or zoom. */ background?: SolidBackgroundConfig | ImageBackgroundConfig; /** * The factor by which the zoom level increases or decreases when the user users buttons or keys to zoom in or out. Should be above 1. * @default 2 */ zoomFactor?: number; /** * The rate by which the view of the canvas moves when the user users buttons or keys to pan at a default zoom level in diagram units. Should be above 1. * @default 100 */ panRate?: number; /** * Whether sections can be highlighted individually or the whole node must be highlighted when highlighting a section. * @default true */ highlightSections?: boolean; /** * Possible values of the priority threshold that the user can toggle between to hide nodes whose priority value is below it. * If it is possible to toggle the priority threshold via the filter button, it should have at least two values. * @default [] */ priorityThresholds?: number[]; } /** * Possible styles for the grid of the diagram. Each corresponds to a different configuration with different attributes. */ export type GridStyle = 'none' | 'dots' | 'lines' | 'image'; /** * Configuration of the guide grid of the diagram. */ export interface GridConfig { /** * Whether the grid is present in the diagram. * @default true */ enabled?: boolean; /** * The style of the grid. * @default "dots" */ style: GridStyle; /** * Distance between each point of the grid of this diagram in diagram units. * @default 10 */ spacing?: number | [number, number]; /** * When true, the user moving or stretching nodes will cause their corners to automatically snap to the closest grid point. * Does not have an effect in ancillary grids. * @default false */ snap?: boolean; } /** * A grid with no points are marked by dots. */ export interface EmptyGridConfig extends GridConfig { style: 'none'; } /** * A grid where the points are marked by dots. */ export interface DotsGridConfig extends GridConfig { style: 'dots'; /** * Color of grid elements such as the points or axes. * @default "rgba(0, 0, 0, 0.1)" */ color?: string; /** * In a range between 0 and 1, how thick the points of the grid are relative to the distance between them. * @default 0.05 */ thickness?: number; } /** * A grid where the points are marked by lines. */ export interface LinesGridConfig extends GridConfig { style: 'lines'; /** * Color of grid elements such as the points or axes. * @default "rgba(0, 0, 0, 0.1)" */ color?: string; /** * In a range between 0 and 1, how thick the points of the grid are relative to the distance between them. * @default 0.05 */ thickness?: number; } /** * A grid which consists of an image. */ export interface ImageGridConfig extends GridConfig { style: 'image'; /** * The source of the image to use as grid. * This image is placed such that the 0,0 point of the diagram is in the center of the image. */ image: string; } /** * Possible styles for the background of the diagram. Each corresponds to a different configuration with different attributes. */ export type BackgroundStyle = 'solid' | 'image'; /** * Configuration of the background of the diagram. */ export interface BackgroundConfig { /** * The style of the background. */ style: BackgroundStyle; } /** * A background which consists of a solid color. */ export interface SolidBackgroundConfig extends BackgroundConfig { style: 'solid'; /** * The color of the background. * @default '#FFFFFF' */ color?: string; } /** * A background which consists of an image. */ export interface ImageBackgroundConfig extends BackgroundConfig { style: 'image'; /** * The source of the image to use as background. */ image: string; } export interface ContextMenuConfig { /** * Custom buttons to be added to the context menu. * @default [] */ customButtons?: ContextMenuButtonConfig[]; } export interface ContextMenuButtonConfig { /** * Text on the button. */ name: string; /** * File path to the image icon used by this button. */ image?: string; /** * A function which is executed when the user clicks on this button. * @param canvas The diagram's canvas. */ onPress?: (canvas: Canvas) => void; /** * A function which given the canvas determines if the button should be present if the user opens a context menu on the canvas. * @param canvas The diagram's canvas. * @returns `true` if the button should be present on the menu, `false` otherwise. */ condition?: (canvas: Canvas) => boolean; }