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(annotation/Label): fix doc types and padding #989

Merged
merged 2 commits into from
Jan 11, 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
6 changes: 3 additions & 3 deletions packages/visx-annotation/src/components/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ function getCompletePadding(padding: LabelProps['backgroundPadding']) {
if (typeof padding === 'number') {
return { top: padding, right: padding, bottom: padding, left: padding };
}
return { ...DEFAULT_PADDING, padding };
return { ...DEFAULT_PADDING, ...padding };
}

export default function AnnotationLabel({
anchorLineStroke,
export default function Label({
anchorLineStroke = '#222',
backgroundFill = '#eaeaea',
backgroundPadding,
backgroundProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint jsx-a11y/label-has-associated-control: 'off', @typescript-eslint/no-explicit-any: 'off' */
import React, { useMemo, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import appleStock, { AppleStock } from '@visx/mock-data/lib/mocks/appleStock';
import { PickD3Scale, scaleTime, scaleLinear } from '@visx/scale';
import { extent } from 'd3-array';
Expand Down Expand Up @@ -86,6 +86,14 @@ export default function ExampleControls({
dx: compact ? -50 : -100,
dy: compact ? -30 : -50,
});
// update annotation position when scale's change
useEffect(() => {
setAnnotationPosition(currPosition => ({
...currPosition,
x: xScale(getDate(annotateDatum)) ?? 0,
y: yScale(getStockValue(annotateDatum)) ?? 0,
}));
}, [xScale, yScale]);

return (
<>
Expand Down