Skip to content

Commit 4b27d18

Browse files
committed
Organize LineChart types and exports
1 parent f6cf4f1 commit 4b27d18

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export { default as LineChart } from './line-chart';
22
export type {
3+
AnnotationStyles,
4+
LineChartAnnotationProps,
35
RenderLineStartGlyphProps,
46
LineChartProps,
57
TooltipDatum,
68
CurveType,
7-
} from './line-chart';
8-
export type { AnnotationStyles } from './types';
9+
} from './types';

projects/js-packages/charts/src/components/line-chart/line-chart.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,16 @@ import { withResponsive } from '../private/with-responsive';
2727
import { AccessibleTooltip, useKeyboardNavigation } from '../tooltip';
2828
import styles from './line-chart.module.scss';
2929
import { LineChartAnnotation, LineChartAnnotationsOverlay } from './private';
30-
import type { BaseChartProps, DataPoint, DataPointDate, SeriesData, Optional } from '../../types';
30+
import type { CurveType, RenderLineStartGlyphProps, LineChartProps, TooltipDatum } from './types';
31+
import type { DataPoint, DataPointDate, SeriesData, Optional } from '../../types';
3132
import type { ResponsiveConfig } from '../private/with-responsive';
3233
import type { TickFormatter } from '@visx/axis';
3334
import type { GlyphProps } from '@visx/xychart';
3435
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
3536
import type { FC, ReactNode, Ref, SVGProps } from 'react';
3637

37-
export type CurveType = 'smooth' | 'linear' | 'monotone';
38-
3938
const X_TICK_WIDTH = 100;
4039

41-
export type RenderLineStartGlyphProps< Datum extends object > = GlyphProps< Datum > & {
42-
glyphStyle?: SVGProps< SVGCircleElement >;
43-
};
44-
4540
const defaultRenderGlyph = < Datum extends object >(
4641
props: RenderLineStartGlyphProps< Datum >
4742
) => {
@@ -116,27 +111,6 @@ const getCurveType = ( type?: CurveType, smoothing?: boolean ) => {
116111
}
117112
};
118113

