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

[86by6f2gg][d3-chart] added compact horizontal bar chart #1477

Merged
merged 19 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 6 additions & 0 deletions semcore/d3-chart/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).

## [3.50.0] - 2024-06-28

### Added

- `CompactHorizontalBar` chart.

## [3.49.0] - 2024-07-13

### Changed
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions semcore/d3-chart/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Line,
Donut,
HorizontalBar,
CompactHorizontalBar,
GroupBar,
minMax,
Area,
Expand Down Expand Up @@ -2638,6 +2639,85 @@ describe('d3 charts visual regression', () => {

await expect(await snapshot(<Component />)).toMatchImageSnapshot(task);
});

test.concurrent('should render Compact horizontal bar chart', async ({ task }) => {
const data = [
{
category: 'Schema.org (Microdata)',
value: 0,
},
{
category: 'Open graph',
value: 9650,
},
{
category: 'Twitter cards',
value: 7650,
},
{
category: 'Microformats',
value: 14650,
},
{
category: 'Schema.org (JSON-LD)',
value: 135650,
},
];

const Component: React.FC = () => {
const MARGIN = 30;
const width = 500;
const height = 500;

const sum = data.reduce((acc, d) => acc + d.value, 0);

const xScale = scaleLinear().range([0, width]).domain([0, sum]);

const yScale = scaleBand()
.range([height - MARGIN, MARGIN])
.domain([...data].reverse().map((d) => d.category))
.paddingInner(0.6)
.paddingOuter(0.2);

return (
<Plot data={data} scale={[xScale, yScale]} width={width} height={height}>
<CompactHorizontalBar x='value' y='category'>
<CompactHorizontalBar.Hover />
<CompactHorizontalBar.Tooltip>
{({ index }: any) => {
return {
children: (
<>
<CompactHorizontalBar.Tooltip.Title>
{data[index].category}
</CompactHorizontalBar.Tooltip.Title>
<Flex justifyContent='space-between'>
<CompactHorizontalBar.Tooltip.Dot mr={4}>
Bar
</CompactHorizontalBar.Tooltip.Dot>
<Text bold>{data[index].value}</Text>
</Flex>
</>
),
};
}}
</CompactHorizontalBar.Tooltip>
<CompactHorizontalBar.Annotation>
<CompactHorizontalBar.Label />
<CompactHorizontalBar.Percent />
<CompactHorizontalBar.Value />
</CompactHorizontalBar.Annotation>
<CompactHorizontalBar.Bar>
<CompactHorizontalBar.Bar.Background />
<CompactHorizontalBar.Bar.Fill />
</CompactHorizontalBar.Bar>
</CompactHorizontalBar>
</Plot>
);
};

await expect(await snapshot(<Component />)).toMatchImageSnapshot(task);
});
});

describe('Focus skip to content after plot', () => {
Expand Down
Loading
Loading