Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ export function BaseGlyphSeries<
if (!isValidNumber(y)) return null;
return {
key: `${i}`,
index: i,
x,
y,
color: colorAccessor?.(datum, i) ?? color,
size: typeof size === 'function' ? size(datum) : size,
datum,
};
})
.filter((point) => point) as GlyphProps<Datum>[],
.filter((point) => !!point) satisfies GlyphProps<Datum>[],
[color, colorAccessor, data, getScaledX, getScaledY, size],
);

Expand Down
11 changes: 9 additions & 2 deletions packages/visx-xychart/test/components/GlyphSeries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { vi } from 'vitest';
import React, { useContext, useEffect } from 'react';
import { render, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import type { GlyphProps } from '../../src';
import { AnimatedGlyphSeries, DataContext, GlyphSeries, useEventEmitter } from '../../src';
import getDataContext from '../mocks/getDataContext';
import setupTooltipTest from '../mocks/setupTooltipTest';
Expand Down Expand Up @@ -59,15 +60,21 @@ describe('<GlyphSeries />', () => {
});

it('should render a custom Glyph for each Datum', () => {
const customRenderGlyph = () => <rect className="custom-glyph" />;
const customRenderGlyph = (props: GlyphProps<{}>) => (
<rect className="custom-glyph" data-index={props.index} />
);
const { container } = render(
<DataContext.Provider value={getDataContext({ key: 'glyph', ...series })}>
<svg>
<GlyphSeries dataKey={'glyph'} {...series} renderGlyph={customRenderGlyph} />
</svg>
</DataContext.Provider>,
);
expect(container.querySelectorAll('.custom-glyph')).toHaveLength(series.data.length);
const glyphs = container.querySelectorAll('.custom-glyph');

expect(glyphs).toHaveLength(series.data.length);
expect(glyphs[0]).toHaveAttribute('data-index', '0');
expect(glyphs[1]).toHaveAttribute('data-index', '1');
});

it('should invoke showTooltip/hideTooltip on pointermove/pointerout', async () => {
Expand Down