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

feat(marker): add MarkerCircle2, same as Circle but default refX to mid point instead of zero. fixes #1756 #1840

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions packages/visx-demo/src/sandboxes/visx-curve/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as allCurves from '@visx/curve';
import { Group } from '@visx/group';
import { LinePath } from '@visx/shape';
import { scaleTime, scaleLinear } from '@visx/scale';
import { MarkerArrow, MarkerCross, MarkerX, MarkerCircle, MarkerLine } from '@visx/marker';
import { MarkerArrow, MarkerCross, MarkerX, MarkerCircle2, MarkerLine } from '@visx/marker';
import generateDateValue, { DateValue } from '@visx/mock-data/lib/generators/genDateValue';

type CurveType = keyof typeof allCurves;
Expand Down Expand Up @@ -89,7 +89,7 @@ export default function Example({ width, height, showControls = true }: CurvePro
strokeOpacity={0.6}
markerUnits="userSpaceOnUse"
/>
<MarkerCircle id="marker-circle" fill="#333" size={2} refX={2} />
<MarkerCircle2 id="marker-circle" fill="#333" size={2} />
<MarkerArrow id="marker-arrow-odd" stroke="#333" size={8} strokeWidth={1} />
<MarkerLine id="marker-line" fill="#333" size={16} strokeWidth={1} />
<MarkerArrow id="marker-arrow" fill="#333" refX={2} size={6} />
Expand Down
1 change: 1 addition & 0 deletions packages/visx-marker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { default as MarkerArrow } from './markers/Arrow';
export { default as MarkerCross } from './markers/Cross';
export { default as MarkerX } from './markers/X';
export { default as MarkerCircle } from './markers/Circle';
export { default as MarkerCircle2 } from './markers/Circle2';
export { default as MarkerLine } from './markers/Line';
28 changes: 28 additions & 0 deletions packages/visx-marker/src/markers/Circle2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import Marker, { MarkerComponentProps } from './Marker';

export default function MarkerCircle2({
id,
size = 9,
strokeWidth = 1,
...restProps
}: MarkerComponentProps) {
const diameter = size * 2;
const bounds = diameter + strokeWidth;
const mid = bounds / 2;
return (
<Marker
id={id}
markerWidth={bounds}
markerHeight={bounds}
refX={mid}
refY={mid}
orient="auto-start-reverse"
markerUnits="strokeWidth"
strokeWidth={strokeWidth}
{...restProps}
>
<circle r={size} cx={mid} cy={mid} />
</Marker>
);
}
36 changes: 36 additions & 0 deletions packages/visx-marker/test/Circle2.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { shallow } from 'enzyme';
import { MarkerCircle2, Marker } from '../src';

const Wrapper = (restProps = {}) =>
shallow(<MarkerCircle2 id="marker-circle-test" {...restProps} />);

describe('<MarkerCircle />', () => {
test('it should be defined', () => {
expect(MarkerCircle2).toBeDefined();
});

test('it should render a <Marker> containing a <circle>', () => {
const marker = Wrapper().find(Marker);
const circle = marker.dive().find('circle');
expect(marker).toHaveLength(1);
expect(circle).toHaveLength(1);
});

test('it should size correctly', () => {
const size = 8;
const strokeWidth = 1;
const marker = Wrapper({ size, strokeWidth }).find(Marker);
const circle = marker.dive().find('circle');
const diameter = size * 2;
const bounds = diameter + strokeWidth;
const mid = bounds / 2;
expect(marker.prop('markerWidth')).toEqual(bounds);
expect(marker.prop('markerHeight')).toEqual(bounds);
expect(marker.prop('refX')).toEqual(mid);
expect(marker.prop('refY')).toEqual(mid);
expect(circle.prop('r')).toEqual(size);
expect(circle.prop('cx')).toEqual(mid);
expect(circle.prop('cy')).toEqual(mid);
});
});
Loading