119-
export interface LineChartProps extends BaseChartProps< SeriesData[] > {
120-
withGradientFill: boolean;
121-
smoothing?: boolean;
122-
curveType?: CurveType;
123-
renderTooltip?: ( params: RenderTooltipParams< DataPointDate > ) => ReactNode;
124-
withStartGlyphs?: boolean;
125-
renderGlyph?: < Datum extends object >( props: GlyphProps< Datum > ) => ReactNode;
126-
glyphStyle?: SVGProps< SVGCircleElement >;
127-
withLegendGlyph?: boolean;
128-
withTooltipCrosshairs?: {
129-
showVertical?: boolean;
130-
showHorizontal?: boolean;
131-
};
132-
children?: ReactNode;
133-
}
134-
135-
export type TooltipDatum = {
136-
key: string;
137-
value: number;
138-
};
139-
140114
const renderDefaultTooltip = ( params: RenderTooltipParams< DataPointDate > ) => {
141115
const { tooltipData } = params;
142116
const nearestDatum = tooltipData?.nearestDatum?.datum;

projects/js-packages/charts/src/components/line-chart/private/line-chart-annotation.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { isSafari } from '../../../utils';
1414
import LineChartAnnotationLabelWithPopover, {
1515
POPOVER_BUTTON_SIZE,
1616
} from './line-chart-annotation-label-popover';
17-
import type { DataPointDate } from '../../../types';
18-
import type { AnnotationStyles } from '../types';
17+
import type { LineChartAnnotationProps } from '../types';
1918
import type { LabelProps } from '@visx/annotation/lib/components/Label';
2019
import type { TextProps } from '@visx/text';
2120
import type { FC } from 'react';
@@ -25,17 +24,6 @@ type SubjectType = 'circle' | 'line-vertical' | 'line-horizontal';
2524
const ANNOTATION_MAX_WIDTH = 125; // visx default
2625
const ANNOTATION_INIT_HEIGHT = 100;
2726

28-
export type LineChartAnnotationProps = {
29-
datum: DataPointDate;
30-
title: string;
31-
subtitle?: string;
32-
subjectType?: SubjectType;
33-
styles?: AnnotationStyles;
34-
testId?: string;
35-
renderLabel?: FC< { title: string; subtitle?: string } >;
36-
renderLabelPopover?: FC< { title: string; subtitle?: string } >;
37-
};
38-
3927
export const getLabelPosition = ( {
4028
subjectType,
4129
x,
Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import type { CircleSubjectProps } from '@visx/annotation/lib/components/CircleSubject';
2-
import type { ConnectorProps } from '@visx/annotation/lib/components/Connector';
3-
import type { LabelProps } from '@visx/annotation/lib/components/Label';
4-
import type { LineSubjectProps } from '@visx/annotation/lib/components/LineSubject';
1+
import { CircleSubjectProps } from '@visx/annotation/lib/components/CircleSubject';
2+
import { ConnectorProps } from '@visx/annotation/lib/components/Connector';
3+
import { LabelProps } from '@visx/annotation/lib/components/Label';
4+
import { LineSubjectProps } from '@visx/annotation/lib/components/LineSubject';
5+
import type { BaseChartProps, DataPointDate, SeriesData } from '../../types';
6+
import type { GlyphProps } from '@visx/xychart';
7+
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
8+
import type { ReactNode, SVGProps, FC } from 'react';
59

610
export type AnnotationStyles = {
711
circleSubject?: Omit< CircleSubjectProps, 'x' | 'y' > & { fill?: string };
@@ -12,3 +16,41 @@ export type AnnotationStyles = {
1216
y?: number | 'start' | 'end';
1317
};
1418
};
19+
20+
export type LineChartAnnotationProps = {
21+
datum: DataPointDate;
22+
title: string;
23+
subtitle?: string;
24+
subjectType?: 'circle' | 'line-vertical' | 'line-horizontal';
25+
styles?: AnnotationStyles;
26+
testId?: string;
27+
renderLabel?: FC< { title: string; subtitle?: string } >;
28+
renderLabelPopover?: FC< { title: string; subtitle?: string } >;
29+
};
30+
31+
export type CurveType = 'smooth' | 'linear' | 'monotone';
32+
33+
export type RenderLineStartGlyphProps< Datum extends object > = GlyphProps< Datum > & {
34+
glyphStyle?: SVGProps< SVGCircleElement >;
35+
};
36+
37+
export interface LineChartProps extends BaseChartProps< SeriesData[] > {
38+
withGradientFill: boolean;
39+
smoothing?: boolean;
40+
curveType?: CurveType;
41+
renderTooltip?: ( params: RenderTooltipParams< DataPointDate > ) => ReactNode;
42+
withStartGlyphs?: boolean;
43+
renderGlyph?: < Datum extends object >( props: GlyphProps< Datum > ) => ReactNode;
44+
glyphStyle?: SVGProps< SVGCircleElement >;
45+
withLegendGlyph?: boolean;
46+
withTooltipCrosshairs?: {
47+
showVertical?: boolean;
48+
showHorizontal?: boolean;
49+
};
50+
children?: ReactNode;
51+
}
52+
53+
export type TooltipDatum = {
54+
key: string;
55+
value: number;
56+
};

projects/js-packages/charts/src/components/private/default-glyph/default-glyph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataContext } from '@visx/xychart';
22
import { useContext } from 'react';
3-
import type { RenderLineStartGlyphProps } from '../../line-chart/line-chart';
3+
import type { RenderLineStartGlyphProps } from '../../line-chart';
44

55
export const DefaultGlyph = < Datum extends object >(
66
props: RenderLineStartGlyphProps< Datum >

0 commit comments

Comments
 (0)