Skip to content

Commit

Permalink
fix(xychart, annotation): optional dataKey, label styles (#1072)
Browse files Browse the repository at this point in the history
* fix(xychart/BaseAnnotation): make dataKey optional

* fix(annotation/Label): add fontFamily to sub/titleStyle
  • Loading branch information
williaster authored Feb 18, 2021
1 parent a8aa0ce commit fb6ef2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit fb6ef2e

Please sign in to comment.