UNPKG

@ansible/react-json-chart-builder

Version:

A chart builder component in react, which uses JSON for schema.

135 lines (134 loc) 3.96 kB
import { ChartBarProps, ChartProps as PFChartProps, ChartTooltipProps as PFChartTooltipProps, ChartStackProps, ChartGroupProps, ChartPieProps as PFChartPieProps, ChartLineProps, ChartAreaProps, ChartScatterProps, ChartThemeColor, ChartAxisProps as PFChartAxisProps, ChartLabelProps, ChartLegendTooltipProps } from '@patternfly/react-charts/victory'; import { ChartFunctions } from './Functions/types'; export * from './Functions/types'; export interface PaddingProps { top: number; bottom: number; left: number; right: number; } export interface PaddingPropsOptional { top?: number; bottom?: number; left?: number; right?: number; } export declare enum ChartKind { simple = "simple", group = "group", stack = "stack", wrapper = "wrapper" } export declare enum ChartType { bar = "bar", line = "line", area = "area", scatter = "scatter" } export declare enum ChartTopLevelType { chart = "chart", pie = "pie" } export interface ChartDataSerie { serie: Record<string, string | number>[]; hidden: boolean; name: string; } export interface ChartLegendEntry { name: string; childName?: string; tooltipText?: string; [key: string]: string | number; } export interface ChartData { series: ChartDataSerie[]; legend?: ChartLegendEntry[]; } interface ChartBase { id: number; kind: ChartKind; parent: number; } export interface ChartTooltipProps { type?: string; props?: PFChartTooltipProps; standalone?: boolean; labelName?: string; labelFormat?: string; } export type ChartSimpleProps = ChartBarProps | ChartLineProps | ChartAreaProps | ChartScatterProps; export interface ChartSimple extends ChartBase { kind: ChartKind.simple; props: ChartSimpleProps; name?: string; type: ChartType; tooltip?: ChartTooltipProps; onClick?: string; dataComponent?: string; } export interface ChartGroup extends ChartBase { kind: ChartKind.group; props?: ChartGroupProps; template?: number; } export interface ChartStack extends ChartBase { kind: ChartKind.stack; props?: ChartStackProps; } export interface ChartAxisProps extends Omit<PFChartAxisProps, 'tickFormat'> { tickFormat?: string; labelProps?: ChartLabelProps; turncateAt?: number; wrapText?: boolean; } export interface ChartLegendProps { interactive?: boolean; position: 'bottom' | 'right'; orientation: 'horizontal' | 'vertical'; turncateAt?: number; wrapText?: boolean; hasTooltip?: boolean; } export interface ChartTopLevelElement extends ChartBase { kind: ChartKind.wrapper; parent: null; type: ChartTopLevelType; } export interface ChartProps extends Omit<PFChartProps, 'padding'> { padding?: PaddingPropsOptional; } export interface ChartPieProps extends Omit<PFChartPieProps, 'padding'> { padding?: PaddingPropsOptional; } export interface ChartWrapperTooltipProps { mouseFollow?: boolean; stickToAxis?: 'x' | 'y'; cursor?: boolean; labelFormat?: string; legendTooltip?: { legendData?: ChartLegendTooltipProps['legendData']; titleProperyForLegend?: string; }; } export interface ChartWrapper extends ChartTopLevelElement { type: ChartTopLevelType.chart; props?: ChartProps; xAxis: ChartAxisProps; yAxis: ChartAxisProps; legend?: ChartLegendProps; tooltip?: ChartWrapperTooltipProps; } export interface ChartPie extends ChartTopLevelElement { type: ChartTopLevelType.pie; props?: ChartPieProps; legend?: ChartLegendProps; tooltip?: PFChartTooltipProps; } export type ChartTopSchemaElement = ChartWrapper | ChartPie; export type ChartSchemaElement = ChartSimple | ChartTopSchemaElement | ChartGroup | ChartStack; export interface ChartInterface { schema: ChartSchemaElement[]; functions: ChartFunctions; dataState: [ChartData, (data: ChartData) => void]; } export { ChartThemeColor };