@neo4j-ndl/react-charts
Version:
React implementation of charts from Neo4j Design System
163 lines • 6 kB
TypeScript
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { type EChartsOption, type LineSeriesOption, type RegisteredSeriesOption, type SetOptionOpts } from 'echarts';
export type HexColor = `#${string}`;
export type Condition = 'greater' | 'greaterOrEqual' | 'less' | 'lessOrEqual' | 'equal' | 'notEqual';
export type Values<T> = T[keyof T];
export type SeriesOption = Values<RegisteredSeriesOption>;
export type EchartsSeries = SeriesOption | SeriesOption[];
type CustomCondition = (lineValue: unknown, thresholdLineValue: unknown) => boolean;
export interface ThresholdLineSeriesOption<T extends NotificationType> extends Omit<LineSeriesOption, 'type'> {
type: 'thresholdLine';
yAxis: number;
xAxis: [number, number];
notificationType: T;
color?: string;
condition?: Condition;
customConditionText?: string;
customCondition?: CustomCondition;
}
export type NeedleSeries = [
ThresholdLineSeriesOption<'warning'>,
ThresholdLineSeriesOption<'danger'>,
...SeriesOption[]
] | [ThresholdLineSeriesOption<'danger'>, ...SeriesOption[]] | [ThresholdLineSeriesOption<'warning'>, ...SeriesOption[]] | SeriesOption[];
export interface ChartProps {
/** The dataset configuration for the chart. Can be a single dataset or an array of datasets. */
dataset: EChartsOption['dataset'];
/** The series configuration for the chart. Defines what data to display and how to display it. */
series: NeedleSeries;
/** X-axis configuration for the chart. */
xAxis?: EChartsOption['xAxis'];
/** Y-axis configuration for the chart. */
yAxis?: EChartsOption['yAxis'];
/** Legend configuration for the chart. */
legend?: {
show?: boolean;
/** @deprecated No longer has any effect since wrapping is now automatic, will be removed in v 5 */
wrappingType?: 'wrapping' | 'truncation' | 'overflow';
};
/** Additional ECharts options to merge with the chart configuration. */
option?: Omit<EChartsOption, 'series' | 'dataset' | 'legend' | 'xAxis' | 'yAxis'>;
/** Custom CSS styles to apply to the chart container. */
style?: React.CSSProperties;
/** Settings for how ECharts should update the chart. */
settings?: SetOptionOpts;
/** Whether the chart is in a loading state. */
isLoading?: boolean;
/** Callback functions for chart interactions. */
callbacks?: {
onZoom?: (params: {
startValue: number;
endValue: number;
}) => void;
};
/** Data zoom configuration for the chart. */
dataZoom?: EChartsOption['dataZoom'];
/** Whether the zoom in the chart is disabled */
isChartZoomDisabled?: boolean;
/** Custom color palette that overrides the default categorical colors. */
palette?: HexColor[];
}
export interface ChartEmptyProps {
/** A text displayed to the user when the chart is empty. */
message?: React.ReactNode;
/** The type of chart. This is used to render the appropriate icon. */
type?: 'line' | 'pie' | 'bar';
/** Optional element (preferably a TextButton) that should provide the user with an action. */
action?: React.ReactNode;
}
/**
* Chart tooltip
*/
export interface ChartTooltipProps {
children: React.ReactNode;
className?: string;
isOpen?: boolean;
style?: React.CSSProperties;
anchorPosition?: {
x: number;
y: number;
};
ref?: React.Ref<HTMLDivElement>;
}
export type NotificationType = 'warning' | 'danger';
export type Notification = {
leadingElement: React.ReactNode;
trailingElement: React.ReactNode;
notificationType: NotificationType;
id: string;
};
export type ChartTooltipContentProps = {
leadingElement?: React.ReactNode;
trailingElement?: React.ReactNode;
indentSquareColor?: string;
notifications?: Notification[];
ref?: React.Ref<HTMLDivElement>;
};
/**
* Legend
*/
export interface LegendItemProps {
name: string;
children: React.ReactNode;
as?: 'button' | 'div';
className?: string;
color?: string;
selected?: boolean;
deSelected?: boolean;
onLegendItemClick?: () => void;
hasButtons?: boolean;
onLegendItemMouseEnter?: () => void;
onLegendItemMouseLeave?: () => void;
ref?: React.Ref<HTMLButtonElement> & React.Ref<HTMLDivElement>;
}
export type LegendProps = {
series: {
name: string;
color: string;
}[];
ref?: React.Ref<HTMLDivElement>;
};
export type HtmlAttributes<T extends React.ElementType> = React.ComponentPropsWithoutRef<T> & {
[key: `data-${string}`]: string | undefined;
};
type BaseProps<T extends React.ElementType> = {
/**
* Additional classnames will be applied to the root element.
*/
className?: string;
/**
* Additional css styling. Will be applied to the root element.
*/
style?: React.CSSProperties;
/**
* Html attributes to apply to the root element. This will override any default html attributes, use with caution.
*/
htmlAttributes?: HtmlAttributes<T>;
/**
* A ref to apply to the root element.
*/
ref?: React.ComponentPropsWithRef<T>['ref'];
};
export type CommonProps<T extends React.ElementType, P> = P & BaseProps<T>;
export {};
//# sourceMappingURL=chart-types.d.ts.map