@adobe/react-spectrum-charts
Version:
Declarative library for composing Spectrum visualizations in React.
156 lines • 6.52 kB
TypeScript
import { RefObject } from 'react';
import { Item, Scene, SceneGroup, SceneItem, ScenegraphEvent, View } from 'vega';
import { Datum, MarkBounds } from '@spectrum-charts/vega-spec-builder';
import { ThumbnailPopoverConfig } from '../hooks/useAxisThumbnailPopover';
import { MarkMouseInputDetail } from '../hooks/useMarkMouseInputDetails';
import { MarkOnClickDetail } from '../hooks/useMarkOnClickDetails';
export type ActionItem = Item | undefined | null;
type ViewEventCallback = (event: ScenegraphEvent, item: ActionItem) => void;
export interface GetOnMarkClickCallbackArgs {
chartView: RefObject<View | undefined>;
hiddenSeries: string[];
chartId: string;
selectedData: RefObject<Datum | null>;
selectedDataBounds: RefObject<MarkBounds | undefined>;
selectedDataName: RefObject<string | undefined>;
setHiddenSeries: (hiddenSeries: string[]) => void;
legendIsToggleable?: boolean;
legendHasPopover?: boolean;
onLegendClick?: (seriesName: string) => void;
trigger: 'click' | 'contextmenu';
markHasPopover?: boolean;
thumbnailPopoverConfig?: ThumbnailPopoverConfig;
}
/**
* Generates the callback for the mark click handler
* @param chartView
* @param hiddenSeries
* @param chartId
* @param selectedData
* @param selectedDataBounds
* @param selectedDataName
* @param setHiddenSeries
* @param legendIsToggleable
* @param onLegendClick
* @returns
*/
export declare const getOnMarkClickCallback: (args: GetOnMarkClickCallbackArgs) => ViewEventCallback;
export declare const triggerPopover: (chartId: string, itemName: string | undefined, trigger: 'click' | 'contextmenu') => void;
/**
* Returns the callback to be used for the `onClick` prop on a mark.
* @param chartView - The mutable ref object containing the chart view.
* @param onClickMarkDetails - The details for all marks with the onClick prop.
* @returns The callback to be used for the `onClick` prop on a mark.
*/
export declare const getOnChartMarkClickCallback: (chartView: RefObject<View | undefined>, onClickMarkDetails?: MarkOnClickDetail[]) => ViewEventCallback;
/**
* Returns the callback to be used for the `onContextMenu` prop on a mark.
* Invokes the mark's onContextMenu with the native event and datum so the consumer can show a custom context menu.
* @param chartView - The mutable ref object containing the chart view.
* @param markClickDetails - The details for all marks with the onContextMenu prop.
* @returns The callback for contextmenu events.
*/
export declare const getOnChartMarkContextMenuCallback: (chartView: RefObject<View | undefined>, markClickDetails?: MarkOnClickDetail[]) => ViewEventCallback;
/**
* Updates the hidden series when a legend item is clicked
* @param item
* @param onLegendMouseInput
* @returns
*/
export declare const handleLegendItemMouseInput: (item: ActionItem, onLegendMouseInput?: (seriesName: string) => void) => void;
/**
* Generates the callback for mouse events (both legend and mark hover)
* @param onLegendMouseInput
* @param markHoverDetails
* @returns
*/
export declare const getOnMouseInputCallback: (onLegendMouseInput?: (seriesName: string) => void, markMouseInputDetails?: MarkMouseInputDetail[]) => ViewEventCallback;
/**
* Checks if the clicked item is a legend item
* @param item
* @returns
*/
export declare const isLegendItem: (item: Item) => boolean;
/**
* Updates the hidden series when a legend item is clicked
* @param item
* @param hiddenSeries
* @param setHiddenSeries
* @returns
*/
export declare const handleLegendItemClick: (item: NonNullable<ActionItem>, { chartView, hiddenSeries, chartId, selectedData, selectedDataBounds, selectedDataName, setHiddenSeries, legendHasPopover, legendIsToggleable, onLegendClick, trigger, }: GetOnMarkClickCallbackArgs) => void;
/**
* Gets the value of the clicked legend item
* @param item
* @returns
*/
export declare const getLegendItemValue: (item: unknown) => string | undefined;
/**
* Checks if the clicked item is a group mark item
* @param item
* @returns
*/
export declare const isGroupMarkItem: (item: Item) => boolean;
/**
* Checks if the clicked item is an area mark item
* @param item
* @returns
*/
export declare const isAreaMarkItem: (item: ActionItem) => boolean;
/**
* Gets the item that should be used for the selected point when the user clicks on an area mark
* The default clicked mark is the entire area
* This will traverse the object to get the correct associated point
* @param item
* @returns
*/
export declare const getItemForAreaMark: (item: ActionItem) => ActionItem;
/**
* Gets the bounds for an item provided by the click handler.
* If the item is in a group that has an offset (like for a grouped bar),
* then the offset is added to the bounds.
* @param item
* @returns MarkBounds
*/
export declare const getItemBounds: (item: ActionItem) => MarkBounds;
/**
* Gets the bounds for an item provided by the click handler.
* If the item is in a group that has an offset (like for a grouped bar),
* then the offset is added to the bounds.
* @param item
* @returns MarkBounds
*/
export declare const getItemName: (item: ActionItem) => string | undefined;
/**
* Gets the the group offset for the provided item.
*
* Mark groups can be nested multiple levels deep.
* This function will recursively step through all groups to get the total offset.
* @param item
* @returns
*/
export declare const getGroupOffset: (item: ActionItem) => {
x: number;
y: number;
};
/**
* Returns true if the item is an axis thumbnail mark (image mark whose name includes AxisThumbnail).
* @param item
* @returns
*/
export declare const isThumbnailItem: (item: ActionItem) => boolean;
/**
* Traverses the Vega scenegraph to find the first item whose mark name starts with `${markNamePrefix}_`
* and whose datum contains the given dimension value.
* @param view
* @param markNamePrefix - e.g. 'bar0'
* @param dimensionField - e.g. 'category'
* @param dimensionValue - the value to match
* @returns the matching Item & SceneItem, or undefined if not found
*/
export declare const findSceneItemByDimension: (view: View, markNamePrefix: string, dimensionField: string, dimensionValue: unknown) => (Item & SceneItem) | undefined;
export declare function isItemSceneItem(item: unknown): item is Item & SceneItem;
export declare const isSceneGroup: (item: unknown) => item is SceneGroup;
export declare const isScene: (item: unknown) => item is Scene;
export {};
//# sourceMappingURL=markClickUtils.d.ts.map