@linkurious/ogma-annotations-react
Version:
A react component to add ogma annotations with react
135 lines (114 loc) • 4.95 kB
TypeScript
import { Annotation } from '@linkurious/ogma-annotations';
import { AnnotationCollection } from '@linkurious/ogma-annotations';
import { AnnotationFeature } from '@linkurious/ogma-annotations';
import { ArrowStyles } from '@linkurious/ogma-annotations';
import { Control } from '@linkurious/ogma-annotations';
import { default as default_2 } from 'react';
import { ReactElement } from 'react';
import { TextStyle } from '@linkurious/ogma-annotations';
declare type AnnotationAction = {
type: AnnotationActionType;
payload: Annotation;
};
declare type AnnotationActionType = "add" | "remove" | "update";
/**
* Creates a React context for managing annotations with type safety.
*
* @type {Context<IAnnotationsContext>} A typed context for annotation-related
* state and operations
*/
export declare const AnnotationsContext: default_2.Context<IAnnotationsContext>;
/**
* Provides a context provider for managing annotations in a graph visualization.
*
* This component handles the state and interactions for creating, selecting,
* and styling annotations, including arrow and text annotations.
*
* @param {Props} props - The component props containing child elements
* @returns {ReactElement} A context provider with annotation management capabilities
*/
export declare const AnnotationsContextProvider: ({ children, annotations: initialAnnotations }: Props) => default_2.JSX.Element;
export declare const BLACK = "#333333";
/**
* Creates a React context for managing annotations with optional type safety.
*
* @returns {Context<IAnnotationsContext | null>} A context for annotation-related state and operations that can be null
*/
export declare function createAnnotationsContext(): default_2.Context<IAnnotationsContext | null>;
/**
* Default arrow style for annotations.
* @type {ArrowStyles}
*/
export declare const defaultArrowStyle: ArrowStyles;
/**
* List of default colors for annotations.
* @type {string[]}
*/
export declare const defaultColors: string[];
/**
* Default text style for annotations.
* @type {TextStyle}
*/
export declare const defaultTextStyle: TextStyle;
/**
* List of available fonts for annotations.
*/
export declare const fonts: string[];
export declare const fontSizes: number[];
/**
* Defines the context interface for managing annotations in a React application.
*
* @interface
* @description Provides state and methods for handling annotation collections,
* current annotation selection, styling, and editor control.
*/
export declare interface IAnnotationsContext {
/** Current annotations in the application. */
annotations: AnnotationCollection;
/** Updates the annotations in the application. */
updateAnnotations: default_2.Dispatch<AnnotationAction>;
/** The currently selected annotation in the application. */
currentAnnotation: AnnotationFeature | null;
/** Sets the currently selected annotation in the application. */
setCurrentAnnotation: (annotation: AnnotationFeature | null) => void;
/** The current arrow style for annotations. */
arrowStyle: ArrowStyles;
/** The current width factor for arrow annotations. */
arrowWidthFactor: number;
/** Sets the width factor for arrow annotations. */
setArrowWidthFactor: (arrowWidthFactor: number) => void;
/** Sets the current arrow style for annotations. */
setArrowStyle: (arrowStyle: ArrowStyles) => void;
/** The current text style for annotations. */
textStyle: TextStyle;
/** The current size factor for text annotations in regards to node sizes. */
textSizeFactor: number;
/** Sets the size factor for text annotations. */
setTextSizeFactor: (textSizeFactor: number) => void;
/** Sets the current text style for annotations. */
setTextStyle: (textStyle: TextStyle) => void;
/** The annotations editor for managing annotations. See {@link AnnotationsEditor} */
editor: Control;
/** Sets the current annotations editor for managing annotations. */
setEditor: (editor: Control) => void;
}
export declare function interpolate(t: number, min?: number, max?: number): number;
export declare function mean(array: number[]): number;
export declare function normalize(t: number, min?: number, max?: number): number;
declare interface Props {
children: ReactElement;
annotations?: AnnotationCollection;
}
/**
* Default relative padding for text annotations.
*/
export declare const RELATIVE_PADDING = 0.25;
export declare const TRANSPARENT = "none";
/**
* Retrieves the current annotations context for accessing and managing annotations.
*
* @returns {IAnnotationsContext} The current annotations context with methods and
* state for annotation management
*/
export declare const useAnnotationsContext: () => IAnnotationsContext;
export { }