Skip to content

Commit

Permalink
fix(annotation/Label): fix doc types and padding (#989)
Browse files Browse the repository at this point in the history
* fix(annotation/Label): fix doc types, add default anchorLineStroke, fix object padding

* fix(demo/annotation): update position on scale changes
  • Loading branch information
williaster authored Jan 11, 2021
1 parent bb4431e commit d6db693
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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

0 comments on commit d6db693

Please sign in to comment.