Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xychart, annotation): optional dataKey, label styles #1072

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/visx-annotation/src/components/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,24 @@ export default function Label({
return { x: adjustedX, y: adjustedY };
}, [propsX, x, dx, propsY, y, dy, horizontalAnchor, verticalAnchor, width, height]);

const titleFontFamily = titleProps?.fontFamily;
const titleStyle = useMemo(
() => ({
fontSize: titleFontSize,
fontWeight: titleFontWeight,
fontFamily: titleFontFamily,
}),
[titleFontSize, titleFontWeight],
[titleFontSize, titleFontWeight, titleFontFamily],
) as React.CSSProperties;

const subtitleFontFamily = subtitleProps?.fontFamily;
const subtitleStyle = useMemo(
() => ({
fontSize: subtitleFontSize,
fontWeight: subtitleFontWeight,
fontFamily: subtitleFontFamily,
}),
[subtitleFontSize, subtitleFontWeight],
[subtitleFontSize, subtitleFontWeight, subtitleFontFamily],
) as React.CSSProperties;

const anchorLineOrientation = Math.abs(dx) > Math.abs(dy) ? 'vertical' : 'horizontal';
Expand Down Expand Up @@ -177,7 +181,6 @@ export default function Label({
)}
{title && (
<Text
// @ts-ignore useMeasure expects HTML ref
innerRef={titleRef}
fill={fontColor}
verticalAnchor="start"
Expand All @@ -193,7 +196,6 @@ export default function Label({
)}
{subtitle && (
<Text
// @ts-ignore useMeasure expects HTML ref
innerRef={subtitleRef}
fill={fontColor}
verticalAnchor="start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type BaseAnnotationProps<
/** Annotation component to render. */
AnnotationComponent: React.FC<AnnotationProps> | React.FC<EditableAnnotationProps>;
/** Key for series to which datum belongs (used for x/yAccessors). Alternatively xAccessor + yAccessor may be specified. */
dataKey: string;
dataKey?: string;
/** Datum to annotate, used for Annotation positioning. */
datum: Datum;
/** If dataKey is not specified, you must specify an xAccessor for datum. */
Expand Down Expand Up @@ -63,7 +63,8 @@ export default function BaseAnnotation<
return null;
}

const registryEntry = propsXAccessor && propsYAccessor ? null : dataRegistry?.get(dataKey);
const registryEntry =
(propsXAccessor && propsYAccessor) || dataKey == null ? null : dataRegistry?.get(dataKey);
const xAccessor = propsXAccessor || registryEntry?.xAccessor;
const yAccessor = propsYAccessor || registryEntry?.yAccessor;

Expand Down