@peripheries/charts 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +8 -2
- package/index.css +1 -0
- package/index.d.ts +1 -0
- package/index.js +6961 -0
- package/package.json +25 -4
- package/types/charts/AreaChart/AreaChart.d.ts +22 -0
- package/types/charts/BarChart/BarChart.d.ts +21 -0
- package/types/charts/BarLineChart/BarLineChart.d.ts +22 -0
- package/types/charts/DonutChart/DonutChart.d.ts +6 -0
- package/types/charts/LineChart/LineChart.d.ts +27 -0
- package/types/charts/MetricChart/MetricChart.d.ts +21 -0
- package/types/charts/PieChart/PieChart.d.ts +26 -0
- package/types/charts/ScatterChart/ScatterChart.d.ts +22 -0
- package/types/charts/Sparkline/Sparkline.d.ts +17 -0
- package/types/charts/WaterfallChart/WaterfallChart.d.ts +21 -0
- package/types/charts/_shared/ChartFrame.d.ts +42 -0
- package/types/charts/_shared/axis-utils.d.ts +21 -0
- package/types/charts/_shared/brush-range.d.ts +22 -0
- package/types/charts/_shared/encodings.d.ts +41 -0
- package/types/charts/_shared/palette.d.ts +12 -0
- package/types/charts/_shared/reference-lines.d.ts +19 -0
- package/types/charts/_shared/scales.d.ts +14 -0
- package/types/charts/_shared/types.d.ts +66 -0
- package/types/charts/_shared/use-dimensions.d.ts +12 -0
- package/types/charts/_shared/use-focus.d.ts +23 -0
- package/types/charts/_shared/use-hover.d.ts +23 -0
- package/types/charts/primitives/Axis/Axis.d.ts +22 -0
- package/types/charts/primitives/ChartTooltip/ChartTooltip.d.ts +17 -0
- package/types/charts/primitives/Legend/Legend.d.ts +13 -0
- package/types/charts/primitives/PlotArea/PlotArea.d.ts +14 -0
- package/types/charts/primitives/ReferenceLine/ReferenceLine.d.ts +33 -0
- package/types/index.charts.d.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peripheries/charts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The shared charts lineage, built on @stack/core",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/peripheries-components/stack-components.git"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"*.css"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"./index.css": "./index.css"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": "^19.2.4"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@types/d3-scale": "4.0.9"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow, type CurveType, type ReferenceLineSpec, type Series } from '../_shared/types';
|
|
3
|
+
export interface AreaChartProps extends ChartCellProps {
|
|
4
|
+
series?: readonly Series[] | string;
|
|
5
|
+
data?: readonly ChartRow[];
|
|
6
|
+
x?: string;
|
|
7
|
+
y?: string | readonly string[];
|
|
8
|
+
xAxis?: AxisConfig;
|
|
9
|
+
yAxis?: AxisConfig;
|
|
10
|
+
height?: number;
|
|
11
|
+
colors?: readonly string[];
|
|
12
|
+
stacked?: boolean;
|
|
13
|
+
fillOpacity?: number;
|
|
14
|
+
curve?: CurveType;
|
|
15
|
+
legend?: boolean;
|
|
16
|
+
tooltip?: boolean;
|
|
17
|
+
margins?: Partial<ChartMargins>;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
referenceLines?: readonly ReferenceLineSpec[];
|
|
21
|
+
}
|
|
22
|
+
export declare function AreaChart({ stacked, className, ...rest }: AreaChartProps): ReactElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow, type Series } from '../_shared/types';
|
|
3
|
+
export interface BarChartProps extends ChartCellProps {
|
|
4
|
+
series?: readonly Series[] | string;
|
|
5
|
+
data?: readonly ChartRow[];
|
|
6
|
+
x?: string;
|
|
7
|
+
y?: string | readonly string[];
|
|
8
|
+
label?: string;
|
|
9
|
+
value?: string | readonly string[];
|
|
10
|
+
xAxis?: AxisConfig;
|
|
11
|
+
yAxis?: AxisConfig;
|
|
12
|
+
height?: number;
|
|
13
|
+
colors?: readonly string[];
|
|
14
|
+
mode?: 'grouped' | 'stacked';
|
|
15
|
+
legend?: boolean;
|
|
16
|
+
tooltip?: boolean;
|
|
17
|
+
margins?: Partial<ChartMargins>;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function BarChart({ series, data, x, y, label, value, xAxis, yAxis, height, colors, mode, legend, tooltip, margins: marginOverride, title, description, size, baseProps, isLoading, error, className, style, }: BarChartProps): ReactElement;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow, type CurveType, type Series } from '../_shared/types';
|
|
3
|
+
export interface BarLineChartProps extends ChartCellProps {
|
|
4
|
+
barSeries?: readonly Series[];
|
|
5
|
+
lineSeries?: readonly Series[];
|
|
6
|
+
data?: readonly ChartRow[];
|
|
7
|
+
x?: string;
|
|
8
|
+
bar?: string | readonly string[];
|
|
9
|
+
line?: string | readonly string[];
|
|
10
|
+
xAxis?: AxisConfig;
|
|
11
|
+
yLeft?: AxisConfig;
|
|
12
|
+
yRight?: AxisConfig;
|
|
13
|
+
height?: number;
|
|
14
|
+
colors?: readonly string[];
|
|
15
|
+
curve?: CurveType;
|
|
16
|
+
legend?: boolean;
|
|
17
|
+
tooltip?: boolean;
|
|
18
|
+
margins?: Partial<ChartMargins>;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function BarLineChart({ barSeries, lineSeries, data, x, bar, line, xAxis, yLeft, yRight, height, colors, curve, legend, tooltip, margins: marginOverride, title, description, size, baseProps, isLoading, error, className, style, }: BarLineChartProps): ReactElement;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { type PieChartProps } from '../PieChart/PieChart';
|
|
3
|
+
export interface DonutChartProps extends Omit<PieChartProps, 'innerRadius'> {
|
|
4
|
+
innerRadius?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function DonutChart({ innerRadius, className, ...rest }: DonutChartProps): ReactElement;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type ChartRange } from '../_shared/brush-range';
|
|
3
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow, type CurveType, type ReferenceLineSpec, type Series } from '../_shared/types';
|
|
4
|
+
export type { ChartRange } from '../_shared/brush-range';
|
|
5
|
+
export interface LineChartProps extends ChartCellProps {
|
|
6
|
+
series?: readonly Series[] | string;
|
|
7
|
+
data?: readonly ChartRow[];
|
|
8
|
+
x?: string;
|
|
9
|
+
y?: string | readonly string[];
|
|
10
|
+
xAxis?: AxisConfig;
|
|
11
|
+
yAxis?: AxisConfig;
|
|
12
|
+
height?: number;
|
|
13
|
+
colors?: readonly string[];
|
|
14
|
+
markers?: boolean;
|
|
15
|
+
fill?: boolean;
|
|
16
|
+
fillOpacity?: number;
|
|
17
|
+
curve?: CurveType;
|
|
18
|
+
legend?: boolean;
|
|
19
|
+
tooltip?: boolean;
|
|
20
|
+
margins?: Partial<ChartMargins>;
|
|
21
|
+
title?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
referenceLines?: readonly ReferenceLineSpec[];
|
|
24
|
+
selectedRange?: ChartRange | null;
|
|
25
|
+
onSelectRange?: (range: ChartRange | null) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function LineChart({ series, data, x, y, xAxis, yAxis, height, colors, markers, fill, fillOpacity, curve, legend, tooltip, margins: marginOverride, title, description, referenceLines, selectedRange, onSelectRange, size, baseProps, isLoading, error, className, style, }: LineChartProps): ReactElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import type { AxisFormat, ChartCellProps, ChartRow, DataPoint } from '../_shared/types';
|
|
3
|
+
export interface MetricChartProps extends ChartCellProps {
|
|
4
|
+
label: string;
|
|
5
|
+
value?: number | string;
|
|
6
|
+
format?: AxisFormat;
|
|
7
|
+
delta?: number | string;
|
|
8
|
+
deltaFormat?: AxisFormat;
|
|
9
|
+
deltaTone?: 'success' | 'danger' | 'neutral';
|
|
10
|
+
caption?: string;
|
|
11
|
+
trend?: readonly DataPoint[];
|
|
12
|
+
data?: readonly ChartRow[];
|
|
13
|
+
x?: string;
|
|
14
|
+
y?: string;
|
|
15
|
+
trendColor?: string;
|
|
16
|
+
trendHeight?: number;
|
|
17
|
+
trendTooltip?: boolean;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function MetricChart({ label, value, format, delta, deltaFormat, deltaTone, caption, trend, data, x, y, trendColor, trendHeight, trendTooltip, title, description, size, baseProps, isLoading, error, className, style, }: MetricChartProps): ReactElement;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type Slice } from '../_shared/encodings';
|
|
3
|
+
import type { AxisFormat, ChartCellProps, ChartRow } from '../_shared/types';
|
|
4
|
+
export type PieDatum = Slice;
|
|
5
|
+
export interface PieChartProps extends ChartCellProps {
|
|
6
|
+
slices?: readonly PieDatum[];
|
|
7
|
+
data?: readonly ChartRow[];
|
|
8
|
+
label?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
height?: number;
|
|
11
|
+
colors?: readonly string[];
|
|
12
|
+
innerRadius?: number;
|
|
13
|
+
outerRadius?: number;
|
|
14
|
+
padAngle?: number;
|
|
15
|
+
sliceStroke?: string;
|
|
16
|
+
sliceStrokeWidth?: number;
|
|
17
|
+
legend?: boolean;
|
|
18
|
+
tooltip?: boolean;
|
|
19
|
+
format?: AxisFormat;
|
|
20
|
+
valueFormatter?: (value: number) => string;
|
|
21
|
+
centerLabel?: string;
|
|
22
|
+
centerSublabel?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function PieChart({ slices: slicesProp, data, label, value, height, colors, innerRadius, outerRadius, padAngle, sliceStroke, sliceStrokeWidth, legend, tooltip, format, valueFormatter, centerLabel, centerSublabel, title, description, size, baseProps, isLoading, error, className, style, }: PieChartProps): ReactElement;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow, type Series } from '../_shared/types';
|
|
3
|
+
export interface ScatterChartProps extends ChartCellProps {
|
|
4
|
+
series?: readonly Series[] | string;
|
|
5
|
+
data?: readonly ChartRow[];
|
|
6
|
+
x?: string;
|
|
7
|
+
y?: string | readonly string[];
|
|
8
|
+
label?: string;
|
|
9
|
+
xAxis?: AxisConfig;
|
|
10
|
+
yAxis?: AxisConfig;
|
|
11
|
+
height?: number;
|
|
12
|
+
colors?: readonly string[];
|
|
13
|
+
pointRadius?: number;
|
|
14
|
+
sizeKey?: string;
|
|
15
|
+
sizeRange?: readonly [number, number];
|
|
16
|
+
legend?: boolean;
|
|
17
|
+
tooltip?: boolean;
|
|
18
|
+
margins?: Partial<ChartMargins>;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function ScatterChart({ series, data, x, y, label, xAxis, yAxis, height, colors, pointRadius, sizeKey, sizeRange, legend, tooltip, margins: marginOverride, title, description, size, baseProps, isLoading, error, className, style, }: ScatterChartProps): ReactElement;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import type { AxisFormat, ChartCellProps, ChartRow, DataPoint } from '../_shared/types';
|
|
3
|
+
export interface SparklineProps extends ChartCellProps {
|
|
4
|
+
data?: readonly DataPoint[] | readonly ChartRow[];
|
|
5
|
+
x?: string;
|
|
6
|
+
y?: string;
|
|
7
|
+
height?: number;
|
|
8
|
+
color?: string;
|
|
9
|
+
fill?: boolean;
|
|
10
|
+
strokeWidth?: number;
|
|
11
|
+
tooltip?: boolean;
|
|
12
|
+
format?: AxisFormat;
|
|
13
|
+
xFormat?: AxisFormat;
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function Sparkline({ data, x, y, height, color, fill, strokeWidth, tooltip, format, xFormat, title, description, size, baseProps, isLoading, error, className, style, }: SparklineProps): ReactElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type Step } from '../_shared/encodings';
|
|
3
|
+
import { type AxisConfig, type ChartCellProps, type ChartMargins, type ChartRow } from '../_shared/types';
|
|
4
|
+
export type WaterfallBarDatum = Step;
|
|
5
|
+
export interface WaterfallChartProps extends ChartCellProps {
|
|
6
|
+
bars?: readonly WaterfallBarDatum[];
|
|
7
|
+
data?: readonly ChartRow[];
|
|
8
|
+
label?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
total?: string;
|
|
11
|
+
xAxis?: AxisConfig;
|
|
12
|
+
yAxis?: AxisConfig;
|
|
13
|
+
height?: number;
|
|
14
|
+
valueFormatter?: (v: number) => string;
|
|
15
|
+
valueLabels?: boolean;
|
|
16
|
+
margins?: Partial<ChartMargins>;
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function valueDomain(bars: readonly Pick<Step, 'base' | 'value'>[], plotHeight?: number): [number, number];
|
|
21
|
+
export declare function WaterfallChart({ bars, data, label, value, total, xAxis, yAxis, height, valueFormatter, valueLabels, margins: marginOverride, title, description, size, baseProps, isLoading, error, className, style, }: WaterfallChartProps): ReactElement;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement, ReactNode, Ref } from 'react';
|
|
2
|
+
import { type ChartLocale } from './axis-utils';
|
|
3
|
+
import type { AxisFormat, AxisType, Series } from './types';
|
|
4
|
+
export type ChartState = 'ready' | 'loading' | 'error' | 'empty';
|
|
5
|
+
export declare function chartState({ hasData, isLoading, error }: {
|
|
6
|
+
hasData: boolean;
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
error?: unknown;
|
|
9
|
+
}): ChartState;
|
|
10
|
+
export interface ChartTable {
|
|
11
|
+
columns: readonly string[];
|
|
12
|
+
rows: ReadonlyArray<ReadonlyArray<string>>;
|
|
13
|
+
}
|
|
14
|
+
export interface ChartFrameProps {
|
|
15
|
+
chartClass: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
measureRef?: Ref<HTMLDivElement>;
|
|
23
|
+
state: ChartState;
|
|
24
|
+
table?: ChartTable | null;
|
|
25
|
+
legend?: ReactNode;
|
|
26
|
+
tooltip?: ReactNode;
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
export declare function ChartFrame({ chartClass, className, style, title, description, width, height, measureRef, state, table, legend, tooltip, children, }: ChartFrameProps): ReactElement;
|
|
30
|
+
export declare function ChartDataTable({ table }: {
|
|
31
|
+
table: ChartTable;
|
|
32
|
+
}): ReactElement;
|
|
33
|
+
export interface SeriesTableOptions {
|
|
34
|
+
xLabel: string;
|
|
35
|
+
xType?: AxisType;
|
|
36
|
+
xFormat?: AxisFormat;
|
|
37
|
+
xFormatter?: (v: number | Date | string) => string;
|
|
38
|
+
yFormat?: AxisFormat;
|
|
39
|
+
yFormatter?: (v: number | Date | string) => string;
|
|
40
|
+
loc?: ChartLocale;
|
|
41
|
+
}
|
|
42
|
+
export declare function seriesTable(series: readonly Series[], opts: SeriesTableOptions): ChartTable;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AxisConfig, type AxisFormat, type ChartMargins } from './types';
|
|
2
|
+
export interface ChartLocale {
|
|
3
|
+
locale: string;
|
|
4
|
+
currency: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_LOCALE: ChartLocale;
|
|
7
|
+
export declare function chartLocale(baseProps?: unknown): ChartLocale;
|
|
8
|
+
export declare function formatValue(value: number | Date | string, format?: AxisFormat, loc?: ChartLocale): string;
|
|
9
|
+
export declare function timeTickFormatter(ticks: readonly Date[], loc?: ChartLocale): (v: number | Date | string) => string;
|
|
10
|
+
export declare function axisFormatter(config: AxisConfig | undefined, loc?: ChartLocale, fallback?: AxisFormat): (v: number | Date | string) => string;
|
|
11
|
+
export declare function targetTickCount(range: number, pixelsPerTick?: number): number;
|
|
12
|
+
export declare function estimateLabelWidth(text: string): number;
|
|
13
|
+
export declare function computeYAxisMargin(sampleValues: readonly (number | Date | string)[], format?: AxisFormat, formatter?: (v: number | Date | string) => string, min?: number, loc?: ChartLocale): number;
|
|
14
|
+
export declare const NARROW_MARGINS: ChartMargins;
|
|
15
|
+
export declare function chartMargins({ narrow, yTicks, yAxis, loc, override, }: {
|
|
16
|
+
narrow: boolean;
|
|
17
|
+
yTicks: readonly (number | Date | string)[];
|
|
18
|
+
yAxis?: AxisConfig;
|
|
19
|
+
loc?: ChartLocale;
|
|
20
|
+
override?: Partial<ChartMargins>;
|
|
21
|
+
}): ChartMargins;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AxisType } from './types';
|
|
2
|
+
export type ChartRange = readonly [number | string | Date, number | string | Date];
|
|
3
|
+
export declare function asChartRange(value: unknown): ChartRange | null;
|
|
4
|
+
type OrdinalScale = {
|
|
5
|
+
(v: string): number | undefined;
|
|
6
|
+
domain: () => string[];
|
|
7
|
+
step?: () => number;
|
|
8
|
+
};
|
|
9
|
+
export declare function invertPointScale(scale: OrdinalScale, selection: readonly [number, number]): [string, string] | null;
|
|
10
|
+
export declare function projectPointRange(scale: {
|
|
11
|
+
(v: string): number | undefined;
|
|
12
|
+
step?: () => number;
|
|
13
|
+
}, from: string, to: string): {
|
|
14
|
+
x: number;
|
|
15
|
+
width: number;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function projectRange(range: ChartRange | null | undefined, xScale: unknown, xType: AxisType): {
|
|
18
|
+
x: number;
|
|
19
|
+
width: number;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function rangeFromPixels(selection: readonly [number, number], xScale: unknown, xType: AxisType): ChartRange | null;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AxisType, DataPoint, Series, XYEncodings } from './types';
|
|
2
|
+
export declare function toNumber(value: unknown): number | null;
|
|
3
|
+
export declare function toX(value: unknown): DataPoint['x'] | null;
|
|
4
|
+
export declare function cleanSeries(series: readonly unknown[]): Series[];
|
|
5
|
+
export declare function toSeries(enc: XYEncodings): Series[];
|
|
6
|
+
export declare function toPoints(data: unknown, keys?: {
|
|
7
|
+
x?: string;
|
|
8
|
+
y?: string;
|
|
9
|
+
}): DataPoint[];
|
|
10
|
+
export interface Slice {
|
|
11
|
+
id: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
value: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function toSlices(data: unknown, keys?: {
|
|
17
|
+
label?: string;
|
|
18
|
+
value?: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
}): Slice[];
|
|
21
|
+
export declare function cleanSlices(slices: readonly unknown[]): Slice[];
|
|
22
|
+
export interface Step {
|
|
23
|
+
label: string;
|
|
24
|
+
base: number;
|
|
25
|
+
value: number;
|
|
26
|
+
display: number;
|
|
27
|
+
color?: string;
|
|
28
|
+
total?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function cleanSteps(bars: readonly unknown[]): Step[];
|
|
31
|
+
export declare function toSteps(data: unknown, keys?: {
|
|
32
|
+
label?: string;
|
|
33
|
+
value?: string;
|
|
34
|
+
total?: string;
|
|
35
|
+
}): Step[];
|
|
36
|
+
export declare function inferXType(series: readonly Series[]): AxisType;
|
|
37
|
+
export declare const hasPoints: (series: readonly Series[]) => boolean;
|
|
38
|
+
export declare function xValues(series: readonly Series[]): Array<{
|
|
39
|
+
key: string;
|
|
40
|
+
x: DataPoint['x'];
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tone } from '@stack/core';
|
|
2
|
+
export declare const CHART_SERIES_COUNT = 8;
|
|
3
|
+
export declare function seriesToken(index: number): string;
|
|
4
|
+
export declare function toneColor(tone: Tone): string;
|
|
5
|
+
export declare function resolveColor(declared: string | undefined | null): string | undefined;
|
|
6
|
+
export declare function resolveSeriesColor(declared: string | undefined | null, index: number): string;
|
|
7
|
+
export declare function chartColors(seriesCount: number, override?: readonly (string | undefined)[]): string[];
|
|
8
|
+
export declare function useChartColors(seriesCount: number, override?: readonly (string | undefined)[]): string[];
|
|
9
|
+
export declare function seriesColors(series: readonly {
|
|
10
|
+
color?: string;
|
|
11
|
+
}[], override?: readonly (string | undefined)[]): string[];
|
|
12
|
+
export declare function markerPath(index: number, size?: number): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AxisType, ReferenceLineSpec } from './types';
|
|
2
|
+
export interface ProjectedReferenceLine {
|
|
3
|
+
key: string;
|
|
4
|
+
x?: number;
|
|
5
|
+
y?: number;
|
|
6
|
+
stroke?: string;
|
|
7
|
+
strokeDasharray?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
labelPosition?: ReferenceLineSpec['labelPosition'];
|
|
10
|
+
labelColor?: string;
|
|
11
|
+
labelFontSize?: number;
|
|
12
|
+
}
|
|
13
|
+
interface ProjectArgs {
|
|
14
|
+
xType: AxisType;
|
|
15
|
+
xScale: unknown;
|
|
16
|
+
yScale: (v: number) => number;
|
|
17
|
+
}
|
|
18
|
+
export declare function projectReferenceLines(specs: readonly ReferenceLineSpec[] | undefined, { xType, xScale, yScale }: ProjectArgs): ProjectedReferenceLine[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ScaleBand, type ScaleLinear, type ScalePoint, type ScaleTime } from 'd3-scale';
|
|
2
|
+
import type { AxisType, DataPoint, Series } from './types';
|
|
3
|
+
export declare function buildYScale(series: readonly Series[], range: [number, number], options?: {
|
|
4
|
+
includeZero?: boolean;
|
|
5
|
+
stacked?: boolean;
|
|
6
|
+
}): ScaleLinear<number, number>;
|
|
7
|
+
export declare function buildXLinearScale(series: readonly Series[], range: [number, number]): ScaleLinear<number, number>;
|
|
8
|
+
export declare function buildXTimeScale(series: readonly Series[], range: [number, number]): ScaleTime<number, number>;
|
|
9
|
+
export declare function buildXBandScale(series: readonly Series[], range: [number, number], padding?: number): ScaleBand<string>;
|
|
10
|
+
export declare function buildXPointScale(series: readonly Series[], range: [number, number]): ScalePoint<string>;
|
|
11
|
+
export declare function orderedXKeys(series: readonly Series[]): string[];
|
|
12
|
+
export declare function pointXKey(p: Pick<DataPoint, 'x'>): string;
|
|
13
|
+
export declare function coerceX(x: DataPoint['x'], type: AxisType): number | string;
|
|
14
|
+
export declare function xPosition(scale: unknown, type: AxisType, p: Pick<DataPoint, 'x'>): number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export interface DataPoint {
|
|
3
|
+
x: number | string | Date;
|
|
4
|
+
y: number;
|
|
5
|
+
[extra: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface Series<T extends DataPoint = DataPoint> {
|
|
8
|
+
id: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
color?: string;
|
|
11
|
+
strokeDasharray?: string;
|
|
12
|
+
data: T[];
|
|
13
|
+
}
|
|
14
|
+
export type ChartRow = Readonly<Record<string, unknown>>;
|
|
15
|
+
export interface XYEncodings {
|
|
16
|
+
data?: readonly ChartRow[];
|
|
17
|
+
x?: string;
|
|
18
|
+
y?: string | readonly string[];
|
|
19
|
+
series?: readonly Series[] | string;
|
|
20
|
+
}
|
|
21
|
+
export interface CategoryEncodings {
|
|
22
|
+
data?: readonly ChartRow[];
|
|
23
|
+
label?: string;
|
|
24
|
+
value?: string | readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ChartSize {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ChartCellProps {
|
|
31
|
+
size?: ChartSize;
|
|
32
|
+
baseProps?: unknown;
|
|
33
|
+
isLoading?: boolean;
|
|
34
|
+
error?: Error | string | null;
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
}
|
|
38
|
+
export type AxisType = 'time' | 'linear' | 'band';
|
|
39
|
+
export type AxisFormat = 'date' | 'date-short' | 'currency' | 'percent' | 'number' | 'compact';
|
|
40
|
+
export interface AxisConfig {
|
|
41
|
+
type?: AxisType;
|
|
42
|
+
format?: AxisFormat;
|
|
43
|
+
label?: string;
|
|
44
|
+
formatter?: (value: number | Date | string) => string;
|
|
45
|
+
ticks?: number;
|
|
46
|
+
axisLine?: boolean;
|
|
47
|
+
tickLine?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface ReferenceLineSpec {
|
|
50
|
+
x?: number | string | Date;
|
|
51
|
+
y?: number;
|
|
52
|
+
color?: string;
|
|
53
|
+
strokeDasharray?: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
labelPosition?: 'top' | 'insideTopLeft' | 'insideTopRight' | 'insideBottomLeft' | 'insideBottomRight';
|
|
56
|
+
labelColor?: string;
|
|
57
|
+
labelFontSize?: number;
|
|
58
|
+
}
|
|
59
|
+
export type CurveType = 'linear' | 'monotone';
|
|
60
|
+
export interface ChartMargins {
|
|
61
|
+
top: number;
|
|
62
|
+
right: number;
|
|
63
|
+
bottom: number;
|
|
64
|
+
left: number;
|
|
65
|
+
}
|
|
66
|
+
export declare const DEFAULT_MARGINS: ChartMargins;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { ChartSize } from './types';
|
|
3
|
+
export interface ChartDimensions {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const NARROW_WIDTH = 480;
|
|
8
|
+
export declare const isNarrow: (width: number) => boolean;
|
|
9
|
+
export declare function useDimensions(height: number, size?: ChartSize): {
|
|
10
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
11
|
+
dims: ChartDimensions;
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type FocusEvent, type KeyboardEvent } from 'react';
|
|
2
|
+
export interface FocusIndex {
|
|
3
|
+
row: number;
|
|
4
|
+
col: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UseChartFocusArgs {
|
|
7
|
+
lengths: readonly number[];
|
|
8
|
+
onFocusTarget: (row: number, col: number, el: Element) => void;
|
|
9
|
+
onBlurTarget: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface ChartTargetProps {
|
|
12
|
+
tabIndex: 0 | -1;
|
|
13
|
+
ref: (el: SVGElement | null) => void;
|
|
14
|
+
onFocus: (e: FocusEvent<SVGElement>) => void;
|
|
15
|
+
onBlur: () => void;
|
|
16
|
+
onKeyDown: (e: KeyboardEvent<SVGElement>) => void;
|
|
17
|
+
'data-focused'?: 'true';
|
|
18
|
+
}
|
|
19
|
+
export declare function nextFocus(lengths: readonly number[], at: FocusIndex, key: string): FocusIndex | null;
|
|
20
|
+
export declare function useChartFocus({ lengths, onFocusTarget, onBlurTarget }: UseChartFocusArgs): {
|
|
21
|
+
focused: FocusIndex | null;
|
|
22
|
+
targetProps: (row: number, col: number) => ChartTargetProps;
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PointerEvent } from 'react';
|
|
2
|
+
export interface HoverState<P> {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
payload: P;
|
|
6
|
+
}
|
|
7
|
+
export interface UseChartHoverArgs<P> {
|
|
8
|
+
viewBoxWidth: number;
|
|
9
|
+
viewBoxHeight: number;
|
|
10
|
+
findNearest: (svgX: number, svgY: number) => {
|
|
11
|
+
payload: P;
|
|
12
|
+
anchorX: number;
|
|
13
|
+
anchorY: number;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
export interface UseChartHoverResult<P> {
|
|
17
|
+
hover: HoverState<P> | null;
|
|
18
|
+
onPointerMove: (e: PointerEvent<SVGElement>) => void;
|
|
19
|
+
onPointerLeave: () => void;
|
|
20
|
+
showAt: (payload: P, anchorX: number, anchorY: number, from?: Element | null) => void;
|
|
21
|
+
hide: () => void;
|
|
22
|
+
}
|
|
23
|
+
export declare function useChartHover<P>({ viewBoxWidth, viewBoxHeight, findNearest }: UseChartHoverArgs<P>): UseChartHoverResult<P>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { type ChartLocale } from '../../_shared/axis-utils';
|
|
3
|
+
import type { AxisConfig, ChartMargins } from '../../_shared/types';
|
|
4
|
+
type Scale = {
|
|
5
|
+
(v: never): number;
|
|
6
|
+
ticks?: (count?: number) => unknown[];
|
|
7
|
+
domain: () => unknown[];
|
|
8
|
+
bandwidth?: () => number;
|
|
9
|
+
};
|
|
10
|
+
export interface AxisProps {
|
|
11
|
+
orientation: 'bottom' | 'left' | 'right';
|
|
12
|
+
scale: Scale;
|
|
13
|
+
margins: ChartMargins;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
config?: AxisConfig;
|
|
17
|
+
gridlines?: boolean;
|
|
18
|
+
locale?: ChartLocale;
|
|
19
|
+
narrow?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function Axis({ orientation, scale, margins, width, height, config, gridlines, locale, narrow }: AxisProps): ReactElement;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
export interface ChartTooltipRow {
|
|
3
|
+
id: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
value: ReactNode;
|
|
6
|
+
color?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ChartTooltipProps {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
visible: boolean;
|
|
12
|
+
containerWidth?: number;
|
|
13
|
+
heading?: ReactNode;
|
|
14
|
+
rows?: readonly ChartTooltipRow[];
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare function ChartTooltip({ x, y, visible, containerWidth, heading, rows, children }: ChartTooltipProps): ReactElement | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
export interface LegendItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
color: string;
|
|
6
|
+
kind?: 'square' | 'line' | 'marker';
|
|
7
|
+
dash?: string;
|
|
8
|
+
marker?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LegendProps {
|
|
11
|
+
items: readonly LegendItem[];
|
|
12
|
+
}
|
|
13
|
+
export declare function Legend({ items }: LegendProps): ReactElement | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { ChartMargins } from '../../_shared/types';
|
|
3
|
+
export interface PlotAreaProps {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
margins: ChartMargins;
|
|
7
|
+
background?: ReactNode;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
overlay?: ReactNode;
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
interactive?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function PlotArea({ width, height, margins, background, children, overlay, title, description, interactive }: PlotAreaProps): ReactElement;
|