Skip to content

Commit

Permalink
fix rect animation
Browse files Browse the repository at this point in the history
  • Loading branch information
holtzy committed Jul 24, 2024
1 parent 8518ef4 commit 6cc59d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions viz/PopulationPyramidArt/plot/HistogramLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const HistogramLayer = ({
return [...new Set(data.map((d) => d.AgeGrpStart))];
}, [data]);

const yScale = scaleBand().range([height, 0]).domain(allAges).padding(0.01);
const yScale = scaleBand().range([height, 0]).domain(allAges).padding(0.4);

const allRectFemales = data.map((d) => {
if (Number(d.PopFemale) === 0) {
Expand All @@ -35,7 +35,7 @@ export const HistogramLayer = ({
x={xScaleFemale(0)}
y={yScale(d.AgeGrpStart) || 0}
width={xScaleFemale(Number(d.PopFemale)) - xScaleFemale(0)}
height={8}
height={yScale.bandwidth()}
opacity={histogramOpacity}
color="white"
value={Number(d.PopFemale)}
Expand All @@ -56,7 +56,7 @@ export const HistogramLayer = ({
x={xScaleMale(Number(d.PopMale))}
y={yScale(d.AgeGrpStart) || 0}
width={xScaleMale(0) - xScaleMale(Number(d.PopMale))}
height={8}
height={yScale.bandwidth()}
opacity={histogramOpacity}
color="white"
value={Number(d.PopMale)}
Expand Down
2 changes: 1 addition & 1 deletion viz/PopulationPyramidArt/plot/RectItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const RectItem = ({
opacity={springProps.opacity}
width={springProps.width}
height={height}
x={x}
x={springProps.x}
y={y}
/>
{value > 0.1 && (
Expand Down
25 changes: 12 additions & 13 deletions viz/PopulationPyramidArt/sections/WeirdosSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import { Legend } from '../plot/Legend';
import { DataItem } from '../types';
import { HorizontalTabBar } from '../HorizontalTabBar';

const weirdCountries = [
'Sint Maarten',
'Qatar',
'Monaco',
'Japan',
'Bahrain',
'Italy',
];

type WeirdosSectionProps = {
data: DataItem[];
allGroupsWithCode: string[];
Expand All @@ -25,6 +16,14 @@ export const WeirdosSection = ({
const [highlightedYear, setHighlightedYear] = useState<number | undefined>();
const [selectedGroup, setSelectedGroup] = useState(0);

const weirdCountriesWithCode = allGroupsWithCode.filter((d) =>
['Sint Maarten', 'Qatar', 'Monaco', 'Japan', 'Bahrain', 'Italy'].includes(
d.split('---')[0]
)
);

const weirdCountries = weirdCountriesWithCode.map((c) => c.split('---')[0]);

const selectedData = data
.filter((d) => d.Location === weirdCountries[selectedGroup])
.filter((d) => Number(d.Time) === 2024);
Expand All @@ -34,9 +33,7 @@ export const WeirdosSection = ({
<div className="relative w-full h-12 flex justify-center">
<HorizontalTabBar
selectedItem={selectedGroup}
items={allGroupsWithCode.filter((d) =>
weirdCountries.includes(d.split('---')[0])
)}
items={weirdCountriesWithCode}
setSelectedItem={setSelectedGroup}
isActive={false}
hasGradient={false}
Expand Down Expand Up @@ -67,8 +64,10 @@ export const WeirdosSection = ({
</p>

{tabBar}
</div>

<div className="h-96 w-full">
<div className="wrapper">
<div className="w-full" style={{ height: 600 }}>
<ResponsivePopulationPyramid
data={selectedData}
highlightedYear={highlightedYear}
Expand Down

0 comments on commit 6cc59d1

Please sign in to comment.